Skip to content

Commit

Permalink
Adding possibility to use dep tree to find associated verbs
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCousyn committed Nov 23, 2020
1 parent d5f133c commit cd408a1
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 306 deletions.
1 change: 1 addition & 0 deletions configFiles/generalConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"minSupportNode": 0.25,
"minConfidenceRelation": 0.5,
"useVerb": true,
"useDepTreeToFindAssociatedVerb": true,
"useSpecificStruct": true
}
93 changes: 42 additions & 51 deletions getRawGraphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,49 @@ async function getAssociatedVerbs(tokInfoObjects, processedSentences)
return await from(tokInfoObjects)
.pipe(concatMap(async tokInfoObject =>
{
let nearestVerb = await from(processedSentences[tokInfoObject.indexSentence])
.pipe(filter(tokInfo => tokInfo.POS.startsWith("VB")))
.pipe(reduce((goodTokInfoVerb, tokInfoVerb) =>
//Search the nearest verb in the dependency parse tree
let nearestVerb = null;
if(GENERAL_CONFIG.useDepTreeToFindAssociatedVerb)
{
let sentence = processedSentences[tokInfoObject.indexSentence];
let rootNode = tokInfoObject.depParsed.parent === -1;
let currTok = sentence[tokInfoObject.depParsed.parent] ;
while(nearestVerb === null && !rootNode)
{
if(goodTokInfoVerb === null || (Math.abs(tokInfoObject.indexToken - tokInfoVerb.indexToken) < Math.abs(tokInfoObject.indexToken - goodTokInfoVerb.indexToken)))
if(currTok.depParsed.type === "VP" || currTok.depParsed.type.startsWith("VB"))
{
nearestVerb = currTok;
nearestVerb = {...nearestVerb, definitions: await wordpos.lookupVerb(nearestVerb.pureForm)};
}
else
{
goodTokInfoVerb = tokInfoVerb;
if(currTok.depParsed.parent === -1)
{
rootNode = true;
}
else
{
currTok = sentence[currTok.depParsed.parent];
}
}
return goodTokInfoVerb;
}, null))
.pipe(filter(goodTokInfoVerb => goodTokInfoVerb !== null))
.pipe(concatMap(async verbTokInfo => ({...verbTokInfo, definitions: await wordpos.lookupVerb(verbTokInfo.pureForm)})))
.toPromise();
}
}
else
{
nearestVerb = await from(processedSentences[tokInfoObject.indexSentence])
.pipe(filter(tokInfo => tokInfo.POS.startsWith("VB")))
.pipe(reduce((goodTokInfoVerb, tokInfoVerb) =>
{
if(goodTokInfoVerb === null || (Math.abs(tokInfoObject.indexToken - tokInfoVerb.indexToken) < Math.abs(tokInfoObject.indexToken - goodTokInfoVerb.indexToken)))
{
goodTokInfoVerb = tokInfoVerb;
}
return goodTokInfoVerb;
}, null))
.pipe(filter(goodTokInfoVerb => goodTokInfoVerb !== null))
.pipe(concatMap(async verbTokInfo => ({...verbTokInfo, definitions: await wordpos.lookupVerb(verbTokInfo.pureForm)})))
.toPromise();
}

//If no verb in sentence or the nearest verb has no definition in wordnet
if(nearestVerb === undefined || nearestVerb === null || nearestVerb.definitions.length === 0)
Expand All @@ -104,45 +134,6 @@ async function getAssociatedVerbs(tokInfoObjects, processedSentences)
.pipe(filter(arr => arr !== null))
.pipe(toArray())
.toPromise();

/*let objVerbArrays = await Promise.all(
tokInfoObjects.map(async tokInfoObject =>
{
let currentSentence = processedSentences[tokInfoObject.indexSentence];
//Identify verbs in current sentence
let promiseVerbs = currentSentence.filter(tokInfo => tokInfo.POS.startsWith("VB"))
.map(async verbTokInfo => ({...verbTokInfo, definitions: await wordpos.lookupVerb(verbTokInfo.pureForm)}));
let verbs = await Promise.all(promiseVerbs);
//If no verb in sentence
if(verbs.length === 0)
{
return null;
}
//Find the nearest verb
let nearestVerb = verbs.reduce((goodTokInfoVerb, tokInfoVerb, index, array) =>
{
if(goodTokInfoVerb === null || (Math.abs(tokInfoObject.indexToken - tokInfoVerb.indexToken) < Math.abs(tokInfoObject.indexToken - goodTokInfoVerb.indexToken)))
{
goodTokInfoVerb = tokInfoVerb;
}
return goodTokInfoVerb;
}, null);
//If the nearest verb has no definition in wordnet
if(nearestVerb.definitions.length === 0)
{
return null;
}
return [nearestVerb, tokInfoObject];
}));
//Removing null values (token without associated verbs)
return objVerbArrays.filter(arr => arr !== null);*/
}

async function getOrderedObjectsFromTextFin(cleanText, useOfPredeterminedObjects, predeterminedObjectsOneActivty, useVerb)
Expand Down Expand Up @@ -213,9 +204,9 @@ async function getOrderedObjectsFromTextFin(cleanText, useOfPredeterminedObjects
let tokInfosWithVerbs = await getAssociatedVerbs(validTokensInfos, processedSentences);

//Only keep the pure form of the token to avoid synonyms abundance
let validTokens = tokInfosWithVerbs.map(tokInfoWithVerbs =>
let validTokens = tokInfosWithVerbs.map(([nearestVerb, tokInfoObject]) =>
{
return `${tokInfoWithVerbs[0].definitions[0].lemma}||${tokInfoWithVerbs[1].definitions[0].lemma}`
return `${nearestVerb.definitions[0].lemma}||${tokInfoObject.definitions[0].lemma}`;
});

//Delete duplicates (keep the first only)
Expand Down
42 changes: 23 additions & 19 deletions output/processedActivityResults.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
1
],
[
"be||meat",
"make||meat",
1
]
]
Expand All @@ -52,7 +52,7 @@
1
],
[
"be||meat",
"make||meat",
1
]
]
Expand All @@ -64,14 +64,14 @@
0.5,
[
[
"be||meat",
"make||meat",
1
]
]
]
],
[
"be||meat",
"make||meat",
[
0.5,
[]
Expand Down Expand Up @@ -103,7 +103,7 @@
1
],
[
"reduce||heating_system",
"continue||heating_system",
1
],
[
Expand Down Expand Up @@ -139,7 +139,7 @@
1
],
[
"reduce||heating_system",
"continue||heating_system",
1
],
[
Expand Down Expand Up @@ -171,7 +171,7 @@
1
],
[
"reduce||heating_system",
"continue||heating_system",
1
],
[
Expand Down Expand Up @@ -199,7 +199,7 @@
1
],
[
"reduce||heating_system",
"continue||heating_system",
1
],
[
Expand All @@ -223,7 +223,7 @@
1
],
[
"reduce||heating_system",
"continue||heating_system",
1
],
[
Expand All @@ -243,7 +243,7 @@
0.5,
[
[
"reduce||heating_system",
"continue||heating_system",
1
],
[
Expand All @@ -258,7 +258,7 @@
]
],
[
"reduce||heating_system",
"continue||heating_system",
[
0.5,
[
Expand Down Expand Up @@ -339,7 +339,7 @@
1
],
[
"keep||kitchen",
"clean||kitchen",
1
],
[
Expand Down Expand Up @@ -367,7 +367,7 @@
1
],
[
"keep||kitchen",
"clean||kitchen",
1
],
[
Expand All @@ -391,7 +391,7 @@
1
],
[
"keep||kitchen",
"clean||kitchen",
1
],
[
Expand All @@ -411,7 +411,7 @@
0.5,
[
[
"keep||kitchen",
"clean||kitchen",
1
],
[
Expand All @@ -426,7 +426,7 @@
]
],
[
"keep||kitchen",
"clean||kitchen",
[
0.5,
[
Expand Down Expand Up @@ -757,7 +757,7 @@
],
[
"stir||pasta",
0.5
0.75
]
]
]
Expand All @@ -781,7 +781,7 @@
],
[
"stir||pasta",
0.6666666666666666
1
]
]
]
Expand All @@ -802,6 +802,10 @@
[
"use||sauce",
0.75
],
[
"stir||pasta",
0.5
]
]
]
Expand Down Expand Up @@ -844,7 +848,7 @@
[
"stir||pasta",
[
0.3,
0.4,
[]
]
],
Expand Down
Loading

0 comments on commit cd408a1

Please sign in to comment.