add nlp parser
All checks were successful
studiorailgun/trpg/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-29 15:52:43 -05:00
parent 19c32468df
commit 2fb22d70fe
7 changed files with 83 additions and 3 deletions

1
.vscode/launch.json vendored
View File

@ -8,6 +8,7 @@
"type": "java",
"name": "Launch Java Program",
"request": "launch",
"vmArgs": "-Xmx4G -Xms1024m",
"mainClass": ""
},
{

23
pom.xml
View File

@ -12,6 +12,7 @@
<dl4j-master.version>1.0.0-M2</dl4j-master.version>
<!-- Change the nd4j.backend property to nd4j-cuda-X-platform to use CUDA GPUs -->
<nd4j.backend>nd4j-native</nd4j.backend>
<corenlp.version>4.5.6</corenlp.version>
</properties>
<dependencies>
@ -46,6 +47,28 @@
</dependency>
<!--Stanford CoreNLP-->
<!--License: GPL-->
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>${corenlp.version}</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>${corenlp.version}</version>
<classifier>models</classifier>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>${corenlp.version}</version>
<classifier>models-english</classifier>
</dependency>
<!--GSON-->
<dependency>

View File

@ -4,6 +4,7 @@ import java.io.File;
import org.studiorailgun.conversation.categorization.SentenceFunctionCategorizor;
import org.studiorailgun.conversation.evaluators.greet.GreetingEval;
import org.studiorailgun.conversation.parser.NLPParser;
import org.studiorailgun.conversation.tracking.Conversation;
import org.studiorailgun.knowledge.KnowledgeWeb;
@ -30,6 +31,9 @@ public class Globals {
GreetingEval.init();
SentenceFunctionCategorizor.init();
//init nlp parser
NLPParser.init();
//init web
Globals.web = FileUtils.loadObjectFromFile(new File(webPath), KnowledgeWeb.class);
Globals.web.initLinks();

View File

@ -3,7 +3,7 @@ package org.studiorailgun.conversation;
import java.util.Scanner;
import org.studiorailgun.Globals;
import org.studiorailgun.conversation.parser.CommandParser;
import org.studiorailgun.conversation.command.CommandParser;
import org.studiorailgun.conversation.tracking.Quote;
public class AgentLoop {

View File

@ -1,4 +1,4 @@
package org.studiorailgun.conversation.parser;
package org.studiorailgun.conversation.command;
import org.studiorailgun.conversation.AgentLoop;
import org.studiorailgun.conversation.llm.LLMLoop;

View File

@ -2,7 +2,7 @@ package org.studiorailgun.conversation.llm;
import java.util.Scanner;
import org.studiorailgun.conversation.parser.CommandParser;
import org.studiorailgun.conversation.command.CommandParser;
import org.studiorailgun.kobold.KoboldPrinter;
import org.studiorailgun.kobold.KoboldRequest;

View File

@ -0,0 +1,52 @@
package org.studiorailgun.conversation.parser;
import edu.stanford.nlp.coref.data.CorefChain;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.ie.util.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.semgraph.*;
import edu.stanford.nlp.trees.*;
import java.util.*;
/**
* Parses a sentence
*/
public class NLPParser {
public static String text = "Joe Smith was born in California. " +
"In 2017, he went to Paris, France in the summer. " +
"His flight left at 3:00pm on July 10th, 2017. " +
"After eating some escargot for the first time, Joe said, \"That was delicious!\" " +
"He sent a postcard to his sister Jane Smith. " +
"After hearing about Joe's trip, Jane decided she might go to France one day.";
static StanfordCoreNLP pipeline;
/**
* Initializes the part-of-speech Parser
*/
public static void init(){
// set up pipeline properties
Properties props = new Properties();
// set the list of annotators to run
props.setProperty("annotators", "tokenize,pos,lemma,ner,parse,depparse,coref,kbp,quote");
// set a property for an annotator, in this case the coref annotator is being set to use the neural algorithm
props.setProperty("coref.algorithm", "neural");
// build pipeline
pipeline = new StanfordCoreNLP(props);
}
/**
* Parses the input sentence
* @param input The input sentence
*/
public static void parse(String input){
// create a document object
CoreDocument document = new CoreDocument(text);
// annnotate the document
pipeline.annotate(document);
//TODO: grab information from document here
}
}