示例#1
0
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 ))
示例#2
0
 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')
示例#3
0
 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' )
示例#4
0
 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' )
示例#5
0
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' )
示例#6
0
 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' )
示例#7
0
 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' )
示例#8
0
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')
示例#9
0
    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' )
示例#10
0
    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' )
示例#11
0
    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' )
示例#12
0
    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' )
示例#13
0
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()
示例#14
0
 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' )
示例#15
0
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()
示例#16
0
 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' )
示例#17
0
def post( st ):
    ms = getMorphemes( st['txt'], None, cfg1('morph_blacklist') )
    s = ms2str( ms )
    infoMsg( '----- All -----\n' + s )
示例#18
0
def post(st):  # :: State -> State
    infoMsg('Tagged all notes containing morphemes in that db')
    return st
示例#19
0
 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' )
示例#20
0
def post( st ):
    if len(st['morphemes']) == 0:
        infoMsg('----- No morphemes, check your filters -----')
        return
    s = ms2str( st['morphemes'] )
    infoMsg( '----- All -----\n' + s )
示例#21
0
def post( st ): # :: State -> State
    infoMsg( 'Tagged all notes containing morphemes in that db' )
    return st
示例#22
0
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' )