1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _lodash = require('lodash');
|
8 |
|
9 | var _lodash2 = _interopRequireDefault(_lodash);
|
10 |
|
11 | var _async = require('async');
|
12 |
|
13 | var _async2 = _interopRequireDefault(_async);
|
14 |
|
15 | var _wordpos = require('wordpos');
|
16 |
|
17 | var _wordpos2 = _interopRequireDefault(_wordpos);
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20 |
|
21 | const wordpos = new _wordpos2.default();
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | process.on('unhandledRejection', err => {
|
28 | throw err;
|
29 | });
|
30 |
|
31 |
|
32 |
|
33 | const lookup = function lookup(word, pointerSymbol = '~', cb) {
|
34 | let pos = null;
|
35 |
|
36 | const match = word.match(/~(\w)$/);
|
37 | if (match) {
|
38 | pos = match[1];
|
39 | word = word.replace(match[0], '');
|
40 | }
|
41 |
|
42 | return wordpos.lookup(word).then(results => {
|
43 | const synets = [];
|
44 |
|
45 | results.forEach(result => {
|
46 | result.ptrs.forEach(part => {
|
47 | if (pos !== null && part.pos === pos && part.pointerSymbol === pointerSymbol) {
|
48 | synets.push(part);
|
49 | } else if (pos === null && part.pointerSymbol === pointerSymbol) {
|
50 | synets.push(part);
|
51 | }
|
52 | });
|
53 | });
|
54 |
|
55 | const itor = (word1, next) => {
|
56 | wordpos.seek(word1.synsetOffset, word1.pos).then(sub => {
|
57 | next(null, sub.lemma);
|
58 | });
|
59 | };
|
60 |
|
61 | _async2.default.map(synets, itor, (err, items) => {
|
62 | items = _lodash2.default.uniq(items);
|
63 | items = items.map(x => x.replace(/_/g, ' '));
|
64 | cb(err, items);
|
65 | });
|
66 | });
|
67 | };
|
68 |
|
69 | exports.default = {
|
70 | lookup
|
71 | }; |
\ | No newline at end of file |