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

Commit 6e6ce19

Browse files
committed
refactored sentiment trainer to be able to use files from tests
1 parent 0d6770a commit 6e6ce19

File tree

6 files changed

+148
-3
lines changed

6 files changed

+148
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
target/
22
*iml
33
dependency-reduced-pom.xml
4+
**/.DS_Store

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,36 +96,42 @@
9696
<artifactId>slf4j-simple</artifactId>
9797
<version>1.7.21</version>
9898
</dependency>
99+
99100
<dependency>
100101
<groupId>junit</groupId>
101102
<artifactId>junit</artifactId>
102103
<version>4.12</version>
103104
<scope>test</scope>
104105
</dependency>
106+
105107
<dependency>
106108
<groupId>com.graphaware.neo4j</groupId>
107109
<artifactId>runtime</artifactId>
108110
<version>${graphaware.version}</version>
109111
<scope>test</scope>
110112
</dependency>
113+
111114
<dependency>
112115
<groupId>com.graphaware.neo4j</groupId>
113116
<artifactId>server</artifactId>
114117
<version>${graphaware.version}</version>
115118
<scope>test</scope>
116119
</dependency>
120+
117121
<dependency>
118122
<groupId>com.graphaware.neo4j</groupId>
119123
<artifactId>tests</artifactId>
120124
<version>${graphaware.version}</version>
121125
<scope>test</scope>
122126
</dependency>
127+
123128
<dependency>
124129
<groupId>com.graphaware.neo4j</groupId>
125130
<artifactId>resttest</artifactId>
126131
<scope>test</scope>
127132
<version>${resttest.version}</version>
128133
</dependency>
134+
129135
<dependency>
130136
<groupId>com.graphaware.neo4j</groupId>
131137
<artifactId>nlp</artifactId>
@@ -134,6 +140,13 @@
134140
<scope>test</scope>
135141
</dependency>
136142

143+
<dependency>
144+
<groupId>com.sun.jersey</groupId>
145+
<artifactId>jersey-server</artifactId>
146+
<version>1.19.1</version>
147+
<scope>test</scope>
148+
</dependency>
149+
137150
</dependencies>
138151

