@scrabble-solver/word-definitions 2.13.5-alpha.0 → 2.13.5-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/crawl.d.ts +2 -0
- package/build/crawl.js +19 -0
- package/build/getWordDefinition.d.ts +1 -2
- package/build/getWordDefinition.js +2 -1
- package/build/index.d.ts +2 -1
- package/build/index.js +2 -4
- package/build/languages/english.d.ts +3 -0
- package/build/languages/english.js +28 -0
- package/build/languages/french.d.ts +3 -0
- package/build/languages/french.js +22 -0
- package/build/languages/german.d.ts +3 -0
- package/build/languages/german.js +70 -0
- package/build/languages/index.d.ts +7 -0
- package/build/languages/index.js +33 -0
- package/build/languages/persian.d.ts +3 -0
- package/build/languages/persian.js +23 -0
- package/build/languages/polish.d.ts +3 -0
- package/build/languages/polish.js +24 -0
- package/build/languages/romanian.d.ts +3 -0
- package/build/languages/romanian.js +26 -0
- package/build/languages/spanish.d.ts +3 -0
- package/build/languages/spanish.js +39 -0
- package/build/lib/index.d.ts +3 -3
- package/build/lib/index.js +3 -6
- package/build/lib/normalizeDefinition.d.ts +1 -2
- package/build/lib/normalizeDefinition.js +3 -2
- package/build/lib/request.d.ts +2 -2
- package/build/lib/request.js +2 -1
- package/build/lib/unique.d.ts +1 -2
- package/build/lib/unique.js +2 -1
- package/build/parse.d.ts +3 -0
- package/build/parse.js +24 -0
- package/build/types.d.ts +1 -1
- package/package.json +3 -3
- package/src/crawl.ts +18 -0
- package/src/getWordDefinition.ts +1 -3
- package/src/index.ts +2 -1
- package/src/{parse/parseEnglish.ts → languages/english.ts} +11 -4
- package/src/languages/french.ts +22 -0
- package/src/{parse/parseGerman.ts → languages/german.ts} +12 -5
- package/src/languages/index.ts +7 -0
- package/src/{parse/parseFarsi.ts → languages/persian.ts} +11 -4
- package/src/{parse/parsePolish.ts → languages/polish.ts} +11 -4
- package/src/{parse/parseRomanian.ts → languages/romanian.ts} +11 -4
- package/src/{parse/parseSpanish.ts → languages/spanish.ts} +11 -4
- package/src/lib/index.ts +3 -3
- package/src/lib/normalizeDefinition.ts +1 -3
- package/src/lib/request.ts +1 -3
- package/src/lib/unique.ts +1 -3
- package/src/{parse/parse.test.ts → parse.test.ts} +5 -7
- package/src/parse.ts +25 -0
- package/src/types.ts +1 -1
- package/src/crawl/crawl.ts +0 -26
- package/src/crawl/crawlEnglish.ts +0 -11
- package/src/crawl/crawlFarsi.ts +0 -11
- package/src/crawl/crawlFrench.ts +0 -11
- package/src/crawl/crawlGerman.ts +0 -11
- package/src/crawl/crawlPolish.ts +0 -11
- package/src/crawl/crawlRomanian.ts +0 -11
- package/src/crawl/crawlSpanish.ts +0 -11
- package/src/crawl/index.ts +0 -6
- package/src/parse/index.ts +0 -8
- package/src/parse/parse.ts +0 -34
- package/src/parse/parseFrench.ts +0 -15
- /package/src/{parse/__tests__ → __tests__}/expected/de-DE.hm.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/de-DE.ho.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/de-DE.kolla.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/de-DE.vom.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/en-US.awe.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/en-US.oe.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/en-US.pawn.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/en-US.pawnee.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/en-US.pean.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/en-US.wiz.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/es-ES.corma.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/es-ES.portero.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/expected/ro-RO.aciua.json +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/de-DE.hm.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/de-DE.ho.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/de-DE.kolla.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/de-DE.vom.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/en-US.awe.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/en-US.oe.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/en-US.pawn.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/en-US.pawnee.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/en-US.pean.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/en-US.wiz.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/es-ES.corma.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/es-ES.portero.html +0 -0
- /package/src/{parse/__tests__ → __tests__}/input/ro-RO.aciua.html +0 -0
package/build/crawl.d.ts
ADDED
package/build/crawl.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.crawl = void 0;
|
|
4
|
+
const types_1 = require("@scrabble-solver/types");
|
|
5
|
+
const languages_1 = require("./languages");
|
|
6
|
+
const crawlPerLocale = {
|
|
7
|
+
[types_1.Locale.DE_DE]: languages_1.german.crawl,
|
|
8
|
+
[types_1.Locale.EN_GB]: languages_1.english.crawl,
|
|
9
|
+
[types_1.Locale.EN_US]: languages_1.english.crawl,
|
|
10
|
+
[types_1.Locale.ES_ES]: languages_1.spanish.crawl,
|
|
11
|
+
[types_1.Locale.FA_IR]: languages_1.persian.crawl,
|
|
12
|
+
[types_1.Locale.FR_FR]: languages_1.french.crawl,
|
|
13
|
+
[types_1.Locale.PL_PL]: languages_1.polish.crawl,
|
|
14
|
+
[types_1.Locale.RO_RO]: languages_1.romanian.crawl,
|
|
15
|
+
};
|
|
16
|
+
const crawl = (locale, word) => {
|
|
17
|
+
return crawlPerLocale[locale](word);
|
|
18
|
+
};
|
|
19
|
+
exports.crawl = crawl;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { Locale, WordDefinition } from '@scrabble-solver/types';
|
|
2
|
-
declare const getWordDefinition: (locale: Locale, word: string, isAllowed: boolean) => Promise<WordDefinition>;
|
|
3
|
-
export default getWordDefinition;
|
|
2
|
+
export declare const getWordDefinition: (locale: Locale, word: string, isAllowed: boolean) => Promise<WordDefinition>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWordDefinition = void 0;
|
|
3
4
|
const types_1 = require("@scrabble-solver/types");
|
|
4
5
|
const crawl_1 = require("./crawl");
|
|
5
6
|
const parse_1 = require("./parse");
|
|
@@ -9,4 +10,4 @@ const getWordDefinition = async (locale, word, isAllowed) => {
|
|
|
9
10
|
const wordDefinition = new types_1.WordDefinition({ definitions, exists, isAllowed, word });
|
|
10
11
|
return wordDefinition;
|
|
11
12
|
};
|
|
12
|
-
exports.
|
|
13
|
+
exports.getWordDefinition = getWordDefinition;
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -13,13 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
17
|
exports.getWordDefinition = void 0;
|
|
21
18
|
var getWordDefinition_1 = require("./getWordDefinition");
|
|
22
|
-
Object.defineProperty(exports, "getWordDefinition", { enumerable: true, get: function () { return
|
|
19
|
+
Object.defineProperty(exports, "getWordDefinition", { enumerable: true, get: function () { return getWordDefinition_1.getWordDefinition; } });
|
|
23
20
|
__exportStar(require("./crawl"), exports);
|
|
21
|
+
__exportStar(require("./languages"), exports);
|
|
24
22
|
__exportStar(require("./lib"), exports);
|
|
25
23
|
__exportStar(require("./parse"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = exports.crawl = void 0;
|
|
4
|
+
const cheerio_1 = require("cheerio");
|
|
5
|
+
const lib_1 = require("../lib");
|
|
6
|
+
const DOES_NOT_EXIST_MESSAGE =
|
|
7
|
+
// eslint-disable-next-line max-len
|
|
8
|
+
"The word you've entered isn't in the dictionary. Click on a spelling suggestion below or try again using the search bar above.";
|
|
9
|
+
const crawl = (word) => {
|
|
10
|
+
return (0, lib_1.request)({
|
|
11
|
+
protocol: 'https',
|
|
12
|
+
hostname: 'www.merriam-webster.com',
|
|
13
|
+
path: `/dictionary/${encodeURIComponent(word)}`,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.crawl = crawl;
|
|
17
|
+
const parse = (html) => {
|
|
18
|
+
const $ = (0, cheerio_1.load)(html);
|
|
19
|
+
$('strong.mw_t_bc').replaceWith(', ');
|
|
20
|
+
$('.text-lowercase').remove();
|
|
21
|
+
$('.sub-content-thread').remove();
|
|
22
|
+
const $definitions = $('[id^=dictionary-entry]').find('.dtText, .cxl-ref');
|
|
23
|
+
return {
|
|
24
|
+
definitions: Array.from($definitions).map((definition) => $(definition).text().replace(/\n/g, '')),
|
|
25
|
+
exists: $('.spelling-suggestion-text').text().trim() !== DOES_NOT_EXIST_MESSAGE,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.parse = parse;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = exports.crawl = void 0;
|
|
4
|
+
const cheerio_1 = require("cheerio");
|
|
5
|
+
const lib_1 = require("../lib");
|
|
6
|
+
const crawl = (word) => {
|
|
7
|
+
return (0, lib_1.request)({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'www.cnrtl.fr',
|
|
10
|
+
path: `/definition/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.crawl = crawl;
|
|
14
|
+
const parse = (html) => {
|
|
15
|
+
const $ = (0, cheerio_1.load)(html);
|
|
16
|
+
const $definitions = $('.tlf_cdefinition');
|
|
17
|
+
return {
|
|
18
|
+
definitions: Array.from($definitions).map((definition) => $(definition).text()),
|
|
19
|
+
exists: $('#vitemselected span').length > 0,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.parse = parse;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = exports.crawl = void 0;
|
|
4
|
+
const cheerio_1 = require("cheerio");
|
|
5
|
+
const lib_1 = require("../lib");
|
|
6
|
+
const crawl = (word) => {
|
|
7
|
+
return (0, lib_1.request)({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'www.dwds.de',
|
|
10
|
+
path: `/wb/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.crawl = crawl;
|
|
14
|
+
const parse = (html) => {
|
|
15
|
+
const $ = (0, cheerio_1.load)(html);
|
|
16
|
+
const definitions = [parseBedeutungsubersicht, parseBedeutungen, parseBedeutung].reduce((results, parseDefinition) => (results.length === 0 ? parseDefinition($) : results), []);
|
|
17
|
+
const exists = Array.from($('.label-danger')).every((label) => $(label).text() !== 'Hinweis');
|
|
18
|
+
return { definitions, exists };
|
|
19
|
+
};
|
|
20
|
+
exports.parse = parse;
|
|
21
|
+
const parseBedeutungsubersicht = ($) => {
|
|
22
|
+
Array.from($('.bedeutungsuebersicht ol > li > a')).forEach((item) => {
|
|
23
|
+
$(item).text($(item).text().replace(/\n/g, ''));
|
|
24
|
+
});
|
|
25
|
+
Array.from($('.bedeutungsuebersicht ol > li > ol > li')).forEach((item) => {
|
|
26
|
+
const text = `\n${$(item).text().replace(/\n/g, '')}`;
|
|
27
|
+
const $text = $(`<div>${text}</div>`);
|
|
28
|
+
$(item).replaceWith($text);
|
|
29
|
+
});
|
|
30
|
+
Array.from($('.bedeutungsuebersicht ol > li > ol')).forEach((list) => {
|
|
31
|
+
const $list = $(list);
|
|
32
|
+
const html = $list.html() || '';
|
|
33
|
+
const $html = $(`<div>${html}</div>`);
|
|
34
|
+
const $prev = $list.prev('a');
|
|
35
|
+
if ($prev) {
|
|
36
|
+
$prev.append($html);
|
|
37
|
+
$(list).remove();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
$(list).replaceWith($html);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return parseDefinitions($, $('.bedeutungsuebersicht ol > li'));
|
|
44
|
+
};
|
|
45
|
+
const parseBedeutung = ($) => {
|
|
46
|
+
return parseDefinitions($, $('.dwdswb-lesart .dwdswb-definition-spezifizierung'));
|
|
47
|
+
};
|
|
48
|
+
const parseBedeutungen = ($) => {
|
|
49
|
+
const definitions = parseDefinitions($, $('.dwdswb-lesart .dwdswb-definition'));
|
|
50
|
+
if (definitions.length > 0) {
|
|
51
|
+
return definitions;
|
|
52
|
+
}
|
|
53
|
+
const $references = $('.dwdswb-lesart .dwdswb-verweis');
|
|
54
|
+
const references = Array.from($references).reduce((result, reference) => {
|
|
55
|
+
const html = reference.attribs['data-content'] || '<span />';
|
|
56
|
+
const values = $(html)
|
|
57
|
+
.text()
|
|
58
|
+
.split(';')
|
|
59
|
+
.map((value) => value.trim());
|
|
60
|
+
return result.concat(values);
|
|
61
|
+
}, []);
|
|
62
|
+
return references;
|
|
63
|
+
};
|
|
64
|
+
const parseDefinitions = ($, $definitions) => {
|
|
65
|
+
return Array.from($definitions).map((definition) => $(definition)
|
|
66
|
+
.text()
|
|
67
|
+
.replace(/[ ]+/g, ' ')
|
|
68
|
+
.replace(/[ ]\n/g, '\n')
|
|
69
|
+
.replace(/^[0-9]+\.\s/g, ''));
|
|
70
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as english from './english';
|
|
2
|
+
export * as german from './german';
|
|
3
|
+
export * as french from './french';
|
|
4
|
+
export * as persian from './persian';
|
|
5
|
+
export * as polish from './polish';
|
|
6
|
+
export * as romanian from './romanian';
|
|
7
|
+
export * as spanish from './spanish';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.spanish = exports.romanian = exports.polish = exports.persian = exports.french = exports.german = exports.english = void 0;
|
|
27
|
+
exports.english = __importStar(require("./english"));
|
|
28
|
+
exports.german = __importStar(require("./german"));
|
|
29
|
+
exports.french = __importStar(require("./french"));
|
|
30
|
+
exports.persian = __importStar(require("./persian"));
|
|
31
|
+
exports.polish = __importStar(require("./polish"));
|
|
32
|
+
exports.romanian = __importStar(require("./romanian"));
|
|
33
|
+
exports.spanish = __importStar(require("./spanish"));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = exports.crawl = void 0;
|
|
4
|
+
const cheerio_1 = require("cheerio");
|
|
5
|
+
const lib_1 = require("../lib");
|
|
6
|
+
const DOES_NOT_EXIST_MESSAGE = '404 Page Not Found';
|
|
7
|
+
const crawl = (word) => {
|
|
8
|
+
return (0, lib_1.request)({
|
|
9
|
+
protocol: 'https',
|
|
10
|
+
hostname: 'www.vajehyab.com',
|
|
11
|
+
path: `/moein/${encodeURIComponent(word)}`,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
exports.crawl = crawl;
|
|
15
|
+
const parse = (html) => {
|
|
16
|
+
const $ = (0, cheerio_1.load)(html);
|
|
17
|
+
const $definitions = $('[itemprop=articleBody]');
|
|
18
|
+
return {
|
|
19
|
+
definitions: Array.from($definitions).map((definition) => $(definition).text()),
|
|
20
|
+
exists: $('#container h1').text() !== DOES_NOT_EXIST_MESSAGE,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.parse = parse;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = exports.crawl = void 0;
|
|
4
|
+
const cheerio_1 = require("cheerio");
|
|
5
|
+
const lib_1 = require("../lib");
|
|
6
|
+
const crawl = (word) => {
|
|
7
|
+
return (0, lib_1.request)({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'sjp.pl',
|
|
10
|
+
path: `/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.crawl = crawl;
|
|
14
|
+
const parse = (html) => {
|
|
15
|
+
const $ = (0, cheerio_1.load)(html);
|
|
16
|
+
const $header = $($('h1')[0]);
|
|
17
|
+
const $isAllowed = $header.next();
|
|
18
|
+
const $definitions = $header.next().next().next().next();
|
|
19
|
+
return {
|
|
20
|
+
definitions: $definitions.text().trim().split(/\d+\./),
|
|
21
|
+
exists: $isAllowed.text().trim().indexOf('dopuszczalne w grach') >= 0,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.parse = parse;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = exports.crawl = void 0;
|
|
4
|
+
const cheerio_1 = require("cheerio");
|
|
5
|
+
const lib_1 = require("../lib");
|
|
6
|
+
const crawl = (word) => {
|
|
7
|
+
return (0, lib_1.request)({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'dexonline.ro',
|
|
10
|
+
path: `/definitie/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.crawl = crawl;
|
|
14
|
+
const parse = (html) => {
|
|
15
|
+
const $ = (0, cheerio_1.load)(html);
|
|
16
|
+
const $activeTab = $('.tab-pane.show.active');
|
|
17
|
+
$('.type-example').remove();
|
|
18
|
+
const $definitions = $activeTab.find('li.type-meaning.depth-0 > .meaningContainer .def.html');
|
|
19
|
+
$definitions.find('.meaningTree').remove();
|
|
20
|
+
const definitions = Array.from($definitions).map((definition) => $(definition).text().replace(/\n/g, ''));
|
|
21
|
+
return {
|
|
22
|
+
definitions,
|
|
23
|
+
exists: definitions.length > 0,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.parse = parse;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = exports.crawl = void 0;
|
|
4
|
+
const cheerio_1 = require("cheerio");
|
|
5
|
+
const lib_1 = require("../lib");
|
|
6
|
+
const crawl = (word) => {
|
|
7
|
+
return (0, lib_1.request)({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'www.diccionarios.com',
|
|
10
|
+
path: `/diccionario/espanol/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.crawl = crawl;
|
|
14
|
+
const parse = (html) => {
|
|
15
|
+
const $ = (0, cheerio_1.load)(html);
|
|
16
|
+
$('.verdBold14 + .gris11 + .gris13').remove();
|
|
17
|
+
$('br + .gris13').remove();
|
|
18
|
+
$('.grisItalic13 + .gris13').remove();
|
|
19
|
+
$('font[class^="verd"]').remove();
|
|
20
|
+
$('font.gris11').remove();
|
|
21
|
+
$('font[class^="grisBold"]').remove();
|
|
22
|
+
$('font[class^="grisItalic"]').remove();
|
|
23
|
+
Array.from($('.gris13')).forEach((element) => {
|
|
24
|
+
const children = $(element).find('.gris13');
|
|
25
|
+
if (children && children.length > 0) {
|
|
26
|
+
children.remove();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const definitions = Array.from($('.dcom-search-result .gris13'));
|
|
30
|
+
return {
|
|
31
|
+
definitions: definitions
|
|
32
|
+
.map((definition) => $(definition).text().trim())
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.map((definition) => definition.replace(/\s+\.$/g, ''))
|
|
35
|
+
.map((definition) => (definition.endsWith('.') ? definition : `${definition}.`)),
|
|
36
|
+
exists: $('.wrapper > p > strong').text() !== 'No se ha encontrado la palabra exacta',
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
exports.parse = parse;
|
package/build/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { normalizeDefinition } from './normalizeDefinition';
|
|
2
|
+
export { request } from './request';
|
|
3
|
+
export { unique } from './unique';
|
package/build/lib/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.unique = exports.request = exports.normalizeDefinition = void 0;
|
|
7
4
|
var normalizeDefinition_1 = require("./normalizeDefinition");
|
|
8
|
-
Object.defineProperty(exports, "normalizeDefinition", { enumerable: true, get: function () { return
|
|
5
|
+
Object.defineProperty(exports, "normalizeDefinition", { enumerable: true, get: function () { return normalizeDefinition_1.normalizeDefinition; } });
|
|
9
6
|
var request_1 = require("./request");
|
|
10
|
-
Object.defineProperty(exports, "request", { enumerable: true, get: function () { return
|
|
7
|
+
Object.defineProperty(exports, "request", { enumerable: true, get: function () { return request_1.request; } });
|
|
11
8
|
var unique_1 = require("./unique");
|
|
12
|
-
Object.defineProperty(exports, "unique", { enumerable: true, get: function () { return
|
|
9
|
+
Object.defineProperty(exports, "unique", { enumerable: true, get: function () { return unique_1.unique; } });
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare const normalizeDefinition: (definition: string) => string;
|
|
2
|
-
export default normalizeDefinition;
|
|
1
|
+
export declare const normalizeDefinition: (definition: string) => string;
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizeDefinition = void 0;
|
|
6
7
|
const striptags_1 = __importDefault(require("striptags"));
|
|
7
8
|
const EMPHASIS_TAGS = ['a', 'b', 'em', 'internalXref'];
|
|
8
9
|
const normalizeHtmlTags = (definition) => (0, striptags_1.default)((0, striptags_1.default)(definition, EMPHASIS_TAGS), undefined, '"');
|
|
@@ -40,6 +41,6 @@ const normalizers = [
|
|
|
40
41
|
const normalizeDefinition = (definition) => {
|
|
41
42
|
const normalized = normalizers.reduce((result, normalize) => normalize(result), definition);
|
|
42
43
|
const hasChanged = normalized !== definition;
|
|
43
|
-
return hasChanged ? normalizeDefinition(normalized) : normalized;
|
|
44
|
+
return hasChanged ? (0, exports.normalizeDefinition)(normalized) : normalized;
|
|
44
45
|
};
|
|
45
|
-
exports.
|
|
46
|
+
exports.normalizeDefinition = normalizeDefinition;
|
package/build/lib/request.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import { RequestOptions } from 'http';
|
|
|
3
3
|
interface Options extends RequestOptions {
|
|
4
4
|
protocol?: 'http' | 'https';
|
|
5
5
|
}
|
|
6
|
-
declare const request: ({ protocol, ...options }: Options) => Promise<string>;
|
|
7
|
-
export
|
|
6
|
+
export declare const request: ({ protocol, ...options }: Options) => Promise<string>;
|
|
7
|
+
export {};
|
package/build/lib/request.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.request = void 0;
|
|
3
4
|
const follow_redirects_1 = require("follow-redirects");
|
|
4
5
|
const request = ({ protocol, ...options }) => {
|
|
5
6
|
const agent = protocol === 'https' ? follow_redirects_1.https : follow_redirects_1.http;
|
|
@@ -23,4 +24,4 @@ const request = ({ protocol, ...options }) => {
|
|
|
23
24
|
.on('error', reject);
|
|
24
25
|
});
|
|
25
26
|
};
|
|
26
|
-
exports.
|
|
27
|
+
exports.request = request;
|
package/build/lib/unique.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare const unique: <T>(array: T[]) => T[];
|
|
2
|
-
export default unique;
|
|
1
|
+
export declare const unique: <T>(array: T[]) => T[];
|
package/build/lib/unique.js
CHANGED
package/build/parse.d.ts
ADDED
package/build/parse.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = void 0;
|
|
4
|
+
const types_1 = require("@scrabble-solver/types");
|
|
5
|
+
const languages_1 = require("./languages");
|
|
6
|
+
const lib_1 = require("./lib");
|
|
7
|
+
const parsePerLocale = {
|
|
8
|
+
[types_1.Locale.DE_DE]: languages_1.german.parse,
|
|
9
|
+
[types_1.Locale.EN_GB]: languages_1.english.parse,
|
|
10
|
+
[types_1.Locale.EN_US]: languages_1.english.parse,
|
|
11
|
+
[types_1.Locale.ES_ES]: languages_1.spanish.parse,
|
|
12
|
+
[types_1.Locale.FA_IR]: languages_1.persian.parse,
|
|
13
|
+
[types_1.Locale.FR_FR]: languages_1.french.parse,
|
|
14
|
+
[types_1.Locale.PL_PL]: languages_1.polish.parse,
|
|
15
|
+
[types_1.Locale.RO_RO]: languages_1.romanian.parse,
|
|
16
|
+
};
|
|
17
|
+
const parse = (locale, html) => {
|
|
18
|
+
const { definitions, exists } = parsePerLocale[locale](html);
|
|
19
|
+
return {
|
|
20
|
+
definitions: (0, lib_1.unique)(definitions.map(lib_1.normalizeDefinition).filter(Boolean)),
|
|
21
|
+
exists,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.parse = parse;
|
package/build/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scrabble-solver/word-definitions",
|
|
3
|
-
"version": "2.13.5-alpha.
|
|
3
|
+
"version": "2.13.5-alpha.2",
|
|
4
4
|
"description": "Scrabble Solver 2 - Word definitions",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"clean": "rimraf build/"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@scrabble-solver/types": "^2.13.5-alpha.
|
|
26
|
+
"@scrabble-solver/types": "^2.13.5-alpha.2",
|
|
27
27
|
"cheerio": "^1.0.0-rc.12",
|
|
28
28
|
"follow-redirects": "^1.15.5",
|
|
29
29
|
"striptags": "^3.2.0"
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/follow-redirects": "^1.14.4"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "95703c052d4874a7fffcd2a296a5be4fe25b6b72"
|
|
35
35
|
}
|
package/src/crawl.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Locale } from '@scrabble-solver/types';
|
|
2
|
+
|
|
3
|
+
import { english, french, german, persian, polish, romanian, spanish } from './languages';
|
|
4
|
+
|
|
5
|
+
const crawlPerLocale: Record<Locale, (word: string) => Promise<string>> = {
|
|
6
|
+
[Locale.DE_DE]: german.crawl,
|
|
7
|
+
[Locale.EN_GB]: english.crawl,
|
|
8
|
+
[Locale.EN_US]: english.crawl,
|
|
9
|
+
[Locale.ES_ES]: spanish.crawl,
|
|
10
|
+
[Locale.FA_IR]: persian.crawl,
|
|
11
|
+
[Locale.FR_FR]: french.crawl,
|
|
12
|
+
[Locale.PL_PL]: polish.crawl,
|
|
13
|
+
[Locale.RO_RO]: romanian.crawl,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const crawl = (locale: Locale, word: string): Promise<string> => {
|
|
17
|
+
return crawlPerLocale[locale](word);
|
|
18
|
+
};
|
package/src/getWordDefinition.ts
CHANGED
|
@@ -3,11 +3,9 @@ import { Locale, WordDefinition } from '@scrabble-solver/types';
|
|
|
3
3
|
import { crawl } from './crawl';
|
|
4
4
|
import { parse } from './parse';
|
|
5
5
|
|
|
6
|
-
const getWordDefinition = async (locale: Locale, word: string, isAllowed: boolean): Promise<WordDefinition> => {
|
|
6
|
+
export const getWordDefinition = async (locale: Locale, word: string, isAllowed: boolean): Promise<WordDefinition> => {
|
|
7
7
|
const html = await crawl(locale, word);
|
|
8
8
|
const { definitions, exists } = parse(locale, html);
|
|
9
9
|
const wordDefinition = new WordDefinition({ definitions, exists, isAllowed, word });
|
|
10
10
|
return wordDefinition;
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
export default getWordDefinition;
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { request } from '../lib';
|
|
4
|
+
import { ParsingResult } from '../types';
|
|
4
5
|
|
|
5
6
|
const DOES_NOT_EXIST_MESSAGE =
|
|
6
7
|
// eslint-disable-next-line max-len
|
|
7
8
|
"The word you've entered isn't in the dictionary. Click on a spelling suggestion below or try again using the search bar above.";
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
+
export const crawl = (word: string): Promise<string> => {
|
|
11
|
+
return request({
|
|
12
|
+
protocol: 'https',
|
|
13
|
+
hostname: 'www.merriam-webster.com',
|
|
14
|
+
path: `/dictionary/${encodeURIComponent(word)}`,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const parse = (html: string): ParsingResult => {
|
|
10
19
|
const $ = load(html);
|
|
11
20
|
$('strong.mw_t_bc').replaceWith(', ');
|
|
12
21
|
$('.text-lowercase').remove();
|
|
@@ -19,5 +28,3 @@ const parseEnglish = (html: string): ParseResult => {
|
|
|
19
28
|
exists: $('.spelling-suggestion-text').text().trim() !== DOES_NOT_EXIST_MESSAGE,
|
|
20
29
|
};
|
|
21
30
|
};
|
|
22
|
-
|
|
23
|
-
export default parseEnglish;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { load } from 'cheerio';
|
|
2
|
+
|
|
3
|
+
import { request } from '../lib';
|
|
4
|
+
import { ParsingResult } from '../types';
|
|
5
|
+
|
|
6
|
+
export const crawl = (word: string): Promise<string> => {
|
|
7
|
+
return request({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'www.cnrtl.fr',
|
|
10
|
+
path: `/definition/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const parse = (html: string): ParsingResult => {
|
|
15
|
+
const $ = load(html);
|
|
16
|
+
const $definitions = $('.tlf_cdefinition');
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
definitions: Array.from($definitions).map((definition) => $(definition).text()),
|
|
20
|
+
exists: $('#vitemselected span').length > 0,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { Cheerio, CheerioAPI, Element, load } from 'cheerio';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { request } from '../lib';
|
|
4
|
+
import { ParsingResult } from '../types';
|
|
5
|
+
|
|
6
|
+
export const crawl = (word: string): Promise<string> => {
|
|
7
|
+
return request({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'www.dwds.de',
|
|
10
|
+
path: `/wb/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
4
13
|
|
|
5
|
-
const
|
|
14
|
+
export const parse = (html: string): ParsingResult => {
|
|
6
15
|
const $ = load(html);
|
|
7
16
|
|
|
8
17
|
const definitions = [parseBedeutungsubersicht, parseBedeutungen, parseBedeutung].reduce<string[]>(
|
|
9
|
-
(results,
|
|
18
|
+
(results, parseDefinition) => (results.length === 0 ? parseDefinition($) : results),
|
|
10
19
|
[],
|
|
11
20
|
);
|
|
12
21
|
const exists = Array.from($('.label-danger')).every((label) => $(label).text() !== 'Hinweis');
|
|
@@ -76,5 +85,3 @@ const parseDefinitions = ($: CheerioAPI, $definitions: Cheerio<Element>) => {
|
|
|
76
85
|
.replace(/^[0-9]+\.\s/g, ''),
|
|
77
86
|
);
|
|
78
87
|
};
|
|
79
|
-
|
|
80
|
-
export default parseGerman;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as english from './english';
|
|
2
|
+
export * as german from './german';
|
|
3
|
+
export * as french from './french';
|
|
4
|
+
export * as persian from './persian';
|
|
5
|
+
export * as polish from './polish';
|
|
6
|
+
export * as romanian from './romanian';
|
|
7
|
+
export * as spanish from './spanish';
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { request } from '../lib';
|
|
4
|
+
import { ParsingResult } from '../types';
|
|
4
5
|
|
|
5
6
|
const DOES_NOT_EXIST_MESSAGE = '404 Page Not Found';
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
export const crawl = (word: string): Promise<string> => {
|
|
9
|
+
return request({
|
|
10
|
+
protocol: 'https',
|
|
11
|
+
hostname: 'www.vajehyab.com',
|
|
12
|
+
path: `/moein/${encodeURIComponent(word)}`,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const parse = (html: string): ParsingResult => {
|
|
8
17
|
const $ = load(html);
|
|
9
18
|
const $definitions = $('[itemprop=articleBody]');
|
|
10
19
|
|
|
@@ -13,5 +22,3 @@ const parseFarsi = (html: string): ParseResult => {
|
|
|
13
22
|
exists: $('#container h1').text() !== DOES_NOT_EXIST_MESSAGE,
|
|
14
23
|
};
|
|
15
24
|
};
|
|
16
|
-
|
|
17
|
-
export default parseFarsi;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { request } from '../lib';
|
|
4
|
+
import { ParsingResult } from '../types';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
+
export const crawl = (word: string): Promise<string> => {
|
|
7
|
+
return request({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'sjp.pl',
|
|
10
|
+
path: `/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const parse = (html: string): ParsingResult => {
|
|
6
15
|
const $ = load(html);
|
|
7
16
|
const $header = $($('h1')[0]);
|
|
8
17
|
const $isAllowed = $header.next();
|
|
@@ -13,5 +22,3 @@ const parsePolish = (html: string): ParseResult => {
|
|
|
13
22
|
exists: $isAllowed.text().trim().indexOf('dopuszczalne w grach') >= 0,
|
|
14
23
|
};
|
|
15
24
|
};
|
|
16
|
-
|
|
17
|
-
export default parsePolish;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { request } from '../lib';
|
|
4
|
+
import { ParsingResult } from '../types';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
+
export const crawl = (word: string): Promise<string> => {
|
|
7
|
+
return request({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'dexonline.ro',
|
|
10
|
+
path: `/definitie/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const parse = (html: string): ParsingResult => {
|
|
6
15
|
const $ = load(html);
|
|
7
16
|
|
|
8
17
|
const $activeTab = $('.tab-pane.show.active');
|
|
@@ -16,5 +25,3 @@ const parseRomanian = (html: string): ParseResult => {
|
|
|
16
25
|
exists: definitions.length > 0,
|
|
17
26
|
};
|
|
18
27
|
};
|
|
19
|
-
|
|
20
|
-
export default parseRomanian;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { request } from '../lib';
|
|
4
|
+
import { ParsingResult } from '../types';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
+
export const crawl = (word: string): Promise<string> => {
|
|
7
|
+
return request({
|
|
8
|
+
protocol: 'https',
|
|
9
|
+
hostname: 'www.diccionarios.com',
|
|
10
|
+
path: `/diccionario/espanol/${encodeURIComponent(word)}`,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const parse = (html: string): ParsingResult => {
|
|
6
15
|
const $ = load(html);
|
|
7
16
|
$('.verdBold14 + .gris11 + .gris13').remove();
|
|
8
17
|
$('br + .gris13').remove();
|
|
@@ -31,5 +40,3 @@ const parseSpanish = (html: string): ParseResult => {
|
|
|
31
40
|
exists: $('.wrapper > p > strong').text() !== 'No se ha encontrado la palabra exacta',
|
|
32
41
|
};
|
|
33
42
|
};
|
|
34
|
-
|
|
35
|
-
export default parseSpanish;
|
package/src/lib/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { normalizeDefinition } from './normalizeDefinition';
|
|
2
|
+
export { request } from './request';
|
|
3
|
+
export { unique } from './unique';
|
|
@@ -46,10 +46,8 @@ const normalizers: Normalize[] = [
|
|
|
46
46
|
(definition) => definition.trim(),
|
|
47
47
|
];
|
|
48
48
|
|
|
49
|
-
const normalizeDefinition = (definition: string): string => {
|
|
49
|
+
export const normalizeDefinition = (definition: string): string => {
|
|
50
50
|
const normalized = normalizers.reduce((result, normalize) => normalize(result), definition);
|
|
51
51
|
const hasChanged = normalized !== definition;
|
|
52
52
|
return hasChanged ? normalizeDefinition(normalized) : normalized;
|
|
53
53
|
};
|
|
54
|
-
|
|
55
|
-
export default normalizeDefinition;
|
package/src/lib/request.ts
CHANGED
|
@@ -5,7 +5,7 @@ interface Options extends RequestOptions {
|
|
|
5
5
|
protocol?: 'http' | 'https';
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
const request = ({ protocol, ...options }: Options): Promise<string> => {
|
|
8
|
+
export const request = ({ protocol, ...options }: Options): Promise<string> => {
|
|
9
9
|
const agent = protocol === 'https' ? https : http;
|
|
10
10
|
|
|
11
11
|
return new Promise((resolve, reject) => {
|
|
@@ -27,5 +27,3 @@ const request = ({ protocol, ...options }: Options): Promise<string> => {
|
|
|
27
27
|
.on('error', reject);
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
-
|
|
31
|
-
export default request;
|
package/src/lib/unique.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Locale } from '@scrabble-solver/types';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
5
|
-
import parse from './parse';
|
|
5
|
+
import { parse } from './parse';
|
|
6
6
|
|
|
7
7
|
export const readTestFile = (filepath: string): string => {
|
|
8
8
|
const absoluteFilepath = path.resolve(__dirname, '__tests__', filepath);
|
|
@@ -26,11 +26,9 @@ const tests = [
|
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
describe('parse', () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
expect(parse(locale, input)).toEqual(JSON.parse(expected));
|
|
34
|
-
});
|
|
29
|
+
it.each(tests)(`[$locale] "$word"`, ({ locale, word }) => {
|
|
30
|
+
const input = readTestFile(`input/${locale}.${word}.html`);
|
|
31
|
+
const expected = readTestFile(`expected/${locale}.${word}.json`);
|
|
32
|
+
expect(parse(locale, input)).toEqual(JSON.parse(expected));
|
|
35
33
|
});
|
|
36
34
|
});
|
package/src/parse.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Locale } from '@scrabble-solver/types';
|
|
2
|
+
|
|
3
|
+
import { english, french, german, persian, polish, romanian, spanish } from './languages';
|
|
4
|
+
import { normalizeDefinition, unique } from './lib';
|
|
5
|
+
import { ParsingResult } from './types';
|
|
6
|
+
|
|
7
|
+
const parsePerLocale: Record<Locale, (html: string) => ParsingResult> = {
|
|
8
|
+
[Locale.DE_DE]: german.parse,
|
|
9
|
+
[Locale.EN_GB]: english.parse,
|
|
10
|
+
[Locale.EN_US]: english.parse,
|
|
11
|
+
[Locale.ES_ES]: spanish.parse,
|
|
12
|
+
[Locale.FA_IR]: persian.parse,
|
|
13
|
+
[Locale.FR_FR]: french.parse,
|
|
14
|
+
[Locale.PL_PL]: polish.parse,
|
|
15
|
+
[Locale.RO_RO]: romanian.parse,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const parse = (locale: Locale, html: string): ParsingResult => {
|
|
19
|
+
const { definitions, exists } = parsePerLocale[locale](html);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
definitions: unique(definitions.map(normalizeDefinition).filter(Boolean)),
|
|
23
|
+
exists,
|
|
24
|
+
};
|
|
25
|
+
};
|
package/src/types.ts
CHANGED
package/src/crawl/crawl.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Locale } from '@scrabble-solver/types';
|
|
2
|
-
|
|
3
|
-
import crawlEnglish from './crawlEnglish';
|
|
4
|
-
import crawlFarsi from './crawlFarsi';
|
|
5
|
-
import crawlFrench from './crawlFrench';
|
|
6
|
-
import crawlGerman from './crawlGerman';
|
|
7
|
-
import crawlPolish from './crawlPolish';
|
|
8
|
-
import crawlRomanian from './crawlRomanian';
|
|
9
|
-
import crawlSpanish from './crawlSpanish';
|
|
10
|
-
|
|
11
|
-
const crawlPerLocale: Record<Locale, (word: string) => Promise<string>> = {
|
|
12
|
-
[Locale.DE_DE]: crawlGerman,
|
|
13
|
-
[Locale.EN_GB]: crawlEnglish,
|
|
14
|
-
[Locale.EN_US]: crawlEnglish,
|
|
15
|
-
[Locale.ES_ES]: crawlSpanish,
|
|
16
|
-
[Locale.FA_IR]: crawlFarsi,
|
|
17
|
-
[Locale.FR_FR]: crawlFrench,
|
|
18
|
-
[Locale.PL_PL]: crawlPolish,
|
|
19
|
-
[Locale.RO_RO]: crawlRomanian,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const crawl = (locale: Locale, word: string): Promise<string> => {
|
|
23
|
-
return crawlPerLocale[locale](word);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export default crawl;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { request } from '../lib';
|
|
2
|
-
|
|
3
|
-
const crawlEnglish = (word: string): Promise<string> => {
|
|
4
|
-
return request({
|
|
5
|
-
protocol: 'https',
|
|
6
|
-
hostname: 'www.merriam-webster.com',
|
|
7
|
-
path: `/dictionary/${encodeURIComponent(word)}`,
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export default crawlEnglish;
|
package/src/crawl/crawlFarsi.ts
DELETED
package/src/crawl/crawlFrench.ts
DELETED
package/src/crawl/crawlGerman.ts
DELETED
package/src/crawl/crawlPolish.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { request } from '../lib';
|
|
2
|
-
|
|
3
|
-
const crawlRomanian = (word: string): Promise<string> => {
|
|
4
|
-
return request({
|
|
5
|
-
protocol: 'https',
|
|
6
|
-
hostname: 'dexonline.ro',
|
|
7
|
-
path: `/definitie/${encodeURIComponent(word)}`,
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export default crawlRomanian;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { request } from '../lib';
|
|
2
|
-
|
|
3
|
-
const crawlSpanish = (word: string): Promise<string> => {
|
|
4
|
-
return request({
|
|
5
|
-
protocol: 'https',
|
|
6
|
-
hostname: 'www.diccionarios.com',
|
|
7
|
-
path: `/diccionario/espanol/${encodeURIComponent(word)}`,
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export default crawlSpanish;
|
package/src/crawl/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { default as crawl } from './crawl';
|
|
2
|
-
export { default as crawlEnglish } from './crawlEnglish';
|
|
3
|
-
export { default as crawlFrench } from './crawlFrench';
|
|
4
|
-
export { default as crawlPolish } from './crawlPolish';
|
|
5
|
-
export { default as crawlSpanish } from './crawlSpanish';
|
|
6
|
-
export { default as crawlGerman } from './crawlGerman';
|
package/src/parse/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { default as parse } from './parse';
|
|
2
|
-
export { default as parseEnglish } from './parseEnglish';
|
|
3
|
-
export { default as parseFarsi } from './parseFarsi';
|
|
4
|
-
export { default as parseFrench } from './parseFrench';
|
|
5
|
-
export { default as parseGerman } from './parseGerman';
|
|
6
|
-
export { default as parsePolish } from './parsePolish';
|
|
7
|
-
export { default as parseRomanian } from './parseRomanian';
|
|
8
|
-
export { default as parseSpanish } from './parseSpanish';
|
package/src/parse/parse.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Locale } from '@scrabble-solver/types';
|
|
2
|
-
|
|
3
|
-
import { normalizeDefinition, unique } from '../lib';
|
|
4
|
-
import { ParseResult } from '../types';
|
|
5
|
-
|
|
6
|
-
import parseEnglish from './parseEnglish';
|
|
7
|
-
import parseFarsi from './parseFarsi';
|
|
8
|
-
import parseFrench from './parseFrench';
|
|
9
|
-
import parseGerman from './parseGerman';
|
|
10
|
-
import parsePolish from './parsePolish';
|
|
11
|
-
import parseRomanian from './parseRomanian';
|
|
12
|
-
import parseSpanish from './parseSpanish';
|
|
13
|
-
|
|
14
|
-
const parsePerLocale: Record<Locale, (html: string) => ParseResult> = {
|
|
15
|
-
[Locale.DE_DE]: parseGerman,
|
|
16
|
-
[Locale.EN_GB]: parseEnglish,
|
|
17
|
-
[Locale.EN_US]: parseEnglish,
|
|
18
|
-
[Locale.ES_ES]: parseSpanish,
|
|
19
|
-
[Locale.FA_IR]: parseFarsi,
|
|
20
|
-
[Locale.FR_FR]: parseFrench,
|
|
21
|
-
[Locale.PL_PL]: parsePolish,
|
|
22
|
-
[Locale.RO_RO]: parseRomanian,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const parse = (locale: Locale, html: string): ParseResult => {
|
|
26
|
-
const { definitions, exists } = parsePerLocale[locale](html);
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
definitions: unique(definitions.map(normalizeDefinition).filter(Boolean)),
|
|
30
|
-
exists,
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export default parse;
|
package/src/parse/parseFrench.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { load } from 'cheerio';
|
|
2
|
-
|
|
3
|
-
import { ParseResult } from '../types';
|
|
4
|
-
|
|
5
|
-
const parseFrench = (html: string): ParseResult => {
|
|
6
|
-
const $ = load(html);
|
|
7
|
-
const $definitions = $('.tlf_cdefinition');
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
definitions: Array.from($definitions).map((definition) => $(definition).text()),
|
|
11
|
-
exists: $('#vitemselected span').length > 0,
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default parseFrench;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|