Пример #1
0
    def __init__(self, processor: TextProcessor,
                 algorithm=None, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.graph = GraphModule(self)
        self.graph.get_relation_text = self._describe_relation

        self.graphWidgetLayout.addWidget(self.graph.widget)
        self.processor = processor
        self.setupAlgorithms(algorithm)

        self.describer = Describer(self.algorithm, processor)
        self.populateGraph()

        self.actionSaveGraph.triggered.connect(self.saveGraph)

        self.excludeZerosCheckBox.stateChanged.connect(
            self.updateGraph)
        self.thresholdSlider.valueChanged.connect(
            self.updateGraph)
        self.algorithmComboBox.currentIndexChanged.connect(self.updateGraph)

        self.relayoutButton.clicked.connect(
            lambda: self.graph.relayout_graph(
                self.layoutComboBox.currentText()))

        self.gravityCheckBox.stateChanged.connect(self.toggle_gravity)
        self.gravityCheckBox.setChecked(
            SupremeSettings()['graphmodule_gravity_enabled'])

        self.graph.start_gravity()
    def __init__(self, algorithm: AbstractAlgorithm, processor, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.settings = SupremeSettings()
        self.textBrowser = TextBrowser(self)
        self.textBrowserLayout.addWidget(self.textBrowser)

        self.algorithm = algorithm
        self.processor = processor
        self.elementsLabel.setText(str(len(self.processor.analyzer)**2))
        self.describer = Describer(algorithm, processor)
        self.plotter = Plotter(self.processor, self.algorithm)

        self.result_matrix = None
        self.hide_empty = False
        self.thresholdSlider.valueChanged.connect(
            self._on_threshold_slider_value_changed)
        self.hideEmptyCheckBox.stateChanged.connect(
            self._on_hide_empty_checkbox_state_changed)
        self.graphButton.clicked.connect(self._on_show_graph)
        self.splitter.setStretchFactor(0, 1)
        self.splitter.setStretchFactor(1, 2)

        self.exportButton.clicked.connect(self._on_export)
        self.updateButton.clicked.connect(self.update_results)
Пример #3
0
 def test_describe_community(self):
     processor = _fill_db()
     algorithm = processor.algorithms[0]
     desc = Describer(algorithm, processor)
     disp = GraphAlgDispatcher(processor, algorithm)
     results = disp.dispatch_community()
     comm_desc = desc.describe_community_results(results)
     self.assertGreater(len(comm_desc), 0)
Пример #4
0
 def create_html(self):
     algs = [
         alg for alg in self.graph_algs
         if self.settings['algorithms'][alg.name]
     ]
     describer = Describer(self.algorithm, self.processor)
     dispatcher = GraphAlgDispatcher(self.processor, self.algorithm)
     results = dispatcher.dispatch_centrality(self._test_func)
     return describer.describe_centrality_results(results)
Пример #5
0
    def test_describe(self):
        self.processor = _fill_db()
        self.algorithm = self.processor.algorithms[0]

        desc = Describer(self.algorithm, self.processor)
        node_desc = desc.describe_node(self.processor.analyzer[0])
        self.assertGreater(len(node_desc), 0)
        alg_desc = desc.describe_results()
        self.assertGreater(len(alg_desc), 0)
        total_desc = desc.describe_results(all_algs=True)
        self.assertGreaterEqual(len(total_desc), 0)
Пример #6
0
 def create_html(self):
     describer = Describer(None, self.processor)
     return describer.describe_results(accs=False, all_algs=True)
Пример #7
0
 def create_html(self):
     describer = Describer(self.algorithm, self.processor)
     return describer.describe_results()
Пример #8
0
class GraphWindow(QMainWindow, Ui_GraphWindow):
    def __init__(self, processor: TextProcessor,
                 algorithm=None, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.graph = GraphModule(self)
        self.graph.get_relation_text = self._describe_relation

        self.graphWidgetLayout.addWidget(self.graph.widget)
        self.processor = processor
        self.setupAlgorithms(algorithm)

        self.describer = Describer(self.algorithm, processor)
        self.populateGraph()

        self.actionSaveGraph.triggered.connect(self.saveGraph)

        self.excludeZerosCheckBox.stateChanged.connect(
            self.updateGraph)
        self.thresholdSlider.valueChanged.connect(
            self.updateGraph)
        self.algorithmComboBox.currentIndexChanged.connect(self.updateGraph)

        self.relayoutButton.clicked.connect(
            lambda: self.graph.relayout_graph(
                self.layoutComboBox.currentText()))

        self.gravityCheckBox.stateChanged.connect(self.toggle_gravity)
        self.gravityCheckBox.setChecked(
            SupremeSettings()['graphmodule_gravity_enabled'])

        self.graph.start_gravity()

    def setupAlgorithms(self, algorithm=None):
        alg_list = [alg.name for alg in self.processor.algorithms]
        self.algorithmComboBox.addItems(alg_list)
        self.algorithmComboBox.setCurrentIndex(0)
        if algorithm:
            self.algorithm = algorithm
            self.algorithmComboBox.setCurrentIndex(
                self.processor.algorithms.index(self.algorithm))
        else:
            self.onChangeAlgorithms(alg_list[0])

    def toggle_gravity(self, state):
        state = state != 0
        SupremeSettings()['graphmodule_gravity_enabled'] = state
        if state is False:
            self.graph.stop_gravity()
        else:
            self.graph.start_gravity()

    def onChangeAlgorithms(self, name: str):
        self.algorithm = self.processor.alg_by_name(name)

    def getNodeParams(self, node: TextNode):
        x = np.random.random() * 400 - 200
        y = np.random.random() * 400 - 200
        color = QColor.fromRgbF(
            *[np.random.random() * 0.5 + 0.5 for _ in range(3)])
        return x, y, color

    def updateGraph(self):
        self.graph.clear()
        self.populateGraph()

    def _describe_relation(self, item):
        id1, id2 = item
        rel = self.processor.get_relation(self.algorithm.name, id1, id2)
        text = self.describer.describe_query_relation(rel, id1, id2)
        return text

    def populateGraph(self):
        min_val = self.thresholdSlider.value() / 100
        head, res = self.processor.get_node_id_list(
            self.algorithm.name, self.excludeZerosCheckBox.isChecked(),
            min_val)
        nodes = self.processor.get_node_list(head)
        for node in nodes:
            info = self.describer.describe_node(node)
            x, y, color = self.getNodeParams(node)
            self.graph.add_node(node.order_id, x, y, color=color,
                                label=str(node.label), info=info)
        if res:
            for id1, id2, intersection in res:
                if min_val < 1:
                    weight = (intersection - min_val + 0.005) \
                           / (1 - min_val)
                else:
                    weight = 1
                info = (id1, id2)
                self.graph.add_edge(id1, id2, ud=True, info=info,
                                    weight=weight)

    def saveGraph(self):
        self.graph.save_graph()
class AlgorithmResults(QWidget, Ui_AlgorithmResult):
    def __init__(self, algorithm: AbstractAlgorithm, processor, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.settings = SupremeSettings()
        self.textBrowser = TextBrowser(self)
        self.textBrowserLayout.addWidget(self.textBrowser)

        self.algorithm = algorithm
        self.processor = processor
        self.elementsLabel.setText(str(len(self.processor.analyzer)**2))
        self.describer = Describer(algorithm, processor)
        self.plotter = Plotter(self.processor, self.algorithm)

        self.result_matrix = None
        self.hide_empty = False
        self.thresholdSlider.valueChanged.connect(
            self._on_threshold_slider_value_changed)
        self.hideEmptyCheckBox.stateChanged.connect(
            self._on_hide_empty_checkbox_state_changed)
        self.graphButton.clicked.connect(self._on_show_graph)
        self.splitter.setStretchFactor(0, 1)
        self.splitter.setStretchFactor(1, 2)

        self.exportButton.clicked.connect(self._on_export)
        self.updateButton.clicked.connect(self.update_results)

    def _on_hide_empty_checkbox_state_changed(self, value):
        self.hide_empty = value
        if self.settings['result_auto_update']:
            self.update_results()

    def _on_threshold_slider_value_changed(self, value):
        self.min_val = value / 100
        if self.result_matrix:
            if not self.hide_empty:
                self.result_matrix.set_min_val(self.min_val)
            elif self.settings['result_auto_update']:
                self.update_results()

    def _on_item_clicked(self, item: TextNode):
        self.textBrowser.setHtml(
            self.describer.describe_node(item))

    def _on_show_graph(self):
        from ui import GraphWindow
        self.graph_window = GraphWindow(self.processor, self.algorithm, self)
        self.graph_window.show()

    def _on_relation_clicked(self, item):
        id1, id2, intersection = item
        rel = self.processor.get_relation(self.algorithm.name, id1, id2)
        id1 = f"{id1} [{self.processor.get_node_label(id1)}]"
        id2 = f"{id2} [{self.processor.get_node_label(id2)}]"
        self.textBrowser.setHtml(
            self.describer.describe_query_relation(rel, id1, id2))

    def _on_export(self):
        min_val = self.thresholdSlider.value() / 100
        Plotter.display(self.plotter.algorithm_matrix(min_val))

    def update_results(self):
        min_val = self.thresholdSlider.value() / 100
        matrix, head = self.processor.get_matrix(
            self.algorithm.name, self.hide_empty, min_val)
        head_items = self.processor.get_node_list(head)
        head_names = self.processor.get_node_label_list(head)
        if self.result_matrix:
            self.resultMatrixLayout.removeWidget(self.result_matrix)
            self.result_matrix.deleteLater()
        else:
            for i in range(self.resultMatrixLayout.count()):
                self.resultMatrixLayout.removeItem(
                    self.resultMatrixLayout.itemAt(i))
            self.loadLabel.deleteLater()

        self.result_matrix = MatrixWidget(matrix, head_names, head_items,
                                          min_val, self)
        self.result_matrix.item_clicked.connect(self._on_item_clicked)
        self.result_matrix.relation_clicked.connect(self._on_relation_clicked)
        self.resultMatrixLayout.addWidget(self.result_matrix)

    def _set_matrix_widget(self, widget: MatrixWidget):
        if self.result_matrix:
            self.resultMatrixLayout.removeWidget(self.result_matrix)
            self.result_matrix.deleteLater()
        self.result_matrix = widget
        self.result_matrix.item_clicked.connect(self._on_item_clicked)
        self.result_matrix.relation_clicked.connect(self._on_relation_clicked)
        self.resultMatrixLayout.addWidget(self.result_matrix)
Пример #10
0
 def _make_global_description(self):
     desc = Describer(None, self.processor)
     results_html = desc.describe_results(all_algs=True)
     self.textBrowser.setHtml(results_html)