Example #1
0
    def exec_(self):
        result = super(FunctionDialog, self).exec_()
        if result == QtWidgets.QDialog.Accepted:
            if self.checkable:
                l = []
                for i in range(self.ui.list_functions.count()):
                    item = self.ui.list_functions.item(i)
                    if self.ui.list_functions.itemWidget(item).checkState():
                        l.append(item.data(QtCore.Qt.UserRole))
                return l
            else:
                value = utf8(self.ui.edit_function_value.text())
                escaped_value = value.replace("'", "\'")
                columns = [x.data(QtCore.Qt.UserRole) for x
                           in self.ui.widget_selection.selectedItems()]

                if self._auto_label:
                    label = None
                else:
                    label = utf8(self.ui.edit_label.text())
                func = self.function_list[self.ui.list_functions.currentRow()]
                aggr = utf8(self.ui.combo_combine.currentText())
                if aggr == "":
                    aggr = func.default_aggr

                return (func, columns, escaped_value, aggr, label)
        else:
            return None
Example #2
0
    def exec_(self):
        result = super(FunctionDialog, self).exec_()
        if result == QtWidgets.QDialog.Accepted:
            if self.checkable:
                l = []
                for i in range(self.ui.list_functions.count()):
                    item = self.ui.list_functions.item(i)
                    if self.ui.list_functions.itemWidget(item).checkState():
                        l.append(item.data(QtCore.Qt.UserRole))
                return l
            else:
                value = utf8(self.ui.edit_function_value.text())
                escaped_value = value.replace("'", "\'")
                columns = [
                    x.data(QtCore.Qt.UserRole)
                    for x in self.ui.widget_selection.selectedItems()
                ]

                if self._auto_label:
                    label = None
                else:
                    label = utf8(self.ui.edit_label.text())
                func = self.function_list[self.ui.list_functions.currentRow()]
                aggr = utf8(self.ui.combo_combine.currentText())
                if aggr == "":
                    aggr = func.default_aggr

                return (func, columns, escaped_value, aggr, label)
        else:
            return None
Example #3
0
    def get_values(self):
        """
        Retrieve the current values from the dialog.

        Returns:
        --------
        tup : tuple
            A tuple with the elements (column, operator, value, stage).

            'column' a string containing the resource feature name of the
            currently selected column.
            'dtype' the dtype of the column
            'operator' is an integer corresponding to one of the values
            defined in ``defines.py``.
            'value' is a string containing the content of the value textedit.
            'stage' is either FILTER_STAGE_FINAL or
            FILTER_STAGE_BEFORE_TRANSFORM (defined in ``defines.py``)
        """
        feature = utf8(self.ui.list_columns.currentItem().data(FeatureRole))
        dtype = self.ui.list_columns.currentItem().data(DtypeRole)
        value = utf8(self.ui.edit_value.text())

        # determine which operator radio button is checked:
        for radio in self.radio_operators:
            if getattr(self.ui, self.radio_operators[radio]).isChecked():
                operator = globals()[radio]

        if self.ui.check_before_transformation.isChecked():
            stage = FILTER_STAGE_BEFORE_TRANSFORM
        else:
            stage = FILTER_STAGE_FINAL

        return feature, dtype, operator, value, stage
Example #4
0
    def add_source_label(self, name, content=None):
        """
        Add the label 'name' with value 'content' to the context viewer.
        """
        layout_row = self.ui.form_information.count()
        self.ui.source_name = QtWidgets.QLabel(self)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ui.source_name.sizePolicy().hasHeightForWidth())
        self.ui.source_name.setSizePolicy(sizePolicy)
        self.ui.source_name.setAlignment(QtCore.Qt.AlignRight
                                         | QtCore.Qt.AlignTop
                                         | QtCore.Qt.AlignTrailing)
        self.ui.source_name.setTextInteractionFlags(
            QtCore.Qt.LinksAccessibleByMouse
            | QtCore.Qt.TextSelectableByKeyboard
            | QtCore.Qt.TextSelectableByMouse)
        self.ui.form_information.setWidget(layout_row,
                                           QtWidgets.QFormLayout.LabelRole,
                                           self.ui.source_name)
        self.ui.source_content = QtWidgets.QLabel(self)
        self.ui.source_content.setWordWrap(True)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ui.source_content.sizePolicy().hasHeightForWidth())
        self.ui.source_content.setSizePolicy(sizePolicy)
        self.ui.source_content.setAlignment(QtCore.Qt.AlignLeading
                                            | QtCore.Qt.AlignLeft
                                            | QtCore.Qt.AlignTop)
        self.ui.source_content.setTextInteractionFlags(
            QtCore.Qt.LinksAccessibleByMouse
            | QtCore.Qt.TextSelectableByKeyboard
            | QtCore.Qt.TextSelectableByMouse)
        self.ui.form_information.setWidget(layout_row,
                                           QtWidgets.QFormLayout.FieldRole,
                                           self.ui.source_content)

        if name:
            if content is None:
                name = "<b>{}</b>".format(name)
            else:
                name = utf8(name).strip()
                if not name.endswith(":"):
                    name += ":"
            self.ui.source_name.setText(name)

        if content:
            content = utf8(content).strip()
            if os.path.exists(content) or "://" in content:
                content = "<a href={0}>{0}</a>".format(content)
                self.ui.source_content.setOpenExternalLinks(True)
                self.ui.source_content.setTextInteractionFlags(
                    QtCore.Qt.TextBrowserInteraction)
            self.ui.source_content.setText(content)
    def restore_settings(self):
        self.ui.radio_read_files.blockSignals(True)
        self.ui.radio_only_module.blockSignals(True)
        try:
            self.resize(options.settings.value("corpusinstaller_size"))
        except TypeError:
            pass

        if isinstance(self, BuilderGui):
            target = "corpusinstaller_data_path"
        else:
            target = "corpusinstaller_corpus_source"
        self.ui.input_path.setText(utf8(options.settings.value(target, "")))

        val = options.settings.value("corpusinstaller_read_files", "true")
        self.activate_read(val == "true" or val is True)

        self.ui.check_use_metafile.setChecked(False)
        self.ui.label_metafile.setText("")
        meta = options.settings.value("corpusinstaller_metafile", None)
        if meta is not None:
            val = options.settings.value("corpusinstaller_use_metafile",
                                         "false")
            self.ui.check_use_metafile.setChecked(val == "true" or val is True)
            self.ui.label_metafile.setText(utf8(meta))

        val = options.settings.value("corpusinstaller_use_nltk", "false")
        self.ui.use_pos_tagging.setChecked(val == "true" or val is True)
        val = options.settings.value("corpusinstaller_use_ngram_table",
                                     "false")
        self.ui.check_n_gram.setChecked(val == "true" or val is True)
        self.ui.spin_n.setValue(
            int(options.settings.value("corpusinstaller_n_gram_width", 2)))
        self.ui.radio_read_files.blockSignals(False)
        self.ui.radio_only_module.blockSignals(False)
