From 9ff39934c5aba79fa28128275300bc4d224cc307 Mon Sep 17 00:00:00 2001 From: austin Date: Mon, 30 Dec 2024 22:18:18 -0500 Subject: [PATCH] query evaluation work --- data/dictionary/verbs.csv | 11 ++++- .../evaluators/query/QueryEval.java | 42 +++++++++++-------- .../conversation/parser/bank/Lemma.java | 17 ++++++++ .../conversation/parser/depend/Predicate.java | 8 ++++ 4 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/studiorailgun/conversation/parser/bank/Lemma.java diff --git a/data/dictionary/verbs.csv b/data/dictionary/verbs.csv index b15f834..10accc8 100644 --- a/data/dictionary/verbs.csv +++ b/data/dictionary/verbs.csv @@ -1,2 +1,9 @@ -word,lemma,valence,tense,mood,aspect -be,be,2,?,?,? +word,lemma +be,be +am,be +is,be +are,be +was,be +were,be +being,be +been,be \ No newline at end of file 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 f7dca05..c3a264c 100644 --- a/src/main/java/org/studiorailgun/conversation/evaluators/query/QueryEval.java +++ b/src/main/java/org/studiorailgun/conversation/evaluators/query/QueryEval.java @@ -3,7 +3,8 @@ package org.studiorailgun.conversation.evaluators.query; import java.util.Iterator; import java.util.Set; -import org.studiorailgun.conversation.parser.PennTreebankTagSet; +import org.studiorailgun.conversation.parser.depend.Clause; +import org.studiorailgun.conversation.parser.depend.Predicate; import org.studiorailgun.conversation.tracking.Conversation; import org.studiorailgun.conversation.tracking.Quote; import org.studiorailgun.conversation.tracking.Sentence; @@ -23,30 +24,35 @@ public class QueryEval { */ public static void evaluate(Conversation conversation, Quote quote, Sentence sentence){ SemanticGraph semanticGraph = sentence.getGraph(); - if(semanticGraph.getRoots().size() > 1){ - String message = "Multiple roots to sentence!\n" + - "\"" + quote.getRaw() + "\"\n" + - semanticGraph; - throw new UnsupportedOperationException(message); - } - IndexedWord root = semanticGraph.getFirstRoot(); - if(PennTreebankTagSet.isVerb(root.tag())){ - if(PennTreebankTagSet.isBe(root.tag())){ - QueryEval.evaluateBe(conversation, quote, sentence); - } else { - String message = "Unsupported root verb type!\n" + - "\"" + sentence.getRaw() + "\"\n" + - semanticGraph; - throw new UnsupportedOperationException(message); - } + Clause mainClause = sentence.getMainClause(); + Predicate predicate = mainClause.getPredicate(); + + + if(predicate.getCopular() != null){ + QueryEval.evaluateCopular(conversation,quote,sentence); } else { - String message = "Unsupported root type!\n" + + String message = "Unsupported predicate type!\n" + "\"" + sentence.getRaw() + "\"\n" + semanticGraph; throw new UnsupportedOperationException(message); } } + /** + * Evaluates a copular sentence + * @param conversation The conversation + * @param quote The quote + * @param sentence The sentence + */ + private static void evaluateCopular(Conversation conversation, Quote quote, Sentence sentence){ + SemanticGraph semanticGraph = sentence.getGraph(); + Clause mainClause = sentence.getMainClause(); + Predicate predicate = mainClause.getPredicate(); + IndexedWord copular = predicate.getCopular(); + //todo, different logic based on type of copular verb + QueryEval.evaluateBe(conversation, quote, sentence); + } + /** * Evaluates an equivalence query * @param conversation The conversation diff --git a/src/main/java/org/studiorailgun/conversation/parser/bank/Lemma.java b/src/main/java/org/studiorailgun/conversation/parser/bank/Lemma.java new file mode 100644 index 0000000..fcd400c --- /dev/null +++ b/src/main/java/org/studiorailgun/conversation/parser/bank/Lemma.java @@ -0,0 +1,17 @@ +package org.studiorailgun.conversation.parser.bank; + +/** + * A lemma lookup bank + */ +public class Lemma { + + /** + * Gets the lemma of a word + * @param word The word + * @return The lemma of the word + */ + public static String getLemma(String word){ + return "be"; + } + +} diff --git a/src/main/java/org/studiorailgun/conversation/parser/depend/Predicate.java b/src/main/java/org/studiorailgun/conversation/parser/depend/Predicate.java index ec00e06..9500aca 100644 --- a/src/main/java/org/studiorailgun/conversation/parser/depend/Predicate.java +++ b/src/main/java/org/studiorailgun/conversation/parser/depend/Predicate.java @@ -127,6 +127,14 @@ public class Predicate { this.copularVerb = copularWord; } + /** + * Gets the copular verb + * @return The copular verb if it exists, null otherwise + */ + public IndexedWord getCopular(){ + return this.copularVerb; + } + /** * Sets the existential status of the predicate * @param existential true if existential, false otherwise