139152

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,22 @@ else if (alg.toLowerCase().equals("sentiment")) {
364364
SentimentModelTool sentModel = new SentimentModelTool(fileTrain, modelId, lang, params);
365365
sentModel.train();
366366
result = sentModel.validate();
367-
sentModel.saveModel(fileOut);
367+
String[] dirPathSplit = fileTrain.split(File.separator);
368+
String fileOutToUse = null;
369+
if (dirPathSplit.length > 2) {
370+
StringBuilder sb = new StringBuilder("");
371+
for (int i = 0; i < dirPathSplit.length -2; ++i) {
372+
sb.append(dirPathSplit[i]).append(File.separator);
373+
}
374+
fileOutToUse = sb.toString() + fileOut;
375+
} else {
376+
fileOutToUse = fileOut;
377+
}
378+
System.out.println("Saving model to " + fileOutToUse);
379+
sentModel.saveModel(fileOutToUse);
368380
// incorporate this model to the OpenNLPPipeline
369381
if (sentModel.getModel() != null) {
370-
customSentimentModels.put(newKey, fileOut);
382+
customSentimentModels.put(newKey, fileOutToUse);
371383
//sentimentDetectors.put(newKey, new DocumentCategorizerME((DoccatModel) sentModel.getModel()));
372384
}
373385
} else {

src/main/java/com/graphaware/nlp/processor/opennlp/model/OpenNLPGenericModelTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class ImprovisedInputStreamFactory implements InputStreamFactory {
211211
}
212212
try {
213213
if (this.inputSourceStr.startsWith("file://")) {
214-
this.inputSourceFile = new File(new URI(this.inputSourceStr));
214+
this.inputSourceFile = new File(new URI(this.inputSourceStr.replace("file://", "")));
215215
} else if (this.inputSourceStr.startsWith("/")) {
216216
this.inputSourceFile = new File(this.inputSourceStr);
217217
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.graphaware.nlp.processor.opennlp.model;
2+
3+
import com.graphaware.nlp.NLPIntegrationTest;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.*;
7+
8+
public class CustomSentimentModelIntegrationTest extends NLPIntegrationTest {
9+
10+
@Test
11+
public void testTrainCustomModelWithProcedure() {
12+
String p = getClass().getClassLoader().getResource("import/sentiment_tweets.train").getPath();
13+
String q = "CALL ga.nlp.processor.train({textProcessor: \"com.graphaware.nlp.processor.opennlp.OpenNLPTextProcessor\", modelIdentifier: \"component-en\", alg: \"sentiment\", inputFile: \""+p+"\" , lang: \"en\"})";
14+
executeInTransaction(q, (result -> {
15+
assertTrue(result.hasNext());
16+
}));
17+
}
18+
19+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
3 Watching a nice movie
2+
1 The painting is ugly, will return it tomorrow...
3+
3 One of the best soccer games, worth seeing it
4+
3 Very tasty, not only for vegetarians
5+
3 Super party!
6+
1 Too early to travel..need a coffee
7+
1 Damn..the train is late again...
8+
1 Bad news, my flight just got cancelled.
9+
3 Happy birthday mr. president
10+
3 Just watch it. Respect.
11+
3 Wonderful sunset.
12+
3 Bravo, first title in 2014!
13+
1 Had a bad evening, need urgently a beer.
14+
1 I put on weight again
15+
3 On today's show we met Angela, a woman with an amazing story
16+
3 I fell in love again
17+
1 I lost my keys
18+
3 On a trip to Iceland
19+
3 Happy in Berlin
20+
1 I hate Mondays
21+
3 Love the new book I reveived for Christmas
22+
1 He killed our good mood
23+
3 I am in good spirits again
24+
3 This guy creates the most awesome pics ever
25+
1 The dark side of a selfie.
26+
3 Cool! John is back!
27+
3 Many rooms and many hopes for new residents
28+
1 False hopes for the people attending the meeting
29+
3 I set my new year's resolution
30+
1 The ugliest car ever!
31+
1 Feeling bored
32+
1 Need urgently a pause
33+
3 Nice to see Ana made it
34+
3 My dream came true
35+
1 I didn't see that one coming
36+
1 Sorry mate, there is no more room for you
37+
1 Who could have possibly done this?
38+
3 I won the challenge
39+
1 I feel bad for what I did
40+
3 I had a great time tonight
41+
3 It was a lot of fun
42+
3 Thank you Molly making this possible
43+
1 I just did a big mistake
44+
3 I love it!!
45+
1 I never loved so hard in my life
46+
1 I hate you Mike!!
47+
1 I hate to say goodbye
48+
3 Lovely!
49+
3 Like and share if you feel the same
50+
1 Never try this at home
51+
1 Don't spoil it!
52+
3 I love rock and roll
53+
1 The more I hear you, the more annoyed I get
54+
3 Finnaly passed my exam!
55+
3 Lovely kittens
56+
1 I just lost my appetite
57+
1 Sad end for this movie
58+
1 Lonely, I am so lonely
59+
3 Beautiful morning
60+
3 She is amazing
61+
3 Enjoying some time with my friends
62+
3 Special thanks to Marty
63+
3 Thanks God I left on time
64+
3 Greateful for a wonderful meal
65+
3 So happy to be home
66+
1 Hate to wait on a long queue
67+
1 No cab available
68+
1 Electricity outage, this is a nightmare
69+
1 Nobody to ask about directions
70+
3 Great game!
71+
3 Nice trip
72+
3 I just received a pretty flower
73+
3 Excellent idea
74+
3 Got a new watch. Feeling happy
75+
1 I feel sick
76+
1 I am very tired
77+
3 Such a good taste
78+
1 Such a bad taste
79+
3 Enjoying brunch
80+
1 I don't recommend this restaurant
81+
3 Thank you mom for supporting me
82+
1 I will never ever call you again
83+
1 I just got kicked out of the contest
84+
3 Smiling
85+
1 Big pain to see my team loosing
86+
1 Bitter defeat tonight
87+
1 My bike was stollen
88+
3 Great to see you!
89+
1 I lost every hope for seeing him again
90+
3 Nice dress!
91+
3 Stop wasting my time
92+
3 I have a great idea
93+
3 Excited to go to the pub
94+
3 Feeling proud
95+
3 Cute bunnies
96+
1 Cold winter ahead
97+
1 Hopless struggle..
98+
1 Ugly hat
99+
3 Big hug and lots of love
100+
3 I hope you have a wonderful celebration

0 commit comments

Comments
 (0)