elifinkelshteyn / alphabet-detector Goto Github PK
View Code? Open in Web Editor NEWA library to detect what alphabet something is written in.
License: MIT License
A library to detect what alphabet something is written in.
License: MIT License
This doesn't work for me(currently in the reamde):
from alphabet_detector import AlphabetDetector
ad = AlphabetDetector()
Should be this way:
from alphabet_detector.alphabet_detector import AlphabetDetector
ad = AlphabetDetector()
My text is:
'ÃÄÂ ÃÁÁÁÁÁÁÂÈÄÂÆ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03\x17.\x04 \x11\x03\x17\x19;\x11 \x11\x03!\x04\x17\x04 \x18\x04\x11/\x03\x11\x03$10.$/ \x9b\x9b\x9b\x9b\nÃÄÃ ÊÊÁÂÁÉÅÈÅÂ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03\x18\x11 \x11"$\x03\x0f\x11\x03\x04//\x19/\x03/$1;\x04\x03!$"0\x11\x19.$\x03\x11\x03$1 \x9b\x9b\x9b\x9b\nÃÄÄ ÂÊÊÊÁÂÂÇÆÁÄÄ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 .$ /$"\x03 \x04"\x0f\x19\x0f$\x03\x0f\x11\x03\x04.\x041\x1e$\x03\x11\x03$10.$/\x03\x9b\x03\x0f$!\x19"\x17$/\x03\x17$!\x11/\x03\x0f\x11\x03\x040\x04\x19\x0f\x11/ ÂÇÉÆÁ\x03\x03\x17$\x03\x9f\x03\x04"0$"\x19$\x03\x04 6\x11/\x03!\x04 \x18\x04\x0f$\x9bÁÁÁÁ\x03\x03\x03\x17$\x03\x9f\x03 \x11 /$\x03!\x04"$\x11 \x03\x16\x04 \x18\x04\x0f\x04\x9b\x9b\x9b\nÃÄÅ ÂÊÊÊÁÂÂÇÆÃÃÁ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03\x1e$6\x11. \x19\x03\x17$!\x11/\x03\x0f\x11\x03/$1/\x04 \x9b\x9b\x9b\x9b\nÃÄÆ ÂÊÊÊÁÂÂÇÆÆÅÉ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x04 .\x04\x04$\x03\x17$";\x04\x17\x04\x03\x0f\x04\x03/\x19 6\x04\x03\x9b\x03\x1e$/\x11\x03\x16\x04\x171"\x0f\x11/\x03\x0f\x11\x03/$1;\x04 \x9b\x9b\x9b\x9b\nÃÄÇ ÂÊÊÊÁÂÃÇÁÈÂÁ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x17\x19 !\x04.\x03!\x04.0\x19"/\x03 1/0$\x0f\x19$\x03\x9b\x03\x1e$.\x17\x11\x03!$\x18\x04!!\x04\x0f\x03\x181//\x11\x19" \x9b\x9b\x9b\x9b\nÃÄÈ ÂÊÊÊÁÂÄÂÁÁÂÈ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x04"0$"\x19$\x03\x16.\x04" \x19/
$\x03\x0f$ /\x03/\x04"0$/\x03\x9b\x03\x17\x11.\x04 \x0f$\x03\x16.\x04" \x19/$\x03\x0f$ /\x03/\x04"0$/ ÂÂÆÉÂ\x03\x03\x17$\x03\x9f\x03\x11."\x11/0$\x03\x171\x19!\x04.\x04\x11/\x03.$ \x11.\x9bÂÂÆÉÂ\x03\x03\x17$\x03\x9f\x03\x11."\x11/0$\x03\x171\x19!\x04.\x04\x11/\x03.$ \x11.\x9b\x9b\x9b\nÃÄÉ ÂÊÊÊÁÂÄÅÇÂÄÆ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03$\x0f\x04\x19.\x03\x04!\x11.\x19 $\x03\x0f\x11\x03/$1/\x04 \x9b\x9b\x9b\x9b\nÃÄÊ ÊÈÁÂÁÁÇÂÄÆ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e$\x04-1\x19!\x03\x17\x11.\x04 \x0f$\x03\x0f\x04\x03 1"\x18\x04\x03\x9b\x03!\x04. \x19\x04"$\x03\x04\x0f$.9\x04"\x03\x11\x03$10.$/ \x9b\x9b\x9b\x9b\nÃÅÁ ÂÊÊÊÁÂÅÄÅÊÆÇ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 /\x19 6\x19$\x03\x16\x11."\x04"\x0f\x11/\x03\x0f\x11\x03!\x19.\x04"\x0f\x04\x03\x9b\x03\x04\x0f\x04 0$\x03$+\x11/\x03!\x04.0\x19"/ ÇÉÊÄ\x03\x03\x03\x17$ \x03\x9f\x03\x1e$/\x11\x03"1"\x11/\x03\x0f\x11\x03/$1;\x04\x9b\x9b\x9b\x9b\nÃÅÂ ÂÊÊÊÁÂÅÈÆÃÂÁ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03\x11\x0f/$"\x03\x1e$/\x11\x03\x0f\x11\x03$ \x196\x11\x19.\x04 \x9b\x9b\x9b\x9b\nÃÅÃ ÂÊÊÊÁÂÆÂÅÆÊÄ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03.$\x0f.\x19\x17$\x03"$ .\x11\x03\x0f\x04\x03/\x19 6\x04 \x9b\x9b\x9b\x9b\nÃÅÄ ÂÊÊÊÁÂÆÂÊÈÅÊ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04$/!\x04.\x03+\x19"0$ \x03\x0f\x11\x03!\x11$\x03\x9b\x03 \x11$ !\x04.\x03\x17$";\x04\x17\x04\x03\x0f\x11\x03/$1/\x04 \x9b\x9b\x9b\x9b\nÃÅÅ ÂÊÊÊÁÂÆÃÅÊÈÂ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03\x1e$/\x11\x16\x19\x03\x1f \x11 \x11.\x03.$\x0f.\x19\x171\x11/\x03 \x04.\x0f$/$ ÆÁÉÅ\x03\x03\x03\x17$\x03\x9f\x03\x04"0$"\x19$\x037\x04"\x0f\x11. \x04\x04"\x03 \x040\x19/0\x04\x9b\x9b\x9b\x9b\nÃÅÆ ÂÊÊÊÁÂÇÂÁÄÉÁ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 .$!\x19 /$"\x03 \x04"\x0f\x19\x0f$\x03\x0f\x11\x03\x04.\x041\x1e$\x03\x9b\x03\x04"0$"\x19$\x03 \x04.$/\x03 \x04.\x0f$ /$ \x9b\x9b\x9b\x9b\nÃÅÇ ÂÊÊÊÁÂÇÅÈÈÅÈ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03+\x041 $\x03\x04 6\x11/\x03\x0f\x04\x03!$0\x04\x03\x11\x03$10.$/ ÆÁÉÅ\x03\x03\x03\x17$\x03\x9f\x03\x04"0$"\x19$\x037\x04"\x0f\x11. \x04\x04"\x03 \x040\x19/0\x04\x9b\x9b\x9b\x9b\nÃÅÈ ÂÊÊÊÁÃÁÅÂÆÆÊ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03\x1e$\x04$\x03\x04 \x11.0$\x03 \x04.\x0f$/$\x03"1"\x11/ \x9b\x9b\x9b\x9b\nÃÅÉ ÂÊÊÊÁÂÈÄÃÉÊÃ Â\x04\x036\x04.\x04\x03 .\x19!\x19"\x04 \x16$.!$/\x04 \x1e1/0\x19 \x04\x03+1 \x19 \x04\x03\x9b\x03\x04 \x11//\x04"\x0f.$\x03.$\x0f.\x19\x171\x11/\x03\x0f\x11\x03$ \x196\x11\x19.\x04 ÂÈÂÉÊ\x03\x03\x17$\x03\x9f\x03\x04"\x0f.\x11\x03 1 \x19$\x03!\x11"\x0f\x11/\x03\x0f\x11\x03$ \x196\x11\x19.\x04\x9b\x9b\x9b\x9b\nANO XIV - EDIÇÃO Nº 3243 Suplemento - SEÇÃO I DISPONIBILIZAÇÃO: terça-feira, 01/06/2021'
Code:
ad.detect_alphabet(text)
Ouput:
{'LATIN', 'MASCULINE'}
How to obtain only russian words? Using CYRILLIC
I also get something like ќе
and ївка
, etc.
>>> alphabet_detector.is_cjk("無限")
True
>>> alphabet_detector.is_cjk("無限を分")
False
>>> alphabet_detector.is_cjk("を分")
False
>>> alphabet_detector.is_cjk("分")
True
>>> alphabet_detector.is_cjk("を")
False
Kanji returns true for CJK, but not hiragana or katakana.
From the code I can see there are only selected languages supported. Would be nice to see what languages are supported and raise an error/warning if the langauge is not supported. Right now, a bool is returned on ENGLISH
.
Not sure if by default all the languages are support. Correct me if I am wrong.
Add tests with py.test.
Korean Hangul characters are marked as false when is_cjk(korean_text_here) is run.
Sometimes one would not need to iterate over the complete string, when the only thing of interest is if a string contains at least one character of a given type.
Thus a function like this would be convenient:
ad.contains_alphabet_chars(u'100 漢字', 'CJK')
I know, that the following does already work, but this will iterate over the complete string:
'CJK' in ad.detect_alphabet(u'100 漢字')
Hello Eli!
I would like to cite your code on a paper, if that's ok with you. Could you add a citation file so that I can do that through github's UI? Thanks!
I dont know if this is a desired behavior, but when i run only_alphabet_chars on an empty string it always returns True.
Since this is no character I would expect to return None of False.
ad = AlphabetDetector()
print(ad.only_alphabet_chars('', 'LATIN'))
print(ad.only_alphabet_chars('', 'GREEK'))
Hi, thanks for designing this small useful alphabet detecting package. It works good enough for me, but I noticed the ad.__dict__
instance variable. The body of this dictionary is basically of the form:
{'LATIN': {'ε': False, 'm': True, 'e': True, 'a': True, 'n': True, 's': True, 'g': True, 'r': True}}
Would it be more efficient if we store it like the following:
{'LATIN': {'m', 'g', 'k', 'e'}, 'GREEK': {'ε', 'λ', 'ά'}, 'CJK': {'你', '好'}}
I know it took its current structure because you wrapped up the discussion in a StackExchange thread, but I think as the number of queries increases, the former dictionary will be very memory consuming, while the latter should save memory and also be efficient in time?
Hope to have more discussion!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.