def buildIndex(): fldbk = dataIndex.fldbk indexList = [] errorList = [] dict = dataIndex.exDict fldbk.iErrorBox.clear() fldbk.iSortingBox.setCurrentIndex(0) tokenCount = 0 for key in dict: try: line = dict[key].find('Line').text lineList = autoparsing.cleanLine(line) morphList = dict[key].find('Mrph').text.split('\t') glossList = dict[key].find('ILEG').text.split('\t') for i in range(0, len(morphList)): morph = morphList[i] if len(morph) == 0: morph = '[-]' gloss = glossList[i] if len(gloss) == 0: gloss = '[-]' indexList.append(lineList[i] + '\t' + morph + '\t' + gloss + '\t' + key + ':' + str(i+1) + '\n') tokenCount +=1 except (TypeError, AttributeError): pass except IndexError: errorList.append(key) if len(errorList) != 0: for key in errorList: item = QtWidgets.QListWidgetItem() item.setText(key) fldbk.iErrorBox.addItem(item) indexList = sorted(indexList) prevMorph = '' trimmedList = [] for i, item in enumerate(indexList): index = item.index('\tEX') if item[:index-1] != prevMorph: prevMorph = item[:index-1] trimmedList.append(item) else: trimmedList[-1] = trimmedList[-1][:-1] + item[index:] indexString = ''.join(trimmedList)[:-1] wordformCount = formattingHandlers.addCommas(len(trimmedList)) tokenCount = formattingHandlers.addCommas(tokenCount) fldbk.iIndex.setText(indexString) # fldbk.tabWidget.setCurrentIndex(7) fldbk.iWordformLbl.setText("Wordforms: " + str(wordformCount)) fldbk.iTokensLbl.setText("Tokens: " + str(tokenCount)) fldbk.iSortNowBtn.setStyleSheet('background: #6698FF;')
def navListBuilderLex(fldbk): '''make models for the lex Navs''' navModelL = QtGui.QStandardItemModel() for node in dataIndex.root.iter('Lex'): LexID = node.attrib.get('LexID') Orth = node.findtext('Orth') dataIndex.lexDict[LexID] = node item = QtGui.QStandardItem(Orth) item.setData(LexID, 32) navModelL.appendRow(item) proxyModelL = Alphabetizer.Alphabetizer(fldbk) proxyModelL.setSourceModel(navModelL) proxyModelL.setDynamicSortFilter(True) fldbk.hLexNav.setModel(proxyModelL) fldbk.lLexNav.setModel(proxyModelL) fldbk.hLexNav.setSelectionModel(fldbk.lLexNav.selectionModel()) s = str(formattingHandlers.addCommas(navModelL.rowCount())) if s == '1': fldbk.hLexiconLabel.setText("Lexicon: 1 entry") else: fldbk.hLexiconLabel.setText("Lexicon: %s entries" % s)
def navListBuilderData(fldbk): navModelD = QtGui.QStandardItemModel() for node in dataIndex.root.iter('Dset'): dsetID = node.attrib.get('DsetID') dTitle = node.findtext('Title') dTitle = formattingHandlers.XMLtoPlainText(dTitle) dataIndex.dataDict[dsetID] = node item = QtGui.QStandardItem(dTitle) item.setData(dsetID, 32) navModelD.appendRow(item) proxyModelD = QtCore.QSortFilterProxyModel() proxyModelD.setSourceModel(navModelD) proxyModelD.setSortCaseSensitivity(0) proxyModelD.sort(0, QtCore.Qt.AscendingOrder) fldbk.hDataNav.setModel(proxyModelD) fldbk.dDataNav.setModel(proxyModelD) s = str(formattingHandlers.addCommas(navModelD.rowCount())) if s == '1': fldbk.hDatasetLabel.setText("Datasets: 1 dataset") else: fldbk.hDatasetLabel.setText("Datasets: %s datasets" % s) fldbk.hDataNav.setSelectionModel(fldbk.dDataNav.selectionModel())
def sortIndex(fldbk,indexString,index=0): '''have to trap this because fieldbook.py triggers this routine when it fills the Sorting bos on the index card (and there is no index to sort)''' try: indexList = indexString.split('\n') except AttributeError: return indexListList = [] for item in indexList: itemList = item.split('\t') indexListList.append(itemList) sortedIndexList = sorted(indexListList, key = lambda s: s[index]) finalList = [] for item in sortedIndexList: itemString = '\t'.join(item) finalList.append(itemString) indexString = '\n'.join(finalList) if indexString[0] == '\n': indexString = indexString[1:] fldbk.iIndex.setText(indexString) fldbk.iSortNowBtn.setStyleSheet('background: #6698FF;') wordformCount = formattingHandlers.addCommas(len(indexList)) fldbk.iWordformLbl.setText("Wordforms: " + str(wordformCount))
def navListBuilderText(fldbk): navModelT = QtGui.QStandardItemModel() for node in dataIndex.root.iter('Text'): TextID = node.attrib.get('TextID') Title = node.findtext('Title') Title = formattingHandlers.XMLtoPlainText(Title) dataIndex.textDict[TextID] = node item = QtGui.QStandardItem(Title) item.setData(TextID, 32) navModelT.appendRow(item) proxyModelT = QtCore.QSortFilterProxyModel() proxyModelT.setSourceModel(navModelT) proxyModelT.setSortCaseSensitivity(0) proxyModelT.sort(0, QtCore.Qt.AscendingOrder) fldbk.hTextNav.setModel(proxyModelT) fldbk.tTextNav.setModel(proxyModelT) fldbk.hTextNav.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) fldbk.tTextNav.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) s = str(formattingHandlers.addCommas(navModelT.rowCount())) if s == '1': fldbk.hTextsLabel.setText("Texts: 1 text") else: fldbk.hTextsLabel.setText("Texts: %s texts" % s) fldbk.hTextNav.setSelectionModel(fldbk.tTextNav.selectionModel())