small work on assignment transfer
All checks were successful
studiorailgun/trpg/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-30 17:25:56 -05:00
parent c298dddb7c
commit 28488da1a5
6 changed files with 81 additions and 5 deletions

View File

@ -7,8 +7,6 @@ sitting in a tavern by a fireplace
Comprehend the sentence "My name is ${name}"
- Figure out that we're assigning a value
- Figure out what values we're assigning
- Transfer statement eval

View File

@ -1,11 +1,14 @@
package org.studiorailgun.conversation.evaluators.transfer;
import org.studiorailgun.Globals;
import org.studiorailgun.conversation.evaluators.query.NounStack;
import org.studiorailgun.conversation.parser.NLPDependencies;
import org.studiorailgun.conversation.parser.PennTreebankTagSet;
import org.studiorailgun.conversation.tracking.Conversation;
import org.studiorailgun.conversation.tracking.Quote;
import org.studiorailgun.conversation.tracking.Sentence;
import org.studiorailgun.knowledge.KnowledgeWeb;
import org.studiorailgun.knowledge.query.NodePropQuery;
import edu.stanford.nlp.ling.IndexedWord;
import edu.stanford.nlp.semgraph.SemanticGraph;
@ -71,7 +74,7 @@ public class TransferEval {
SemanticGraph graph = sentence.getGraph();
IndexedWord verb = NLPDependencies.getCopular(graph);
if(PennTreebankTagSet.isBe(verb.tag())){
TransferEval.evaluateEquivalenceStatement(conversation, quote, sentence, noun1, noun2);
TransferEval.evaluateAssignmentStatement(conversation, quote, sentence, noun1, noun2);
} else {
throw new Error("Unsupported verb type! " + graph);
}
@ -83,8 +86,14 @@ public class TransferEval {
* @param quote The quote
* @param sentence The sentence
*/
private static void evaluateEquivalenceStatement(Conversation conversation, Quote quote, Sentence sentence, NounStack noun1, NounStack noun2){
throw new UnsupportedOperationException("Need to actually perform the equivalence transforms in the knowledge web!");
private static void evaluateAssignmentStatement(Conversation conversation, Quote quote, Sentence sentence, NounStack noun1, NounStack noun2){
//if there is no node with this name already, create one
System.out.println(sentence.getGraph());
String noun1RootText = noun1.getIndexedWord().originalText();
if(NodePropQuery.byName(noun1RootText).size() < 1){
Globals.web.createNode(noun1RootText);
}
}
/**

View File

@ -79,4 +79,21 @@ public class PennTreebankTagSet {
}
}
/**
* Checks if this tag is a proper noun or not
* @param tag The tag
* @return true if it is a proper noun, false otherwise
*/
public static boolean isProperNoun(String tag){
switch(tag){
case "NP":
case "NPS": {
return true;
}
default: {
return false;
}
}
}
}

View File

@ -335,4 +335,15 @@ public class KnowledgeWeb {
return anchors;
}
/**
* Creates a new node
* @param name The name of the node
* @return The node
*/
public Node createNode(String name){
Node node = new Node(name);
this.nodes.put(node.getId(), node);
return node;
}
}

View File

@ -0,0 +1,24 @@
package org.studiorailgun.knowledge.query;
import java.util.List;
import java.util.stream.Collectors;
import org.studiorailgun.Globals;
import org.studiorailgun.knowledge.Node;
/**
* Get a node by a property of the node
*/
public class NodePropQuery {
/**
* Gets all nodes in the web with a given name
* @param name The name of the node
* @return The list of nodes in the web that have that name
*/
public static List<Node> byName(String name){
return Globals.web.getNodes().stream().filter(node -> node.getName().equals(name)).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,17 @@
package org.studiorailgun;
import org.junit.Test;
import org.studiorailgun.conversation.ConvAI;
/**
* Test assigning values via transfer statements
*/
public class AssignmentTransferTests {
@Test
public void testTransferName(){
// Globals.init("./data/webs/test/web.json");
// ConvAI.simFrame("My name is John.");
}
}