@scrabble-solver/word-definitions 2.9.1 → 2.9.3
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/LICENSE +1 -1
- package/build/getWordDefinition.d.ts +1 -1
- package/build/getWordDefinition.js +3 -3
- package/build/lib/normalizeDefinition.js +3 -1
- package/build/parse/parse.js +2 -2
- package/build/parse/parseEnglish.js +7 -7
- package/build/parse/parseFrench.js +3 -6
- package/build/parse/parseGerman.js +54 -16
- package/build/parse/parsePolish.js +3 -6
- package/build/parse/parseSpanish.js +3 -6
- package/build/types.d.ts +1 -1
- package/package.json +5 -5
- package/src/getWordDefinition.ts +3 -3
- package/src/lib/normalizeDefinition.ts +4 -1
- package/src/parse/__tests__/expected/de-DE.hm.json +4 -0
- package/src/parse/__tests__/expected/de-DE.ho.json +9 -0
- package/src/parse/__tests__/expected/de-DE.kolla.json +4 -0
- package/src/parse/__tests__/expected/de-DE.vom.json +16 -0
- package/src/parse/__tests__/expected/en-US.awe.json +1 -1
- package/src/parse/__tests__/expected/en-US.pawn.json +1 -1
- package/src/parse/__tests__/expected/en-US.pawnee.json +1 -1
- package/src/parse/__tests__/expected/en-US.pean.json +1 -1
- package/src/parse/__tests__/expected/en-US.wiz.json +1 -1
- package/src/parse/__tests__/expected/es-ES.corma.json +1 -1
- package/src/parse/__tests__/expected/es-ES.portero.json +1 -1
- package/src/parse/__tests__/input/de-DE.hm.html +873 -0
- package/src/parse/__tests__/input/de-DE.ho.html +1144 -0
- package/src/parse/__tests__/input/de-DE.kolla.html +980 -0
- package/src/parse/__tests__/input/de-DE.vom.html +738 -0
- package/src/parse/parse.test.ts +4 -0
- package/src/parse/parse.ts +2 -2
- package/src/parse/parseEnglish.ts +8 -4
- package/src/parse/parseFrench.ts +3 -3
- package/src/parse/parseGerman.ts +71 -12
- package/src/parse/parsePolish.ts +3 -3
- package/src/parse/parseSpanish.ts +3 -3
- package/src/types.ts +1 -1
package/src/parse/parse.test.ts
CHANGED
|
@@ -10,6 +10,10 @@ export const readTestFile = (filepath: string): string => {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
const tests = [
|
|
13
|
+
{ locale: Locale.DE_DE, word: 'hm' },
|
|
14
|
+
{ locale: Locale.DE_DE, word: 'ho' },
|
|
15
|
+
{ locale: Locale.DE_DE, word: 'kolla' },
|
|
16
|
+
{ locale: Locale.DE_DE, word: 'vom' },
|
|
13
17
|
{ locale: Locale.EN_US, word: 'awe' },
|
|
14
18
|
{ locale: Locale.EN_US, word: 'pawn' },
|
|
15
19
|
{ locale: Locale.EN_US, word: 'pawnee' },
|
package/src/parse/parse.ts
CHANGED
|
@@ -19,11 +19,11 @@ const parsePerLocale: Record<Locale, (html: string) => ParseResult> = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const parse = (locale: Locale, html: string): ParseResult => {
|
|
22
|
-
const { definitions,
|
|
22
|
+
const { definitions, exists } = parsePerLocale[locale](html);
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
definitions: unique(definitions.map(normalizeDefinition).filter(Boolean)),
|
|
26
|
-
|
|
26
|
+
exists,
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
3
|
import { ParseResult } from '../types';
|
|
4
4
|
|
|
5
|
+
const DOES_NOT_EXIST_MESSAGE =
|
|
6
|
+
// eslint-disable-next-line max-len
|
|
7
|
+
"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
|
+
|
|
5
9
|
const parseEnglish = (html: string): ParseResult => {
|
|
6
|
-
const $ =
|
|
10
|
+
const $ = load(html);
|
|
7
11
|
$('strong.mw_t_bc').replaceWith(', ');
|
|
8
12
|
$('.text-lowercase').remove();
|
|
9
13
|
$('[id^=dictionary-entry]').find('.dtText > *:not(a)').remove();
|
|
10
14
|
const $definitions = $('[id^=dictionary-entry]').find('.dtText, .cxl-ref');
|
|
11
15
|
|
|
12
16
|
return {
|
|
13
|
-
definitions: Array.from($definitions).map((definition) => $(definition).text()),
|
|
14
|
-
|
|
17
|
+
definitions: Array.from($definitions).map((definition) => $(definition).text().replace(/\n/g, '')),
|
|
18
|
+
exists: $('.spelling-suggestion-text').text().trim() !== DOES_NOT_EXIST_MESSAGE,
|
|
15
19
|
};
|
|
16
20
|
};
|
|
17
21
|
|
package/src/parse/parseFrench.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
3
|
import { ParseResult } from '../types';
|
|
4
4
|
|
|
5
5
|
const parseFrench = (html: string): ParseResult => {
|
|
6
|
-
const $ =
|
|
6
|
+
const $ = load(html);
|
|
7
7
|
const $definitions = $('.tlf_cdefinition');
|
|
8
8
|
|
|
9
9
|
return {
|
|
10
10
|
definitions: Array.from($definitions).map((definition) => $(definition).text()),
|
|
11
|
-
|
|
11
|
+
exists: $('#vitemselected span').length > 0,
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
|
package/src/parse/parseGerman.ts
CHANGED
|
@@ -1,21 +1,80 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Cheerio, CheerioAPI, Element, load } from 'cheerio';
|
|
2
2
|
|
|
3
3
|
import { ParseResult } from '../types';
|
|
4
4
|
|
|
5
5
|
const parseGerman = (html: string): ParseResult => {
|
|
6
|
-
const $ =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const $ = load(html);
|
|
7
|
+
|
|
8
|
+
const definitions = [parseBedeutungsubersicht, parseBedeutungen, parseBedeutung].reduce<string[]>(
|
|
9
|
+
(results, parse) => (results.length === 0 ? parse($) : results),
|
|
10
|
+
[],
|
|
11
|
+
);
|
|
12
|
+
const exists = Array.from($('.label-danger')).every((label) => $(label).text() !== 'Hinweis');
|
|
13
|
+
|
|
14
|
+
return { definitions, exists };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const parseBedeutungsubersicht = ($: CheerioAPI): string[] => {
|
|
18
|
+
Array.from($('.bedeutungsuebersicht ol > li > a')).forEach((item) => {
|
|
19
|
+
$(item).text($(item).text().replace(/\n/g, ''));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
Array.from($('.bedeutungsuebersicht ol > li > ol > li')).forEach((item) => {
|
|
23
|
+
const text = `\n${$(item).text().replace(/\n/g, '')}`;
|
|
24
|
+
const $text = $(`<div>${text}</div>`);
|
|
25
|
+
$(item).replaceWith($text);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
Array.from($('.bedeutungsuebersicht ol > li > ol')).forEach((list) => {
|
|
29
|
+
const $list = $(list);
|
|
30
|
+
const html = $list.html() || '';
|
|
31
|
+
const $html = $(`<div>${html}</div>`);
|
|
32
|
+
const $prev = $list.prev('a');
|
|
33
|
+
|
|
34
|
+
if ($prev) {
|
|
35
|
+
$prev.append($html);
|
|
36
|
+
$(list).remove();
|
|
37
|
+
} else {
|
|
38
|
+
$(list).replaceWith($html);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return parseDefinitions($, $('.bedeutungsuebersicht ol > li'));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const parseBedeutung = ($: CheerioAPI): string[] => {
|
|
46
|
+
return parseDefinitions($, $('.dwdswb-lesart .dwdswb-definition-spezifizierung'));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const parseBedeutungen = ($: CheerioAPI): string[] => {
|
|
50
|
+
const definitions = parseDefinitions($, $('.dwdswb-lesart .dwdswb-definition'));
|
|
51
|
+
|
|
52
|
+
if (definitions.length > 0) {
|
|
53
|
+
return definitions;
|
|
13
54
|
}
|
|
14
55
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
56
|
+
const $references = $('.dwdswb-lesart .dwdswb-verweis');
|
|
57
|
+
const references = Array.from($references).reduce<string[]>((result, reference) => {
|
|
58
|
+
const html = reference.attribs['data-content'] || '<span />';
|
|
59
|
+
const values = $(html)
|
|
60
|
+
.text()
|
|
61
|
+
.split(';')
|
|
62
|
+
.map((value) => value.trim());
|
|
63
|
+
|
|
64
|
+
return result.concat(values);
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
return references;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const parseDefinitions = ($: CheerioAPI, $definitions: Cheerio<Element>) => {
|
|
71
|
+
return Array.from($definitions).map((definition) =>
|
|
72
|
+
$(definition)
|
|
73
|
+
.text()
|
|
74
|
+
.replace(/[ ]+/g, ' ')
|
|
75
|
+
.replace(/[ ]\n/g, '\n')
|
|
76
|
+
.replace(/^[0-9]+\.\s/g, ''),
|
|
77
|
+
);
|
|
19
78
|
};
|
|
20
79
|
|
|
21
80
|
export default parseGerman;
|
package/src/parse/parsePolish.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
3
|
import { ParseResult } from '../types';
|
|
4
4
|
|
|
5
5
|
const parsePolish = (html: string): ParseResult => {
|
|
6
|
-
const $ =
|
|
6
|
+
const $ = load(html);
|
|
7
7
|
const $header = $($('h1')[0]);
|
|
8
8
|
const $isAllowed = $header.next();
|
|
9
9
|
const $definitions = $header.next().next().next().next();
|
|
10
10
|
|
|
11
11
|
return {
|
|
12
12
|
definitions: $definitions.text().trim().split(/\d+\./),
|
|
13
|
-
|
|
13
|
+
exists: $isAllowed.text().trim().indexOf('dopuszczalne w grach') >= 0,
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
3
|
import { ParseResult } from '../types';
|
|
4
4
|
|
|
5
5
|
const parseSpanish = (html: string): ParseResult => {
|
|
6
|
-
const $ =
|
|
6
|
+
const $ = load(html);
|
|
7
7
|
$('.verdBold14 + .gris11 + .gris13').remove();
|
|
8
8
|
$('br + .gris13').remove();
|
|
9
9
|
$('.grisItalic13 + .gris13').remove();
|
|
@@ -28,7 +28,7 @@ const parseSpanish = (html: string): ParseResult => {
|
|
|
28
28
|
.filter(Boolean)
|
|
29
29
|
.map((definition) => definition.replace(/\s+\.$/g, ''))
|
|
30
30
|
.map((definition) => (definition.endsWith('.') ? definition : `${definition}.`)),
|
|
31
|
-
|
|
31
|
+
exists: $('.wrapper > p > strong').text() !== 'No se ha encontrado la palabra exacta',
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
34
|
|
package/src/types.ts
CHANGED