forked from ines/spacy-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlanguage.js
More file actions
19 lines (17 loc) · 704 Bytes
/
language.js
File metadata and controls
19 lines (17 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { Doc } from './tokens';
import { makeRequest } from './util';
export default class Language {
constructor(model, api = 'http://localhost:8080') {
const self = this;
return async function(text) {
const { words, spaces, attrs } = await self.makeDoc(model, text, api);
return new Doc(words, spaces, attrs);
}
}
async makeDoc(model, text, api) {
const json = await makeRequest(api, 'parse', { model, text })
const words = json.tokens.map(({ text }) => text);
const spaces = json.tokens.map(({ whitespace }) => Boolean(whitespace));
return { words, spaces, attrs: Object.assign({}, json, { api }) }
}
}