Example #6
0
    def __init__(self, res_from=None, rc_from=None, parent=None):
        super(LinkSelect, self).__init__(parent)
        self.res_from = res_from
        try:
            self.corpus_name = res_from.name
        except AttributeError:
            self.corpus_name = None
        self.rc_from = rc_from

        self.ui = Ui_LinkSelect()
        self.ui.setupUi(self)
        self.from_text = utf8(self.ui.label_from.text())
        self.from_corpus_text = utf8(self.ui.label_from_corpus.text())
        self.to_text = utf8(self.ui.label_to.text())
        self.explain_text = utf8(self.ui.label_explain.text())

        self.insert_data()
        self.ui.combo_corpus.currentIndexChanged.connect(self.external_changed)
        self.ui.tree_resource.currentItemChanged.connect(self.resource_changed)
        self.ui.tree_external.currentItemChanged.connect(self.external_resource_changed)

        self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)

        try:
            self.resize(options.settings.value("linkselect_size"))
        except TypeError:
            pass

        self.ui.tree_resource.setup_resource(get_toplevel_window().resource,
                                             skip=("coquery", "db"),
                                             checkable=False,
                                             links=False)
        self.ui.tree_resource.allSetExpanded(True)
        self.ui.tree_resource.setCurrentItemByString(self.rc_from)
Example #7
0
 def test_qstring(self):
     s2 = 'unaccented text for testing'
     s4 = 'ȧƈƈḗƞŧḗḓ ŧḗẋŧ ƒǿř ŧḗşŧīƞɠ'
     s6 = QtCore.QString(s2)
     s7 = QtCore.QString(s4)
     self.assertEqual(type(utf8(s6)), type(u""))
     self.assertEqual(type(utf8(s7)), type(u""))
    def restore_settings(self):
        self.ui.radio_read_files.blockSignals(True)
        self.ui.radio_only_module.blockSignals(True)
        try:
            self.resize(options.settings.value("corpusinstaller_size"))
        except TypeError:
            pass

        if isinstance(self, BuilderGui):
            target = "corpusinstaller_data_path"
        else:
            target = "corpusinstaller_corpus_source"
        self.ui.input_path.setText(utf8(options.settings.value(target, "")))

        val = options.settings.value("corpusinstaller_read_files", "true")
        self.activate_read(val == "true" or val is True)

        self.ui.check_use_metafile.setChecked(False)
        self.ui.label_metafile.setText("")
        meta = options.settings.value("corpusinstaller_metafile", None)
        if meta is not None:
            val = options.settings.value("corpusinstaller_use_metafile",
                                         "false")
            self.ui.check_use_metafile.setChecked(val == "true" or
                                                  val is True)
            self.ui.label_metafile.setText(utf8(meta))

        val = options.settings.value("corpusinstaller_use_nltk", "false")
        self.ui.use_pos_tagging.setChecked(val == "true" or val is True)
        val = options.settings.value("corpusinstaller_use_ngram_table", "false")
        self.ui.check_n_gram.setChecked(val == "true" or val is True)
        self.ui.spin_n.setValue(
            int(options.settings.value("corpusinstaller_n_gram_width", 2)))
        self.ui.radio_read_files.blockSignals(False)
        self.ui.radio_only_module.blockSignals(False)
Example #9
0
 def change_substitution(self, i, j):
     current_item = self.ui.widget_selection.currentItem()
     col = current_item.data(QtCore.Qt.UserRole)
     key = utf8(self.ui.table_substitutions.item(i, 0).text())
     value = utf8(self.ui.table_substitutions.item(i, 1).text())
     key = self._key_dtype(key, col)
     self.substitutions[col][key] = value
