-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added python script to determine the language.
- Loading branch information
1 parent
ab16ad0
commit 8d90ec6
Showing
2 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# This script classifies the language of a file based on an advance NLP AI model. | ||
# (Well or just some clever programming actually.) | ||
# | ||
# Usage: | ||
# python3 classlang.py filetocheck | ||
# Returns: | ||
# A string corresponding to the most likely language in the file. | ||
# | ||
# To be used in conjunction with vim spelllang setting to automatically select the language. | ||
|
||
import sys | ||
|
||
# Only look at first 100 lines | ||
startoffile = open(sys.argv[1], encoding='utf-8').readlines()[0:99] | ||
|
||
print(startoffile) | ||
|
||
commonWordsDict = { | ||
"en_us" : [" the "," and "," a ", " to ", "The ", " an "], | ||
"nl" : [" de "," en "," in ", " van ", " op ", "De ", "Het "] | ||
} | ||
|
||
langs = list(commonWordsDict.keys()) | ||
indexDict = dict(zip(range(0,len(langs)), langs)) | ||
print(indexDict) | ||
|
||
def countOccurences(lang): | ||
print(lang) | ||
tot = 0 | ||
for l in startoffile: | ||
for w in commonWordsDict[lang]: | ||
print(l) | ||
print(w) | ||
tot += l.count(w) | ||
return tot | ||
|
||
def classifyLanguage(): | ||
scores = map(countOccurences, langs) | ||
scl = list(scores) | ||
print(scl) | ||
maxVal = max(scl) | ||
print(maxVal) | ||
maxIdx = scl.index(maxVal) | ||
print(indexDict[maxIdx]) | ||
|
||
classifyLanguage() |
This file was deleted.
Oops, something went wrong.