small work on assignment transfer
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
c298dddb7c
commit
28488da1a5
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
17
src/test/java/org/studiorailgun/AssignmentTransferTests.java
Normal file
17
src/test/java/org/studiorailgun/AssignmentTransferTests.java
Normal 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.");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user