Example #10
0
 def exec_(self):
     result = super(TextgridExportDialog, self).exec_()
     if result == QtWidgets.QDialog.Accepted:
         columns = []
         columns = [
             x.data(QtCore.Qt.UserRole)
             for x in self.ui.list_columns.selectedItems()
         ]
         return {
             "output_path":
             utf8(self.ui.edit_output_path.text()),
             "columns":
             columns,
             "one_grid_per_match":
             self.ui.radio_one_per_match.isChecked(),
             "remember_time":
             self.ui.check_remember.checkState() != QtCore.Qt.Unchecked,
             "sound_path": ("" if self.ui.check_copy_sounds.checkState()
                            == QtCore.Qt.Unchecked else utf8(
                                self.ui.edit_sound_path.text())),
             "file_prefix":
             utf8(self.ui.edit_file_prefix.text()),
             "left_padding":
             float(self.ui.spin_left_padding.value()),
             "right_padding":
             float(self.ui.spin_right_padding.value())
         }
     else:
         return None
Example #11
0
 def add_legend(self, levels=None, loc="lower left"):
     """
     Add a legend to the figure, using the current option settings.
     """
     if levels:
         legend_bar = [
             plt.Rectangle(
                 (0, 0), 1, 1,
                 fc=self.options["color_palette_values"][i],
                 edgecolor="none") for i, _ in enumerate(levels)
             ]
         self.g.fig.get_axes()[-1].legend(
             legend_bar, levels,
             ncol=self.options.get("label_legend_columns", 1),
             title=utf8(self.options.get("label_legend", "")),
             frameon=True,
             framealpha=0.7,
             loc=loc).draggable()
     else:
         self.g.fig.get_axes()[-1].legend(
             ncol=self.options.get("label_legend_columns", 1),
             title=utf8(self.options.get("label_legend", "")),
             frameon=True,
             framealpha=0.7,
             loc=loc).draggable()
Example #12
0
    def evaluate_regex(self):
        regex = utf8(self.ui.edit_regex.text())
        test_string = utf8(self.ui.edit_test_string.text())

        # put the regex into parentheses if there is no match group:
        if not re.search(r"\([^)]*\)", regex):
            regex = "({})".format(regex)

        match = None
        try:
            match = re.search(regex, test_string)
        except Exception as e:
            self.ui.label_error.setText(str(e))
            self.ui.label_error.setStyleSheet("""
                background-color: red; color: white; """)
        else:
            self.ui.label_error.setText("")
            self.ui.label_error.setStyleSheet("")

            if not match:
                self.ui.label_error.setText("No match.")
                self.ui.table_groups.setRowCount(0)
                self.ui.edit_regex.setStyleSheet("""
                    background-color: rgb(255, 255, 192); color: black; """)
            else:
                self.ui.edit_regex.setStyleSheet("")
                self.ui.table_groups.setRowCount(len(match.groups()))
                for i, grp in enumerate(match.groups()):
                    self.ui.table_groups.setItem(
                        i, 0, QtWidgets.QTableWidgetItem(str(grp)))
Example #13
0
 def change_description(self):
     string_list = []
     if self._title:
         if self._url:
             string_list.append("<p><b>{name}</b> (<a href='{url}'>{url}</a>)</p>".format(
                 name=self._title, url=self._url))
         else:
             string_list.append("<p><b>{}</b></p>".format(self._title))
     if self._text:
         string_list.append("<p><font size='100%'>{}</font></p>".format(self._text))
     if self._language or self._code:
         string_list.append("<p><b>Language</b></p><p>{}{}</p>".format(
             self._language, " ({})".format(self._code) if self._code else ""))
     if self._references:
         string_list.append(self._references)
     if self._license:
         string_list.append(self._license)
     if self._modules:
         l = []
         for name, module, url in self._modules:
             if url:
                s = "<p>{module} (<a href='{url}'>{url}</a>)</p>".format(
                    module=utf8(module), url=utf8(url))
             else:
                s = "<p>{}</p>".format(module)
             l.append(s)
         string_list.append("<p><b>Required additional Python modules</b></p>{}".format(
             "".join(l)))
     self.corpus_description.setText(
         "".join(string_list))
Example #14
0
    def __init__(self,
                 item,
                 context=True,
                 title="Output column options",
                 parent=None,
                 *args,
                 **kwargs):
        super(CoqResourceMenu, self).__init__(title, parent)

        rc_feature = utf8(item.objectName())
        label = utf8(item.text(0))

        # if shown as context menu, use column name as header:
        if context:
            head = QtWidgets.QLabel("<b>{}</b>".format(label))
            head.setAlignment(QtCore.Qt.AlignCenter)
            action = QtWidgets.QWidgetAction(parent)
            action.setDefaultWidget(head)
            self.addAction(action)

        add_link = QtWidgets.QAction("&Link an external table", parent)
        remove_link = QtWidgets.QAction("&Remove linked table", parent)
        view_entries = QtWidgets.QAction("View all &values", parent)
        view_uniques = QtWidgets.QAction("View &unique values", parent)

        # linked table:
        if hasattr(item, "link"):
            self.addAction(remove_link)
            remove_link.triggered.connect(
                lambda: self.removeItemRequested.emit(item))
        elif not (rc_feature.endswith("_table")):
            if not rc_feature.startswith("coquery"):
                self.addAction(view_uniques)
                self.addAction(view_entries)
                view_entries.triggered.connect(
                    lambda: self.viewEntriesRequested.emit(item))
                view_uniques.triggered.connect(
                    lambda: self.viewUniquesRequested.emit(item))

                # Only enable the 'View' entries if the SQL connection is
                # working:
                view_uniques.setEnabled(
                    options.cfg.gui.test_mysql_connection())
                view_entries.setEnabled(
                    options.cfg.gui.test_mysql_connection())

                self.addSeparator()

                if not hasattr(item.parent(), "link"):
                    self.addAction(add_link)
                    add_link.triggered.connect(
                        lambda: self.addLinkRequested.emit(item))

        else:
            unavailable = QtWidgets.QAction(
                _translate("MainWindow", "No option available for tables.",
                           None), self)
            unavailable.setDisabled(True)
            self.addAction(unavailable)
