Example #1
0
    def generateKwargs(self):
        ##------------------
        try:
            frequency_cutoff = float(self.minFreqEdit.text())
        except ValueError:
            frequency_cutoff = 0.0
        ##-------------------

        kwargs = {
            'corpusModel': self.corpusModel,
            'algorithm': self.algorithmWidget.value(),
            'context': self.variantsWidget.value(),
            'sequence_type': self.tierWidget.value(),
            'type_token': self.typeTokenWidget.value(),
            'frequency_cutoff': frequency_cutoff,
            'probability_type': self.probabilityTypeWidget.value()
        }

        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:
                w = self.corpusModel.corpus.find(text)
            except KeyError:
                reply = QMessageBox.critical(
                    self, "Invalid information",
                    "The spelling specified does match any words in the corpus."
                )
                return
            kwargs['query'] = [w]
        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 == 'file':
            path = self.fileWidget.value()
            if not path:
                reply = QMessageBox.critical(self, "Missing information",
                                             "Please enter a file path.")
                return
            if not os.path.exists(path):
                reply = QMessageBox.critical(
                    self, "Invalid information",
                    "The file path entered was not found.")
                return
            kwargs['query'] = list()
            text = load_words_neighden(path)
            for t in text:
                if isinstance(t, str):
                    try:
                        w = self.corpusModel.corpus.find(t)
                    except KeyError:
                        reply = QMessageBox.critical(
                            self, "Invalid information",
                            "The spelling '{}' was not found in the corpus.".
                            format(t))
                        return
                kwargs['query'].append(w)
        elif self.compType == 'all':
            column = self.columnEdit.text()
            if column == '':
                reply = QMessageBox.critical(self, "Missing information",
                                             "Please enter a column name.")
                return
            colName = column.replace(' ', '_')
            attribute = Attribute(colName, 'numeric', column)
            if column in self.corpusModel.columns:

                msgBox = QMessageBox(
                    QMessageBox.Warning, "Duplicate columns",
                    "'{}' is already the name of a column.  Overwrite?".format(
                        column), QMessageBox.NoButton, self)
                msgBox.addButton("Overwrite", QMessageBox.AcceptRole)
                msgBox.addButton("Cancel", QMessageBox.RejectRole)
                if msgBox.exec_() != QMessageBox.AcceptRole:
                    return
            kwargs['attribute'] = attribute

        return kwargs
Example #2
0
    def generateKwargs(self):

        if self.useQuadratic.isChecked() and int(
                self.maxDistanceEdit.text()) != 1:
            self.useQuadratic.setChecked(False)

        if self.maxDistanceEdit.text() == '':
            max_distance = None
        else:
            max_distance = float(self.maxDistanceEdit.text())
        ##------------------
        try:
            frequency_cutoff = float(self.minFreqEdit.text())
        except ValueError:
            frequency_cutoff = 0.0
        ##-------------------
        alg = self.algorithmWidget.value()
        typeToken = self.typeTokenWidget.value()

        if self.fileRadio.isChecked():  #using list of words not in corpus
            file_type = self.fileOptions.currentText().split(' ')[-1].strip()
            for tiername in [
                    self.tierWidget.tierSelect.itemText(i)
                    for i in range(self.tierWidget.tierSelect.count())
            ]:
                if tiername == file_type:
                    self.tierWidget.tierSelect.setCurrentText(tiername)
                    break

        kwargs = {
            'corpusModel': self.corpusModel,
            'algorithm': alg,
            'context': self.variantsWidget.value(),
            'sequence_type': self.tierWidget.value(),
            'type_token': typeToken,
            'max_distance': max_distance,
            'frequency_cutoff': frequency_cutoff,
            'num_cores': self.settings['num_cores'],
            'force_quadratic': self.useQuadratic.isChecked(),
            'file_type': self.fileOptions.currentText().split()[-1],
            'tier_type': self.tierWidget.attValue()
        }

        out_file = self.saveFileWidget.value()
        if out_file == '':
            out_file = None
        else:
            kwargs['output_filename'] = out_file

        kwargs['file_list'] = None
        if self.compType is None:
            reply = QMessageBox.critical(
                self, "Missing information",
                'Please select an option from the "Query" section in the middle of the window.'
            )
            return
        elif self.compType == 'one':
            text = self.oneWordEdit.text()
            if not text:
                reply = QMessageBox.critical(self, "Missing information",
                                             "Please specify a word.")
                return
            try:
                w = self.corpusModel.corpus.find(text)
            except KeyError:
                reply = QMessageBox.critical(
                    self, "Invalid information",
                    "The spelling specified does match any words in the corpus."
                )
                return
            kwargs['query'] = [w]
            kwargs['output_filename'] = out_file
        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]
            kwargs['output_filename'] = out_file
        elif self.compType == 'file':
            path = self.fileWidget.value()
            kwargs['file_list'] = path
            if not path:
                reply = QMessageBox.critical(self, "Missing information",
                                             "Please enter a file path.")
                return
            if not os.path.exists(path):
                reply = QMessageBox.critical(
                    self, "Invalid information",
                    "The file path entered was not found.")
                return
            kwargs['query'] = list()
            text = load_words_neighden(path)
            for t in text:
                kwargs['query'].append(t)
        elif self.compType == 'all':
            column = self.columnEdit.text()
            if column == '':
                reply = QMessageBox.critical(self, "Missing information",
                                             "Please enter a column name.")
                return
            colName = column.replace(' ', '_')
            attribute = Attribute(colName, 'numeric', column)
            if column in self.corpusModel.columns:

                msgBox = QMessageBox(
                    QMessageBox.Warning, "Duplicate columns",
                    "'{}' is already the name of a column.  Overwrite?".format(
                        column), QMessageBox.NoButton, self)
                msgBox.addButton("Overwrite", QMessageBox.AcceptRole)
                msgBox.addButton("Cancel", QMessageBox.RejectRole)
                if msgBox.exec_() != QMessageBox.AcceptRole:
                    return
            kwargs['attribute'] = attribute
        return kwargs
