Example #1
0
    def __init__( self, parent=None ):
        super( AdaptiveSubWin, self ).__init__( parent )
        self.setWindowTitle( 'Adaptive Subs' )
        self.grid = grid = QGridLayout( self )
        self.vbox = vbox = QVBoxLayout()

        self.matureFmt  = QLineEdit( u'%(jpn)s' )
        self.knownFmt   = QLineEdit( u'%(jpn)s [%(eng)s]' )
        self.unknownFmt = QLineEdit( u'%(eng)s [%(N_k)s] [%(unknowns)s]' )
        self.morphemizer = QComboBox()

        for morphemizer in getAllMorphemizers():
            self.morphemizer.addItem(morphemizer.getDescription())

        self.vbox.addWidget( QLabel( 'Mature Format' ) )
        self.vbox.addWidget( self.matureFmt )
        self.vbox.addWidget( QLabel( 'Known Format' ) )
        self.vbox.addWidget( self.knownFmt )
        self.vbox.addWidget( QLabel( 'Unknown Format' ) )
        self.vbox.addWidget( self.unknownFmt )
        self.vbox.addWidget( QLabel( 'Morpheme Engine (Morphemizer)' ) )
        self.vbox.addWidget( self.morphemizer )

        self.goBtn = mkBtn( 'Convert subs', self.onGo, self, vbox )

        grid.addLayout( vbox, 0, 0 )
Example #2
0
    def __init__(self, parent=None):
        super(AdaptiveSubWin, self).__init__(parent)
        self.setWindowTitle('Adaptive Subs')
        self.grid = grid = QGridLayout(self)
        self.vbox = vbox = QVBoxLayout()

        self.matureFmt = QLineEdit(u'%(jpn)s')
        self.knownFmt = QLineEdit(u'%(jpn)s [%(eng)s]')
        self.unknownFmt = QLineEdit(u'%(eng)s [%(N_k)s] [%(unknowns)s]')
        self.morphemizer = QComboBox()

        for morphemizer in getAllMorphemizers():
            self.morphemizer.addItem(morphemizer.getDescription())

        self.vbox.addWidget(QLabel('Mature Format'))
        self.vbox.addWidget(self.matureFmt)
        self.vbox.addWidget(QLabel('Known Format'))
        self.vbox.addWidget(self.knownFmt)
        self.vbox.addWidget(QLabel('Unknown Format'))
        self.vbox.addWidget(self.unknownFmt)
        self.vbox.addWidget(QLabel('Morpheme Engine (Morphemizer)'))
        self.vbox.addWidget(self.morphemizer)

        self.goBtn = mkBtn('Convert subs', self.onGo, self, vbox)

        grid.addLayout(vbox, 0, 0)