Example #15
0
 def external_resource_changed(self, current, prev):
     to_res = utf8(self.ui.combo_corpus.currentText())
     to_feature = utf8(current.text(0))
     if current.parent():
         to_table = utf8(current.parent().text(0))
     else:
         to_table = "invalid"
     self.set_to_labels(to=to_res, to_resource=to_feature, to_table=to_table)
     self.check_dialog()
Example #16
0
 def accept(self, *args):
     super(TextgridExportDialog, self).accept(*args)
     options.settings.setValue("textgridexport_size", self.size())
     options.settings.setValue("textgridexport_radio_one_per_match", self.ui.radio_one_per_match.isChecked())
     options.settings.setValue("textgridexport_check_extract_sound", bool(self.ui.check_copy_sounds.checkState()))
     options.settings.setValue("textgridexport_sound_path", utf8(self.ui.edit_sound_path.text()))
     options.settings.setValue("textgridexport_output_path", utf8(self.ui.edit_output_path.text()))
     options.settings.setValue("textgridexport_left_padding", float(self.ui.spin_left_padding.value()))
     options.settings.setValue("textgridexport_right_padding", float(self.ui.spin_right_padding.value()))
     options.settings.setValue("textgridexport_check_remember", bool(self.ui.check_remember.checkState()))
     options.settings.setValue("textgridexport_file_prefix", utf8(self.ui.edit_file_prefix.text()))
Example #17
0
 def resource_changed(self, current, prev):
     if current.parent():
         from_table = utf8(current.parent().text(0))
         from_resource = utf8(current.text(0))
     else:
         from_table = "<not selected>"
         from_resource = "<not selected>"
     self.set_from_labels(from_res=self.corpus_name,
                          from_table=from_table,
                          from_resource=from_resource)
     self.check_dialog()
Example #18
0
    def open_link(self, link):
        """
        Process any link clicked from the corpus description label.

        Usually, the URL of the link is opened. One exception is the link
        '_to_clipboard', which copies the references to the clipboard.
        """
        if utf8(link) == "_to_clipboard":
            QtWidgets.QApplication.clipboard().setText("\n".join([utf8(x) for x in self._reference_list]))
        else:
            QtWidgets.QDesktopServices.openUrl(QtCore.QUrl(link))
Example #19
0
 def external_resource_changed(self, current, prev):
     to_res = utf8(self.ui.combo_corpus.currentText())
     to_feature = utf8(current.text(0))
     if current.parent():
         to_table = utf8(current.parent().text(0))
     else:
         to_table = "invalid"
     self.set_to_labels(to=to_res,
                        to_resource=to_feature,
                        to_table=to_table)
     self.check_dialog()
Example #20
0
 def resource_changed(self, current, prev):
     if current.parent():
         from_table = utf8(current.parent().text(0))
         from_resource = utf8(current.text(0))
     else:
         from_table = "<not selected>"
         from_resource = "<not selected>"
     self.set_from_labels(
         from_res=self.corpus_name,
         from_table=from_table,
         from_resource=from_resource)
     self.check_dialog()
Example #21
0
 def test_utf8_type(self):
     s1 = b'unaccented text for testing'
     s2 = 'unaccented text for testing'
     s3 = u'unaccented text for testing'
     s4 = 'ȧƈƈḗƞŧḗḓ ŧḗẋŧ ƒǿř ŧḗşŧīƞɠ'
     s5 = u'ȧƈƈḗƞŧḗḓ ŧḗẋŧ ƒǿř ŧḗşŧīƞɠ'
     # test types:
     self.assertEqual(type(utf8(s1)), type(u""))
     self.assertEqual(type(utf8(s2)), type(u""))
     self.assertEqual(type(utf8(s3)), type(u""))
     self.assertEqual(type(utf8(s4)), type(u""))
     self.assertEqual(type(utf8(s5)), type(u""))
Example #22
0
    def add_stopword_list(self):
        lang = utf8(self.ui.combo_language.currentText())
        
        stopwords = []
        for line in open(os.path.join(options.cfg.stopword_path, 
                               "{}.txt".format(code_by_language(lang))), "r"):
            if not line.strip().startswith("#"):
                stopwords.append(line.strip())

        for word in sorted(set(stopwords)):
            if not self.ui.stopword_list.hasTag(word):
                self.ui.stopword_list.addTag(utf8(word))