Example #3
0
    def generateKwargs(self):
        if self.maxDistanceEdit.text() == '':
            max_distance = None
        else:
            max_distance = float(self.maxDistanceEdit.text())

        alg = self.algorithmWidget.value()
        typeToken = self.typeTokenWidget.value()

        kwargs = {'corpusModel':self.corpusModel,
                'algorithm': alg,
                'context': self.variantsWidget.value(),
                'sequence_type':self.tierWidget.value(),
                'type_token':typeToken,
                'max_distance':max_distance,
                'num_cores':self.settings['num_cores'],}
        out_file = self.saveFileWidget.value()
        if out_file == '':
            out_file = None

        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:
                w = self.corpusModel.corpus.find(text)
            except KeyError:
                reply = QMessageBox.critical(self,
                        "Invalid information", "The spelling specified does match any words in the corpus.")
                return
            kwargs['query'] = [w]
            kwargs['output_filename'] = out_file
        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]
            kwargs['output_filename'] = out_file
        elif self.compType == 'file':
            path = self.fileWidget.value()
            if not path:
                reply = QMessageBox.critical(self,
                        "Missing information", "Please enter a file path.")
                return
            if not os.path.exists(path):
                reply = QMessageBox.critical(self,
                        "Invalid information", "The file path entered was not found.")
                return
            kwargs['query'] = list()
            text = load_words_neighden(path)
            for t in text:
                if isinstance(t,str):
                    try:
                        w = self.corpusModel.corpus.find(t)
                    except KeyError:
                        reply = QMessageBox.critical(self,
                                "Invalid information", "The spelling '{}' was not found in the corpus.".format(t))
                        return
                else:
                    w = t
                kwargs['query'].append(w)
        elif self.compType == 'all':
            column = self.columnEdit.text()
            if column == '':
                reply = QMessageBox.critical(self,
                        "Missing information", "Please enter a column name.")
                return
            colName = column.lower().replace(' ','_')
            attribute = Attribute(colName,'numeric',column)
            if column in self.corpusModel.columns:

                msgBox = QMessageBox(QMessageBox.Warning, "Duplicate columns",
                        "'{}' is already the name of a column.  Overwrite?".format(column), QMessageBox.NoButton, self)
                msgBox.addButton("Overwrite", QMessageBox.AcceptRole)
                msgBox.addButton("Cancel", QMessageBox.RejectRole)
                if msgBox.exec_() != QMessageBox.AcceptRole:
                    return
            kwargs['attribute'] = attribute
        return kwargs
    def generateKwargs(self):
        ##------------------
        try:
            frequency_cutoff = float(self.minFreqEdit.text())
        except ValueError:
            frequency_cutoff = 0.0
        ##-------------------
        
        kwargs = {'corpusModel':self.corpusModel,
                'algorithm': self.algorithmWidget.value(),
                'context': self.variantsWidget.value(),
                'sequence_type':self.tierWidget.value(),
                'type_token':self.typeTokenWidget.value(),
                'frequency_cutoff':frequency_cutoff,
                'probability_type':self.probabilityTypeWidget.value(),
                'log_count': self.useLogScale.isEnabled() and self.useLogScale.isChecked()}

        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:
                w = self.corpusModel.corpus.find(text)
            except KeyError:
                reply = QMessageBox.critical(self,
                        "Invalid information", "The spelling specified does match any words in the corpus.")
                return
            kwargs['query'] = [w]
        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 == 'file':
            path = self.fileWidget.value()
            if not path:
                reply = QMessageBox.critical(self,
                        "Missing information", "Please enter a file path.")
                return
            if not os.path.exists(path):
                reply = QMessageBox.critical(self,
                        "Invalid information", "The file path entered was not found.")
                return
            kwargs['query'] = list()
            text = load_words_neighden(path)
            for t in text:
                if isinstance(t,str):
                    try:
                        w = self.corpusModel.corpus.find(t)
                    except KeyError:
                        reply = QMessageBox.critical(self,
                                "Invalid information", "The spelling '{}' was not found in the corpus.".format(t))
                        return
                kwargs['query'].append(w)
        elif self.compType == 'all':
            column = self.columnEdit.text()
            if column == '':
                reply = QMessageBox.critical(self,
                        "Missing information", "Please enter a column name.")
                return
            colName = column.replace(' ','_')
            attribute = Attribute(colName,'numeric',column)
            if column in self.corpusModel.columns:

                msgBox = QMessageBox(QMessageBox.Warning, "Duplicate columns",
                        "'{}' is already the name of a column.  Overwrite?".format(column), QMessageBox.NoButton, self)
                msgBox.addButton("Overwrite", QMessageBox.AcceptRole)
                msgBox.addButton("Cancel", QMessageBox.RejectRole)
                if msgBox.exec_() != QMessageBox.AcceptRole:
                    return
            kwargs['attribute'] = attribute

        return kwargs