Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(nlp): Dutch added to contenful #1249

Merged
merged 3 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/botonic-plugin-contentful/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/botonic-plugin-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@nlpjs/lang-uk": "^4.17.0",
"@nlpjs/lang-sl": "^4.17.0",
"@nlpjs/lang-hu": "^4.17.0",
"@nlpjs/lang-nl": "^4.17.0",
"@nlpjs/ner": "^4.17.0",
"@nlpjs/similarity": "^4.17.0",
"@types/joi": "^14.3.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/botonic-plugin-contentful/src/nlp/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const CROATIAN = 'hr'
export const SLOVAK = 'sk'
export const SLOVENIAN = 'sl'
export const HUNGARIAN = 'hu'
export const DUTCH = 'nl'

export const SUPPORTED_LOCALES = [
SPANISH,
Expand All @@ -40,6 +41,7 @@ export const SUPPORTED_LOCALES = [
SLOVAK,
SLOVENIAN,
HUNGARIAN,
DUTCH,
]

export function checkLocale(locale: Locale): Locale {
Expand Down
5 changes: 5 additions & 0 deletions packages/botonic-plugin-contentful/src/nlp/stemmer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ const stemmers = new SingletonMap<Stemmer>({
const StemmerHu = require('@nlpjs/lang-hu/src/stemmer-hu')
return new StemmerHu()
},
[locales.DUTCH]: () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const StemmerNl = require('@nlpjs/lang-nl/src/stemmer-nl')
return new StemmerNl()
},
})

export function stemmerFor(locale: Locale): Stemmer {
Expand Down
146 changes: 146 additions & 0 deletions packages/botonic-plugin-contentful/src/nlp/stopwords/stopwords-nl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
//from https://github.com/axa-group/nlp.js/blob/master/packages/lang-nl/src/stopwords-nl.js
export const nlDefaultStopWords = [
'aan',
'af',
'al',
'alles',
'als',
'altijd',
'andere',
'ben',
'bij',
'daar',
'dan',
'dat',
'de',
'der',
'deze',
'die',
'dit',
'doch',
'doen',
'door',
'dus',
'een',
'eens',
'en',
'er',
'ge',
'geen',
'geweest',
'haar',
'had',
'heb',
'hebben',
'heeft',
'hem',
'het',
'hier',
'hij',
'hoe',
'hun',
'iemand',
'iets',
'ik',
'in',
'is',
'ja',
'je ',
'kan',
'kon',
'kunnen',
'maar',
'me',
'meer',
'men',
'met',
'mij',
'mijn',
'moet',
'na',
'naar',
'niet',
'niets',
'nog',
'nu',
'of',
'om',
'omdat',
'ons',
'ook',
'op',
'over',
'reeds',
'te',
'tegen',
'toch',
'toen',
'tot',
'u',
'uit',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to remove all 1 letters, only the full alphabet below

'uw',
'van',
'veel',
'voor',
'want',
'waren',
'was',
'wat',
'we',
'wel',
'werd',
'wezen',
'wie',
'wij',
'wil',
'worden',
'zal',
'ze',
'zei',
'zelf',
'zich',
'zij',
'zijn',
'zo',
'zonder',
'zou',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'$',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'_',
'-',
]
7 changes: 7 additions & 0 deletions packages/botonic-plugin-contentful/src/nlp/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { frDefaultStopWords } from './stopwords/stopwords-fr'
import { hrDefaultStopWords } from './stopwords/stopwords-hr'
import { huDefaultStopWords } from './stopwords/stopwords-hu'
import { itDefaultStopWords } from './stopwords/stopwords-it'
import { nlDefaultStopWords } from './stopwords/stopwords-nl'
import { plDefaultStopWords } from './stopwords/stopwords-pl'
import { ptDefaultStopWords } from './stopwords/stopwords-pt'
import { roDefaultStopWords } from './stopwords/stopwords-ro'
Expand Down Expand Up @@ -168,6 +169,11 @@ const lazyTokenizers = new SingletonMap<Tokenizer>({
const TokenizerHu = require('@nlpjs/lang-hu/src/tokenizer-hu')
return new TokenizerHu()
},
[locales.DUTCH]: () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const TokenizerNl = require('@nlpjs/lang-nl/src/tokenizer-nl')
return new TokenizerNl()
},
})

export function tokenizerPerLocale(locale: Locale): Tokenizer {
Expand Down Expand Up @@ -203,6 +209,7 @@ export const DEFAULT_STOP_WORDS: { [key: string]: string[] } = {
sk: skDefaultStopWords,
sl: slDefaultStopWords,
hu: huDefaultStopWords,
nl: nlDefaultStopWords,
}

export function stopWordsFor(locale: string): string[] {
Expand Down
14 changes: 14 additions & 0 deletions packages/botonic-plugin-contentful/src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,20 @@ declare module '@nlpjs/lang-hu/src/stemmer-hu' {
export = StemmerHu
}

declare module '@nlpjs/lang-nl/src/tokenizer-nl' {
import Tokenizer from '@nlpjs/core/src/tokenizer'

class TokenizerNl extends Tokenizer {}
export = TokenizerNl
}

declare module '@nlpjs/lang-nl/src/stemmer-nl' {
import BaseStemmer from '@nlpjs/core/src/base-stemmer'

class StemmerNl extends BaseStemmer {}
export = StemmerNl
}

declare module 'sort-stream' {
function sort(func: (a: any, b: any) => number): any
export = sort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ test.each<any>([
new Word('hulyeseget', 'hulyeseg'),
],
],
[
'nl',
'ik ga winkelen',
[Word.StopWord('ik'), new Word('ga', 'ga'), new Word('winkelen', 'winkel')],
],
])(
'TEST: stemmer removes stopwords: lang=%s input="%j"',
(locale: string, raw: string, words: Word[]) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/botonic-plugin-contentful/tests/nlp/stemmer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ test.each<any>([
['sl', 'hoditi', ['hodit']],
['hu', 'Európai', ['europ']],
['hu', 'érvelni', ['erveln']],
['nl', 'beklimmen', ['beklimm']],
['nl', 'rennen', ['renn']],
])(
'TEST: stemmer removes final letters(%s) =>%j',
(locale: string, raw: string, expected: string) => {
Expand Down