Example #23
0
    def check_gui(self, func=None, only_label=False):
        self.ui.parameter_box.setEnabled(self.max_parameters > 0)
        self.ui.box_combine.setEnabled(len(self.columns) > 1)

        if not self.edit_label:
            self.ui.widget_label.hide()
        else:
            self.ui.widget_label.show()

        func = self.function_list[self.ui.list_functions.currentRow()]
        if not only_label:
            current_combine = str(self.ui.combo_combine.currentText())
            self.ui.combo_combine.clear()
            for x in func.combine_modes:
                self.ui.combo_combine.addItem(x)
            if current_combine in func.combine_modes:
                self.ui.combo_combine.setCurrentIndex(func.combine_modes.index(current_combine))
            else:
                self.ui.combo_combine.setCurrentIndex(0)

            if func.parameters == 0 or self.max_parameters == 0:
                self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(True)
                self.ui.edit_function_value.setStyleSheet('QLineEdit { background-color: white; }')
            else:
                if not func.validate_input(utf8(self.ui.edit_function_value.text())):
                    self.ui.edit_function_value.setStyleSheet('QLineEdit { background-color: rgb(255, 255, 192) }')
                    self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
                else:
                    self.ui.edit_function_value.setStyleSheet('QLineEdit { background-color: white; }')
                    self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(True)

            self.ui.list_functions.item(self.ui.list_functions.currentRow()).setSelected(True)

        aggr = str(self.ui.combo_combine.currentText())
        if aggr == "":
            aggr = func.default_aggr

        session = get_toplevel_window().Session
        tmp_func = func(
            columns=self.columns,
            value=utf8(self.ui.edit_function_value.text()),
            aggr=aggr,
            session=session)

        if self._auto_label:
            try:
                manager = managers.get_manager(options.cfg.MODE, session.Resource.name)
            except AttributeError:
                pass
            else:
                # only set the auto label if a manager is available
                self.ui.edit_label.setText(tmp_func.get_label(session=session, manager=manager))
Example #24
0
    def add_stopword_list(self):
        lang = utf8(self.ui.combo_language.currentText())

        stopwords = []
        for line in open(
                os.path.join(options.cfg.stopword_path,
                             "{}.txt".format(code_by_language(lang))), "r"):
            if not line.strip().startswith("#"):
                stopwords.append(line.strip())

        for word in sorted(set(stopwords)):
            if not self.ui.stopword_list.hasTag(word):
                self.ui.stopword_list.addTag(utf8(word))
Example #25
0
 def exec_(self, *args, **kwargs):
     result = super(CSVOptionDialog, self).exec_(*args, **kwargs)
     if result:
         quote = dict(zip(quote_chars.values(), quote_chars.keys()))[
             utf8(self.ui.quote_char.currentText())]
         return CSVOptions(
             sep=self.separator,
             selected_column=self.ui.query_column.value(),
             header=self.ui.file_has_headers.isChecked(),
             skip_lines=int(self.ui.ignore_lines.value()),
             encoding=utf8(self.ui.combo_encoding.currentText()),
             quote_char=quote,
             file_name=utf8(self.ui.edit_file_name.text()),
             dtypes=self.file_table.dtypes)
Example #26
0
 def exec_(self, *args, **kwargs):
     result = super(CSVOptionDialog, self).exec_(*args, **kwargs)
     if result:
         quote = dict(zip(quote_chars.values(), quote_chars.keys()))[utf8(
             self.ui.quote_char.currentText())]
         return CSVOptions(sep=self.separator,
                           selected_column=self.ui.query_column.value(),
                           header=self.ui.file_has_headers.isChecked(),
                           skip_lines=int(self.ui.ignore_lines.value()),
                           encoding=utf8(
                               self.ui.combo_encoding.currentText()),
                           quote_char=quote,
                           file_name=utf8(self.ui.edit_file_name.text()),
                           dtypes=self.file_table.dtypes)
Example #27
0
    def external_changed(self, index):
        if type(index) == int:
            corpus = utf8(self.ui.combo_corpus.itemText(index))
        else:
            corpus = utf8(index)
        if not corpus:
            return

        resource, _, _ = options.get_resource(corpus)
        self.ui.tree_external.setup_resource(resource,
                                             skip=("coquery"),
                                             checkable=False,
                                             links=False,
                                             view_tables=True)
        self.ui.tree_external.allSetExpanded(True)
Example #28
0
    def external_changed(self, index):
        if type(index) == int:
            corpus = utf8(self.ui.combo_corpus.itemText(index))
        else:
            corpus = utf8(index)
        if not corpus:
            return

        resource, _, _ = options.get_resource(corpus)
        self.ui.tree_external.setup_resource(resource,
                                             skip=("coquery"),
                                             checkable=False,
                                             links=False,
                                             view_tables=True)
        self.ui.tree_external.allSetExpanded(True)
