Changeset - 252d3b1bca60
[Not reviewed]
default
0 3 0
Laman - 2 years ago 2022-10-17 19:12:22

models file included in the package
3 files changed with 5 insertions and 2 deletions:
0 comments (0 inline, 0 general)
setup.cfg
Show inline comments
 
@@ -9,12 +9,15 @@ classifiers =
 
    License :: OSI Approved :: GNU General Public License v3 (GPLv3)
 
    Operating System :: OS Independent
 

	
 
long_description = file: README.md
 
long_description_content_type = text/markdown
 

	
 
[options]
 
packages =
 
    languedoc
 
package_dir =
 
    =src
 
python_requires = >=3.6
 

	
 
[options.package_data]
 
languedoc = models.json.gz
src/languedoc/predict.py
Show inline comments
 
import os
 
import re
 
import itertools
 
import json
 
import gzip
 

	
 
TOP_NGRAM_COUNT = 3000
 
MODEL_PATH = os.path.join(os.path.dirname(__file__), "../../models.json.gz")
 
MODEL_PATH = os.path.join(os.path.dirname(__file__), "models.json.gz")
 

	
 

	
 
def preprocess(text):
 
	text = re.sub(r"[\W\d_]+", " ", " "+text+" ")
 
	return text.lower()
 

	
 

	
 
def extract_kgram_freqs(text, k):
 
	n = len(text)
 
	d = dict()
 

	
 
	for i in range(0, n-k+1):
src/languedoc/train.py
Show inline comments
 
@@ -65,25 +65,25 @@ def cross_validate(sample_sets):
 
					predicted_lang = identify(t, test_models)
 
					if predicted_lang == real_lang:
 
						score += 1
 
					else:
 
						print(real_lang, predicted_lang, t)
 
					max_score += 1
 

	
 
	return score / max_score, (score, max_score)
 

	
 

	
 
DATA_DIR = os.path.join(os.path.dirname(__file__), "../../data")
 
LANG_DIRS = sorted([x.path for x in os.scandir(DATA_DIR)])
 
MODEL_PATH = os.path.join(os.path.dirname(__file__), "../../models.json.gz")
 
MODEL_PATH = os.path.join(os.path.dirname(__file__), "models.json.gz")
 

	
 
if __name__ == "__main__":
 
	samples = []
 

	
 
	for d in LANG_DIRS:
 
		lang = os.path.basename(d)
 
		lang_samples = SampleSet(lang)
 
		samples.append(lang_samples)
 

	
 
		for file in sorted(os.scandir(d), key=lambda f: f.name):
 
			with open(file) as f:
 
				text = f.read()
0 comments (0 inline, 0 general)