def run(): start = time.time() # update DBs for dPath in deckPaths: deck = getDeck( dPath ) if not deck: continue try: dm = DeckMgr( deck ) if dm.cfg['enabled'] == 'yes': dm.updateDbs() dm.saveCfg() finally: closeDeck( deck ) upDbTime = time.time() log( 'Dbs updated in %f' % (upDbTime-start) ) # update decks for dPath in deckPaths: deck = getDeck( dPath ) if not deck: continue try: dm = DeckMgr( deck ) if dm.cfg['enabled'] == 'yes': dm.updateDeck() dm.saveCfg() finally: closeDeck( deck ) util.lastUpdate = upDeckTime = time.time() log( 'Decks updated in %f' % (upDeckTime-upDbTime) ) log( 'Full update completed in %d sec' % (upDeckTime-start) ) infoMsg('MorphMan Full update completed in %d sec' % ( upDeckTime-start ))
def onSaveResults(self): destPath = QFileDialog.getSaveFileName(caption='Save results to?', directory=dbsPath + os.sep + 'results.db') if not destPath: return if not hasattr(self, 'db'): return errorMsg('No results to save') self.db.save(str(destPath)) infoMsg('Saved successfully')
def onExtractTxtFile( self ): srcPath = QFileDialog.getOpenFileName( caption='Text file to extract from?', directory=util.dbPath ) if not srcPath: return destPath = QFileDialog.getSaveFileName( caption='Save morpheme db to?', directory=util.dbPath + 'textFile.db' ) if not destPath: return db = M.MorphDb.mkFromFile( str(srcPath) ) db.save( str(destPath) ) infoMsg( 'Success', 'Txt Extract' )
def onExtractTxtFile( self ): srcPath = QFileDialog.getOpenFileName( caption='Text file to extract from?', directory=dbsPath ) if not srcPath: return destPath = QFileDialog.getSaveFileName( caption='Save morpheme db to?', directory=dbsPath + os.sep + 'textFile.db' ) if not destPath: return mat = cfg1('text file import maturity') db = MorphDb.mkFromFile( str(srcPath), getAllMorphemizers()[self.morphemizerComboBox.currentIndex()], mat ) if db: db.save( str(destPath) ) infoMsg( 'Extracted successfully' )
def post( st ): util.killMecab( st ) allM = st['db'].keys() # morphemes to learn allF = uniqueFlatten( st['mfmap'].values() ) # facts to learn from ps = getMatches( st, allM, allF ) infoMsg( 'Successfully matched %d pairs.' % len(ps), p=st['ed'] ) for m,f in ps: f['matchedMorpheme'] = u'%s' % m.base infoMsg( 'Saved' )
def restartAuto( self ): try: util.updater.term() except AttributeError: pass # no updater instance yet except ValueError: pass # bad tid => already stopped except ThreadError: pass # not active except SystemError: # async exc failed errorMsg( 'Unable to stop auto' ) auto.main() infoMsg( 'Restarted' )
def onExtractTxtFile( self ): srcPath = QFileDialog.getOpenFileName( caption='Text file to extract from?', directory=dbsPath ) if not srcPath: return destPath = QFileDialog.getSaveFileName( caption='Save morpheme db to?', directory=dbsPath + os.sep + 'textFile.db' ) if not destPath: return mat = cfg1('text file import maturity') db = MorphDb.mkFromFile( str(srcPath), mat ) if db: db.save( str(destPath) ) infoMsg( 'Extracted successfully' )
def post(st): util.killMecab(st) allM = st['db'].keys() # morphemes to learn allF = uniqueFlatten(st['mfmap'].values()) # facts to learn from ps = getMatches(st, allM, allF) infoMsg('Successfully matched %d pairs.' % len(ps), p=st['ed']) for m, f in ps: f['matchedMorpheme'] = u'%s' % m.base infoMsg('Saved')
def onGo( self ): mFmt = unicode( self.matureFmt.text() ) kFmt = unicode( self.knownFmt.text() ) uFmt = unicode( self.unknownFmt.text() ) morphemizer = getAllMorphemizers()[self.morphemizer.currentIndex()] inFile = QFileDialog.getOpenFileName( caption='Dueling subs to process', directory=dbsPath ) if not inFile: return outFile = QFileDialog.getSaveFileName( caption='Save adaptive subs to', directory=dbsPath ) if not outFile: return adaptiveSubs.run( inFile, outFile, morphemizer, mFmt, kFmt, uFmt ) infoMsg( 'Completed successfully' )
def onGo( self ): ws = parseWhitelist( self.whitelist.text() ) bs = parseWhitelist( self.blacklist.text() ) mFmt = unicode( self.matureFmt.text() ) kFmt = unicode( self.knownFmt.text() ) uFmt = unicode( self.unknownFmt.text() ) inFile = QFileDialog.getOpenFileName( caption='Dueling subs to process', directory=dbsPath ) if not inFile: return outFile = QFileDialog.getSaveFileName( caption='Save adaptive subs to', directory=dbsPath ) if not outFile: return adaptiveSubs.run( inFile, outFile, ws, bs, mFmt, kFmt, uFmt ) infoMsg( 'Completed successfully' )
def onGo( self ): ws = parseWhitelist( self.whitelist.text() ) bs = parseWhitelist( self.blacklist.text() ) mFmt = unicode( self.matureFmt.text() ) kFmt = unicode( self.knownFmt.text() ) uFmt = unicode( self.unknownFmt.text() ) inFile = QFileDialog.getOpenFileName( caption='Dueling subs to process', directory=util.dbPath ) if not inFile: return outFile = QFileDialog.getSaveFileName( caption='Save adaptive subs to', directory=util.dbPath ) if not outFile: return adaptiveSubs.run( inFile, outFile, ws, bs, mFmt, kFmt, uFmt ) infoMsg( 'Completed successfully' )
def getMatches( st, allM, allF ): pairs = [] for m in allM: # for ea morpheme we want to learn if m not in st['mfmap']: continue for f in st['mfmap'][m]: # for ea fact we can learn said morpheme from pairs.append( (m,f) ) # add morpheme,fact pair to graph A, B = [], [] for (a,b) in pairs: if a not in A: A.append( a ) if b not in B: B.append( b ) g = ML.Graph() g.mkMatch( pairs ) infoMsg( '%d possible pairings for %d/%d morphemes to %d/%d facts, %s. Calculating now...' % ( len(pairs), len(A), len(allM), len(B), len(allF), g.complexity() ), p=st['ed'] ) return g.doMatch()
def stopAuto( self ): try: util.updater.term() infoMsg( 'Auto stopping' ) except AttributeError: # no updater instance yet infoMsg( 'Auto never started' ) except ValueError: # bad tid infoMsg( 'Auto already stopped' ) except ThreadError: # not active infoMsg( 'Auto already stopped' ) except SystemError: # async exc failed errorMsg( 'Unable to stop auto' )
def getMatches(st, allM, allF): pairs = [] for m in allM: # for ea morpheme we want to learn if m not in st['mfmap']: continue for f in st['mfmap'][m]: # for ea fact we can learn said morpheme from pairs.append((m, f)) # add morpheme,fact pair to graph A, B = [], [] for (a, b) in pairs: if a not in A: A.append(a) if b not in B: B.append(b) g = ML.Graph() g.mkMatch(pairs) infoMsg( '%d possible pairings for %d/%d morphemes to %d/%d facts, %s. Calculating now...' % (len(pairs), len(A), len(allM), len(B), len(allF), g.complexity()), p=st['ed']) return g.doMatch()
def onSaveResults( self ): destPath = QFileDialog.getSaveFileName( caption='Save results to?', directory=dbsPath + os.sep + 'results.db' ) if not destPath: return if not hasattr( self, 'db' ): return errorMsg( 'No results to save' ) self.db.save( str(destPath) ) infoMsg( 'Saved successfully' )
def post( st ): ms = getMorphemes( st['txt'], None, cfg1('morph_blacklist') ) s = ms2str( ms ) infoMsg( '----- All -----\n' + s )
def post(st): # :: State -> State infoMsg('Tagged all notes containing morphemes in that db') return st
def onSaveResults( self ): destPath = QFileDialog.getSaveFileName( caption='Save results to?', directory=util.dbPath + 'results.db' ) if not destPath: return self.db.save( str(destPath) ) infoMsg( 'Success', 'Save db' )
def post( st ): if len(st['morphemes']) == 0: infoMsg('----- No morphemes, check your filters -----') return s = ms2str( st['morphemes'] ) infoMsg( '----- All -----\n' + s )
def post( st ): # :: State -> State infoMsg( 'Tagged all notes containing morphemes in that db' ) return st
def post(st): ms = getMorphemes(st['morphemizer'], st['txt']) s = ms2str(ms) infoMsg('----- All -----\n' + s)
def post( st ): st['morphDb'].save( st['dbpath'] ) infoMsg( 'DB saved with extracted morphemes' )