How to tokenize Japanese in Python
dampfkraft.com
dampfkraft.com
https://github.com/polm/fugashi/issues/23
(Also, if you learned about Chrome's Japaense tokenization on HN, that was me too!)
Do languages like German which is rife with compound words have any overlap in tokenization or do you end up with completely different strategies?
For German, the task is much easier, since most words are already separated by spaces, so only compound nouns might be problematic, but it's rare for those to have more than one possible segmentation. (There are of course exceptions, like e.g. Wachstube, which could be either Wach-Stube or Wachs-Tube. EDIT for non-German speakers: cognates are watch-stove = guardroom, wax-tube = tube of wax.)
Ofc in chinese (and japanese) the ambiguity is much higher. Especially when abbreviation comes into the mix
This is how humans do it though. https://pingtype.github.io/docs/advanced.html#spacing
If you have some Chinese text that you want to read, throw it into Pingtype (my program) and it should help you to pick up the vocabulary! https://pingtype.github.io/
Humans do a bit more than simple prefix matching, though. E.g. most people won't read 有权利 as 有权/利 because that doesn't make much sense.
alright programmer question: why was the magic number 5? Are there no chinese words that are longer than 5 characters? Or does 5 characters cover 99.999% of all possible cases, and is therefore "good enough"?
There are some words that are longer (e.g. Mesopotamia) but in practice those are basically all proper nouns.
Maybe that's intended but then apparently this is pointless if you want to know how things are pronounced.
UniDic has a rule that a "word" (or a "short unit word" 短単位, the unit used in UniDic) can't be more than two "minimal units", where an example of a minimal unit is a kanji with a Chinese reading. So 麩菓子 can't be a word, and in this case it's 菓子 with 麩 on the front.
You can read more about short unit words here.
https://unidic.ninjal.ac.jp/glossary#suw
It's not a perfect tradeoff, and I think it can be improved, but it does have its advantages.
It is my observation that the programmer of native Indo-European languages tend to have a delusion that their native language is so fundamental that any language processing they deemed necessary must be applied to the any and all languages in the world.
Which cause the locale library in most programming languages tend to have a feature that's unfit for Japanese and it break the Japanese. Yes, the presence of the locale library break the Japanese language support.
These locale libraries modify the string binary and break the Japanese encoding. You can't easily implement no-op local for Japanese because these modification are often cause by the fundamental common part of the library rather than language specific part.
People have a good intention. They want to support multiple languages. but it's a delusion that passing the string binary to locale library magically solve the problem. The locale libraries were often written badly for Japanese so it break the Japanese. I would like to call it locale-tainted.
Since The locale library is part of the standard library of the programming languages and many software relies on it. We can't just avoid using locale library without massive refactoring of the source code which is impossible given the available resource for localization. So if we, the unfortunate Japanese programmer, got a job of localizing locale-tainted existing software to Japanese, we have to come up some workarounds.
Modifying the source code to remove the locale library usage is the best but often not possible. Hooking locale library to replace it with Japanese-safe version are dirty workaround but it requires to reimplement most of the text manipulation which cost many man-monthes and rigorous testing, Imagine implementing a printf/regex library to replace the standard library that satisfy all the use case in the wild. The worst workaround is let the stupid locale library do whatever the stupid Japanese breaking string binary transformation they damn want, then, reverse-transform after the string binary passing through the locale library to fix the mess. A mess that was unnecessary in the first place.
I was involved in C++ Standard Committee but people out there are so delusional they think it's a good idea for a new standard library to depend on broken locale library because it help the localization. Those delusional people are also designing Unicode library now. They won't fart out a good library under such delusion. I lost all hope for this industry.
So please. Don't introduce stupid unnecessary language processing to the language you don't understand. Make our job less horrible.
> These locale libraries modify the string binary and break the Japanese encoding. You can't easily implement no-op local for Japanese because these modification are often cause by the fundamental common part of the library rather than language specific part.
Can you give an example of a situation where that happens? Is it an issue with e.g Shift-JIS encoding vs. Unicode?