def main(): from sqlalchemy import create_engine from noj import init_db engine = create_engine('sqlite:///../../test.sqlite', echo=False) init_db(engine) schema_path = '../../schemas/dictionary_schema_1.0.0a.xsd' # importable_path = '../converters/daijirin2/daijirin2_importable.xml' #importable_path = '../converters/jmdict/jmdict-importable.xml' importable_path = sys.argv[1] # importable_path = '../../schemas/example_dictionary_1.0.0a.xml' import progressbar as pb widgets = ['Importing: ', pb.Percentage(), ' ', pb.Bar(), ' ', pb.Timer(), ' '] session = Session() importer = DictionaryWalker(importable_path) parser = JapaneseParser() visitor = DictionaryImporterVisitor(session, parser) importer.validate_schema(schema_path) pbar = pb.ProgressBar(widgets=widgets, maxval=len(importer)).start() for i in importer.import_generator(visitor): pbar.update(i) session.commit() session.close() pbar.finish()
def main(): from sqlalchemy import create_engine from noj import init_db from noj.model.profiles import ProfileManager from noj.tools.check_platform import isWin, isMac pm = ProfileManager() #engine = create_engine('sqlite:///../../test.sqlite', echo=False) engine = create_engine(pm.database_connect_string(), echo=False) init_db(engine) if isWin: collection_path = 'C:\Users\Mathew\Documents\Anki\User 1\collection.anki2' else: collection_path = '/Users/mathew/Documents/Anki/User 1/collection.anki2' import progressbar as pb widgets = ['Importing: ', pb.Percentage(), ' ', pb.Bar(), ' ', pb.Timer(), ' '] session = Session() # importer = AnkiWalker(collection_path, 'Japanese', # expression_field='Expression', meaning_field='Meaning') importer = AnkiWalker(collection_path, 'Core 2000 Japanese Vocabulary', expression_field='Sentence - Kanji', meaning_field='Sentence - English', sound_field='Sentence - Audio') parser = JapaneseParser() visitor = create_anki_sync_visitor(session, parser, pm) print importer._get_media_folder_path() pbar = pb.ProgressBar(widgets=widgets, maxval=len(importer)).start() for i in importer.import_generator(visitor): pbar.update(i) session.commit() session.close() pbar.finish()
def main(): import sys import logging from sqlalchemy import create_engine from noj import init_db from noj.model.profiles import ProfileManager logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO) pm = ProfileManager() pm.database_file = 'jmdict.sqlite' # pm.database_file = 'daijirin2.sqlite' print pm.database_connect_string() search_word = u'面白い' # search_word = u'先生' # search_word = u'悪どい' # search_word = u'スポーツ' # search_word = u'生く' if len(sys.argv) == 2: print sys.getdefaultencoding() search_word = sys.argv[1].decode(sys.stdin.encoding) engine = create_engine(pm.database_connect_string(), echo=True) init_db(engine) session = Session() lookup = AsyncLookup() # ues = _lookup_ues_by_entry(search_word, 100, None, None) # print unicode(ues) result = lookup.lookup_ues_by_entry(search_word, limit=100) print 'waiting for results' ues = result.get() session.close()
def main(): import sys from sqlalchemy import create_engine from noj import init_db from noj.model.profiles import ProfileManager logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO) pm = ProfileManager() pm.database_file = "jmdict.sqlite" # pm.database_file = 'daijirin2.sqlite' print pm.database_connect_string() # search_word = u'面白い' # search_word = u'先生' # search_word = u'悪どい' # search_word = u'スポーツ' # search_word = u'生く' search_word = u"怪物" if len(sys.argv) == 2: print sys.getdefaultencoding() search_word = sys.argv[1].decode(sys.stdin.encoding) engine = create_engine(pm.database_connect_string(), echo=True) init_db(engine) session = Session() lookup = LookupUEs() logging.info("start") # ues = lookup.lookup_ues_by_entry(session, search_word, 100) # ues = lookup.lookup_ues_by_expression(session, search_word, 100) dict_result = lookup.lookup_entries(session, search_word, 100) print "dict:", unicode(dict_result) logging.info("done") # ues = lookup.lookup_ues_by_entry(session, u'先生') # print len(ues) # return # ues = search_expressions(session, search_word) # print unicode(ues) # print ues.get_count(), len(ues) # for ue, entry, definition in ues: # print ue.get_n_score() # print ue.expression.expression # print ue.meaning # print # break # for ue in ues: # print ue.get_n_score() # print ue.expression.expression # print ue.meaning # for d in ue.definition_assocs: # print d.number, d.definition.breadcrumb_string(), d.definition.entry.breadcrumb_string() # print # break logging.info("done") # session.commit() session.close()