-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor(lyra): removes natural as dependency
- Loading branch information
1 parent
0c142d0
commit d472a46
Showing
12 changed files
with
116 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ jest.config.js | |
*.html | ||
*.svg | ||
*.dpack | ||
get-imdb-dataset.mjs | ||
get-imdb-dataset.mjs | ||
**/tap-snapshots/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Language } from "./languages"; | ||
|
||
const splitRegex: Record<Language, RegExp> = { | ||
dutch: /[^a-z0-9_'-]+/gim, | ||
english: /[^a-z0-9_'-]+/gim, | ||
french: /[^a-z0-9äâàéèëêïîöôùüûœç-]+/gim, | ||
italian: /[^a-z0-9_'-]+/gim, | ||
norwegian: /[^a-z0-9_æøåÆØÅäÄöÖüÜ]+/gim, | ||
portugese: /[^a-zà-úÀ-Ú]/gim, | ||
russian: /[^a-zа-яА-ЯёЁ]+/gim, | ||
spanish: /[^a-zA-Zá-úÁ-ÚñÑüÜ]+/gim, | ||
swedish: /[^a-z0-9_åÅäÄöÖüÜ-]+/gim, | ||
}; | ||
|
||
export function tokenize(input: string, language: Language = "english") { | ||
const splitRule = splitRegex[language]; | ||
const tokens = input.toLowerCase().split(splitRule); | ||
return Array.from(new Set(trim(tokens))); | ||
} | ||
|
||
function trim(text: string[]): string[] { | ||
while (text[text.length - 1] === "") { | ||
text.pop(); | ||
} | ||
while (text[0] === "") { | ||
text.shift(); | ||
} | ||
return text; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export type Language = typeof SUPPORTED_LANGUAGES[number]; | ||
|
||
export const SUPPORTED_LANGUAGES = [ | ||
"dutch", | ||
"english", | ||
"french", | ||
"italian", | ||
"norwegian", | ||
"portugese", | ||
"russian", | ||
"spanish", | ||
"swedish", | ||
] as const; |
Oops, something went wrong.