Пример #1
0
def get_edict():
    if getattr(get_edict, '_cached', None) is not None:
        return get_edict._cached

    with sopen(get_data_loc('edict', extension=''), mode='r') as edf:
        edict = auto_format.load_dictionary(edf)

    get_edict._cached = edict

    return edict
Пример #2
0
def get_edict():
    if getattr(get_edict, '_cached', None) is not None:
        return get_edict._cached

    with sopen(get_data_loc('edict', extension=''), mode='r') as edf:
        edict = auto_format.load_dictionary(edf)

    get_edict._cached = edict

    return edict
Пример #3
0
    def test_edict_senses(self):
        """
        Test that senses_by_reading works
        """
        expected = {
            'げっしもく':
            ['(n) (1) Rodentia', '(adj-no) (2) rat-like', 'rodential']
        }

        d = load_dictionary(self.je_edict)
        self.assertEqual(d['齧歯目'].senses_by_reading(), expected)
Пример #4
0
    def test_edict_senses(self):
        """
        Test that senses_by_reading works
        """
        expected = {
            'げっしもく': [
                '(n) (1) Rodentia',
                '(adj-no) (2) rat-like',
                'rodential'
            ]
        }

        d = load_dictionary(self.je_edict)
        self.assertEqual(d['齧歯目'].senses_by_reading(), expected)
Пример #5
0
    def GenerateFiltered(self):
        'Takes EDICT file and inputs its contents into ngram_totals_filtered table'
        edict_file = resource_filename('cjktools_data', 'dict/je_edict')
        edict_stream = codecs.open(edict_file, 'r', encoding='utf-8')
        edict = auto_format.load_dictionary(edict_stream)

        for entry in edict:
            isCommon = u'(P)' in edict[entry].senses

            values_to_insert = [(entry, len(entry), '', 0, isCommon)]
            for reading in edict[entry].readings:
                values_to_insert.append((reading, len(reading), entry, 1, isCommon))

            query = u"""
            INSERT INTO `ngram_totals_filtered`(`gram`, `length`, `parent`, `hasParent`, `isCommon`) VALUES
             """ + ",".join("(%s, %s, %s, %s, %s)" for _ in values_to_insert) + " ON DUPLICATE KEY UPDATE gram=gram"
            flattened_values = [item for sublist in values_to_insert for item in sublist]

            self.checkConnection()
            self.write_cursor.execute(query, flattened_values)
            self.write_con.commit()
Пример #6
0
    def test_edict(self):
        "Tests correct detection and parsing of edict."
        d = load_dictionary(self.je_edict)
        self.assertIsInstance(d, BilingualDictionary)
        self.assertEqual(d.format.name, 'edict')

        self.assertEqual(len(d), 2)

        self._check_lookup(
            d,
            u'齧歯目',
            [u'げっしもく'],
            [u'(n) (1) Rodentia', u'(adj-no) (2) rat-like', u'rodential'],
        )

        self._check_lookup(
            d,
            u'齲歯',
            [u'うし'] * 4 + [u'むしば'] * 4,
            ['(n,adj-no) cavity', 'tooth decay', 'decayed tooth', 'caries'] *
            2,
        )
Пример #7
0
    def test_edict(self):
        "Tests correct detection and parsing of edict."
        d = load_dictionary(self.je_edict)
        self.assertIsInstance(d, BilingualDictionary)
        self.assertEqual(d.format.name, 'edict')

        self.assertEqual(len(d), 2)

        self._check_lookup(
            d,
            u'齧歯目',
            [u'げっしもく'],
            [u'(n) (1) Rodentia', u'(adj-no) (2) rat-like', u'rodential'],
        )

        self._check_lookup(
            d,
            u'齲歯',
            [u'うし']*4 + [u'むしば']*4,
            ['(n,adj-no) cavity', 'tooth decay', 'decayed tooth',
                'caries']*2,
        )
Пример #8
0
 def load_dictionaries(self):
     if self.edict is None:
         self.edict = auto_format.load_dictionary(self.edict_file)
Пример #9
0
def load_dict(path):
    with io.open(path, encoding='utf-8') as edict_file:
        dict = auto_format.load_dictionary(edict_file)
        return dict
Пример #10
0
    def initializeResources(self):
        
        """Initialize Options"""
#        self.options = Options()
        self.loadingStatus = u''
        
        self.qload = QuickLoad(self.options)
        if self.options.isLoadingOnStart():
            self.qload.exec_()
        
        """Pre-initialization"""
        self.animationTimer = ()
        self.progressTimer = ()
        self.grid_layout =()
        
        """Initialize Statistics"""
        self.stats = Stats()
        
        """Config Here"""
        self.initializeComposition()
        self.initializeComponents()
        self.setMenus()
        self.trayIcon.show()
        #self.startTrayLoading()
        
        """"Initialize Dictionaries    (will take a some time!)"""
        time_start = datetime.now()
        
        self.trayIcon.showMessage('Loading...', 'Initializing dictionaries', QSystemTrayIcon.MessageIcon.Information, 20000 )
        # kanji composition #
        if self.options.isLoadingRadk(): self.rdk = RadkDict()
        else: self.loadingStatus += '--> Radikt disabled!\n'
        # edict dictionary
        if self.options.isLoadingEdict():
            edict_file = resource_filename('cjktools_data', 'dict/je_edict')
            self.edict = auto_format.load_dictionary(edict_file)
        else: 
            self.edict = None
            self.loadingStatus += '--> Edict disabled!\n'
        # kanjidict dictionary #
        if self.options.isLoadingKdict(): self.kjd = kanjidic.Kanjidic()
        else: 
            self.kjd = None
            self.loadingStatus += '--> Kanjidict disabled!\n'
        # Kanji.Odyssey groups #
        self.groups = KanjiGrouper()
        if self.options.isLoadingGroups(): self.groups.loadgroupsFromDump()
        else: self.loadingStatus += '--> Kanji.Odyssey disabled!\n'
        
        """Initializing srs system"""
        self.trayIcon.showMessage('Loading...', 'Initializing databases', QSystemTrayIcon.MessageIcon.Information, 20000 )
        self.srs = srsScheduler()
        if self.options.isLoadingDb(): self.srs.initializeCurrentSession(self.options.getQuizMode(), self.options.getSessionSize())
        else: self.loadingStatus += '--> Database disabled!\n'
        
        """Jmdict lookup"""
        self.jmdict = DictionaryLookup()
        if self.options.isLoadingJmdict(): 
            self.jmdict.loadJmdictFromDumpRegex()
            self.jmdict.joinTables()
        else: self.loadingStatus += '--> Jmdict disabled!\n'
                
        """Manual add dialog"""
        self.manualAddDialog = ManualAdd(self.srs.db)
        
        if self.loadingStatus != '': self.loadingStatus = '\n\n' + self.loadingStatus
        
        time_end = datetime.now()
        self.loadingTime =  time_end - time_start
Пример #11
0
 def load_dictionaries(self):
     if self.edict is None: self.edict = auto_format.load_dictionary(self.edict_file)