def generateKwargs(self): from corpustools.corpus.classes import Word min_rel = None if self.minEdit.text() != "": try: min_rel = float(self.minEdit.text()) except ValueError: pass max_rel = None if self.maxEdit.text() != "": try: max_rel = float(self.maxEdit.text()) except ValueError: pass kwargs = { "corpusModel": self.corpusModel, "context": self.variantsWidget.value(), "algorithm": self.algorithmWidget.value(), "sequence_type": self.tierWidget.value(), "type_token": self.typeTokenWidget.value(), "min_rel": min_rel, "max_rel": max_rel, } # Error checking if self.compType is None: reply = QMessageBox.critical(self, "Missing information", "Please specify a comparison type.") return elif self.compType == "one": text = self.oneWordEdit.text() if not text: reply = QMessageBox.critical(self, "Missing information", "Please specify a word.") return try: word = self.corpusModel.corpus.find(text) except KeyError: reply = QMessageBox.critical(self, "Invalid information", "'{}' was not found in corpus.".format(text)) return kwargs["query"] = word elif self.compType == "nonword": if self.oneNonword is None: reply = QMessageBox.critical(self, "Missing information", "Please create a word/nonword.") return if not getattr(self.oneNonword, kwargs["sequence_type"]): reply = QMessageBox.critical( self, "Missing information", "Please recreate the word/nonword with '{}' specified.".format(self.tierWidget.displayValue()), ) return kwargs["query"] = self.oneNonword elif self.compType == "two": textOne = self.wordOneEdit.text() textTwo = self.wordTwoEdit.text() if self.nonwordOne is not None: if not getattr(self.nonwordOne, kwargs["sequence_type"]): reply = QMessageBox.critical( self, "Missing information", "Please recreate word/nonword 1 with '{}' specified.".format(self.tierWidget.displayValue()), ) return wordone = self.nonwordOne elif textOne: try: wordOne = self.corpusModel.corpus.find(textOne) except KeyError: reply = QMessageBox.critical( self, "Invalid information", "'{}' was not found in corpus.".format(textOne) ) return elif not textOne: reply = QMessageBox.critical( self, "Missing information", "Please specify either a spelling for word one or create a new word." ) return if self.nonwordTwo is not None: if not getattr(self.nonwordTwo, kwargs["sequence_type"]): reply = QMessageBox.critical( self, "Missing information", "Please recreate word/nonword 2 with '{}' specified.".format(self.tierWidget.displayValue()), ) return wordTwo = self.nonwordTwo elif textTwo: try: wordTwo = self.corpusModel.corpus.find(textTwo) except KeyError: reply = QMessageBox.critical( self, "Invalid information", "'{}' was not found in corpus.".format(textTwo) ) return elif not textTwo: reply = QMessageBox.critical( self, "Missing information", "Please specify either a spelling for word two or create a new word." ) return kwargs["query"] = (wordOne, wordTwo) elif self.compType == "file": pairs_path = self.fileWidget.value() if not pairs_path: reply = QMessageBox.critical(self, "Missing information", "Please enter a file path.") return if not os.path.exists(pairs_path): reply = QMessageBox.critical(self, "Invalid information", "The file path entered was not found.") return kwargs["query"] = read_pairs_file(pairs_path) return kwargs
def generateKwargs(self): from corpustools.corpus.classes import Word min_rel = None if self.minEdit.text() != '': try: min_rel = float(self.minEdit.text()) except ValueError: pass ##------------------ try: frequency_cutoff = float(self.minFreqEdit.text()) except ValueError: frequency_cutoff = 0.0 ##------------------- max_rel = None if self.maxEdit.text() != '': try: max_rel = float(self.maxEdit.text()) except ValueError: pass kwargs = {'corpusModel': self.corpusModel, 'context': self.variantsWidget.value(), 'algorithm': self.algorithmWidget.value(), 'sequence_type': self.tierWidget.value(), 'type_token': self.typeTokenWidget.value(), 'frequency_cutoff': frequency_cutoff, 'min_rel': min_rel, 'max_rel': max_rel} # Error checking if self.compType is None: reply = QMessageBox.critical(self, "Missing information", "Please specify a comparison type.") return elif self.compType == 'one': text = self.oneWordEdit.text() if not text: reply = QMessageBox.critical(self, "Missing information", "Please specify a word.") return try: word = self.corpusModel.corpus.find(text) except KeyError: reply = QMessageBox.critical(self, "Invalid information", "'{}' was not found in corpus.".format(text)) return kwargs['query'] = word elif self.compType == 'nonword': if self.oneNonword is None: reply = QMessageBox.critical(self, "Missing information", "Please create a word/nonword.") return if not getattr(self.oneNonword, kwargs['sequence_type']): reply = QMessageBox.critical(self, "Missing information", "Please recreate the word/nonword with '{}' specified.".format( self.tierWidget.displayValue())) return kwargs['query'] = self.oneNonword elif self.compType == 'two': textOne = self.wordOneEdit.text() textTwo = self.wordTwoEdit.text() if self.nonwordOne is not None: if not getattr(self.nonwordOne, kwargs['sequence_type']): reply = QMessageBox.critical(self, "Missing information", "Please recreate word/nonword 1 with '{}' specified.".format( self.tierWidget.displayValue())) return wordOne = self.nonwordOne elif textOne: try: wordOne = self.corpusModel.corpus.find(textOne) except KeyError: reply = QMessageBox.critical(self, "Invalid information", "'{}' was not found in corpus.".format(textOne)) return elif not textOne: reply = QMessageBox.critical(self, "Missing information", "Please specify either a spelling for word one or create a new word.") return if self.nonwordTwo is not None: if not getattr(self.nonwordTwo, kwargs['sequence_type']): reply = QMessageBox.critical(self, "Missing information", "Please recreate word/nonword 2 with '{}' specified.".format( self.tierWidget.displayValue())) return wordTwo = self.nonwordTwo elif textTwo: try: wordTwo = self.corpusModel.corpus.find(textTwo) except KeyError: reply = QMessageBox.critical(self, "Invalid information", "'{}' was not found in corpus.".format(textTwo)) return elif not textTwo: reply = QMessageBox.critical(self, "Missing information", "Please specify either a spelling for word two or create a new word.") return kwargs['query'] = (wordOne, wordTwo) elif self.compType == 'file': pairs_path = self.fileWidget.value() if not pairs_path: reply = QMessageBox.critical(self, "Missing information", "Please enter a file path.") return if not os.path.exists(pairs_path): reply = QMessageBox.critical(self, "Invalid information", "The file path entered was not found.") return out = list() q = read_pairs_file(pairs_path) for pair in q: w1 = self.corpusModel.corpus.find(pair[0]) w2 = self.corpusModel.corpus.find(pair[1]) out.append((w1, w2)) kwargs['query'] = out #The following is original code, which doesn't seem to work #kwargs['query'] = read_pairs_file(pairs_path) return kwargs
def generateKwargs(self): from corpustools.corpus.classes import Word min_rel = None if self.minEdit.text() != '': try: min_rel = float(self.minEdit.text()) except ValueError: pass ##------------------ try: frequency_cutoff = float(self.minFreqEdit.text()) except ValueError: frequency_cutoff = 0.0 ##------------------- max_rel = None if self.maxEdit.text() != '': try: max_rel = float(self.maxEdit.text()) except ValueError: pass kwargs = {'corpusModel': self.corpusModel, 'context': self.variantsWidget.value(), 'algorithm': self.algorithmWidget.value(), 'sequence_type': self.tierWidget.value(), 'type_token': self.typeTokenWidget.value(), 'frequency_cutoff': frequency_cutoff, 'min_rel': min_rel, 'max_rel': max_rel} # Error checking if self.compType is None: reply = QMessageBox.critical(self, "Missing information", "Please specify a comparison type.") return elif self.compType == 'one': text = self.oneWordEdit.text() if not text: reply = QMessageBox.critical(self, "Missing information", "Please specify a word.") return try: word = self.corpusModel.corpus.find(text) except KeyError: reply = QMessageBox.critical(self, "Invalid information", "'{}' was not found in corpus.".format(text)) return kwargs['query'] = word elif self.compType == 'nonword': if self.oneNonword is None: reply = QMessageBox.critical(self, "Missing information", "Please create a word/nonword.") return if not getattr(self.oneNonword, kwargs['sequence_type']): reply = QMessageBox.critical(self, "Missing information", "Please recreate the word/nonword with '{}' specified.".format( self.tierWidget.displayValue())) return kwargs['query'] = self.oneNonword elif self.compType == 'two': textOne = self.wordOneEdit.text() textTwo = self.wordTwoEdit.text() if self.nonwordOne is not None: if not getattr(self.nonwordOne, kwargs['sequence_type']): reply = QMessageBox.critical(self, "Missing information", "Please recreate word/nonword 1 with '{}' specified.".format( self.tierWidget.displayValue())) return wordOne = self.nonwordOne elif textOne: try: wordOne = self.corpusModel.corpus.find(textOne) except KeyError: reply = QMessageBox.critical(self, "Invalid information", "'{}' was not found in corpus.".format(textOne)) return elif not textOne: reply = QMessageBox.critical(self, "Missing information", "Please specify either a spelling for word one or create a new word.") return if self.nonwordTwo is not None: if not getattr(self.nonwordTwo, kwargs['sequence_type']): reply = QMessageBox.critical(self, "Missing information", "Please recreate word/nonword 2 with '{}' specified.".format( self.tierWidget.displayValue())) return wordTwo = self.nonwordTwo elif textTwo: try: wordTwo = self.corpusModel.corpus.find(textTwo) except KeyError: reply = QMessageBox.critical(self, "Invalid information", "'{}' was not found in corpus.".format(textTwo)) return elif not textTwo: reply = QMessageBox.critical(self, "Missing information", "Please specify either a spelling for word two or create a new word.") return kwargs['query'] = (wordOne, wordTwo) elif self.compType == 'file': pairs_path = self.fileWidget.value() if not pairs_path: reply = QMessageBox.critical(self, "Missing information", "Please enter a file path.") return if not os.path.exists(pairs_path): reply = QMessageBox.critical(self, "Invalid information", "The file path entered was not found.") return kwargs['query'] = read_pairs_file(pairs_path) return kwargs