@@ -34,7 +34,7 @@ You may want to download, apart of the full package, other language models (see
3434
3535### 3. Configure Stanford CoreNLP
3636
37- #### 3.1. Use CoreNLP as HTTP Server
37+ #### 3.1. Using StanfordCoreNLPServer
3838
3939``` bash
4040# Run the server using all jars in the current directory (e.g., the CoreNLP home directory)
@@ -44,35 +44,45 @@ java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -t
4444CoreNLP connects by default via StanfordCoreNLPServer, using port 9000. You can also opt to setup the connection differently:
4545
4646``` javascript
47- import CoreNLP from ' corenlp' ;
47+ import CoreNLP , { Properties , Pipeline , ConnectorServer } from ' corenlp' ;
4848
49- CoreNLP .setup (' English' , new CoreNLP.connector.ConnectorServer ({ dsn: ' http://localhost:9000' }));
49+ const connector = new ConnectorServer ({ dsn: ' http://localhost:9000' });
50+ const props = new Properties ({
51+ annotators: ' tokenize,ssplit,pos,lemma,ner,parse' ,
52+ });
53+ const pipeline = new Pipeline (props, ' English' , connector);
5054```
5155
5256#### 3.2. Use CoreNLP via CLI
5357
5458CoreNLP expects by default the StanfordCoreNLP package to be placed (unzipped) inside the path ` ${YOUR_NPM_PROJECT_ROOT}/corenlp/ ` . You can also opt to setup the CLI interface differently:
5559
5660``` javascript
57- import CoreNLP from ' corenlp' ;
58-
59- CoreNLP .setup (' Spanish' , new CoreNLP.connector.ConnectorCli ({
60- // specify the paths relative to your project root
61- classPath: ' corenlp/stanford-corenlp-full-2017-06-09/*' ,
62- mainClass: ' edu.stanford.nlp.pipeline.StanfordCoreNLP' ,
63- props: ' StanfordCoreNLP-spanish.properties' ,
64- }));
61+ import CoreNLP , { Properties , Pipeline , ConnectorCli } from ' corenlp' ;
62+
63+ const connector = new ConnectorCli ({
64+ classPath: ' corenlp/stanford-corenlp-full-2017-06-09/*' , // specify the paths relative to your npm project root
65+ mainClass: ' edu.stanford.nlp.pipeline.StanfordCoreNLP' , // optional
66+ props: ' StanfordCoreNLP-spanish.properties' , // optional
67+ });
68+ const props = new Properties ({
69+ annotators: ' tokenize,ssplit,pos,lemma,ner,parse' ,
70+ });
71+ const pipeline = new Pipeline (props, ' English' , connector);
6572```
6673
6774### 4. Use it
6875
6976``` javascript
70- // ...
77+ // ... initialize pipeline first (see above)
7178
7279const sent = new CoreNLP.simple.Sentence (' Hello world' );
73- sent . applyAnnotator ( CoreNLP . simple . annotator . TokenizerAnnotator )
74- .then (() => {
80+ pipeline . annotate (sent )
81+ .then (sent => {
7582 console .log (sent .words ());
83+ })
84+ .catch (err => {
85+ console .log (' err' , err);
7686 });
7787```
7888
@@ -84,29 +94,16 @@ NOTE2: The examples below assumes `es6` syntax, if you use require, use as follo
8494### English
8595
8696``` javascript
87- import CoreNLP from ' corenlp' ;
97+ import CoreNLP , { Properties , Pipeline } from ' corenlp' ;
8898
89- CoreNLP .setup (' English' ); // check method docs for more setup options
90- const sent = new CoreNLP.simple.Sentence (' The little dog runs so fast.' );
91- sent .applyAnnotator (CoreNLP .simple .annotator .ParserAnnotator )
92- .then (() => {
93- console .log (' parse' , sent .parse ());
94- console .log (CoreNLP .util .Tree .fromSentence (sent).dump ());
95- })
96- .catch (err => {
97- console .log (' err' , err);
98- });
99- ```
100-
101- ### Spanish
99+ const props = new Properties ({
100+ annotators: ' tokenize,ssplit,pos,lemma,ner,parse' ,
101+ });
102+ const pipeline = new Pipeline (props, ' English' ); // uses ConnectorServer by default
102103
103- ``` javascript
104- import CoreNLP from ' corenlp' ;
105-
106- CoreNLP .setup (' Spanish' ); // check method docs for more setup options
107- const sent = new CoreNLP.simple.Sentence (' El pájaro veloz come kiwi.' );
108- sent .applyAnnotator (CoreNLP .simple .annotator .ParserAnnotator )
109- .then (() => {
104+ const sent = new CoreNLP.simple.Sentence (' The little dog runs so fast.' );
105+ pipeline .annotate (sent)
106+ .then (sent => {
110107 console .log (' parse' , sent .parse ());
111108 console .log (CoreNLP .util .Tree .fromSentence (sent).dump ());
112109 })
@@ -121,6 +118,11 @@ We will update this section soon. In the meantime, you can browse the project c
121118In summary, this NodeJS library aims to replicate the CoreNLP Simple Java interface but in Javascript. There are some minor differences however, for example the need to call ` applyAnnotator ` asynchronously.
122119
123120``` bash
121+ Properties
122+ Pipeline
123+ Service
124+ ConnectorCli
125+ ConnectorServer
124126CoreNLP
125127 connector
126128 ConnectorServer # https://stanfordnlp.github.io/CoreNLP/corenlp-server.html
0 commit comments