Example #3
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' )
Example #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' )
Example #5
0
    def __init__( self, parent=None ):
        super( MorphMan, self ).__init__( parent )
        self.mw = parent
        self.setWindowTitle( 'Morph Man 3 Manager' )
        self.grid = grid = QGridLayout( self )
        self.vbox = vbox = QVBoxLayout()

        # DB Paths
        self.aPathLEdit = QLineEdit()
        vbox.addWidget( self.aPathLEdit )
        self.aPathBtn = mkBtn( 'Browse for DB A', lambda le=self.aPathLEdit: getPath( le ), self, vbox )

        self.bPathLEdit = QLineEdit()
        vbox.addWidget( self.bPathLEdit )
        self.bPathBtn = mkBtn( 'Browse for DB B', lambda le=self.bPathLEdit: getPath( le ), self, vbox )

        # Comparisons
        self.showABtn = mkBtn( 'A', self.onShowA, self, vbox )
        self.AmBBtn = mkBtn( 'A-B', lambda x='A-B': self.onDiff(x), self, vbox )
        self.BmABtn = mkBtn( 'B-A', lambda x='B-A': self.onDiff(x), self, vbox )
        self.symBtn = mkBtn( 'Symmetric Difference', lambda x='sym': self.onDiff(x), self, vbox )
        self.interBtn = mkBtn( 'Intersection', lambda x='inter': self.onDiff(x), self, vbox )
        self.unionBtn = mkBtn( 'Union', lambda x='union': self.onDiff(x), self, vbox )

        # Creation
        ## language class/morphemizer
        self.db = None
        self.morphemizerComboBox = QComboBox()
        for morphemizer in getAllMorphemizers():
            self.morphemizerComboBox.addItem(morphemizer.getDescription())

        vbox.addSpacing(40)
        vbox.addWidget(self.morphemizerComboBox)
        self.extractTxtFileBtn = mkBtn( 'Extract morphemes from file', self.onExtractTxtFile, self, vbox )
        self.saveResultsBtn = mkBtn( 'Save results to db', self.onSaveResults, self, vbox )


        # Display
        vbox.addSpacing(40)
        self.col4Mode = QRadioButton( 'Results as 4col morpheme' )
        self.col4Mode.setChecked( True )
        self.col1Mode = QRadioButton( 'Results as 1col morpheme' )
        vbox.addWidget( self.col4Mode )
        vbox.addWidget( self.col1Mode )
        self.morphDisplay = QTextEdit()
        self.analysisDisplay = QTextEdit()

        # Exporting
        self.adaptiveSubs = mkBtn( 'Adaptive Subs', self.adaptiveSubs, self, vbox )

        # layout
        grid.addLayout( vbox, 0, 0 )
        grid.addWidget( self.morphDisplay, 0, 1 )
        grid.addWidget( self.analysisDisplay, 0, 2 )
Example #6
0
    def __init__( self, parent=None ):
        super( MorphMan, self ).__init__( parent )
        self.mw = parent
        self.setWindowTitle( 'Morph Man 3 Manager' )
        self.grid = grid = QGridLayout( self )
        self.vbox = vbox = QVBoxLayout()

        # DB Paths
        self.aPathLEdit = QLineEdit()
        vbox.addWidget( self.aPathLEdit )
        self.aPathBtn = mkBtn( 'Browse for DB A', lambda le=self.aPathLEdit: getPath( le ), self, vbox )

        self.bPathLEdit = QLineEdit()
        vbox.addWidget( self.bPathLEdit )
        self.bPathBtn = mkBtn( 'Browse for DB B', lambda le=self.bPathLEdit: getPath( le ), self, vbox )

        # Comparisons
        self.showABtn = mkBtn( 'A', self.onShowA, self, vbox )
        self.AmBBtn = mkBtn( 'A-B', lambda x='A-B': self.onDiff(x), self, vbox )
        self.BmABtn = mkBtn( 'B-A', lambda x='B-A': self.onDiff(x), self, vbox )
        self.symBtn = mkBtn( 'Symmetric Difference', lambda x='sym': self.onDiff(x), self, vbox )
        self.interBtn = mkBtn( 'Intersection', lambda x='inter': self.onDiff(x), self, vbox )
        self.unionBtn = mkBtn( 'Union', lambda x='union': self.onDiff(x), self, vbox )

        # Creation
        ## language class/morphemizer
        self.db = None
        self.morphemizerComboBox = QComboBox()
        for morphemizer in getAllMorphemizers():
            self.morphemizerComboBox.addItem(morphemizer.getDescription())

        vbox.addSpacing(40)
        vbox.addWidget(self.morphemizerComboBox)
        self.extractTxtFileBtn = mkBtn( 'Extract morphemes from file', self.onExtractTxtFile, self, vbox )
        self.saveResultsBtn = mkBtn( 'Save results to db', self.onSaveResults, self, vbox )


        # Display
        vbox.addSpacing(40)
        self.col4Mode = QRadioButton( 'Results as 4col morpheme' )
        self.col4Mode.setChecked( True )
        self.col1Mode = QRadioButton( 'Results as 1col morpheme' )
        vbox.addWidget( self.col4Mode )
        vbox.addWidget( self.col1Mode )
        self.morphDisplay = QTextEdit()
        self.analysisDisplay = QTextEdit()

        # Exporting
        self.adaptiveSubs = mkBtn( 'Adaptive Subs', self.adaptiveSubs, self, vbox )

        # layout
        grid.addLayout( vbox, 0, 0 )
        grid.addWidget( self.morphDisplay, 0, 1 )
        grid.addWidget( self.analysisDisplay, 0, 2 )
