diff --git a/src/main/java/org/studiorailgun/conversation/evaluators/query/QueryEval.java b/src/main/java/org/studiorailgun/conversation/evaluators/query/QueryEval.java index 772b9e4..f7dca05 100644 --- a/src/main/java/org/studiorailgun/conversation/evaluators/query/QueryEval.java +++ b/src/main/java/org/studiorailgun/conversation/evaluators/query/QueryEval.java @@ -85,8 +85,6 @@ public class QueryEval { throw new Error("Unhandled interrogative type! " + interrogativeStack.interrogative.toLowerCase()); } } - - System.out.println("Turn this into a query"); } } diff --git a/src/main/java/org/studiorailgun/conversation/parser/NLPParser.java b/src/main/java/org/studiorailgun/conversation/parser/NLPParser.java index 061d1c3..0bde67c 100644 --- a/src/main/java/org/studiorailgun/conversation/parser/NLPParser.java +++ b/src/main/java/org/studiorailgun/conversation/parser/NLPParser.java @@ -4,6 +4,7 @@ import edu.stanford.nlp.pipeline.*; import edu.stanford.nlp.semgraph.*; import java.util.*; +import org.studiorailgun.conversation.parser.depend.Clause; import org.studiorailgun.conversation.tracking.Quote; import org.studiorailgun.conversation.tracking.Sentence; @@ -51,6 +52,9 @@ public class NLPParser { Sentence sentence = new Sentence(coreSentence.text()); sentence.setGraph(graph); quote.addSentence(sentence); + + //parse the higher order relations out of the sentence + sentence.setMainClause(Clause.parse(graph)); } } } diff --git a/src/main/java/org/studiorailgun/conversation/parser/depend/Argument.java b/src/main/java/org/studiorailgun/conversation/parser/depend/Argument.java index 3865fd9..deeb9a1 100644 --- a/src/main/java/org/studiorailgun/conversation/parser/depend/Argument.java +++ b/src/main/java/org/studiorailgun/conversation/parser/depend/Argument.java @@ -7,6 +7,32 @@ import edu.stanford.nlp.ling.IndexedWord; */ public class Argument { + /** + * The type of a given argument + */ + public static enum ArgumentType { + + /** + * A noun or collection of words that functions as a noun + */ + NOMINAL, + + /** + * A subject of a dependent clause in a compound sentence + */ + COMPOUND_MODIFIER, + + /** + * A dependent clause that is functioning as an argument + */ + CLAUSAL_COMPLEMENT, + } + + /** + * The type of this argument + */ + ArgumentType type; + /** * The root of the argument */ @@ -16,7 +42,7 @@ public class Argument { * Constructor * @param root The root of the argument */ - public Argument(IndexedWord root){ + public Argument(IndexedWord root, ArgumentType type){ this.root = root; } diff --git a/src/main/java/org/studiorailgun/conversation/parser/depend/Clause.java b/src/main/java/org/studiorailgun/conversation/parser/depend/Clause.java index 4d03715..2e715ed 100644 --- a/src/main/java/org/studiorailgun/conversation/parser/depend/Clause.java +++ b/src/main/java/org/studiorailgun/conversation/parser/depend/Clause.java @@ -3,6 +3,8 @@ package org.studiorailgun.conversation.parser.depend; import java.util.LinkedList; import java.util.List; +import org.studiorailgun.conversation.parser.depend.Argument.ArgumentType; + import edu.stanford.nlp.ling.IndexedWord; import edu.stanford.nlp.semgraph.SemanticGraph; import edu.stanford.nlp.trees.GrammaticalRelation; @@ -78,7 +80,7 @@ public class Clause { //subjects case "nominal subject": { - Argument arg = new Argument(child); + Argument arg = new Argument(child, ArgumentType.NOMINAL); rVal.arguments.add(arg); rVal.subject = arg; } break; @@ -96,13 +98,13 @@ public class Clause { //direct objects case "direct object": { - Argument arg = new Argument(child); + Argument arg = new Argument(child, ArgumentType.NOMINAL); rVal.arguments.add(arg); } break; //indirect objects case "indirect object": { - Argument arg = new Argument(child); + Argument arg = new Argument(child, ArgumentType.NOMINAL); rVal.arguments.add(arg); } break; @@ -124,14 +126,14 @@ public class Clause { //A subject of a dependent clause in a compound sentence case "compound modifier":{ - Argument arg = new Argument(child); + Argument arg = new Argument(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); + Argument arg = new Argument(child, ArgumentType.CLAUSAL_COMPLEMENT); rVal.arguments.add(arg); } break; @@ -165,7 +167,7 @@ public class Clause { //this is a dependent clause that is functioning as an argument case "clausal complement": { - Argument arg = new Argument(child); + Argument arg = new Argument(child, ArgumentType.CLAUSAL_COMPLEMENT); rVal.arguments.add(arg); } break; diff --git a/src/main/java/org/studiorailgun/conversation/tracking/Sentence.java b/src/main/java/org/studiorailgun/conversation/tracking/Sentence.java index 7a1450d..37474fd 100644 --- a/src/main/java/org/studiorailgun/conversation/tracking/Sentence.java +++ b/src/main/java/org/studiorailgun/conversation/tracking/Sentence.java @@ -1,6 +1,7 @@ package org.studiorailgun.conversation.tracking; import org.studiorailgun.conversation.categorization.SentenceFunctionCategorizor.SentenceFunction; +import org.studiorailgun.conversation.parser.depend.Clause; import edu.stanford.nlp.semgraph.SemanticGraph; @@ -24,6 +25,11 @@ public class Sentence { */ SemanticGraph graph; + /** + * The main clause of the sentence + */ + Clause mainClause; + /** * The parent quote of this sentence */ @@ -69,4 +75,14 @@ public class Sentence { return parent; } + public Clause getMainClause() { + return mainClause; + } + + public void setMainClause(Clause mainClause) { + this.mainClause = mainClause; + } + + + } diff --git a/src/main/java/org/studiorailgun/knowledge/query/filter/PossessionQueryFilter.java b/src/main/java/org/studiorailgun/knowledge/query/filter/PossessionQueryFilter.java index 7914e16..0457592 100644 --- a/src/main/java/org/studiorailgun/knowledge/query/filter/PossessionQueryFilter.java +++ b/src/main/java/org/studiorailgun/knowledge/query/filter/PossessionQueryFilter.java @@ -20,7 +20,7 @@ public class PossessionQueryFilter { return possessions.contains(node); }).collect(Collectors.toList()); if(filtered.size() != 1){ - throw new UnsupportedOperationException("TODO: handle ambiguous case"); + throw new UnsupportedOperationException("TODO: handle ambiguous case " + filtered.size()); } return filtered.get(0); }