2626import java .util .Collections ;
2727import java .util .HashMap ;
2828import java .util .Map ;
29+
30+ import org .junit .BeforeClass ;
2931import org .junit .Test ;
3032import org .neo4j .graphdb .Node ;
3133import org .neo4j .graphdb .QueryExecutionException ;
3840import static org .junit .Assert .assertFalse ;
3941import static org .junit .Assert .assertNull ;
4042
41- public class TextProcessorTest extends EmbeddedDatabaseIntegrationTest {
43+ public class TextProcessorTest extends OpenNLPIntegrationTest {
4244
45+ private static TextProcessor textProcessor ;
4346 private static final String TEXT_PROCESSOR = "com.graphaware.nlp.processor.opennlp.OpenNLPTextProcessor" ;
4447
48+ @ BeforeClass
49+ public static void init () {
50+ textProcessor = ServiceLoader .loadTextProcessor (TEXT_PROCESSOR );
51+ textProcessor .init ();
52+ }
53+
4554 @ Test
4655 public void testAnnotatedText () {
47- TextProcessor textProcessor = ServiceLoader .loadTextProcessor (TEXT_PROCESSOR );
48- textProcessor .init ();
4956 AnnotatedText annotatedText = textProcessor .annotateText ("On 8 May 2013, "
5057 + "one week before the Pakistani election, the third author, "
5158 + "in his keynote address at the Sentiment Analysis Symposium, "
@@ -72,8 +79,6 @@ public void testAnnotatedText() {
7279
7380 @ Test
7481 public void testLemmaLowerCasing () {
75- TextProcessor textProcessor = ServiceLoader .loadTextProcessor (TEXT_PROCESSOR );
76- textProcessor .init ();
7782 AnnotatedText annotateText = textProcessor .annotateText ("Collibra’s Data Governance Innovation: Enabling Data as a Strategic Asset" , OpenNLPTextProcessor .TOKENIZER , "en" , null );
7883
7984 assertEquals (1 , annotateText .getSentences ().size ());
@@ -112,43 +117,39 @@ private ResourceIterator<Object> getTagsIterator(String value) throws QueryExecu
112117
113118 @ Test
114119 public void testAnnotatedTag () {
115- TextProcessor textProcessor = ServiceLoader .loadTextProcessor (TEXT_PROCESSOR );
116- textProcessor .init ();
117120 Tag annotateTag = textProcessor .annotateTag ("winners" , "en" );
118121 assertEquals (annotateTag .getLemma (), "winner" );
119122 }
120123
121- @ Test
122- public void testAnnotationAndConcept () {
123- // ConceptNet5Importer.Builder() - arguments need fixing
124- /*TextProcessor textProcessor = ServiceLoader.loadTextProcessor("com.graphaware.nlp.processor.stanford.StanfordTextProcessor");
125- ConceptNet5Importer conceptnet5Importer = new ConceptNet5Importer.Builder("http://conceptnet5.media.mit.edu/data/5.4", textProcessor)
126- .build();
127- String text = "Say hi to Christophe";
128- AnnotatedText annotateText = textProcessor.annotateText(text, 1, 0, "en", false);
129- List<Node> nodes = new ArrayList<>();
130- try (Transaction beginTx = getDatabase().beginTx()) {
131- Node annotatedNode = annotateText.storeOnGraph(getDatabase(), false);
132- Map<String, Object> params = new HashMap<>();
133- params.put("id", annotatedNode.getId());
134- Result queryRes = getDatabase().execute("MATCH (n:AnnotatedText)-[*..2]->(t:Tag) where id(n) = {id} return t", params);
135- ResourceIterator<Node> tags = queryRes.columnAs("t");
136- while (tags.hasNext()) {
137- Node tag = tags.next();
138- nodes.add(tag);
139- List<Tag> conceptTags = conceptnet5Importer.importHierarchy(Tag.createTag(tag), "en");
140- conceptTags.stream().forEach((newTag) -> {
141- nodes.add(newTag.storeOnGraph(getDatabase(), false));
142- });
143- }
144- beginTx.success();
145- }*/
146- }
124+ // @Test
125+ // public void testAnnotationAndConcept() {
126+ // // ConceptNet5Importer.Builder() - arguments need fixing
127+ // /*TextProcessor textProcessor = ServiceLoader.loadTextProcessor("com.graphaware.nlp.processor.stanford.StanfordTextProcessor");
128+ // ConceptNet5Importer conceptnet5Importer = new ConceptNet5Importer.Builder("http://conceptnet5.media.mit.edu/data/5.4", textProcessor)
129+ // .build();
130+ // String text = "Say hi to Christophe";
131+ // AnnotatedText annotateText = textProcessor.annotateText(text, 1, 0, "en", false);
132+ // List<Node> nodes = new ArrayList<>();
133+ // try (Transaction beginTx = getDatabase().beginTx()) {
134+ // Node annotatedNode = annotateText.storeOnGraph(getDatabase(), false);
135+ // Map<String, Object> params = new HashMap<>();
136+ // params.put("id", annotatedNode.getId());
137+ // Result queryRes = getDatabase().execute("MATCH (n:AnnotatedText)-[*..2]->(t:Tag) where id(n) = {id} return t", params);
138+ // ResourceIterator<Node> tags = queryRes.columnAs("t");
139+ // while (tags.hasNext()) {
140+ // Node tag = tags.next();
141+ // nodes.add(tag);
142+ // List<Tag> conceptTags = conceptnet5Importer.importHierarchy(Tag.createTag(tag), "en");
143+ // conceptTags.stream().forEach((newTag) -> {
144+ // nodes.add(newTag.storeOnGraph(getDatabase(), false));
145+ // });
146+ // }
147+ // beginTx.success();
148+ // }*/
149+ // }
147150
148151 //@Test
149152 public void testSentiment () {
150- TextProcessor textProcessor = ServiceLoader .loadTextProcessor (TEXT_PROCESSOR );
151-
152153 AnnotatedText annotateText = textProcessor .annotateText ("I really hate to study at Stanford, it was a waste of time, I'll never be there again" , OpenNLPTextProcessor .TOKENIZER , "en" , null );
153154 assertEquals (1 , annotateText .getSentences ().size ());
154155 assertEquals (0 , annotateText .getSentences ().get (0 ).getSentiment ());
@@ -172,8 +173,6 @@ public void testSentiment() {
172173
173174 @ Test
174175 public void testAnnotatedTextWithPosition () {
175- TextProcessor textProcessor = ServiceLoader .loadTextProcessor (TEXT_PROCESSOR );
176- textProcessor .init ();
177176 AnnotatedText annotateText = textProcessor .annotateText ("On 8 May 2013, "
178177 + "one week before the Pakistani election, the third author, "
179178 + "in his keynote address at the Sentiment Analysis Symposium, "
@@ -217,8 +216,6 @@ public void testAnnotatedTextWithPosition() {
217216
218217 @ Test
219218 public void testAnnotatedShortText () {
220- TextProcessor textProcessor = ServiceLoader .loadTextProcessor (TEXT_PROCESSOR );
221- textProcessor .init ();
222219 AnnotatedText annotateText = textProcessor .annotateText ("Fixing Batch Endpoint Logging Problem" , OpenNLPTextProcessor .TOKENIZER , "en" , null );
223220
224221 assertEquals (1 , annotateText .getSentences ().size ());
@@ -230,8 +227,6 @@ public void testAnnotatedShortText() {
230227
231228 @ Test
232229 public void testAnnotatedShortText2 () {
233- TextProcessor textProcessor = ServiceLoader .loadTextProcessor (TEXT_PROCESSOR );
234- textProcessor .init ();
235230 AnnotatedText annotateText = textProcessor .annotateText ("Importing CSV data does nothing" , OpenNLPTextProcessor .TOKENIZER , "en" , null );
236231 assertEquals (1 , annotateText .getSentences ().size ());
237232// GraphPersistence peristence = new LocalGraphDatabase(getDatabase());
0 commit comments