argument modifier parsing + clause fix
All checks were successful
studiorailgun/trpg/pipeline/head This commit looks good
All checks were successful
studiorailgun/trpg/pipeline/head This commit looks good
This commit is contained in:
parent
f66f1d6816
commit
4e844b85bf
@ -1,7 +1,6 @@
|
||||
package org.studiorailgun.conversation.evaluators;
|
||||
|
||||
import org.studiorailgun.Globals;
|
||||
import org.studiorailgun.conversation.categorization.SentenceFunctionCategorizor;
|
||||
import org.studiorailgun.conversation.evaluators.goal.GoalEval;
|
||||
import org.studiorailgun.conversation.evaluators.greet.GreetingEval;
|
||||
import org.studiorailgun.conversation.evaluators.query.QueryEval;
|
||||
@ -31,11 +30,6 @@ public class EvaluationTree {
|
||||
//perform NLP evaluation of the quote
|
||||
NLPParser.parse(quote);
|
||||
|
||||
//parse data about the quote
|
||||
for(Sentence sentence : quote.getSentences()){
|
||||
SentenceFunctionCategorizor.categorize(sentence);
|
||||
}
|
||||
|
||||
//add the quote to the conversation
|
||||
conversation.addQuote(quote);
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import edu.stanford.nlp.pipeline.*;
|
||||
import edu.stanford.nlp.semgraph.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.studiorailgun.conversation.categorization.SentenceFunctionCategorizor;
|
||||
import org.studiorailgun.conversation.parser.depend.Clause;
|
||||
import org.studiorailgun.conversation.tracking.Quote;
|
||||
import org.studiorailgun.conversation.tracking.Sentence;
|
||||
@ -57,6 +58,11 @@ public class NLPParser {
|
||||
sentence.setMainClause(Clause.parse(graph));
|
||||
}
|
||||
}
|
||||
|
||||
//parse data about the quote
|
||||
for(Sentence sentence : quote.getSentences()){
|
||||
SentenceFunctionCategorizor.categorize(sentence);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
package org.studiorailgun.conversation.parser.depend;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import edu.stanford.nlp.ling.IndexedWord;
|
||||
import edu.stanford.nlp.semgraph.SemanticGraph;
|
||||
import edu.stanford.nlp.trees.GrammaticalRelation;
|
||||
|
||||
/**
|
||||
* A linguistic argument
|
||||
@ -38,11 +42,36 @@ public class Argument {
|
||||
*/
|
||||
IndexedWord root;
|
||||
|
||||
/**
|
||||
* The possessive modifier being applied to the argument
|
||||
*/
|
||||
IndexedWord possessiveModifier;
|
||||
|
||||
/**
|
||||
* The determiner for the argument
|
||||
*/
|
||||
IndexedWord determiner;
|
||||
|
||||
/**
|
||||
* The preposition being applied to this argument
|
||||
*/
|
||||
IndexedWord preposition;
|
||||
|
||||
/**
|
||||
* The adjective modifying this argument
|
||||
*/
|
||||
IndexedWord adjective;
|
||||
|
||||
/**
|
||||
* The adverb modifying this argument
|
||||
*/
|
||||
IndexedWord adverb;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param root The root of the argument
|
||||
*/
|
||||
public Argument(IndexedWord root, ArgumentType type){
|
||||
private Argument(IndexedWord root, ArgumentType type){
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
@ -54,4 +83,61 @@ public class Argument {
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an argument
|
||||
* @param graph The graph
|
||||
* @param root The root of the argument
|
||||
* @param type The type of the argument
|
||||
* @return The parsed argument
|
||||
*/
|
||||
public static Argument parse(SemanticGraph graph, IndexedWord root, ArgumentType type){
|
||||
Argument rVal = new Argument(root, type);
|
||||
List<IndexedWord> children = graph.getChildList(root);
|
||||
//parse all arguments
|
||||
for(IndexedWord child : children){
|
||||
GrammaticalRelation relation = graph.reln(root, child);
|
||||
switch(relation.getLongName()){
|
||||
|
||||
//possessive modifier
|
||||
case "possession modifier": {
|
||||
rVal.possessiveModifier = child;
|
||||
} break;
|
||||
|
||||
//determiner
|
||||
case "determiner": {
|
||||
rVal.determiner = child;
|
||||
} break;
|
||||
|
||||
//preposition
|
||||
case "nmod_preposition": {
|
||||
rVal.preposition = child;
|
||||
} break;
|
||||
|
||||
//adjective
|
||||
case "adjectival modifier": {
|
||||
rVal.adjective = child;
|
||||
} break;
|
||||
|
||||
//adverb
|
||||
case "adverbial modifier": {
|
||||
rVal.adverb = child;
|
||||
} break;
|
||||
|
||||
//unhandled cases
|
||||
default: {
|
||||
throw new Error("Unsupported relation type! " + relation.getLongName() + "\n" + "for " + child.originalText() + "\n" + graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the possessive modifier of this argument
|
||||
* @return The possessive modifier
|
||||
*/
|
||||
public IndexedWord getPossessiveModifier(){
|
||||
return possessiveModifier;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,6 +38,11 @@ public class Clause {
|
||||
* A paratactic clause
|
||||
*/
|
||||
PARATACTIC,
|
||||
|
||||
/**
|
||||
* A complemental clause
|
||||
*/
|
||||
COMPLEMENT,
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,7 +122,7 @@ public class Clause {
|
||||
|
||||
//subjects
|
||||
case "nominal subject": {
|
||||
Argument arg = new Argument(child, ArgumentType.NOMINAL);
|
||||
Argument arg = Argument.parse(graph, child, ArgumentType.NOMINAL);
|
||||
rVal.arguments.add(arg);
|
||||
rVal.subject = arg;
|
||||
} break;
|
||||
@ -136,14 +141,14 @@ public class Clause {
|
||||
|
||||
//direct objects
|
||||
case "direct object": {
|
||||
Argument arg = new Argument(child, ArgumentType.NOMINAL);
|
||||
Argument arg = Argument.parse(graph, child, ArgumentType.NOMINAL);
|
||||
rVal.arguments.add(arg);
|
||||
rVal.directObject = arg;
|
||||
} break;
|
||||
|
||||
//indirect objects
|
||||
case "indirect object": {
|
||||
Argument arg = new Argument(child, ArgumentType.NOMINAL);
|
||||
Argument arg = Argument.parse(graph, child, ArgumentType.NOMINAL);
|
||||
rVal.arguments.add(arg);
|
||||
} break;
|
||||
|
||||
@ -165,14 +170,14 @@ public class Clause {
|
||||
|
||||
//A subject of a dependent clause in a compound sentence
|
||||
case "compound modifier":{
|
||||
Argument arg = new Argument(child, ArgumentType.COMPOUND_MODIFIER);
|
||||
Argument arg = Argument.parse(graph, child, ArgumentType.COMPOUND_MODIFIER);
|
||||
rVal.arguments.add(arg);
|
||||
rVal.subject = arg;
|
||||
} break;
|
||||
|
||||
//An argument of a verb or adjective
|
||||
case "xclausal complement": {
|
||||
Argument arg = new Argument(child, ArgumentType.CLAUSAL_COMPLEMENT);
|
||||
Argument arg = Argument.parse(graph, child, ArgumentType.CLAUSAL_COMPLEMENT);
|
||||
rVal.arguments.add(arg);
|
||||
} break;
|
||||
|
||||
@ -206,8 +211,8 @@ public class Clause {
|
||||
|
||||
//this is a dependent clause that is functioning as an argument
|
||||
case "clausal complement": {
|
||||
Argument arg = new Argument(child, ArgumentType.CLAUSAL_COMPLEMENT);
|
||||
rVal.arguments.add(arg);
|
||||
Clause clause = Clause.parse(graph, child, ClauseType.COMPLEMENT);
|
||||
rVal.clauses.add(clause);
|
||||
} break;
|
||||
|
||||
/**
|
||||
|
||||
@ -25,8 +25,8 @@ public class ComplexClauseTests {
|
||||
|
||||
//test number of returns
|
||||
assertNotNull(struct.getPredicate());
|
||||
assertEquals(struct.getArguments().size(),2);
|
||||
assertEquals(struct.getClauses().size(), 1);
|
||||
assertEquals(struct.getArguments().size(),1);
|
||||
assertEquals(struct.getClauses().size(), 2);
|
||||
|
||||
//test returned data
|
||||
assertEquals(struct.getPredicate().getRoot().originalText(), "lowered"); //should be copular verb
|
||||
|
||||
31
src/test/java/org/studiorailgun/TransferParsingTests.java
Normal file
31
src/test/java/org/studiorailgun/TransferParsingTests.java
Normal file
@ -0,0 +1,31 @@
|
||||
package org.studiorailgun;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.studiorailgun.conversation.parser.NLPParser;
|
||||
import org.studiorailgun.conversation.parser.depend.Clause;
|
||||
import org.studiorailgun.conversation.tracking.Quote;
|
||||
import org.studiorailgun.conversation.tracking.Sentence;
|
||||
|
||||
/**
|
||||
* Transfer statement parsing tests
|
||||
*/
|
||||
public class TransferParsingTests {
|
||||
|
||||
@Test
|
||||
public void testParse1(){
|
||||
Globals.init("./data/webs/test/web.json");
|
||||
Quote input = new Quote("My name is John.");
|
||||
NLPParser.parse(input);
|
||||
Sentence sentence = input.getSentences().get(0);
|
||||
Clause mainClause = sentence.getMainClause();
|
||||
|
||||
//has a copular verb
|
||||
assertEquals(mainClause.getPredicate().getRoot().originalText(),"John");
|
||||
assertEquals(mainClause.getPredicate().getCopular().originalText(),"is");
|
||||
assertEquals(mainClause.getSubject().getRoot().originalText(), "name");
|
||||
assertEquals(mainClause.getSubject().getPossessiveModifier().originalText(), "My");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user