Skip to content

Commit 85a5ea4

Browse files
committed
docs(runkit): updated example
1 parent d612c76 commit 85a5ea4

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
This library helps making NodeJS applications using the state-of-the-art technology for Natural Language Processing: Stanford CoreNLP.
44

5-
[![Build Status](https://travis-ci.org/gerardobort/node-corenlp.svg?branch=master)](https://travis-ci.org/gerardobort/node-corenlp)
6-
7-
[![Try corenlp on RunKit](https://badge.runkitcdn.com/corenlp.svg)](https://npm.runkit.com/corenlp)
5+
[![Build Status](https://travis-ci.org/gerardobort/node-corenlp.svg?branch=master)](https://travis-ci.org/gerardobort/node-corenlp) [![Try corenlp on RunKit](https://badge.runkitcdn.com/corenlp.svg)](https://npm.runkit.com/corenlp)
86

97
[![NPM package](https://nodei.co/npm/corenlp.png)](https://www.npmjs.com/package/corenlp)
108

examples/runkit.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
1+
// requires ployfill for ES7 async/await
12
require("babel-polyfill");
2-
const corenlp = require("corenlp"), CoreNLP = corenlp.default;
3-
const Properties = corenlp.Properties;
4-
const Pipeline = corenlp.Pipeline;
5-
const ConnectorServer = corenlp.ConnectorServer;
3+
4+
const corenlp = require("corenlp");
5+
const CoreNLP = corenlp.default; // convenient when not using `import`
6+
67
/**
7-
* NOTE: The server http://corenlp.run is used here just for demo purposes.
8+
* IMPORTANT
9+
* The server http://corenlp.run is used here just for demo purposes.
810
* It is not set up to handle a large volume of requests. Instructions for
911
* setting up your own server can be found in the Dedicated Server section (link below).
1012
* @see {@lik https://stanfordnlp.github.io/CoreNLP/corenlp-server.html}
1113
* @see {@link http://corenlp.run}
1214
*/
13-
const connector = new ConnectorServer({ dsn: 'http://corenlp.run' });
14-
const props = new Properties({ annotators: 'tokenize,ssplit,pos,parse' });
15-
const pipeline = new Pipeline(props, 'Spanish', connector);
15+
const connector = new corenlp.ConnectorServer({
16+
dsn: 'http://corenlp.run',
17+
});
18+
19+
// initialize the pipeline and document to annotate
20+
const props = new corenlp.Properties({
21+
annotators: 'tokenize,ssplit,pos,ner,parse',
22+
});
23+
const pipeline = new corenlp.Pipeline(props, 'Spanish', connector);
24+
const sent = new CoreNLP.simple.Sentence(
25+
'Jorge quiere cinco empanadas de queso y carne.'
26+
);
27+
28+
// performs the call to corenlp (in this case via http)
29+
await pipeline.annotate(sent);
30+
31+
// constituency parse string representation
32+
console.log('parse', sent.parse());
1633

17-
const sent = new CoreNLP.simple.Sentence('...contemplando la membrana azul de tus ojos fulminando el tiempo, y el espacio.');
34+
// constituency parse tree representation
35+
const tree = CoreNLP.util.Tree.fromSentence(sent);
1836

19-
// The response might take few seconds...
20-
pipeline.annotate(sent)
21-
.then(sent => {
22-
console.log(sent.tokens().map(token => `${token}: ${token.pos()}`));
23-
console.log(sent.tokens().map(token => `${token}: ${token.posInfo().tag}`));
24-
})
25-
.catch(err => {
26-
console.log('err', err);
27-
});
37+
// traverse the tree leaves and print some props
38+
tree.visitLeaves(node =>
39+
console.log(node.word(), node.pos(), node.token().ner()));
40+
41+
// dump the tree for debugging
42+
console.log(JSON.stringify(tree.dump(), null, 2));

0 commit comments

Comments
 (0)