Example #29
0
    def __init__(self, word_list, default=None, parent=None, icon=None):
        super(Stopwords, self).__init__(parent)

        self._word_list = word_list
        self.ui = Ui_Stopwords()
        self.ui.setupUi(self)

        lang = []
        for file in os.listdir(options.cfg.stopword_path):
            code, ext = os.path.splitext(file)
            if is_language_code(code) and ext == ".txt":
                lang.append(language_by_code(code).capitalize())

        lang = sorted(lang)
        self.ui.combo_language.addItems(lang)
        self.ui.combo_language.setCurrentIndex(lang.index("English"))
        self.ui.button_add_list.clicked.connect(self.add_stopword_list)

        self.ui.buttonBox.button(
            QtWidgets.QDialogButtonBox.Ok).clicked.connect(self.close)
        self.ui.buttonbox_io.button(
            QtWidgets.QDialogButtonBox.Save).clicked.connect(self.save_list)
        self.ui.buttonbox_io.button(
            QtWidgets.QDialogButtonBox.Open).clicked.connect(self.open_list)
        self.ui.buttonbox_io.button(
            QtWidgets.QDialogButtonBox.Reset).clicked.connect(self.reset_list)

        try:
            self.resize(options.settings.value("stopwords_size"))
        except TypeError:
            pass
        ix = self.ui.combo_language.findText(
            utf8(options.settings.value("stopword_language")))
        if ix >= 0:
            self.ui.combo_language.setCurrentIndex(ix)
Example #30
0
 def traverse(node):
     if utf8(node.objectName()) == s:
         return node
     for child in self.nodeItems(node):
         found = traverse(child)
         if found:
             return found
Example #31
0
    def test_utf8_content(self):
        s1a = 'unaccented text for testing'
        s1b = QtCore.QString(s1a)
        s1c = b'unaccented text for testing'
        s1u = u'unaccented text for testing'

        s2a = 'ȧƈƈḗƞŧḗḓ ŧḗẋŧ ƒǿř ŧḗşŧīƞɠ'
        s2b = QtCore.QString(s2a)
        s2u  = u'ȧƈƈḗƞŧḗḓ ŧḗẋŧ ƒǿř ŧḗşŧīƞɠ'

        # test content:
        self.assertEqual(utf8(s1a), s1u)
        self.assertEqual(utf8(s1b), s1u)
        self.assertEqual(utf8(s1c), s1u)
        self.assertEqual(utf8(s2a), s2u)
        self.assertEqual(utf8(s2b), s2u)
Example #32
0
    def __init__(self, word_list, default=None, parent=None, icon=None):
        super(Stopwords, self).__init__(parent)
        
        self._word_list= word_list
        self.ui = Ui_Stopwords()
        self.ui.setupUi(self)
        
        lang = []
        for file in os.listdir(options.cfg.stopword_path):
            code, ext = os.path.splitext(file)
            if is_language_code(code) and ext == ".txt":
                lang.append(language_by_code(code).capitalize())

        lang = sorted(lang)
        self.ui.combo_language.addItems(lang)
        self.ui.combo_language.setCurrentIndex(lang.index("English"))
        self.ui.button_add_list.clicked.connect(self.add_stopword_list)

        self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).clicked.connect(self.close)
        self.ui.buttonbox_io.button(QtWidgets.QDialogButtonBox.Save).clicked.connect(self.save_list)
        self.ui.buttonbox_io.button(QtWidgets.QDialogButtonBox.Open).clicked.connect(self.open_list)
        self.ui.buttonbox_io.button(QtWidgets.QDialogButtonBox.Reset).clicked.connect(self.reset_list)

        try:
            self.resize(options.settings.value("stopwords_size"))
        except TypeError:
            pass
        ix = self.ui.combo_language.findText(utf8(options.settings.value("stopword_language")))
        if ix >= 0:
            self.ui.combo_language.setCurrentIndex(ix)
Example #33
0
 def traverse(node):
     if utf8(node.objectName()) == s:
         return node
     for child in self.nodeItems(node):
         found = traverse(child)
         if found:
             return found
Example #34
0
 def select_file(self, path=""):
     """ Call a file selector, and add file name to query file input. """
     name = QtWidgets.QFileDialog.getExistingDirectory(directory=path, options=QtWidgets.QFileDialog.ReadOnly|QtWidgets.QFileDialog.ShowDirsOnly|QtWidgets.QFileDialog.HideNameFilterDetails)
     # getOpenFileName() returns different types in PyQt and PySide, fix:
     if type(name) == tuple:
         name = name[0]
     return utf8(name)
    def _get_segments(self, speaker_zip, filename):
        file_body = False

        file_name, _ = os.path.splitext(filename)
        phones_file = "{}.phones".format(file_name)
        input_data = speaker_zip.read(phones_file)
        input_data = [utf8(x.strip())
                      for x in input_data.splitlines() if x.strip()]
        segments = []

        for row in input_data:
            if self._interrupted:
                return
            while "  " in row:
                row = row.replace("  ", " ")
            # only process the lines after the hash mark:
            if row == "#":
                file_body = True
            elif file_body:
                try:
                    end_time, _, remain = row.partition(" ")
                    _, _, segment = remain.partition(" ")
                except ValueError:
                    logger.warn(".phones file {}: error in row partitioning ({})".format(filename, row))
                    continue
                end_time = float(end_time)

                # Some segments have the undocumented form 'n; *'. In that
                # case, strip the latter part:
                segment = segment.partition(";")[0].strip()

                if end_time >= 0:
                    segments.append((end_time, segment))
        return segments
