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

Non-ascii letters not recognised #24

Open
premasagar opened this issue May 8, 2018 · 2 comments
Open

Non-ascii letters not recognised #24

premasagar opened this issue May 8, 2018 · 2 comments

Comments

@premasagar
Copy link

premasagar commented May 8, 2018

For this simple query in Spanish, with empty stopwords (or with stopwords; it doesn't matter):

rake.generate("Cuantos años tienes?", {stopwords: []})

I get the error:

TypeError: Cannot read property 'forEach' of null
    at phraseList.forEach
    at Array.forEach
    at Rake.calculatePhraseScores

If I omit the stopwords, then there is no error, but the word "años" is incorrectly split up:

rake.generate("Cuantos años tienes?")

=> [ 'ños tienes', 'Cuantos' ]

I think the code is treating the ñ as a word-break character, leading to the word being split in the second example, and leading to the single character ñ being used as a whole phrase in the function calculatePhraseScores, which leads to the error in the first example. The wordList regex seems to be looking only for 0-9a-z as acceptable word characters, which will be incomplete.

@mmanriquezl
Copy link

It happens the same when the text has any tildes, meaning: áéíóú

@fmalk
Copy link

fmalk commented Mar 29, 2023

Late to the party, but on my own fork I'm testing changing this line

const wordList = phrase.match(/[,.!?;:/‘’“”]|\b[0-9a-z']+\b/gi);
as indicated by @premasagar to this:

phrase.match(/[,.!?;:/‘’“”]|\b[\p{L}\p{M}']+\b/giu);

Which is supports any Unicode letter and some unicode markings, basically making this code work with any language. See Regex Unicode

(Edit: forgot the backspace \p)

hbsardhara09 pushed a commit to hbsardhara09/node-rake-v2 that referenced this issue Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants