Exemple #1
0
def init_db(engine):
    Session.configure(bind=engine)
    Base.metadata.create_all(engine)
    session = Session()

    # Insert library types
    for lib_type, lib_type_id in db_constants.LIB_TYPES_TO_ID.items():
        db.insert(session, models.LibraryType, name=lib_type, id=lib_type_id)

    # Insert usage example list types
    for ue_list_type, ue_list_type_id in db_constants.UE_LIST_TYPES_TO_ID.items():
        db.insert(session, models.UEListType, name=ue_list_type, id=ue_list_type_id)

    # Insert morpheme types
    for mtype, mtype_id in db_constants.MORPHEME_TYPES_TO_ID.items():
        db.insert(session, models.MorphemeType, name=mtype, id=mtype_id)

    # Insert morpheme statuses
    for mstat, mstat_id in db_constants.MORPHEME_STATUSES_TO_ID.items():
        db.insert(session, models.MorphemeStatus, name=mstat, id=mstat_id)

    # Insert known examples list
    db.insert(session, models.UEList, name=db_constants.KNOWN_EXAMPLES_NAME, 
              id=db_constants.KNOWN_EXAMPLES_ID, 
              type_id=db_constants.UE_LIST_TYPES_TO_ID['SYSTEM'])

    session.commit()
    session.close()
Exemple #2
0
    def _import_expression(self, expression):
        expression_id, new = db.insert(self.session, models.Expression, expression=expression)
        if new:
            morpheme_list = self._import_parse_morphemes(expression)
            if len(morpheme_list) > 0:
                for m in morpheme_list:
                    m["expression_id"] = expression_id
                db.insert_many(self.session, models.ExpressionConsistsOf, morpheme_list)

        return expression_id
Exemple #3
0
 def visit_kanji_list(self, kanji_list):
     entry_kanji = list()
     if self.eformat == "J-J1":
         for i, kanji_text in enumerate(kanji_list):
             assert self.last_kana_text is not None
             kanji_id = db.insert(
                 self.session,
                 models.Morpheme,
                 morpheme=uf.unformat_jj1_kanji(kanji_text, self.last_kana_text),
                 type_id=db_constants.MORPHEME_TYPES_TO_ID["KANJI_ENTRY"],
                 status_id=db_constants.MORPHEME_STATUSES_TO_ID["AUTO"],
             )[0]
             entry_kanji.append({"entry_id": self.entry_id, "kanji_id": kanji_id, "number": i + 1})
     else:
         for i, kanji_text in enumerate(kanji_list):
             kanji_id = db.insert(
                 self.session,
                 models.Morpheme,
                 morpheme=kanji_text,
                 type_id=db_constants.MORPHEME_TYPES_TO_ID["KANJI_ENTRY"],
                 status_id=db_constants.MORPHEME_STATUSES_TO_ID["AUTO"],
             )[0]
             entry_kanji.append({"entry_id": self.entry_id, "kanji_id": kanji_id, "number": i + 1})
     db.insert_many(self.session, models.EntryHasKanji, entry_kanji)
Exemple #4
0
    def visit_usage_example(self, ue_type):
        self.ue_obj = models.UsageExample(library_id=self.lib_id)

        ue_type = ue_type.upper()
        ue_type_id = db.insert(self.session, models.UEType, name=ue_type)[0]
        self.ue_obj.type_id = ue_type_id
Exemple #5
0
 def visit_entry_format(self, eformat):
     self.eformat = eformat
     eformat_id = db.insert(self.session, models.EntryFormat, name=self.eformat)[0]
     self.entry_obj.format_id = eformat_id