Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 931b4fd

Browse files
committed
added test for training model
1 parent 6e6ce19 commit 931b4fd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/java/com/graphaware/nlp/processor/opennlp/OpenNLPPipeline.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ else if (alg.toLowerCase().equals("sentiment")) {
365365
sentModel.train();
366366
result = sentModel.validate();
367367
String[] dirPathSplit = fileTrain.split(File.separator);
368-
String fileOutToUse = null;
368+
String fileOutToUse;
369369
if (dirPathSplit.length > 2) {
370370
StringBuilder sb = new StringBuilder("");
371371
for (int i = 0; i < dirPathSplit.length -2; ++i) {

src/test/java/com/graphaware/nlp/processor/opennlp/model/CustomSentimentModelIntegrationTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.graphaware.nlp.NLPIntegrationTest;
44
import org.junit.Test;
55

6+
import java.util.Map;
7+
68
import static org.junit.Assert.*;
79

810
public class CustomSentimentModelIntegrationTest extends NLPIntegrationTest {
@@ -14,6 +16,23 @@ public void testTrainCustomModelWithProcedure() {
1416
executeInTransaction(q, (result -> {
1517
assertTrue(result.hasNext());
1618
}));
19+
20+
String addPipelineQuery = "CALL ga.nlp.processor.addPipeline({textProcessor: 'com.graphaware.nlp.processor.opennlp.OpenNLPTextProcessor', name: 'customSentiment', processingSteps: {tokenize: true, ner: true, sentiment: true, dependency: false, customSentiment: \"component-en\"}})";
21+
executeInTransaction(addPipelineQuery, emptyConsumer());
22+
23+
String insertQ = "CREATE (tweet:Tweet) SET tweet.text = \"African American unemployment is the lowest ever recorded in our country. The Hispanic unemployment rate dropped a full point in the last year and is close to the lowest in recorded history. Dems did nothing for you but get your vote!\"\n" +
24+
"WITH tweet\n" +
25+
"CALL ga.nlp.annotate({text:tweet.text, id:id(tweet), pipeline:\"customSentiment\", checkLanguage:false})\n" +
26+
"YIELD result\n" +
27+
"MERGE (tweet)-[:HAS_ANNOTATED_TEXT]->(result)";
28+
executeInTransaction(insertQ, emptyConsumer());
29+
executeInTransaction("MATCH (n:Sentence) RETURN ANY(x IN labels(n) WHERE x IN ['Positive','Very Positive','Neutral']) AS hasSentiment", (result -> {
30+
assertTrue(result.hasNext());
31+
while (result.hasNext()) {
32+
Map<String, Object> record = result.next();
33+
assertTrue((boolean) record.get("hasSentiment"));
34+
}
35+
}));
1736
}
1837

1938
}

0 commit comments

Comments
 (0)