Skip to content

Commit 55c7309

Browse files
authored
Merge pull request #38 from gerardobort/feature/isomorphism
feat(*): isomorphism
2 parents ffd9e6d + 5a07b62 commit 55c7309

File tree

13 files changed

+2028
-146
lines changed

13 files changed

+2028
-146
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CoreNLP for NodeJS
22

3-
This library helps making NodeJS applications using the state-of-the-art technology for Natural Language Processing: Stanford CoreNLP.
3+
This library helps making NodeJS/Web applications using the state-of-the-art technology for Natural Language Processing: Stanford CoreNLP.
4+
It is compatible with the latest release of [![CoreNLP 3.9.0](https://stanfordnlp.github.io/CoreNLP/#download).
45

56
[![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)
67

@@ -119,7 +120,7 @@ const pipeline = new Pipeline(props, 'English', connector);
119120
```javascript
120121
// ... include dependencies
121122

122-
const props = new Properties({ annotators: 'tokenize,ssplit,pos,lemma,ner' });
123+
const props = new Properties({ annotators: 'tokenize,ssplit,lemma,pos,ner' });
123124
const pipeline = new Pipeline(props, 'English', connector);
124125
const sent = new CoreNLP.simple.Sentence('Hello world');
125126
pipeline.annotate(sent)
@@ -174,7 +175,15 @@ pipeline.annotateSemgrex(expression, true) // similarly use pipeline.annotateTo
174175
});
175176
```
176177

177-
## 5. External Documentation
178+
## 5. Client Side
179+
180+
This library is isomorphic, which means that works as well on a Browser. The API is exactly the same, and you can use it directly by requiring it via a `<script>` tag, using AMD (RequireJS), or within your app bundle.
181+
182+
The browser ready version of `corenlp` can be found as `dist/index.browser.min.js`, once built (`npm run build`).
183+
184+
See the examples folder for more details.
185+
186+
## 6. External Documentation
178187

179188
```bash
180189
Properties
@@ -199,18 +208,18 @@ CoreNLP
199208
DependencyParseAnnotator # https://stanfordnlp.github.io/CoreNLP/depparse.html
200209
RelationExtractorAnnotator # https://stanfordnlp.github.io/CoreNLP/relation.html
201210
CorefAnnotator # https://stanfordnlp.github.io/CoreNLP/coref.html
202-
SentimentAnnotator # https://stanfordnlp.github.io/CoreNLP/sentiment.html - TODO
211+
SentimentAnnotator # https://stanfordnlp.github.io/CoreNLP/sentiment.html - Comming soon...
203212
RelationExtractorAnnotator # https://stanfordnlp.github.io/CoreNLP/relation.html - TODO
204213
NaturalLogicAnnotator # https://stanfordnlp.github.io/CoreNLP/natlog.html - TODO
205214
QuoteAnnotator # https://stanfordnlp.github.io/CoreNLP/quote.html - TODO
206215
util
207216
Tree # http://www.cs.cornell.edu/courses/cs474/2004fa/lec1.pdf
208217
```
209218

210-
## 6. References
219+
## 7. References
211220

212221
This library is *not* maintained by [StanfordNLP](https://github.com/stanfordnlp). However, it's based on and depends on [StanfordNLP/CoreNLP](https://github.com/stanfordnlp/CoreNLP) to function.
213222

214-
### 6.1 [Stanford CoreNLP Reference](https://github.com/stanfordnlp/CoreNLP)
223+
### 7.1 [Stanford CoreNLP Reference](https://github.com/stanfordnlp/CoreNLP)
215224

216225
Manning, Christopher D., Mihai Surdeanu, John Bauer, Jenny Finkel, Steven J. Bethard, and David McClosky. 2014. The Stanford CoreNLP Natural Language Processing Toolkit In Proceedings of the 52nd Annual Meeting of the Association for Computational Linguistics: System Demonstrations, pp. 55-60.

examples/browser/corenlp.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/browser/index.amd.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>corenlp: browser demo (amd)</title>
5+
</head>
6+
<body>
7+
<h1>CoreNLP client side example (AMD)</h1>
8+
<pre id="canvas">Loading annotation data...</pre>
9+
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
10+
<script>
11+
require(['./corenlp.min.js'], function(CoreNLP) {
12+
const connector = new CoreNLP.ConnectorServer({ dsn: 'http://localhost:9000' });
13+
const props = new CoreNLP.Properties({ annotators: 'tokenize,ssplit,pos,lemma,ner,parse' });
14+
const pipeline = new CoreNLP.Pipeline(props, 'Spanish', connector);
15+
const sent = new CoreNLP.default.simple.Sentence('A los pibes les gusta tomar Fernet con Coca.');
16+
pipeline.annotate(sent)
17+
.then(function(sent) {
18+
console.log(sent);
19+
console.log('pos', sent.tokens().map(token => `${token.word()}: ${token.posInfo().tag}`));
20+
console.log('parse', sent.parse());
21+
document.getElementById('canvas').innerHTML = CoreNLP.default.util.Tree.fromSentence(sent).dump();
22+
})
23+
.catch(function(err) {
24+
console.log('err', err);
25+
});
26+
});
27+
</script>
28+
</body>
29+
</html>

examples/browser/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>corenlp: browser demo</title>
5+
</head>
6+
<body>
7+
<h1>CoreNLP client side example</h1>
8+
<pre id="canvas">Loading annotation data...</pre>
9+
<script src="corenlp.min.js"></script>
10+
<script>
11+
const connector = new CoreNLP.ConnectorServer({ dsn: 'http://localhost:9000' });
12+
const props = new CoreNLP.Properties({ annotators: 'tokenize,ssplit,pos,lemma,ner,parse' });
13+
const pipeline = new CoreNLP.Pipeline(props, 'Spanish', connector);
14+
const sent = new CoreNLP.default.simple.Sentence('A los pibes les gusta tomar Fernet con Coca.');
15+
pipeline.annotate(sent)
16+
.then(function(sent) {
17+
console.log(sent);
18+
console.log('pos', sent.tokens().map(token => `${token.word()}: ${token.posInfo().tag}`));
19+
console.log('parse', sent.parse());
20+
document.getElementById('canvas').innerHTML = CoreNLP.default.util.Tree.fromSentence(sent).dump();
21+
})
22+
.catch(function(err) {
23+
console.log('err', err);
24+
});
25+
</script>
26+
</body>
27+
</html>

examples/browser/server.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
python -m SimpleHTTPServer 8000
2+
echo "open http://localhost:8000"

gulpfile.babel.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@ import jsdoc from 'gulp-jsdoc3';
55
import jsdocConfig from './jsdoc.json';
66
import clean from 'gulp-clean';
77
import gulpSequence from 'gulp-sequence';
8+
import browserify from 'browserify';
9+
import source from 'vinyl-source-stream';
10+
import rename from 'gulp-rename';
11+
import minify from 'gulp-minify';
812

913
gulp.task('default', ['build']);
1014

1115
gulp.task('compile', gulpSequence('copy', 'transpile'));
1216

13-
gulp.task('build', gulpSequence('clean', 'copy', 'transpile', 'doc'));
17+
gulp.task('build', gulpSequence(
18+
'clean',
19+
'copy',
20+
'transpile',
21+
'doc',
22+
'build:browser',
23+
'compress:browser',
24+
'copy:example:browser'
25+
));
1426

1527
gulp.task('transpile', () =>
1628
gulp.src(['src/*', 'src/**/*.js'])
@@ -27,6 +39,31 @@ gulp.task('doc', () =>
2739
.pipe(jsdoc(jsdocConfig)));
2840

2941
gulp.task('clean', () =>
30-
gulp.src(['doc', 'dist'], { read: false })
42+
gulp.src(['doc', 'dist', 'examples/browser/corenlp.min.js'], { read: false })
3143
.pipe(clean()));
3244

45+
gulp.task('build:browser', () =>
46+
browserify('src/index.js', {
47+
standalone: 'CoreNLP',
48+
debug: false,
49+
extensions: ['.js', '.json'],
50+
})
51+
.transform('babelify')
52+
.bundle()
53+
.pipe(source('index.browser.js'))
54+
.pipe(gulp.dest('dist/')))
55+
56+
gulp.task('compress:browser', () =>
57+
gulp.src('dist/index.browser.js')
58+
.pipe(minify({
59+
ext: {
60+
src: '.js',
61+
min: '.min.js',
62+
},
63+
}))
64+
.pipe(gulp.dest('dist')));
65+
66+
gulp.task('copy:example:browser', () =>
67+
gulp.src('dist/index.browser.min.js')
68+
.pipe(rename('corenlp.min.js'))
69+
.pipe(gulp.dest('examples/browser')))

0 commit comments

Comments
 (0)