Example #36
0
    def change_filter(self):
        """
        Update the values from the dialog with the content of the currently
        selected filter.

        This method is called whenever the selected filter in the filter list
        is changed.
        """
        selected = self.ui.table_filters.currentItem()
        selected_filter = selected.data(FilterObjectRole)

        if selected_filter is not None:
            # get correct operator radio button:
            radio = getattr(self.ui,
                            self.radio_operators[selected_filter.operator])

            # get correct feature list entry:
            for i in range(self.ui.list_columns.count()):
                item = self.ui.list_columns.item(i)
                if item.data(FeatureRole) == selected_filter.feature:
                    row_number = i

            self.blockSignals(True)

            # update GUI values:
            radio.setChecked(True)
            self.ui.edit_value.setText(utf8(selected_filter.value))
            self.ui.check_before_transformation.setChecked(
                selected_filter.stage == FILTER_STAGE_BEFORE_TRANSFORM)
            self.ui.list_columns.setCurrentRow(row_number)

            self.blockSignals(False)

        self.update_buttons(selected)
 def validate_name_is_unique():
     if utf8(self.ui.corpus_name.text()
             ) in options.cfg.current_resources:
         self.ui.corpus_name.setStyleSheet(
             'QLineEdit {background-color: lightyellow; }')
         self.ui.issue_label.setText(
             "There is already another corpus with this name..")
         button.setEnabled(False)
Example #38
0
 def exec_(self):
     result = super(TextgridExportDialog, self).exec_()
     if result == QtWidgets.QDialog.Accepted:
         columns = []
         columns = [x.data(QtCore.Qt.UserRole) for x
                    in self.ui.list_columns.selectedItems()]
         return {"output_path": utf8(self.ui.edit_output_path.text()),
                 "columns": columns,
                 "one_grid_per_match": self.ui.radio_one_per_match.isChecked(),
                 "remember_time": self.ui.check_remember.checkState() != QtCore.Qt.Unchecked,
                 "sound_path": ("" if self.ui.check_copy_sounds.checkState() == QtCore.Qt.Unchecked else
                                utf8(self.ui.edit_sound_path.text())),
                 "file_prefix": utf8(self.ui.edit_file_prefix.text()),
                 "left_padding": float(self.ui.spin_left_padding.value()),
                 "right_padding": float(self.ui.spin_right_padding.value())}
     else:
         return None
Example #39
0
 def check_gui(self, *args, **kwargs):
     self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(True)
     if not os.path.exists(utf8(self.ui.edit_output_path.text())):
         S = "QLineEdit { background-color: rgb(255, 255, 192) }"
         self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setDisabled(True)
     else:
         S = "QLineEdit {{ background-color: {} }} ".format(
             options.cfg.app.palette().color(QtGui.QPalette.Base).name())
     self.ui.edit_output_path.setStyleSheet(S)
     if self.ui.check_copy_sounds.isChecked():
         if not os.path.exists(utf8(self.ui.edit_sound_path.text())):
             S = "QLineEdit { background-color: rgb(255, 255, 192) }"
             self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setDisabled(True)
         else:
             S = "QLineEdit {{ background-color: {} }} ".format(
                 options.cfg.app.palette().color(QtGui.QPalette.Base).name())
         self.ui.edit_sound_path.setStyleSheet(S)
 def validate_db_does_exist():
     db_exists = sqlhelper.has_database(
         options.cfg.current_server,
         "coq_{}".format(utf8(self.ui.corpus_name.text()).lower()))
     if not db_exists:
         self.ui.corpus_name.setStyleSheet('QLineEdit {background-color: lightyellow; }')
         self.ui.issue_label.setText("There is no database that uses this name.")
         button.setEnabled(False)
Example #41
0
    def __init__(self, item, context=True, title="Output column options", parent=None, *args, **kwargs):
        super(CoqResourceMenu, self).__init__(title, parent)

        rc_feature = utf8(item.objectName())
        label = utf8(item.text(0))

        # if shown as context menu, use column name as header:
        if context:
            head = QtWidgets.QLabel("<b>{}</b>".format(label))
            head.setAlignment(QtCore.Qt.AlignCenter)
            action = QtWidgets.QWidgetAction(parent)
            action.setDefaultWidget(head)
            self.addAction(action)

        add_link = QtWidgets.QAction("&Link an external table", parent)
        remove_link = QtWidgets.QAction("&Remove linked table", parent)
        view_entries = QtWidgets.QAction("View all &values", parent)
        view_uniques = QtWidgets.QAction("View &unique values", parent)

        # linked table:
        if hasattr(item, "link"):
            self.addAction(remove_link)
            remove_link.triggered.connect(lambda: self.removeItemRequested.emit(item))
        elif not (rc_feature.endswith("_table")):
            if not rc_feature.startswith("coquery"):
                self.addAction(view_uniques)
                self.addAction(view_entries)
                view_entries.triggered.connect(lambda: self.viewEntriesRequested.emit(item))
                view_uniques.triggered.connect(lambda: self.viewUniquesRequested.emit(item))

                # Only enable the 'View' entries if the SQL connection is
                # working:
                view_uniques.setEnabled(options.cfg.gui.test_mysql_connection())
                view_entries.setEnabled(options.cfg.gui.test_mysql_connection())

                self.addSeparator()

                if not hasattr(item.parent(), "link"):
                    self.addAction(add_link)
                    add_link.triggered.connect(lambda: self.addLinkRequested.emit(item))

        else:
            unavailable = QtWidgets.QAction(_translate("MainWindow", "No option available for tables.", None), self)
            unavailable.setDisabled(True)
            self.addAction(unavailable)
    def get_arguments_from_gui(self):
        namespace = super(BuilderGui, self).get_arguments_from_gui()

        namespace.name = utf8(self.ui.corpus_name.text())
        namespace.use_nltk = self.ui.use_pos_tagging.checkState()
        namespace.use_meta = self.ui.check_use_metafile.checkState()
        namespace.db_name = "coq_{}".format(namespace.name).lower()
        namespace.one_file = self._onefile
        return namespace
    def select_metafile(self):
        path = os.path.split(utf8(self.ui.label_metafile.text()))[0]
        if not path:
            path = utf8(self.ui.input_path.text())
        if not path:
            path = os.path.expanduser("~")

        name = QtWidgets.QFileDialog.getOpenFileName(directory=path)
        if type(name) is tuple:
            name = name[0]
        if name:
            if not self.builder_class.probe_metadata(name):
                QtWidgets.QMessageBox.critical(
                    self, "Invalid meta data file – Coquery",
                    msg_invalid_metadata, QtWidgets.QMessageBox.Yes)
            else:
                self.ui.label_metafile.setText(name)
                self.ui.check_use_metafile.setChecked(True)