Example #7
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' )
    def rowGuiToFilter(self, rowGui):
        filter = {}

        if rowGui['modelComboBox'].currentIndex() == 0: filter['Type'] = None # no filter "All note types"
        else: filter['Type'] = rowGui['modelComboBox'].currentText()

        filter['Tags'] = rowGui['tagsEntry'].text().replace(',', ' ').split()
        filter['Fields'] = rowGui['fieldsEntry'].text().replace(',', ' ').split()

        filter['Morphemizer'] = getAllMorphemizers()[rowGui['morphemizerComboBox'].currentIndex()].__class__.__name__
        filter['Modify'] = rowGui['modifyCheckBox'].checkState() != Qt.Unchecked

        return filter
Example #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' )
Example #10
0
    def setTableRow(self, rowIndex, data):
        assert rowIndex >= 0, "Negative row numbers? Really?"
        assert len(
            self.rowGui
        ) >= rowIndex, "Row can't be appended because it would leave an empty row"

        rowGui = {}

        modelComboBox = QComboBox()
        active = 0
        modelComboBox.addItem("All note types")
        for i, model in enumerate(mw.col.models.allNames()):
            if model == data['Type']: active = i
            modelComboBox.addItem(model)
        modelComboBox.setCurrentIndex(active + 1)

        active = 1
        morphemizerComboBox = QComboBox()
        for i, m in enumerate(getAllMorphemizers()):
            if m.__class__.__name__ == data['Morphemizer']: active = i
            morphemizerComboBox.addItem(m.getDescription())
        morphemizerComboBox.setCurrentIndex(active)

        item = QStandardItem()
        item.setCheckable(True)
        item.setCheckState(Qt.Checked if data['Modify'] else Qt.Unchecked)

        rowGui['modelComboBox'] = modelComboBox
        rowGui['tagsEntry'] = QLineEdit(', '.join(data['Tags']))
        rowGui['fieldsEntry'] = QLineEdit(', '.join(data['Fields']))
        rowGui['morphemizerComboBox'] = morphemizerComboBox
        rowGui['modifyCheckBox'] = item
        self.tableView.setIndexWidget(self.tableModel.index(rowIndex, 0),
                                      rowGui['modelComboBox'])
        self.tableView.setIndexWidget(self.tableModel.index(rowIndex, 1),
                                      rowGui['tagsEntry'])
        self.tableView.setIndexWidget(self.tableModel.index(rowIndex, 2),
                                      rowGui['fieldsEntry'])
        self.tableView.setIndexWidget(self.tableModel.index(rowIndex, 3),
                                      morphemizerComboBox)
        self.tableModel.setItem(rowIndex, 4, item)

        if len(self.rowGui) == rowIndex:
            self.rowGui.append(rowGui)
        else:
            self.rowGui[rowIndex] = rowGui
Example #11
0
    def rowGuiToFilter(self, rowGui):
        filter = {}

        if rowGui['modelComboBox'].currentIndex() == 0:
            filter['Type'] = None  # no filter "All note types"
        else:
            filter['Type'] = rowGui['modelComboBox'].currentText()

        filter['Tags'] = rowGui['tagsEntry'].text().replace(',', ' ').split()
        filter['Fields'] = rowGui['fieldsEntry'].text().replace(',',
                                                                ' ').split()

        filter['Morphemizer'] = getAllMorphemizers()[
            rowGui['morphemizerComboBox'].currentIndex()].__class__.__name__
        filter['Modify'] = rowGui['modifyCheckBox'].checkState(
        ) != Qt.Unchecked

        return filter
