cchardet 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.gitmodules +3 -0
- data/.rubocop.yml +11 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/README.md +35 -0
- data/Rakefile +15 -0
- data/cchardet.gemspec +30 -0
- data/ext/cchardet/extconf.rb +26 -0
- data/ext/uchardet/.gitignore +1 -0
- data/ext/uchardet/.gitlab-ci.yml +106 -0
- data/ext/uchardet/AUTHORS +16 -0
- data/ext/uchardet/CMakeLists.txt +74 -0
- data/ext/uchardet/COPYING +1316 -0
- data/ext/uchardet/INSTALL +26 -0
- data/ext/uchardet/README.md +295 -0
- data/ext/uchardet/build-mac/uchardet.cpp +7 -0
- data/ext/uchardet/build-mac/uchardet.xcodeproj/project.pbxproj +543 -0
- data/ext/uchardet/build-mac/uchardet.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/ext/uchardet/build-mac/uchardet.xcodeproj/project.xcworkspace/xcshareddata/uchardet.xccheckout +41 -0
- data/ext/uchardet/build-mac/uchardet.xcodeproj/xcshareddata/xcschemes/uchardet-ios.xcscheme +77 -0
- data/ext/uchardet/build-mac/uchardet.xcodeproj/xcshareddata/xcschemes/uchardet.xcscheme +77 -0
- data/ext/uchardet/doc/CMakeLists.txt +6 -0
- data/ext/uchardet/doc/README.maintainer +59 -0
- data/ext/uchardet/doc/uchardet.1 +18 -0
- data/ext/uchardet/script/BuildLangModel.py +533 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangArabicModel.log +142 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangCroatianModel.log +157 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangCzechModel.log +161 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangDanishModel.log +158 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangEsperantoModel.log +110 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangEstonianModel.log +159 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangFinnishModel.log +156 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangFrenchModel.log +116 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangGermanModel.log +159 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangGreekModel.log +272 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangHungarianModel.log +109 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangIrishModel.log +156 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangItalianModel.log +162 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangLatvianModel.log +162 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangLithuanianModel.log +162 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangMalteseModel.log +147 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangPolishModel.log +154 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangPortugueseModel.log +166 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangRomanianModel.log +153 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangSlovakModel.log +158 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangSloveneModel.log +148 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangSpanishModel.log +109 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangSwedishModel.log +151 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangThaiModel.log +141 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangTurkishModel.log +113 -0
- data/ext/uchardet/script/BuildLangModelLogs/LangVietnameseModel.log +121 -0
- data/ext/uchardet/script/README +63 -0
- data/ext/uchardet/script/charsets/codepoints.py +53 -0
- data/ext/uchardet/script/charsets/db.py +73 -0
- data/ext/uchardet/script/charsets/ibm852.py +72 -0
- data/ext/uchardet/script/charsets/iso-8859-1.py +85 -0
- data/ext/uchardet/script/charsets/iso-8859-10.py +73 -0
- data/ext/uchardet/script/charsets/iso-8859-11.py +77 -0
- data/ext/uchardet/script/charsets/iso-8859-13.py +72 -0
- data/ext/uchardet/script/charsets/iso-8859-15.py +80 -0
- data/ext/uchardet/script/charsets/iso-8859-16.py +83 -0
- data/ext/uchardet/script/charsets/iso-8859-2.py +73 -0
- data/ext/uchardet/script/charsets/iso-8859-3.py +75 -0
- data/ext/uchardet/script/charsets/iso-8859-4.py +73 -0
- data/ext/uchardet/script/charsets/iso-8859-6.py +73 -0
- data/ext/uchardet/script/charsets/iso-8859-7.py +73 -0
- data/ext/uchardet/script/charsets/iso-8859-9.py +76 -0
- data/ext/uchardet/script/charsets/mac-centraleurope.py +72 -0
- data/ext/uchardet/script/charsets/tis-620.py +77 -0
- data/ext/uchardet/script/charsets/viscii.py +72 -0
- data/ext/uchardet/script/charsets/windows-1250.py +75 -0
- data/ext/uchardet/script/charsets/windows-1252.py +76 -0
- data/ext/uchardet/script/charsets/windows-1253.py +72 -0
- data/ext/uchardet/script/charsets/windows-1256.py +75 -0
- data/ext/uchardet/script/charsets/windows-1257.py +72 -0
- data/ext/uchardet/script/charsets/windows-1258.py +72 -0
- data/ext/uchardet/script/debug.sh +9 -0
- data/ext/uchardet/script/header-template.cpp +38 -0
- data/ext/uchardet/script/langs/ar.py +59 -0
- data/ext/uchardet/script/langs/cs.py +80 -0
- data/ext/uchardet/script/langs/da.py +69 -0
- data/ext/uchardet/script/langs/de.py +69 -0
- data/ext/uchardet/script/langs/el.py +55 -0
- data/ext/uchardet/script/langs/eo.py +67 -0
- data/ext/uchardet/script/langs/es.py +69 -0
- data/ext/uchardet/script/langs/et.py +57 -0
- data/ext/uchardet/script/langs/fi.py +60 -0
- data/ext/uchardet/script/langs/fr.py +79 -0
- data/ext/uchardet/script/langs/ga.py +60 -0
- data/ext/uchardet/script/langs/hr.py +59 -0
- data/ext/uchardet/script/langs/hu.py +66 -0
- data/ext/uchardet/script/langs/it.py +56 -0
- data/ext/uchardet/script/langs/lt.py +70 -0
- data/ext/uchardet/script/langs/lv.py +69 -0
- data/ext/uchardet/script/langs/mt.py +80 -0
- data/ext/uchardet/script/langs/pl.py +81 -0
- data/ext/uchardet/script/langs/pt.py +80 -0
- data/ext/uchardet/script/langs/ro.py +65 -0
- data/ext/uchardet/script/langs/sk.py +80 -0
- data/ext/uchardet/script/langs/sl.py +59 -0
- data/ext/uchardet/script/langs/sv.py +56 -0
- data/ext/uchardet/script/langs/th.py +55 -0
- data/ext/uchardet/script/langs/tr.py +67 -0
- data/ext/uchardet/script/langs/vi.py +64 -0
- data/ext/uchardet/script/release.sh +8 -0
- data/ext/uchardet/script/win32.sh +7 -0
- data/ext/uchardet/src/Big5Freq.tab +943 -0
- data/ext/uchardet/src/CMakeLists.txt +160 -0
- data/ext/uchardet/src/CharDistribution.cpp +109 -0
- data/ext/uchardet/src/CharDistribution.h +242 -0
- data/ext/uchardet/src/EUCKRFreq.tab +614 -0
- data/ext/uchardet/src/EUCTWFreq.tab +447 -0
- data/ext/uchardet/src/GB2312Freq.tab +491 -0
- data/ext/uchardet/src/JISFreq.tab +589 -0
- data/ext/uchardet/src/JpCntx.cpp +230 -0
- data/ext/uchardet/src/JpCntx.h +140 -0
- data/ext/uchardet/src/LangModels/LangArabicModel.cpp +267 -0
- data/ext/uchardet/src/LangModels/LangBulgarianModel.cpp +249 -0
- data/ext/uchardet/src/LangModels/LangCroatianModel.cpp +298 -0
- data/ext/uchardet/src/LangModels/LangCzechModel.cpp +285 -0
- data/ext/uchardet/src/LangModels/LangDanishModel.cpp +201 -0
- data/ext/uchardet/src/LangModels/LangEsperantoModel.cpp +142 -0
- data/ext/uchardet/src/LangModels/LangEstonianModel.cpp +268 -0
- data/ext/uchardet/src/LangModels/LangFinnishModel.cpp +297 -0
- data/ext/uchardet/src/LangModels/LangFrenchModel.cpp +209 -0
- data/ext/uchardet/src/LangModels/LangGermanModel.cpp +170 -0
- data/ext/uchardet/src/LangModels/LangGreekModel.cpp +231 -0
- data/ext/uchardet/src/LangModels/LangHebrewModel.cpp +220 -0
- data/ext/uchardet/src/LangModels/LangHungarianModel.cpp +171 -0
- data/ext/uchardet/src/LangModels/LangIrishModel.cpp +234 -0
- data/ext/uchardet/src/LangModels/LangItalianModel.cpp +269 -0
- data/ext/uchardet/src/LangModels/LangLatvianModel.cpp +210 -0
- data/ext/uchardet/src/LangModels/LangLithuanianModel.cpp +209 -0
- data/ext/uchardet/src/LangModels/LangMalteseModel.cpp +138 -0
- data/ext/uchardet/src/LangModels/LangPolishModel.cpp +304 -0
- data/ext/uchardet/src/LangModels/LangPortugueseModel.cpp +241 -0
- data/ext/uchardet/src/LangModels/LangRomanianModel.cpp +236 -0
- data/ext/uchardet/src/LangModels/LangRussianModel.cpp +367 -0
- data/ext/uchardet/src/LangModels/LangSlovakModel.cpp +293 -0
- data/ext/uchardet/src/LangModels/LangSloveneModel.cpp +264 -0
- data/ext/uchardet/src/LangModels/LangSpanishModel.cpp +204 -0
- data/ext/uchardet/src/LangModels/LangSwedishModel.cpp +266 -0
- data/ext/uchardet/src/LangModels/LangThaiModel.cpp +267 -0
- data/ext/uchardet/src/LangModels/LangTurkishModel.cpp +175 -0
- data/ext/uchardet/src/LangModels/LangVietnameseModel.cpp +249 -0
- data/ext/uchardet/src/nsBig5Prober.cpp +88 -0
- data/ext/uchardet/src/nsBig5Prober.h +75 -0
- data/ext/uchardet/src/nsCharSetProber.cpp +125 -0
- data/ext/uchardet/src/nsCharSetProber.h +77 -0
- data/ext/uchardet/src/nsCodingStateMachine.h +105 -0
- data/ext/uchardet/src/nsEUCJPProber.cpp +99 -0
- data/ext/uchardet/src/nsEUCJPProber.h +79 -0
- data/ext/uchardet/src/nsEUCKRProber.cpp +91 -0
- data/ext/uchardet/src/nsEUCKRProber.h +81 -0
- data/ext/uchardet/src/nsEUCTWProber.cpp +91 -0
- data/ext/uchardet/src/nsEUCTWProber.h +75 -0
- data/ext/uchardet/src/nsEscCharsetProber.cpp +101 -0
- data/ext/uchardet/src/nsEscCharsetProber.h +70 -0
- data/ext/uchardet/src/nsEscSM.cpp +267 -0
- data/ext/uchardet/src/nsGB2312Prober.cpp +96 -0
- data/ext/uchardet/src/nsGB2312Prober.h +77 -0
- data/ext/uchardet/src/nsHebrewProber.cpp +194 -0
- data/ext/uchardet/src/nsHebrewProber.h +177 -0
- data/ext/uchardet/src/nsLatin1Prober.cpp +182 -0
- data/ext/uchardet/src/nsLatin1Prober.h +73 -0
- data/ext/uchardet/src/nsMBCSGroupProber.cpp +242 -0
- data/ext/uchardet/src/nsMBCSGroupProber.h +81 -0
- data/ext/uchardet/src/nsMBCSSM.cpp +513 -0
- data/ext/uchardet/src/nsPkgInt.h +89 -0
- data/ext/uchardet/src/nsSBCSGroupProber.cpp +343 -0
- data/ext/uchardet/src/nsSBCSGroupProber.h +71 -0
- data/ext/uchardet/src/nsSBCharSetProber.cpp +160 -0
- data/ext/uchardet/src/nsSBCharSetProber.h +258 -0
- data/ext/uchardet/src/nsSJISProber.cpp +98 -0
- data/ext/uchardet/src/nsSJISProber.h +81 -0
- data/ext/uchardet/src/nsUTF8Prober.cpp +87 -0
- data/ext/uchardet/src/nsUTF8Prober.h +66 -0
- data/ext/uchardet/src/nsUniversalDetector.cpp +339 -0
- data/ext/uchardet/src/nsUniversalDetector.h +91 -0
- data/ext/uchardet/src/nscore.h +59 -0
- data/ext/uchardet/src/prmem.h +49 -0
- data/ext/uchardet/src/symbols.cmake +41 -0
- data/ext/uchardet/src/tools/CMakeLists.txt +23 -0
- data/ext/uchardet/src/tools/uchardet.cpp +254 -0
- data/ext/uchardet/src/uchardet.cpp +274 -0
- data/ext/uchardet/src/uchardet.h +136 -0
- data/ext/uchardet/test/CMakeLists.txt +47 -0
- data/ext/uchardet/test/ar/iso-8859-6.txt +3 -0
- data/ext/uchardet/test/ar/utf-8.txt +3 -0
- data/ext/uchardet/test/ar/windows-1256.txt +3 -0
- data/ext/uchardet/test/bg/windows-1251.txt +3 -0
- data/ext/uchardet/test/cs/ibm852.txt +4 -0
- data/ext/uchardet/test/cs/iso-8859-2.txt +4 -0
- data/ext/uchardet/test/cs/mac-centraleurope.txt +4 -0
- data/ext/uchardet/test/cs/utf-8.txt +4 -0
- data/ext/uchardet/test/cs/windows-1250.txt +4 -0
- data/ext/uchardet/test/da/iso-8859-1.txt +7 -0
- data/ext/uchardet/test/da/iso-8859-15.txt +10 -0
- data/ext/uchardet/test/da/utf-8.txt +10 -0
- data/ext/uchardet/test/da/windows-1252.txt +10 -0
- data/ext/uchardet/test/de/iso-8859-1.txt +11 -0
- data/ext/uchardet/test/de/windows-1252.txt +11 -0
- data/ext/uchardet/test/el/iso-8859-7.txt +3 -0
- data/ext/uchardet/test/el/utf-8.txt +3 -0
- data/ext/uchardet/test/el/windows-1253.txt +5 -0
- data/ext/uchardet/test/en/ascii.txt +4 -0
- data/ext/uchardet/test/eo/iso-8859-3.txt +7 -0
- data/ext/uchardet/test/es/iso-8859-1.txt +5 -0
- data/ext/uchardet/test/es/iso-8859-15.txt +5 -0
- data/ext/uchardet/test/es/utf-8.txt +5 -0
- data/ext/uchardet/test/es/windows-1252.txt +5 -0
- data/ext/uchardet/test/et/iso-8859-13.txt +6 -0
- data/ext/uchardet/test/et/iso-8859-15.txt +6 -0
- data/ext/uchardet/test/et/iso-8859-4.txt +6 -0
- data/ext/uchardet/test/et/utf-8.txt +6 -0
- data/ext/uchardet/test/et/windows-1252.txt +6 -0
- data/ext/uchardet/test/et/windows-1257.txt +6 -0
- data/ext/uchardet/test/fi/iso-8859-1.txt +8 -0
- data/ext/uchardet/test/fi/utf-8.txt +8 -0
- data/ext/uchardet/test/fr/iso-8859-1.txt +5 -0
- data/ext/uchardet/test/fr/iso-8859-15.txt +16 -0
- data/ext/uchardet/test/fr/utf-16.be +0 -0
- data/ext/uchardet/test/fr/utf-32.le +0 -0
- data/ext/uchardet/test/fr/utf-8.txt +14 -0
- data/ext/uchardet/test/fr/windows-1252.txt +3 -0
- data/ext/uchardet/test/ga/iso-8859-1.txt +6 -0
- data/ext/uchardet/test/ga/utf-8.txt +6 -0
- data/ext/uchardet/test/ga/windows-1252.txt +6 -0
- data/ext/uchardet/test/he/iso-8859-8.txt +2 -0
- data/ext/uchardet/test/he/utf-8.txt +3 -0
- data/ext/uchardet/test/he/windows-1255.txt +1 -0
- data/ext/uchardet/test/hr/ibm852.txt +4 -0
- data/ext/uchardet/test/hr/iso-8859-13.txt +4 -0
- data/ext/uchardet/test/hr/iso-8859-16.txt +4 -0
- data/ext/uchardet/test/hr/iso-8859-2.txt +4 -0
- data/ext/uchardet/test/hr/mac-centraleurope.txt +4 -0
- data/ext/uchardet/test/hr/utf-8.txt +4 -0
- data/ext/uchardet/test/hr/windows-1250.txt +4 -0
- data/ext/uchardet/test/hu/iso-8859-2.txt +3 -0
- data/ext/uchardet/test/hu/windows-1250.txt +1 -0
- data/ext/uchardet/test/it/iso-8859-1.txt +18 -0
- data/ext/uchardet/test/it/utf-8.txt +18 -0
- data/ext/uchardet/test/ja/euc-jp.txt +10 -0
- data/ext/uchardet/test/ja/iso-2022-jp.txt +8 -0
- data/ext/uchardet/test/ja/shift_jis.txt +1 -0
- data/ext/uchardet/test/ja/utf-16be.txt +0 -0
- data/ext/uchardet/test/ja/utf-16le.txt +0 -0
- data/ext/uchardet/test/ja/utf-8.txt +9 -0
- data/ext/uchardet/test/ko/iso-2022-kr.txt +8 -0
- data/ext/uchardet/test/ko/uhc.smi +16 -0
- data/ext/uchardet/test/ko/utf-16.le +0 -0
- data/ext/uchardet/test/ko/utf-32.be +0 -0
- data/ext/uchardet/test/ko/utf-8.txt +3 -0
- data/ext/uchardet/test/lt/iso-8859-10.txt +3 -0
- data/ext/uchardet/test/lt/iso-8859-13.txt +3 -0
- data/ext/uchardet/test/lt/iso-8859-4.txt +3 -0
- data/ext/uchardet/test/lt/utf-8.txt +3 -0
- data/ext/uchardet/test/lv/iso-8859-10.txt +6 -0
- data/ext/uchardet/test/lv/iso-8859-13.txt +6 -0
- data/ext/uchardet/test/lv/iso-8859-4.txt +6 -0
- data/ext/uchardet/test/lv/utf-8.txt +6 -0
- data/ext/uchardet/test/mt/iso-8859-3.txt +4 -0
- data/ext/uchardet/test/mt/utf-8.txt +4 -0
- data/ext/uchardet/test/pl/ibm852.txt +3 -0
- data/ext/uchardet/test/pl/iso-8859-13.txt +3 -0
- data/ext/uchardet/test/pl/iso-8859-16.txt +3 -0
- data/ext/uchardet/test/pl/iso-8859-2.txt +3 -0
- data/ext/uchardet/test/pl/mac-centraleurope.txt +3 -0
- data/ext/uchardet/test/pl/utf-8.txt +3 -0
- data/ext/uchardet/test/pl/windows-1250.txt +3 -0
- data/ext/uchardet/test/pt/iso-8859-1.txt +6 -0
- data/ext/uchardet/test/pt/utf-8.txt +6 -0
- data/ext/uchardet/test/ro/ibm852.txt +9 -0
- data/ext/uchardet/test/ro/iso-8859-16.txt +9 -0
- data/ext/uchardet/test/ro/utf-8.txt +9 -0
- data/ext/uchardet/test/ro/windows-1250.txt +9 -0
- data/ext/uchardet/test/ru/ibm855.txt +5 -0
- data/ext/uchardet/test/ru/ibm866.txt +11 -0
- data/ext/uchardet/test/ru/iso-8859-5.txt +3 -0
- data/ext/uchardet/test/ru/koi8-r.txt +1 -0
- data/ext/uchardet/test/ru/mac-cyrillic.txt +9 -0
- data/ext/uchardet/test/ru/windows-1251.txt +4 -0
- data/ext/uchardet/test/sk/ibm852.txt +3 -0
- data/ext/uchardet/test/sk/iso-8859-2.txt +3 -0
- data/ext/uchardet/test/sk/mac-centraleurope.txt +3 -0
- data/ext/uchardet/test/sk/utf-8.txt +3 -0
- data/ext/uchardet/test/sk/windows-1250.txt +3 -0
- data/ext/uchardet/test/sl/ibm852.txt +9 -0
- data/ext/uchardet/test/sl/iso-8859-16.txt +9 -0
- data/ext/uchardet/test/sl/iso-8859-2.txt +9 -0
- data/ext/uchardet/test/sl/mac-centraleurope.txt +9 -0
- data/ext/uchardet/test/sl/utf-8.txt +9 -0
- data/ext/uchardet/test/sl/windows-1250.txt +9 -0
- data/ext/uchardet/test/sv/iso-8859-1.txt +10 -0
- data/ext/uchardet/test/sv/utf-8.txt +10 -0
- data/ext/uchardet/test/sv/windows-1252.txt +10 -0
- data/ext/uchardet/test/th/iso-8859-11.txt +5 -0
- data/ext/uchardet/test/th/tis-620.txt +5 -0
- data/ext/uchardet/test/th/utf-8.txt +1 -0
- data/ext/uchardet/test/tr/iso-8859-3.txt +13 -0
- data/ext/uchardet/test/tr/iso-8859-9.txt +13 -0
- data/ext/uchardet/test/uchardet-tests.c +130 -0
- data/ext/uchardet/test/vi/utf-8.txt +4 -0
- data/ext/uchardet/test/vi/viscii.txt +4 -0
- data/ext/uchardet/test/vi/windows-1258.txt +4 -0
- data/ext/uchardet/test/zh/big5.txt +1 -0
- data/ext/uchardet/test/zh/euc-tw.txt +1 -0
- data/ext/uchardet/test/zh/gb18030.txt +1 -0
- data/ext/uchardet/test/zh/utf-8.txt +1 -0
- data/ext/uchardet/uchardet.doap +51 -0
- data/ext/uchardet/uchardet.pc.in +10 -0
- data/lib/cchardet.rb +56 -0
- data/lib/cchardet/lib_finder.rb +32 -0
- data/lib/cchardet/version.rb +5 -0
- metadata +362 -0
data/ext/uchardet/build-mac/uchardet.xcodeproj/project.xcworkspace/xcshareddata/uchardet.xccheckout
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
|
6
|
+
<false/>
|
7
|
+
<key>IDESourceControlProjectIdentifier</key>
|
8
|
+
<string>A3B241B4-458F-47BE-A7FB-AABC82F7C332</string>
|
9
|
+
<key>IDESourceControlProjectName</key>
|
10
|
+
<string>uchardet</string>
|
11
|
+
<key>IDESourceControlProjectOriginsDictionary</key>
|
12
|
+
<dict>
|
13
|
+
<key>7DF9952B76987F54D66D74171482E11FAF33FDCB</key>
|
14
|
+
<string>https://www.freedesktop.org/wiki/Software/uchardet/</string>
|
15
|
+
</dict>
|
16
|
+
<key>IDESourceControlProjectPath</key>
|
17
|
+
<string>build-mac/uchardet.xcodeproj</string>
|
18
|
+
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
|
19
|
+
<dict>
|
20
|
+
<key>7DF9952B76987F54D66D74171482E11FAF33FDCB</key>
|
21
|
+
<string>../../..</string>
|
22
|
+
</dict>
|
23
|
+
<key>IDESourceControlProjectURL</key>
|
24
|
+
<string>https://www.freedesktop.org/wiki/Software/uchardet/</string>
|
25
|
+
<key>IDESourceControlProjectVersion</key>
|
26
|
+
<integer>111</integer>
|
27
|
+
<key>IDESourceControlProjectWCCIdentifier</key>
|
28
|
+
<string>7DF9952B76987F54D66D74171482E11FAF33FDCB</string>
|
29
|
+
<key>IDESourceControlProjectWCConfigurations</key>
|
30
|
+
<array>
|
31
|
+
<dict>
|
32
|
+
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
|
33
|
+
<string>public.vcs.git</string>
|
34
|
+
<key>IDESourceControlWCCIdentifierKey</key>
|
35
|
+
<string>7DF9952B76987F54D66D74171482E11FAF33FDCB</string>
|
36
|
+
<key>IDESourceControlWCCName</key>
|
37
|
+
<string>uchardet</string>
|
38
|
+
</dict>
|
39
|
+
</array>
|
40
|
+
</dict>
|
41
|
+
</plist>
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Scheme
|
3
|
+
LastUpgradeVersion = "0600"
|
4
|
+
version = "1.3">
|
5
|
+
<BuildAction
|
6
|
+
parallelizeBuildables = "YES"
|
7
|
+
buildImplicitDependencies = "YES">
|
8
|
+
<BuildActionEntries>
|
9
|
+
<BuildActionEntry
|
10
|
+
buildForTesting = "YES"
|
11
|
+
buildForRunning = "YES"
|
12
|
+
buildForProfiling = "YES"
|
13
|
+
buildForArchiving = "YES"
|
14
|
+
buildForAnalyzing = "YES">
|
15
|
+
<BuildableReference
|
16
|
+
BuildableIdentifier = "primary"
|
17
|
+
BlueprintIdentifier = "BD49961119FC04E8000945BC"
|
18
|
+
BuildableName = "libuchardet-ios.a"
|
19
|
+
BlueprintName = "uchardet-ios"
|
20
|
+
ReferencedContainer = "container:uchardet.xcodeproj">
|
21
|
+
</BuildableReference>
|
22
|
+
</BuildActionEntry>
|
23
|
+
</BuildActionEntries>
|
24
|
+
</BuildAction>
|
25
|
+
<TestAction
|
26
|
+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
27
|
+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
28
|
+
shouldUseLaunchSchemeArgsEnv = "YES"
|
29
|
+
buildConfiguration = "Debug">
|
30
|
+
<Testables>
|
31
|
+
</Testables>
|
32
|
+
</TestAction>
|
33
|
+
<LaunchAction
|
34
|
+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
35
|
+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
36
|
+
launchStyle = "0"
|
37
|
+
useCustomWorkingDirectory = "NO"
|
38
|
+
buildConfiguration = "Debug"
|
39
|
+
ignoresPersistentStateOnLaunch = "NO"
|
40
|
+
debugDocumentVersioning = "YES"
|
41
|
+
allowLocationSimulation = "YES">
|
42
|
+
<MacroExpansion>
|
43
|
+
<BuildableReference
|
44
|
+
BuildableIdentifier = "primary"
|
45
|
+
BlueprintIdentifier = "BD49961119FC04E8000945BC"
|
46
|
+
BuildableName = "libuchardet-ios.a"
|
47
|
+
BlueprintName = "uchardet-ios"
|
48
|
+
ReferencedContainer = "container:uchardet.xcodeproj">
|
49
|
+
</BuildableReference>
|
50
|
+
</MacroExpansion>
|
51
|
+
<AdditionalOptions>
|
52
|
+
</AdditionalOptions>
|
53
|
+
</LaunchAction>
|
54
|
+
<ProfileAction
|
55
|
+
shouldUseLaunchSchemeArgsEnv = "YES"
|
56
|
+
savedToolIdentifier = ""
|
57
|
+
useCustomWorkingDirectory = "NO"
|
58
|
+
buildConfiguration = "Release"
|
59
|
+
debugDocumentVersioning = "YES">
|
60
|
+
<MacroExpansion>
|
61
|
+
<BuildableReference
|
62
|
+
BuildableIdentifier = "primary"
|
63
|
+
BlueprintIdentifier = "BD49961119FC04E8000945BC"
|
64
|
+
BuildableName = "libuchardet-ios.a"
|
65
|
+
BlueprintName = "uchardet-ios"
|
66
|
+
ReferencedContainer = "container:uchardet.xcodeproj">
|
67
|
+
</BuildableReference>
|
68
|
+
</MacroExpansion>
|
69
|
+
</ProfileAction>
|
70
|
+
<AnalyzeAction
|
71
|
+
buildConfiguration = "Debug">
|
72
|
+
</AnalyzeAction>
|
73
|
+
<ArchiveAction
|
74
|
+
buildConfiguration = "Release"
|
75
|
+
revealArchiveInOrganizer = "YES">
|
76
|
+
</ArchiveAction>
|
77
|
+
</Scheme>
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Scheme
|
3
|
+
LastUpgradeVersion = "0600"
|
4
|
+
version = "1.3">
|
5
|
+
<BuildAction
|
6
|
+
parallelizeBuildables = "YES"
|
7
|
+
buildImplicitDependencies = "YES">
|
8
|
+
<BuildActionEntries>
|
9
|
+
<BuildActionEntry
|
10
|
+
buildForTesting = "YES"
|
11
|
+
buildForRunning = "YES"
|
12
|
+
buildForProfiling = "YES"
|
13
|
+
buildForArchiving = "YES"
|
14
|
+
buildForAnalyzing = "YES">
|
15
|
+
<BuildableReference
|
16
|
+
BuildableIdentifier = "primary"
|
17
|
+
BlueprintIdentifier = "BD49959B19F84840000945BC"
|
18
|
+
BuildableName = "libuchardet.a"
|
19
|
+
BlueprintName = "uchardet"
|
20
|
+
ReferencedContainer = "container:uchardet.xcodeproj">
|
21
|
+
</BuildableReference>
|
22
|
+
</BuildActionEntry>
|
23
|
+
</BuildActionEntries>
|
24
|
+
</BuildAction>
|
25
|
+
<TestAction
|
26
|
+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
27
|
+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
28
|
+
shouldUseLaunchSchemeArgsEnv = "YES"
|
29
|
+
buildConfiguration = "Debug">
|
30
|
+
<Testables>
|
31
|
+
</Testables>
|
32
|
+
</TestAction>
|
33
|
+
<LaunchAction
|
34
|
+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
35
|
+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
36
|
+
launchStyle = "0"
|
37
|
+
useCustomWorkingDirectory = "NO"
|
38
|
+
buildConfiguration = "Debug"
|
39
|
+
ignoresPersistentStateOnLaunch = "NO"
|
40
|
+
debugDocumentVersioning = "YES"
|
41
|
+
allowLocationSimulation = "YES">
|
42
|
+
<MacroExpansion>
|
43
|
+
<BuildableReference
|
44
|
+
BuildableIdentifier = "primary"
|
45
|
+
BlueprintIdentifier = "BD49959B19F84840000945BC"
|
46
|
+
BuildableName = "libuchardet.a"
|
47
|
+
BlueprintName = "uchardet"
|
48
|
+
ReferencedContainer = "container:uchardet.xcodeproj">
|
49
|
+
</BuildableReference>
|
50
|
+
</MacroExpansion>
|
51
|
+
<AdditionalOptions>
|
52
|
+
</AdditionalOptions>
|
53
|
+
</LaunchAction>
|
54
|
+
<ProfileAction
|
55
|
+
shouldUseLaunchSchemeArgsEnv = "YES"
|
56
|
+
savedToolIdentifier = ""
|
57
|
+
useCustomWorkingDirectory = "NO"
|
58
|
+
buildConfiguration = "Release"
|
59
|
+
debugDocumentVersioning = "YES">
|
60
|
+
<MacroExpansion>
|
61
|
+
<BuildableReference
|
62
|
+
BuildableIdentifier = "primary"
|
63
|
+
BlueprintIdentifier = "BD49959B19F84840000945BC"
|
64
|
+
BuildableName = "libuchardet.a"
|
65
|
+
BlueprintName = "uchardet"
|
66
|
+
ReferencedContainer = "container:uchardet.xcodeproj">
|
67
|
+
</BuildableReference>
|
68
|
+
</MacroExpansion>
|
69
|
+
</ProfileAction>
|
70
|
+
<AnalyzeAction
|
71
|
+
buildConfiguration = "Debug">
|
72
|
+
</AnalyzeAction>
|
73
|
+
<ArchiveAction
|
74
|
+
buildConfiguration = "Release"
|
75
|
+
revealArchiveInOrganizer = "YES">
|
76
|
+
</ArchiveAction>
|
77
|
+
</Scheme>
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# How to do a uchardet release #
|
2
|
+
|
3
|
+
* Update UCHARDET_VERSION_MAJOR, UCHARDET_VERSION_MINOR and
|
4
|
+
UCHARDET_VERSION_REVISION as needed in CMakeLists.txt.
|
5
|
+
|
6
|
+
* Update README.md.
|
7
|
+
|
8
|
+
* Commit the version change with the message "Release: version X.Y.Z."
|
9
|
+
|
10
|
+
* Tag your release commit with:
|
11
|
+
|
12
|
+
git tag -a vx.y.z
|
13
|
+
|
14
|
+
The tag message should be have the header "Version x.y.z released." followed
|
15
|
+
by a list of new features or important fixes. This tag message will be
|
16
|
+
considered as the release note, hence have to be carefully crafted.
|
17
|
+
|
18
|
+
Considering that the previous release was va.b.c, you can read the full list
|
19
|
+
of commits between a.b.c and x.y.z with:
|
20
|
+
|
21
|
+
git log va.b.c..
|
22
|
+
|
23
|
+
This should help you to build a proper release note.
|
24
|
+
|
25
|
+
* Push the release and the tag:
|
26
|
+
|
27
|
+
git push
|
28
|
+
git push origin vx.y.z
|
29
|
+
|
30
|
+
* Create a release tarball:
|
31
|
+
|
32
|
+
git archive --format=tar.xz --prefix=uchardet-x.y.z/ vx.y.z >uchardet-x.y.z.tar.xz
|
33
|
+
|
34
|
+
Note: if you have not already set this up, you have to run first:
|
35
|
+
|
36
|
+
git config tar.tar.xz.command "xz -c"
|
37
|
+
|
38
|
+
Cf. EXAMPLES section in `git help archive`.
|
39
|
+
|
40
|
+
* Compute a SHA1 checksum:
|
41
|
+
|
42
|
+
sha1sum uchardet-x.y.x.tar.xz > uchardet-x.y.z.tar.xz.sha1
|
43
|
+
|
44
|
+
* Upload to annarchy download server:
|
45
|
+
|
46
|
+
scp uchardet-x.y.x.tar.xz uchardet-x.y.z.tar.xz.sha1 annarchy.freedesktop.org:/srv/www.freedesktop.org/www/software/uchardet/releases/
|
47
|
+
|
48
|
+
The archive and its checksum file should now be available from:
|
49
|
+
https://www.freedesktop.org/software/uchardet/releases/
|
50
|
+
|
51
|
+
* Make the git tag into a Gitlab release (not automatic).
|
52
|
+
It will be found at: https://gitlab.freedesktop.org/uchardet/uchardet/-/tags/vx.y.z
|
53
|
+
Just click the "Edit release notes" button, and copy paste the tag comment as "release notes".
|
54
|
+
|
55
|
+
* Update the wiki page: https://www.freedesktop.org/wiki/Software/uchardet/
|
56
|
+
The release note link will be:
|
57
|
+
https://gitlab.freedesktop.org/uchardet/uchardet/-/releases/vx.y.z
|
58
|
+
|
59
|
+
* Spread the good news!
|
@@ -0,0 +1,18 @@
|
|
1
|
+
.TH UCHARDET "1" "July 2011" "uchardet " "User Commands"
|
2
|
+
.SH NAME
|
3
|
+
uchardet \- Universal Charset Detector
|
4
|
+
.SH DESCRIPTION
|
5
|
+
uchardet CLI is an encoding detector utility, which takes one or several files in unknown character encoding without any additional information, and attempts to determine the encoding of the texts. Returned encoding names are iconv-compatible.
|
6
|
+
.SS "Usage:"
|
7
|
+
.HP
|
8
|
+
uchardet [\fBOptions\fR] [\fBFile\fR]...
|
9
|
+
.HP
|
10
|
+
\fB\-v\fR
|
11
|
+
Print version and build information.
|
12
|
+
.HP
|
13
|
+
\fB\-h\fR
|
14
|
+
Print help text.
|
15
|
+
.HP
|
16
|
+
.IP
|
17
|
+
.PP
|
18
|
+
uchardet Command Line Interface
|
@@ -0,0 +1,533 @@
|
|
1
|
+
#!/bin/python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
# ##### BEGIN LICENSE BLOCK #####
|
5
|
+
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
6
|
+
#
|
7
|
+
# The contents of this file are subject to the Mozilla Public License Version
|
8
|
+
# 1.1 (the "License"); you may not use this file except in compliance with
|
9
|
+
# the License. You may obtain a copy of the License at
|
10
|
+
# http://www.mozilla.org/MPL/
|
11
|
+
#
|
12
|
+
# Software distributed under the License is distributed on an "AS IS" basis,
|
13
|
+
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
14
|
+
# for the specific language governing rights and limitations under the
|
15
|
+
# License.
|
16
|
+
#
|
17
|
+
# The Original Code is Mozilla Universal charset detector code.
|
18
|
+
#
|
19
|
+
# The Initial Developer of the Original Code is
|
20
|
+
# Netscape Communications Corporation.
|
21
|
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
22
|
+
# the Initial Developer. All Rights Reserved.
|
23
|
+
#
|
24
|
+
# Contributor(s):
|
25
|
+
# Jehan <jehan@girinstud.io>
|
26
|
+
#
|
27
|
+
# Alternatively, the contents of this file may be used under the terms of
|
28
|
+
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
29
|
+
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
30
|
+
# in which case the provisions of the GPL or the LGPL are applicable instead
|
31
|
+
# of those above. If you wish to allow use of your version of this file only
|
32
|
+
# under the terms of either the GPL or the LGPL, and not to allow others to
|
33
|
+
# use your version of this file under the terms of the MPL, indicate your
|
34
|
+
# decision by deleting the provisions above and replace them with the notice
|
35
|
+
# and other provisions required by the GPL or the LGPL. If you do not delete
|
36
|
+
# the provisions above, a recipient may use your version of this file under
|
37
|
+
# the terms of any one of the MPL, the GPL or the LGPL.
|
38
|
+
#
|
39
|
+
# ##### END LICENSE BLOCK #####
|
40
|
+
|
41
|
+
# Third party modules.
|
42
|
+
import unicodedata
|
43
|
+
import subprocess
|
44
|
+
import wikipedia
|
45
|
+
import importlib
|
46
|
+
import optparse
|
47
|
+
import datetime
|
48
|
+
import operator
|
49
|
+
import requests
|
50
|
+
import sys
|
51
|
+
import re
|
52
|
+
import os
|
53
|
+
|
54
|
+
# Custom modules.
|
55
|
+
import charsets.db
|
56
|
+
from charsets.codepoints import *
|
57
|
+
|
58
|
+
# Command line processing.
|
59
|
+
usage = 'Usage: {} <LANG-CODE>\n' \
|
60
|
+
'\nEx: `{} fr`'.format(__file__, __file__)
|
61
|
+
|
62
|
+
description = "Internal tool for uchardet to generate language data."
|
63
|
+
cmdline = optparse.OptionParser(usage, description = description)
|
64
|
+
cmdline.add_option('--max-page',
|
65
|
+
help = 'Maximum number of Wikipedia pages to parse (useful for debugging).',
|
66
|
+
action = 'store', type = 'int', dest = 'max_page', default = None)
|
67
|
+
cmdline.add_option('--max-depth',
|
68
|
+
help = 'Maximum depth when following links from start page (default: 2).',
|
69
|
+
action = 'store', type = 'int',
|
70
|
+
dest = 'max_depth', default = 2)
|
71
|
+
(options, langs) = cmdline.parse_args()
|
72
|
+
if len(langs) < 1:
|
73
|
+
print("Please select at least one language code.\n")
|
74
|
+
exit(1)
|
75
|
+
if len(langs) > 1:
|
76
|
+
print("This script is meant to generate data for one language at a time.\n")
|
77
|
+
exit(1)
|
78
|
+
lang = langs[0]
|
79
|
+
|
80
|
+
# Load the language data.
|
81
|
+
sys_path_backup = sys.path
|
82
|
+
current_dir = os.path.dirname(os.path.realpath(__file__))
|
83
|
+
sys.path = [current_dir + '/langs']
|
84
|
+
|
85
|
+
try:
|
86
|
+
lang = importlib.import_module(lang.lower())
|
87
|
+
except ImportError:
|
88
|
+
print('Unknown language code "{}": '
|
89
|
+
'file "langs/{}.py" does not exist.'.format(lang, lang.lower()))
|
90
|
+
exit(1)
|
91
|
+
sys.path = sys_path_backup
|
92
|
+
|
93
|
+
charsets = charsets.db.load(lang.charsets)
|
94
|
+
|
95
|
+
if not hasattr(lang, 'start_pages') or lang.start_pages is None or \
|
96
|
+
lang.start_pages == []:
|
97
|
+
# Let's start with the main page, assuming it should have links
|
98
|
+
# to relevant pages. In locale wikipedia, this page is usually redirected
|
99
|
+
# to a relevant page.
|
100
|
+
print("Warning: no `start_pages` set for '{}'. Using ['Main_Page'].\n"
|
101
|
+
" If you don't get good data, it is advised to set a "
|
102
|
+
"start_pages` variable yourself.".format(lang.code))
|
103
|
+
lang.start_pages = ['Main_Page']
|
104
|
+
if not hasattr(lang, 'wikipedia_code') or lang.wikipedia_code is None:
|
105
|
+
lang.wikipedia_code = lang.code
|
106
|
+
if not hasattr(lang, 'clean_wikipedia_content') or lang.clean_wikipedia_content is None:
|
107
|
+
lang.clean_wikipedia_content = None
|
108
|
+
if hasattr(lang, 'case_mapping'):
|
109
|
+
lang.case_mapping = bool(lang.case_mapping)
|
110
|
+
else:
|
111
|
+
lang.case_mapping = False
|
112
|
+
if not hasattr(lang, 'custom_case_mapping'):
|
113
|
+
lang.custom_case_mapping = None
|
114
|
+
if not hasattr(lang, 'alphabet') or lang.alphabet is None:
|
115
|
+
lang.alphabet = None
|
116
|
+
|
117
|
+
def local_lowercase(text, lang):
|
118
|
+
lowercased = ''
|
119
|
+
for l in text:
|
120
|
+
if lang.custom_case_mapping is not None and \
|
121
|
+
l in lang.custom_case_mapping:
|
122
|
+
lowercased += lang.custom_case_mapping[l]
|
123
|
+
elif l.isupper() and \
|
124
|
+
lang.case_mapping and \
|
125
|
+
len(unicodedata.normalize('NFC', l.lower())) == 1:
|
126
|
+
lowercased += l.lower()
|
127
|
+
else:
|
128
|
+
lowercased += l
|
129
|
+
return lowercased
|
130
|
+
|
131
|
+
if lang.alphabet is not None:
|
132
|
+
# Allowing to provide an alphabet in string format rather than list.
|
133
|
+
lang.alphabet = list(lang.alphabet)
|
134
|
+
if lang.use_ascii:
|
135
|
+
lang.alphabet += [chr(l) for l in range(65, 91)] + [chr(l) for l in range(97, 123)]
|
136
|
+
if lang.case_mapping or lang.custom_case_mapping is not None:
|
137
|
+
lang.alphabet = [local_lowercase(l, lang) for l in lang.alphabet]
|
138
|
+
#alphabet = []
|
139
|
+
#for l in lang.alphabet:
|
140
|
+
#if l.isupper() and \
|
141
|
+
#lang.custom_case_mapping is not None and \
|
142
|
+
#l in lang.custom_case_mapping:
|
143
|
+
#alphabet.append(lang.custom_case_mapping[l])
|
144
|
+
#elif l.isupper() and \
|
145
|
+
#lang.case_mapping and \
|
146
|
+
#len(unicodedata.normalize('NFC', l.lower())) == 1:
|
147
|
+
#alphabet.append(l.lower())
|
148
|
+
#else:
|
149
|
+
#alphabet.append(l)
|
150
|
+
lang.alphabet = list(set(lang.alphabet))
|
151
|
+
|
152
|
+
# Starting processing.
|
153
|
+
wikipedia.set_lang(lang.wikipedia_code)
|
154
|
+
|
155
|
+
visited_pages = []
|
156
|
+
|
157
|
+
# The full list of letter characters.
|
158
|
+
# The key is the unicode codepoint,
|
159
|
+
# and the value is the occurrence count.
|
160
|
+
characters = {}
|
161
|
+
# Sequence of letters.
|
162
|
+
# The key is the couple (char1, char2) in unicode codepoint,
|
163
|
+
# the value is the occurrence count.
|
164
|
+
sequences = {}
|
165
|
+
prev_char = None
|
166
|
+
|
167
|
+
def process_text(content, lang):
|
168
|
+
global charsets
|
169
|
+
global characters
|
170
|
+
global sequences
|
171
|
+
global prev_char
|
172
|
+
|
173
|
+
if lang.clean_wikipedia_content is not None:
|
174
|
+
content = lang.clean_wikipedia_content(content)
|
175
|
+
# Clean out the Wikipedia syntax for titles.
|
176
|
+
content = re.sub(r'(=+) *([^=]+) *\1',
|
177
|
+
r'\2', content)
|
178
|
+
# Clean multiple spaces. Newlines and such are normalized to spaces,
|
179
|
+
# since they have basically a similar role in the purpose of uchardet.
|
180
|
+
content = re.sub(r'\s+', ' ', content)
|
181
|
+
|
182
|
+
if lang.case_mapping or lang.custom_case_mapping is not None:
|
183
|
+
content = local_lowercase(content, lang)
|
184
|
+
|
185
|
+
# In python 3, strings are UTF-8.
|
186
|
+
# Looping through them return expected characters.
|
187
|
+
for char in content:
|
188
|
+
is_letter = False
|
189
|
+
if ord(char) in characters:
|
190
|
+
characters[ord(char)] += 1
|
191
|
+
is_letter = True
|
192
|
+
else:
|
193
|
+
# We save the character if it is at least in one of the
|
194
|
+
# language encodings and its not a special character.
|
195
|
+
for charset in charsets:
|
196
|
+
# Does the character exist in the charset?
|
197
|
+
try:
|
198
|
+
codepoint = char.encode(charset, 'ignore')
|
199
|
+
except LookupError:
|
200
|
+
# unknown encoding. Use iconv from command line instead.
|
201
|
+
try:
|
202
|
+
call = subprocess.Popen(['iconv', '-f', 'UTF-8', '-t', charset],
|
203
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
204
|
+
stderr=subprocess.DEVNULL)
|
205
|
+
if call.poll() is not None:
|
206
|
+
(_, error) = call.communicate(input='')
|
207
|
+
print('Error: `iconv` ended with error "{}".\n'.format(error))
|
208
|
+
exit(1)
|
209
|
+
(codepoint, _) = call.communicate(input=char.encode('UTF-8'))
|
210
|
+
except FileNotFoundError:
|
211
|
+
print('Error: "{}" is not a supported charset by python and `iconv` is not installed.\n')
|
212
|
+
exit(1)
|
213
|
+
|
214
|
+
if codepoint == b'':
|
215
|
+
continue
|
216
|
+
# ord() is said to return the unicode codepoint.
|
217
|
+
# But it turns out it also gives the codepoint for other
|
218
|
+
# charsets if I turn the string to encoded bytes first.
|
219
|
+
# Not sure if that is a bug or expected.
|
220
|
+
codepoint = ord(codepoint)
|
221
|
+
if charsets[charset].charmap[codepoint] == LET:
|
222
|
+
characters[ord(char)] = 1
|
223
|
+
is_letter = True
|
224
|
+
break
|
225
|
+
if is_letter:
|
226
|
+
if prev_char is not None:
|
227
|
+
if (prev_char, ord(char)) in sequences:
|
228
|
+
sequences[(prev_char, ord(char))] += 1
|
229
|
+
else:
|
230
|
+
sequences[(prev_char, ord(char))] = 1
|
231
|
+
prev_char = ord(char)
|
232
|
+
else:
|
233
|
+
prev_char = None
|
234
|
+
|
235
|
+
def visit_pages(titles, depth, lang, logfd):
|
236
|
+
global visited_pages
|
237
|
+
global options
|
238
|
+
|
239
|
+
if len(titles) == 0:
|
240
|
+
return
|
241
|
+
|
242
|
+
next_titles = []
|
243
|
+
for title in titles:
|
244
|
+
if options.max_page is not None and \
|
245
|
+
len(visited_pages) > options.max_page:
|
246
|
+
return
|
247
|
+
if title in visited_pages:
|
248
|
+
continue
|
249
|
+
visited_pages += [title]
|
250
|
+
try:
|
251
|
+
page = wikipedia.page(title)
|
252
|
+
except (wikipedia.exceptions.PageError,
|
253
|
+
wikipedia.exceptions.DisambiguationError):
|
254
|
+
# Let's just discard a page when I get an exception.
|
255
|
+
print("Discarding page {}.\n".format(title))
|
256
|
+
continue
|
257
|
+
logfd.write("\n{} (revision {})".format(title, page.revision_id))
|
258
|
+
|
259
|
+
process_text(page.content, lang)
|
260
|
+
try:
|
261
|
+
next_titles += page.links
|
262
|
+
except KeyError:
|
263
|
+
pass
|
264
|
+
|
265
|
+
if depth >= options.max_depth:
|
266
|
+
return
|
267
|
+
|
268
|
+
visit_pages (next_titles, depth + 1, lang, logfd)
|
269
|
+
|
270
|
+
language_c = lang.name.replace('-', '_').title()
|
271
|
+
build_log = current_dir + '/BuildLangModelLogs/Lang{}Model.log'.format(language_c)
|
272
|
+
logfd = open(build_log, 'w')
|
273
|
+
logfd.write('= Logs of language model for {} ({}) =\n'.format(lang.name, lang.code))
|
274
|
+
logfd.write('\n- Generated by {}'.format(os.path.basename(__file__)))
|
275
|
+
logfd.write('\n- Started: {}'.format(str(datetime.datetime.now())))
|
276
|
+
logfd.write('\n- Maximum depth: {}'.format(options.max_depth))
|
277
|
+
if options.max_page is not None:
|
278
|
+
logfd.write('\n- Max number of pages: {}'.format(options.max_page))
|
279
|
+
logfd.write('\n\n== Parsed pages ==\n')
|
280
|
+
try:
|
281
|
+
visit_pages(lang.start_pages, 0, lang, logfd)
|
282
|
+
except requests.exceptions.ConnectionError:
|
283
|
+
print('Error: connection to Wikipedia failed. Aborting\n')
|
284
|
+
exit(1)
|
285
|
+
logfd.write('\n\n== End of Parsed pages ==')
|
286
|
+
logfd.write('\n\n- Wikipedia parsing ended at: {}\n'.format(str(datetime.datetime.now())))
|
287
|
+
|
288
|
+
########### CHARACTERS ###########
|
289
|
+
|
290
|
+
# Character ratios.
|
291
|
+
ratios = {}
|
292
|
+
n_char = len(characters)
|
293
|
+
occurrences = sum(characters.values())
|
294
|
+
|
295
|
+
logfd.write("\n{} characters appeared {} times.\n".format(n_char, occurrences))
|
296
|
+
for char in characters:
|
297
|
+
ratios[char] = characters[char] / occurrences
|
298
|
+
#logfd.write("Character '{}' usage: {} ({} %)\n".format(chr(char),
|
299
|
+
# characters[char],
|
300
|
+
# ratios[char] * 100))
|
301
|
+
|
302
|
+
sorted_ratios = sorted(ratios.items(), key=operator.itemgetter(1),
|
303
|
+
reverse=True)
|
304
|
+
# Accumulated ratios of the frequent chars.
|
305
|
+
accumulated_ratios = 0
|
306
|
+
|
307
|
+
# If there is no alphabet defined, we just use the first 64 letters, which was
|
308
|
+
# the original default.
|
309
|
+
# If there is an alphabet, we make sure all the alphabet characters are in the
|
310
|
+
# frequent list, and we stop then. There may therefore be more or less than
|
311
|
+
# 64 frequent characters depending on the language.
|
312
|
+
if lang.alphabet is None:
|
313
|
+
freq_count = 64
|
314
|
+
else:
|
315
|
+
freq_count = 0
|
316
|
+
for order, (char, ratio) in enumerate(sorted_ratios):
|
317
|
+
if len(lang.alphabet) == 0:
|
318
|
+
break
|
319
|
+
if chr(char) in lang.alphabet:
|
320
|
+
lang.alphabet.remove(chr(char))
|
321
|
+
freq_count += 1
|
322
|
+
else:
|
323
|
+
if len(lang.alphabet) > 0:
|
324
|
+
print("Error: alphabet characters are absent from data collection"
|
325
|
+
"\n Please check the configuration or the data."
|
326
|
+
"\n Missing characters: {}".format(", ".join(lang.alphabet)))
|
327
|
+
exit(1)
|
328
|
+
|
329
|
+
logfd.write('\nFirst {} characters:'.format(freq_count))
|
330
|
+
for order, (char, ratio) in enumerate(sorted_ratios):
|
331
|
+
if order >= freq_count:
|
332
|
+
break
|
333
|
+
logfd.write("\n[{:2}] Char {}: {} %".format(order, chr(char), ratio * 100))
|
334
|
+
accumulated_ratios += ratio
|
335
|
+
|
336
|
+
logfd.write("\n\nThe first {} characters have an accumulated ratio of {}.\n".format(freq_count, accumulated_ratios))
|
337
|
+
|
338
|
+
with open(current_dir + '/header-template.cpp', 'r') as header_fd:
|
339
|
+
c_code = header_fd.read()
|
340
|
+
|
341
|
+
c_code += '\n/********* Language model for: {} *********/\n\n'.format(lang.name)
|
342
|
+
c_code += '/**\n * Generated by {}\n'.format(os.path.basename(__file__))
|
343
|
+
c_code += ' * On: {}\n'.format(str(datetime.datetime.now()))
|
344
|
+
c_code += ' **/\n'
|
345
|
+
|
346
|
+
c_code += \
|
347
|
+
"""
|
348
|
+
/* Character Mapping Table:
|
349
|
+
* ILL: illegal character.
|
350
|
+
* CTR: control character specific to the charset.
|
351
|
+
* RET: carriage/return.
|
352
|
+
* SYM: symbol (punctuation) that does not belong to word.
|
353
|
+
* NUM: 0 - 9.
|
354
|
+
*
|
355
|
+
* Other characters are ordered by probabilities
|
356
|
+
* (0 is the most common character in the language).
|
357
|
+
*
|
358
|
+
* Orders are generic to a language. So the codepoint with order X in
|
359
|
+
* CHARSET1 maps to the same character as the codepoint with the same
|
360
|
+
* order X in CHARSET2 for the same language.
|
361
|
+
* As such, it is possible to get missing order. For instance the
|
362
|
+
* ligature of 'o' and 'e' exists in ISO-8859-15 but not in ISO-8859-1
|
363
|
+
* even though they are both used for French. Same for the euro sign.
|
364
|
+
*/
|
365
|
+
"""
|
366
|
+
|
367
|
+
for charset in charsets:
|
368
|
+
charset_c = charset.replace('-', '_').title()
|
369
|
+
CTOM_str = 'static const unsigned char {}_CharToOrderMap[]'.format(charset_c)
|
370
|
+
CTOM_str += ' =\n{'
|
371
|
+
for line in range(0, 16):
|
372
|
+
CTOM_str += '\n '
|
373
|
+
for column in range(0, 16):
|
374
|
+
cp = line * 16 + column
|
375
|
+
cp_type = charsets[charset].charmap[cp]
|
376
|
+
if cp_type == ILL:
|
377
|
+
CTOM_str += 'ILL,'
|
378
|
+
elif cp_type == RET:
|
379
|
+
CTOM_str += 'RET,'
|
380
|
+
elif cp_type == CTR:
|
381
|
+
CTOM_str += 'CTR,'
|
382
|
+
elif cp_type == SYM:
|
383
|
+
CTOM_str += 'SYM,'
|
384
|
+
elif cp_type == NUM:
|
385
|
+
CTOM_str += 'NUM,'
|
386
|
+
else: # LET
|
387
|
+
try:
|
388
|
+
uchar = bytes([cp]).decode(charset)
|
389
|
+
except UnicodeDecodeError:
|
390
|
+
print('Unknown character 0X{:X} in {}.'.format(cp, charset))
|
391
|
+
print('Please verify your charset specification.\n')
|
392
|
+
exit(1)
|
393
|
+
except LookupError:
|
394
|
+
# Unknown encoding. Use iconv instead.
|
395
|
+
try:
|
396
|
+
call = subprocess.Popen(['iconv', '-t', 'UTF-8', '-f', charset],
|
397
|
+
stdin=subprocess.PIPE,
|
398
|
+
stdout=subprocess.PIPE,
|
399
|
+
stderr=subprocess.PIPE)
|
400
|
+
if call.poll() is not None:
|
401
|
+
(_, error) = call.communicate(input='')
|
402
|
+
print('Error: `iconv` ended with error "{}".\n'.format(error))
|
403
|
+
exit(1)
|
404
|
+
(uchar, _) = call.communicate(input=bytes([cp]))
|
405
|
+
uchar = uchar.decode('UTF-8')
|
406
|
+
except FileNotFoundError:
|
407
|
+
print('Error: "{}" is not a supported charset by python and `iconv` is not installed.\n')
|
408
|
+
exit(1)
|
409
|
+
#if lang.case_mapping and uchar.isupper() and \
|
410
|
+
#len(unicodedata.normalize('NFC', uchar.lower())) == 1:
|
411
|
+
# Unless we encounter special cases of characters with no
|
412
|
+
# composed lowercase, we lowercase it.
|
413
|
+
if lang.case_mapping or lang.custom_case_mapping is not None:
|
414
|
+
uchar = local_lowercase(uchar, lang)
|
415
|
+
for order, (char, ratio) in enumerate(sorted_ratios):
|
416
|
+
if char == ord(uchar):
|
417
|
+
CTOM_str += '{:3},'.format(min(249, order))
|
418
|
+
break
|
419
|
+
else:
|
420
|
+
# XXX: we must make sure the character order does not go
|
421
|
+
# over the special characters (250 currently). This may
|
422
|
+
# actually happen when building a model for a language
|
423
|
+
# writable with many different encoding. So let's just
|
424
|
+
# ceil the order value at 249 max.
|
425
|
+
# It may be an interesting alternative to add another
|
426
|
+
# constant for any character with an order > freqCharCount.
|
427
|
+
# Maybe IRR (irrelevant character) or simply CHR.
|
428
|
+
CTOM_str += '{:3},'.format(min(249, n_char))
|
429
|
+
n_char += 1
|
430
|
+
CTOM_str += ' /* {:X}X */'.format(line)
|
431
|
+
CTOM_str += '\n};\n/*'
|
432
|
+
CTOM_str += 'X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF'
|
433
|
+
CTOM_str += ' */\n\n'
|
434
|
+
c_code += CTOM_str
|
435
|
+
|
436
|
+
########### SEQUENCES ###########
|
437
|
+
|
438
|
+
ratios = {}
|
439
|
+
occurrences = sum(sequences.values())
|
440
|
+
ratio_512 = 0
|
441
|
+
ratio_1024 = 0
|
442
|
+
|
443
|
+
sorted_seqs = sorted(sequences.items(), key=operator.itemgetter(1),
|
444
|
+
reverse=True)
|
445
|
+
for order, ((c1, c2), count) in enumerate(sorted_seqs):
|
446
|
+
if order < 512:
|
447
|
+
ratio_512 += count
|
448
|
+
elif order < 1024:
|
449
|
+
ratio_1024 += count
|
450
|
+
else:
|
451
|
+
break
|
452
|
+
ratio_512 /= occurrences
|
453
|
+
ratio_1024 /= occurrences
|
454
|
+
|
455
|
+
logfd.write("\n{} sequences found.\n".format(len(sorted_seqs)))
|
456
|
+
|
457
|
+
c_code += """
|
458
|
+
/* Model Table:
|
459
|
+
* Total sequences: {}
|
460
|
+
* First 512 sequences: {}
|
461
|
+
* Next 512 sequences (512-1024): {}
|
462
|
+
* Rest: {}
|
463
|
+
* Negative sequences: TODO""".format(len(sorted_seqs),
|
464
|
+
ratio_512,
|
465
|
+
ratio_1024,
|
466
|
+
1 - ratio_512 - ratio_1024)
|
467
|
+
|
468
|
+
logfd.write("\nFirst 512 (typical positive ratio): {}".format(ratio_512))
|
469
|
+
logfd.write("\nNext 512 (512-1024): {}".format(ratio))
|
470
|
+
logfd.write("\nRest: {}".format(1 - ratio_512 - ratio_1024))
|
471
|
+
|
472
|
+
c_code += "\n */\n"
|
473
|
+
|
474
|
+
LM_str = 'static const PRUint8 {}LangModel[]'.format(language_c)
|
475
|
+
LM_str += ' =\n{'
|
476
|
+
for line in range(0, freq_count):
|
477
|
+
LM_str += '\n '
|
478
|
+
for column in range(0, freq_count):
|
479
|
+
# Let's not make too long lines.
|
480
|
+
if freq_count > 40 and column == int(freq_count / 2):
|
481
|
+
LM_str += '\n '
|
482
|
+
first_order = int(line)
|
483
|
+
second_order = column
|
484
|
+
if first_order < len(sorted_ratios) and second_order < len(sorted_ratios):
|
485
|
+
(first_char, _) = sorted_ratios[first_order]
|
486
|
+
(second_char, _) = sorted_ratios[second_order]
|
487
|
+
if (first_char, second_char) in sequences:
|
488
|
+
for order, (seq, _) in enumerate(sorted_seqs):
|
489
|
+
if seq == (first_char, second_char):
|
490
|
+
if order < 512:
|
491
|
+
LM_str += '3,'
|
492
|
+
elif order < 1024:
|
493
|
+
LM_str += '2,'
|
494
|
+
else:
|
495
|
+
LM_str += '1,'
|
496
|
+
break
|
497
|
+
else:
|
498
|
+
pass # impossible!
|
499
|
+
LM_str += '0,'
|
500
|
+
else:
|
501
|
+
LM_str += '0,'
|
502
|
+
else:
|
503
|
+
# It may indeed happen that we find less than 64 letters used for a
|
504
|
+
# given language.
|
505
|
+
LM_str += '0,'
|
506
|
+
LM_str += '\n};\n'
|
507
|
+
c_code += LM_str
|
508
|
+
|
509
|
+
for charset in charsets:
|
510
|
+
charset_c = charset.replace('-', '_').title()
|
511
|
+
SM_str = '\n\nconst SequenceModel {}{}Model ='.format(charset_c, language_c)
|
512
|
+
SM_str += '\n{\n '
|
513
|
+
SM_str += '{}_CharToOrderMap,\n {}LangModel,'.format(charset_c, language_c)
|
514
|
+
SM_str += '\n {},'.format(freq_count)
|
515
|
+
SM_str += '\n (float){},'.format(ratio_512)
|
516
|
+
SM_str += '\n {},'.format('PR_TRUE' if lang.use_ascii else 'PR_FALSE')
|
517
|
+
SM_str += '\n "{},"'.format(charset)
|
518
|
+
SM_str += '\n "{}"'.format(lang.code)
|
519
|
+
SM_str += '\n};'
|
520
|
+
c_code += SM_str
|
521
|
+
|
522
|
+
c_code += '\n'
|
523
|
+
|
524
|
+
lang_model_file = current_dir + '/../src/LangModels/Lang{}Model.cpp'.format(language_c)
|
525
|
+
with open(lang_model_file, 'w') as cpp_fd:
|
526
|
+
cpp_fd.write(c_code)
|
527
|
+
|
528
|
+
logfd.write('\n\n- Processing end: {}\n'.format(str(datetime.datetime.now())))
|
529
|
+
logfd.close()
|
530
|
+
|
531
|
+
print("The following language model file has been generated: {}"
|
532
|
+
"\nThe build log is available in: {}"
|
533
|
+
"\nTest them and commit them.".format(lang_model_file, build_log))
|