1
- /*
2
- * This program tests the StanfordCoreNLP node wrapper.
1
+ /* *
2
+ * This program tests the stanford-corenlp-node package.
3
+ * Usage:
4
+ * >
5
+ * > cd my_projects_dir
6
+ * > git clone [email protected] :mhewett/stanford-corenlp-node-example.git
7
+ * > npm install
8
+ * >
9
+ * > cd stanford-corenlp-node-example/example
10
+ * > cp StanfordCoreNLP.example.properties StanfordCoreNLP.properties
11
+ * > cp config.example.json config.json
12
+ * >
13
+ * > [ edit config.json; ensure that "path", "nlpLibDir", and "propsPath" are set correctly]
14
+ * > [ edit StanfordCoreNLP.properties; ensure that the path to the NER dictionary is correct ]
15
+ * >
16
+ * > # finally we are ready to run!
17
+ * > node example-as-package ./config.json
18
+ * >
19
+ *
20
+ * Mike Hewett
21
+ * Dec 2012
22
+
3
23
*/
24
+
25
+ // These are required for TypeScript
4
26
declare var require , process ;
27
+
28
+ // Third-party Node.js packages
5
29
var events = require ( "minpubsub/minpubsub" ) ;
6
30
var nlplib = require ( "stanford-corenlp-node" ) ;
7
31
8
- // Events
32
+ // Event declarations
9
33
var SERVER_AVAILABLE = "Server started" ;
10
34
11
35
// Create an instance of the server, passing in the config file.
12
36
var nlpServer = new nlplib . StanfordCoreNLP . Server ( process . argv [ 2 ] ) ;
13
- console . log ( "NLP server status: " , nlpServer . getStatus ( ) . getState ( ) ) ;
14
37
15
38
// Start the server. This is an asynchronous call.
16
39
// The callback will be run when the NLP library is ready (~20 seconds).
@@ -34,7 +57,10 @@ var testNLP = function() {
34
57
switch ( counter ) {
35
58
case 1 : testString = "Bill Clinton was president from 1992 to 2000. He is not the president any more." ; break ;
36
59
case 2 : testString = "Santa Claus is coming to town." ; break ;
37
- case 3 : nlpServer . stop ( ) ;
60
+ case 3 : console . log ( "NLP server status: " , nlpServer . getStatus ( ) . getState ( ) ) ;
61
+ events . publish ( SERVER_AVAILABLE ) ;
62
+ break ;
63
+ case 4 : nlpServer . stop ( ) ; break ;
38
64
}
39
65
40
66
// Process the string using the NLP library and print the result.
@@ -43,10 +69,10 @@ var testNLP = function() {
43
69
nlpServer . process ( testString ,
44
70
function ( result ) {
45
71
console . log ( JSON . stringify ( JSON . parse ( result ) , null , " " ) ) ;
46
- events . publish ( SERVER_AVAILABLE , testNLP ) ;
72
+ events . publish ( SERVER_AVAILABLE ) ;
47
73
} ) ;
48
74
}
49
75
}
50
76
51
- //Start the test loop by subscribing to the event.
77
+ // Ready the loop by subscribing to the event.
52
78
events . subscribe ( SERVER_AVAILABLE , testNLP ) ;
0 commit comments