def test_load(self): language = Language() # confirm that defaults are used self.assertEquals(language.strings["speed"], "speed") language = Language("base") # confirm that custom values added self.assertEquals(language.strings["speed"], "sebesség") # confirm that not custom defined values are still defaults self.assertEquals(language.strings["long 1"], "dolor sit amet")
def parse_file(): file = open('./languages.txt', 'r') for line in file: lang_name = line.rstrip() l = Language(language = lang_name) db.session.add(l) db.session.commit()
def post(self): """Create a new language and fill it with empty translations""" if not users.is_current_user_admin(): self.error(403) code = self.request.get('code') label = self.request.get('label') language = Language.all().filter('code =', code).get() if language is not None: self.error(500) else: language = Language(code=code, label=label, enabled_in_tool=False, enabled_on_site=False) for phrase in Phrase.all(): translation = Translation(phrase=phrase, text='') translation.put() language.translations.append(translation.key()) language.put() init_cached_languages() self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('')
def add_new(self, tag_id, font_id, language): new_tag = Language(tag_id=tag_id, font_id=font_id, language=language) db_session.add(new_tag) db_session.commit() return new_tag
def _add_translation_if_not_exist(word="", tr="", l1="", l2=""): language = Language(l1=l1, l2=l2) wordrow = Word.query.filter_by(word=word).first() if not wordrow: wordrow = Word(word=word, state="learning", language=language) db.session.add(wordrow) translation = Translation(translation=tr, word=wordrow) db.session.add(translation) db.session.commit()
def add_lang(lang): """Add lang string to db.""" this_lang = Language.query.filter( Language.language_name.ilike(lang)).first() if this_lang: return this_lang = Language(language_name=lang) db.session.add(this_lang) db.session.commit()
def seed_data(): """Create example data for the test database.""" engineering_types = [ 'Full Stack', 'Front End', 'Back End', 'Web', 'Mobile', 'Game', 'DevOps', 'CRM', 'Test', 'Embedded', 'Security', 'Infrastucture', 'Architect', 'Platform', 'Other' ] for name in engineering_types: add_type = EngineeringType(engineer_type=name) db.session.add(add_type) lang_list = open("lang_list.txt") for name in lang_list: add_lang = Language(language_name=name) db.session.add(add_lang) user_1 = User(fname='Denise', lname='Dekker', email='*****@*****.**', password='******', city='Oakland', state='CA', twitter='dmcdekker', linkedin='denise-m-dekker', website_url='dmdekker.io', description='Some long and lovely text about me', engineer_type=3, is_active=True, is_mentor=False, photo='/static/images/denise_dekker.jpg') #relationship = Relationship(mentee_id=user_1) language_id_1 = LanguageMiddle(language_id=3, user=user_1) language_id_2 = LanguageMiddle(language_id=6, user=user_1) language_id_3 = LanguageMiddle(language_id=10, user=user_1) language_id_3 = LanguageMiddle(language_id=16, user=user_1) language_id_3 = LanguageMiddle(language_id=8, user=user_1) education = Education(school_name='Mills College', school_city='Oakland', school_state='CA', degree_level='BA', major='CS', year='2017') ed_id = EducationMiddle(education=education, user=user_1) db.session.add_all([ user_1, language_id_1, language_id_2, language_id_3, education, ed_id ]) db.session.commit()
def process_input_text(text, min_prob=0.9): """Identify language and suggest correction in case of misspellings Takes input text and minimum desired probability for language detection :return detected language, probability, suggestion and similarity """ lang, prob = detect_language(text, min_prob) d = map_language_to_dict(lang) suggestion, similarity = spellcheck(text, d) result = Response(Language(lang, prob), SpellCheck(suggestion, similarity)) return result
def test_save(self): sample_file = "test/lang_en.xml" check_file = "test/lang_check.xml" if isfile(sample_file): remove(sample_file) with open(check_file, "r") as check_file_handle: check_xml = check_file_handle.read() language = Language() language.save(sample_file) with open(sample_file, "r") as sample_file_handle: sample_xml = sample_file_handle.read() self.assertEquals(sample_xml, check_xml)
def import_languages(): for file_path in filter(lambda x: x.startswith('profile_language'), get_parquet_file_paths()): table = pq.read_table(file_path) df = table.to_pandas() for idx, row in df.iterrows(): print(f"lang {idx}") c = Language() c.id = uuid.uuid4().hex c.created = row['created'] c.updated = row['updated'] c.name = row['name'] c.profile_id = row['profile_id'] session.add(c) session.commit()
def example_data(): """Create example data for the test database.""" Dislike.query.delete() Stargazer.query.delete() Watcher.query.delete() Follower.query.delete() Contributor.query.delete() RepoLanguage.query.delete() Language.query.delete() Repo.query.delete() Account.query.delete() User.query.delete() jane = User(user_id="1", login="******", name="Jane", last_crawled=datetime.datetime.now(), last_crawled_depth=2) alex = User(user_id="2", login="******", name="Alex", last_crawled=(datetime.datetime.now() - datetime.timedelta(weeks=6)), last_crawled_depth=2) kelly = User(user_id="3", login="******", name="Kelly") db.session.add_all([jane, alex, kelly]) db.session.commit() jane_account = Account(user_id="1", access_token="abc123") db.session.add(jane_account) db.session.commit() py_repo = Repo(repo_id="1", name="python-repo", description="A Python repository", owner_id="1", last_crawled=datetime.datetime.now(), last_crawled_depth=2, url="https://github.com/jhacks/python-repo", stargazers_count=2) js_repo = Repo(repo_id="2", name="js-repo", description="A Javascript repository", owner_id="1", last_crawled=(datetime.datetime.now() - datetime.timedelta(weeks=6)), last_crawled_depth=1, url="https://github.com/jhacks/js-repo", stargazers_count=1) db.session.add_all([py_repo, js_repo]) db.session.commit() astar = Stargazer(repo_id="1", user_id="2") kstar = Stargazer(repo_id="1", user_id="3") kstar_js = Stargazer(repo_id="2", user_id="3") a_dislike_js = Dislike(repo_id="2", user_id="2") # k_dislike_js = Dislike(repo_id="2", user_id="3") db.session.add_all([astar, kstar, kstar_js, a_dislike_js]) db.session.commit() kwatch = Watcher(repo_id="1", user_id="3") a_j_follow = Follower(user_id="1", follower_id="2") k_j_follow = Follower(user_id="1", follower_id="3") j_a_follow = Follower(user_id="2", follower_id="1") db.session.add_all([kwatch, a_j_follow, k_j_follow, j_a_follow]) db.session.commit() jcon = Contributor(repo_id="1", user_id="1") kcon = Contributor(repo_id="1", user_id="3") db.session.add_all([jcon, kcon]) db.session.commit() # python = Topic(topic_id="1", topic_name="python") # api = Topic(topic_id="2", topic_name="api") # db.session.add_all([python, api]) # db.session.commit() # py_rep1 = RepoTopic(topic_id="1", repo_id="1") # api_rep1 = RepoTopic(topic_id="2", repo_id="1") # db.session.add_all([py_rep1, api_rep1]) # db.session.commit() py_lang = Language(language_id="1", language_name="python") c_lang = Language(language_id="2", language_name="c") db.session.add_all([py_lang, c_lang]) db.session.commit() py_lang_rep1 = RepoLanguage(language_id="1", repo_id="1", language_bytes=5000) c_lang_rep1 = RepoLanguage(language_id="2", repo_id="1", language_bytes=100) db.session.add_all([py_lang_rep1, c_lang_rep1]) db.session.commit()
# define language objects. # i don't currently care about the words and stuff from model import DivergenceModel from model import Language from model import Community import networkx as nx language1 = Language("Language1") language2 = Language("Language2") language3 = Language("Language3") language4 = Language("Language4") language5 = Language("Language5") language6 = Language("Language6") # make a list of the languages to give to the model. languageList = [ language1, language2, language3, language4, language5, language6 ] # input some meanings and forms into the languages for eachlanguage in languageList: eachlanguage.formMeaningDict = {} language1.add_meaning("Lizard", ([("wiri-wiri", 75, 0), ("mirdi", 10, 0)])) language2.add_meaning("Lizard", ([("wiri-wiri", 15, 0)])) language3.add_meaning("Lizard", ([("wiri-wiri", 50, 0), ("mirdi", 10, 0)])) language4.add_meaning("Lizard", ([("julirri", 80, 0), ("jindararda", 40, 0)])) language5.add_meaning("Lizard", ([("jindararda", 70, 0), ("wiri-wiri", 50, 0)])) language6.add_meaning("Lizard", ([("mirdi", 60, 0), ("jindararda", 60, 0)]))
def create_language(language): language = Language(language=language) db.session.add(language) db.session.commit()