Example #44
0
    def from_directory(self):
        global _NLTK_dir
        name = QtWidgets.QFileDialog.getExistingDirectory(directory=options.cfg.textgrids_file_path, options=QtWidgets.QFileDialog.ReadOnly|QtWidgets.QFileDialog.ShowDirsOnly|QtWidgets.QFileDialog.HideNameFilterDetails)
        if type(name) == tuple:
            name = name[0]

        if name:
            _NLTK_dir = utf8(name)
            self.accept()
    def get_arguments_from_gui(self):
        namespace = super(BuilderGui, self).get_arguments_from_gui()

        namespace.name = utf8(self.ui.corpus_name.text())
        namespace.use_nltk = self.ui.use_pos_tagging.checkState()
        namespace.use_meta = self.ui.check_use_metafile.checkState()
        namespace.db_name = "coq_{}".format(namespace.name).lower()
        namespace.one_file = self._onefile
        return namespace
    def _process_words_file(self, tar_file, member, match):
        logger.info("Processing file {}".format(member.name))
              
        conv_id = int(match.group(1))
        side = '"{}"'.format(match.group(2))
        row = self._df_conv[(self._df_conv[self.source_id] == conv_id) & (self._df_conv.Side == side)]
        speaker_id = row.SpeakerId.values[0]
        source_id = row["_index"].values[0]

        input_data = list(tar_file.extractfile(member))

        for row in input_data:
            if self._interrupted:
                return
            try:
                source, start, end, label = [x.strip() for x in row.split()]
            except ValueError:
                print(member.name, row)
                print("---")
                continue
            label = utf8(label)
            source = utf8(source)
            uttered = label
            match = re.match("(.*)\[(.*)\](.*)", label)
            if match:
                matched = match.group(2)
                if matched.startswith("laughter-"):
                    label = matched.partition("laughter-")[-1]
                elif match.group(1) != "" or match.group(3) != "":
                    # incomplete utterance, e.g. 'reall[y]-' or 'sim[ilar]-'
                    label = "{}{}{}".format(*match.groups()).strip("-")
            d = {self.word_label: label.lower(),
                 self.word_uttered: uttered,
                 self.word_transcript: ""}
            self._word_id = self.table(self.word_table).get_or_insert(d)
            
            d = {self.corpus_word_id: int(self._word_id),
                 self.corpus_starttime: float(start),
                 self.corpus_endtime: float(end),
                 self.corpus_file_id: int(self._file_id),
                 self.corpus_source_id: int(source_id),
                 self.corpus_speaker_id: int(speaker_id)}
            self.add_token_to_corpus(d)
            self._duration = max(self._duration, float(end))
 def validate_db_does_exist():
     db_exists = sqlhelper.has_database(
         options.cfg.current_server,
         "coq_{}".format(utf8(self.ui.corpus_name.text()).lower()))
     if not db_exists:
         self.ui.corpus_name.setStyleSheet(
             'QLineEdit {background-color: lightyellow; }')
         self.ui.issue_label.setText(
             "There is no database that uses this name.")
         button.setEnabled(False)
Example #48
0
    def setCurrentItem(self, x):
        """
        Set the current item to the item that has 'x' as its data.
        """
        # look in left list:
        for i in range(self.ui.list_selected.count()):
            item = self.ui.list_selected.item(i)
            if utf8(item.data(QtCore.Qt.UserRole)) == x:
                _last_selected_row = item
                self.ui.list_selected.setCurrentItem(item)
                return

        # look in right list:
        for i in range(self.ui.list_available.count()):
            item = self.ui.list_available.item(i)
            if utf8(item.data(QtCore.Qt.UserRole)) == x:
                _last_available_row = item
                self.ui.list_available.setCurrentItem(item)
                return
Example #49
0
 def reset_substitution(self):
     current_item = self.ui.widget_selection.currentItem()
     column = current_item.data(QtCore.Qt.UserRole)
     for i in range(self.ui.table_substitutions.rowCount()):
         key = self._key_dtype(
                 utf8(self.ui.table_substitutions.item(i, 0).text()),
                 column)
         value = None
         self.ui.table_substitutions.item(i, 1).setText(value)
         self.substitutions[column][key] = value