Example #12
0
    def setTableRow(self, rowIndex, data):
        assert rowIndex >= 0, "Negative row numbers? Really?"
        assert len(self.rowGui) >= rowIndex, "Row can't be appended because it would leave an empty row"

        rowGui = {}

        modelComboBox = QComboBox()
        active = 0
        modelComboBox.addItem("All note types")
        for i, model in enumerate(mw.col.models.allNames()):
            if model == data['Type']: active = i + 1
            modelComboBox.addItem(model)
        modelComboBox.setCurrentIndex(active)

        active = 1
        morphemizerComboBox = QComboBox()
        for i, m in enumerate(getAllMorphemizers()):
            if m.__class__.__name__ == data['Morphemizer']: active = i
            morphemizerComboBox.addItem(m.getDescription())
        morphemizerComboBox.setCurrentIndex(active)

        item = QStandardItem()
        item.setCheckable(True)
        item.setCheckState(Qt.Checked if data['Modify'] else Qt.Unchecked)

        rowGui['modelComboBox'] = modelComboBox
        rowGui['tagsEntry'] = QLineEdit(', '.join(data['Tags']))
        rowGui['fieldsEntry'] = QLineEdit(', '.join(data['Fields']))
        rowGui['morphemizerComboBox'] = morphemizerComboBox
        rowGui['modifyCheckBox'] = item
        self.tableView.setIndexWidget(self.tableModel.index(rowIndex, 0), rowGui['modelComboBox'])
        self.tableView.setIndexWidget(self.tableModel.index(rowIndex, 1), rowGui['tagsEntry'])
        self.tableView.setIndexWidget(self.tableModel.index(rowIndex, 2), rowGui['fieldsEntry'])
        self.tableView.setIndexWidget(self.tableModel.index(rowIndex, 3), morphemizerComboBox)
        self.tableModel.setItem(rowIndex, 4, item)

        if len(self.rowGui) == rowIndex:
            self.rowGui.append(rowGui)
        else:
            self.rowGui[rowIndex] = rowGui
Example #13
0
    def setupUi(self, Form):
        super().setupUi(Form)
        '''
            initialize all values to values in property file

        '''
        # AFileButton
        # BFileButton
        # dbAPath
        # dbBPath
        # showA
        # showB
        # ADiffB
        # BDiffA
        # symmetricDiff
        # ABUnion
        # ABIntersection
        # morphemizer
        # extractMorphemes
        # saveResults

        # onlyWords
        # fullInfo

        # dbTable
        # dbInfo

        self.AFileButton.clicked.connect(lambda: [
            None,
            getPathLE(self.dbAPath,
                      'location of database file',
                      False,
                      startPath=os.path.normpath(p['DEFAULT']['dbdir']),
                      filter_='database dir (*.db)')
        ][0])
        self.BFileButton.clicked.connect(lambda: [
            None,
            getPathLE(self.dbBPath,
                      'location of database file',
                      False,
                      startPath=os.path.normpath(p['DEFAULT']['dbdir']),
                      filter_='database dir (*.db)')
        ][0])

        self.showA.clicked.connect(self.onShowA)
        self.showB.clicked.connect(self.onShowB)

        #comparisons
        self.ADiffB.clicked.connect(lambda: self.DbInteractions('A-B'))
        self.BDiffA.clicked.connect(lambda: self.DbInteractions('B-A'))
        self.symmetricDiff.clicked.connect(lambda: self.DbInteractions('sym'))
        self.ABUnion.clicked.connect(lambda: self.DbInteractions('union'))
        self.ABIntersection.clicked.connect(
            lambda: self.DbInteractions('inter'))

        self.extractMorphemes.clicked.connect(self.onExtractTxtFile)
        self.saveResults.clicked.connect(self.onSaveResults)

        self.db = None

        self.morphemizerComboBox = morphemizerComboBox.MorphemizerComboBox()
        self.morphemizerComboBox.setMorphemizers(getAllMorphemizers())

        self.fullInfo.clicked.connect(self.colModeButtonListener)
        self.onlyMorphs.clicked.connect(self.colModeButtonListener)
        '''
            set actions 
        '''
        self.dbTable.addAction(CopySelectedCellsAction(self.dbTable))