add dependency parsing into main syntax parser
All checks were successful
studiorailgun/trpg/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-30 21:26:09 -05:00
parent 7ccf5cd821
commit bdcf63c421
6 changed files with 56 additions and 10 deletions

View File

@ -85,8 +85,6 @@ public class QueryEval {
throw new Error("Unhandled interrogative type! " + interrogativeStack.interrogative.toLowerCase()); throw new Error("Unhandled interrogative type! " + interrogativeStack.interrogative.toLowerCase());
} }
} }
System.out.println("Turn this into a query");
} }
} }

View File

@ -4,6 +4,7 @@ import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.semgraph.*; import edu.stanford.nlp.semgraph.*;
import java.util.*; import java.util.*;
import org.studiorailgun.conversation.parser.depend.Clause;
import org.studiorailgun.conversation.tracking.Quote; import org.studiorailgun.conversation.tracking.Quote;
import org.studiorailgun.conversation.tracking.Sentence; import org.studiorailgun.conversation.tracking.Sentence;
@ -51,6 +52,9 @@ public class NLPParser {
Sentence sentence = new Sentence(coreSentence.text()); Sentence sentence = new Sentence(coreSentence.text());
sentence.setGraph(graph); sentence.setGraph(graph);
quote.addSentence(sentence); quote.addSentence(sentence);
//parse the higher order relations out of the sentence
sentence.setMainClause(Clause.parse(graph));
} }
} }
} }

View File

@ -7,6 +7,32 @@ import edu.stanford.nlp.ling.IndexedWord;
*/ */
public class Argument { 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 * The root of the argument
*/ */
@ -16,7 +42,7 @@ public class Argument {
* Constructor * Constructor
* @param root The root of the argument * @param root The root of the argument
*/ */
public Argument(IndexedWord root){ public Argument(IndexedWord root, ArgumentType type){
this.root = root; this.root = root;
} }

View File

@ -3,6 +3,8 @@ package org.studiorailgun.conversation.parser.depend;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.studiorailgun.conversation.parser.depend.Argument.ArgumentType;
import edu.stanford.nlp.ling.IndexedWord; import edu.stanford.nlp.ling.IndexedWord;
import edu.stanford.nlp.semgraph.SemanticGraph; import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.trees.GrammaticalRelation; import edu.stanford.nlp.trees.GrammaticalRelation;
@ -78,7 +80,7 @@ public class Clause {
//subjects //subjects
case "nominal subject": { case "nominal subject": {
Argument arg = new Argument(child); Argument arg = new Argument(child, ArgumentType.NOMINAL);
rVal.arguments.add(arg); rVal.arguments.add(arg);
rVal.subject = arg; rVal.subject = arg;
} break; } break;
@ -96,13 +98,13 @@ public class Clause {
//direct objects //direct objects
case "direct object": { case "direct object": {
Argument arg = new Argument(child); Argument arg = new Argument(child, ArgumentType.NOMINAL);
rVal.arguments.add(arg); rVal.arguments.add(arg);
} break; } break;
//indirect objects //indirect objects
case "indirect object": { case "indirect object": {
Argument arg = new Argument(child); Argument arg = new Argument(child, ArgumentType.NOMINAL);
rVal.arguments.add(arg); rVal.arguments.add(arg);
} break; } break;
@ -124,14 +126,14 @@ public class Clause {
//A subject of a dependent clause in a compound sentence //A subject of a dependent clause in a compound sentence
case "compound modifier":{ case "compound modifier":{
Argument arg = new Argument(child); Argument arg = new Argument(child, ArgumentType.COMPOUND_MODIFIER);
rVal.arguments.add(arg); rVal.arguments.add(arg);
rVal.subject = arg; rVal.subject = arg;
} break; } break;
//An argument of a verb or adjective //An argument of a verb or adjective
case "xclausal complement": { case "xclausal complement": {
Argument arg = new Argument(child); Argument arg = new Argument(child, ArgumentType.CLAUSAL_COMPLEMENT);
rVal.arguments.add(arg); rVal.arguments.add(arg);
} break; } break;
@ -165,7 +167,7 @@ public class Clause {
//this is a dependent clause that is functioning as an argument //this is a dependent clause that is functioning as an argument
case "clausal complement": { case "clausal complement": {
Argument arg = new Argument(child); Argument arg = new Argument(child, ArgumentType.CLAUSAL_COMPLEMENT);
rVal.arguments.add(arg); rVal.arguments.add(arg);
} break; } break;

View File

@ -1,6 +1,7 @@
package org.studiorailgun.conversation.tracking; package org.studiorailgun.conversation.tracking;
import org.studiorailgun.conversation.categorization.SentenceFunctionCategorizor.SentenceFunction; import org.studiorailgun.conversation.categorization.SentenceFunctionCategorizor.SentenceFunction;
import org.studiorailgun.conversation.parser.depend.Clause;
import edu.stanford.nlp.semgraph.SemanticGraph; import edu.stanford.nlp.semgraph.SemanticGraph;
@ -24,6 +25,11 @@ public class Sentence {
*/ */
SemanticGraph graph; SemanticGraph graph;
/**
* The main clause of the sentence
*/
Clause mainClause;
/** /**
* The parent quote of this sentence * The parent quote of this sentence
*/ */
@ -69,4 +75,14 @@ public class Sentence {
return parent; return parent;
} }
public Clause getMainClause() {
return mainClause;
}
public void setMainClause(Clause mainClause) {
this.mainClause = mainClause;
}
} }

View File

@ -20,7 +20,7 @@ public class PossessionQueryFilter {
return possessions.contains(node); return possessions.contains(node);
}).collect(Collectors.toList()); }).collect(Collectors.toList());
if(filtered.size() != 1){ if(filtered.size() != 1){
throw new UnsupportedOperationException("TODO: handle ambiguous case"); throw new UnsupportedOperationException("TODO: handle ambiguous case " + filtered.size());
} }
return filtered.get(0); return filtered.get(0);
} }