You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have used this tokenizer with this test string:
"जब मैंने सुबह उठकर खिड़की खोली तो मैंने देखा कि बाहर एक सुंदर सा पक्षी गुनगुनाते हुए पेड़ की डाल पर बैठा था, जिसका रंग सुनहरा था और जिसकी आँखें चमकदार नीली थीं, वह इतना खूबसूरत था कि मैं उसे देखकर मंत्रमुग्ध हो गया।"
And got:
[]string{
"जब",
"म",
"\xe0",
"\xa5",
"\x88",
"\xe0",
"\xa4",
"\x82",
"न",
"\xe0",
"\xa5",
"\x87",
"स",
// and so on
}
In indexes where diacritics are expected there seems to be several separated one-byte long sequence.
So, if I understand correctly this string tokenizer does not try to honor Unicode codepoint/grapheme boundaries in the byte sequence and therefore it is primarily meant for escaped, ASCII-like content right?
It would be nice to have it mentioned in the description that these unicode boundaries are not considered. (github.com/rivo/uniseg seems to be the tool for that).
func (p*TokenizerProvider) process(chunks []string) (common.AnyTokenSliceWrapper, error) {
tsw:=&common.TknSliceWrapper{}
// chunks is []string{testString}for_, chunk:=rangechunks {
stream:=p.instance.ParseString(chunk)
deferstream.Close()
forstream.IsValid() {
token:=stream.CurrentToken()
// the []string provided in the issue comes from the Surfaces of all the tokens of tswcommonToken:= common.Tkn{
Surface: token.ValueString(),
}
tsw.Append(commonToken)
stream.GoNext()
}
}
returntsw, nil
}
Can I use the string जब मैंने सुबह उठकर खिड़की खोली तो मैंने देखा कि बाहर एक सुंदर सा पक्षी गुनगुनाते हुए पेड़ की डाल पर बैठा था, जिसका रंग सुनहरा था और जिसकी आँखें चमकदार नीली थीं, वह इतना खूबसूरत था कि मैं उसे देखकर मंत्रमुग्ध हो गया। in tests? Not needed
Ok, after some investigation I found out that current bug is not a bug. I mean, that for golang's unicode any Devanagari Sign is not a letters (unicode.IsLetter(DevanagariSign) == false). By this reason any Devanagari Sign parsed as unknown token and broke keywords as you wrote. To solve the problem you have to add all Devanagari Signs to keyword symbols:
Interesting! I personally have end up using uniseg's FirstWordInString because I need to support arbitrary language scripts and it seems to handle things at grapheme level and but it would be useful to mention this caveat on the README for future users.
Activity
bzick commentedon Jan 19, 2025
Unicode should works. Can you provide the code of parsing (I'll check configuration) and usage (I'll check used functions)?
tassa-yoniso-manasi-karoto commentedon Jan 19, 2025
My code was something like this:
bzick commentedon Jan 20, 2025
Yep, it's a bug with unicode detection.
Bug found and will be fixed ASAPContinuing my investigations.bzick commentedon Jan 20, 2025
Can I use the stringNot neededजब मैंने सुबह उठकर खिड़की खोली तो मैंने देखा कि बाहर एक सुंदर सा पक्षी गुनगुनाते हुए पेड़ की डाल पर बैठा था, जिसका रंग सुनहरा था और जिसकी आँखें चमकदार नीली थीं, वह इतना खूबसूरत था कि मैं उसे देखकर मंत्रमुग्ध हो गया।in tests?bzick commentedon Jan 20, 2025
Ok, after some investigation I found out that current bug is not a bug. I mean, that for golang's unicode any
Devanagari Signis not a letters (unicode.IsLetter(DevanagariSign) == false). By this reason anyDevanagari Signparsed as unknown token and broke keywords as you wrote. To solve the problem you have to add allDevanagari Signsto keyword symbols:(I am not sure that Devanagari Sign can be first rune in a word)
tassa-yoniso-manasi-karoto commentedon Jan 21, 2025
Interesting! I personally have end up using uniseg's FirstWordInString because I need to support arbitrary language scripts and it seems to handle things at grapheme level and but it would be useful to mention this caveat on the README for future users.
bzick commentedon Jan 21, 2025
I think I will add maker(sign) support as a settings via
unicode.IsMarker()#34 add diacritic support
#34 add diacritic support