Example #1
0
    def run(self, path):
        """
        Perform CSV file generation.
        :type path: str
        """
        if self.diagrams is None:
            dialog = DiagramSelectionDialog(self.session)
            if not dialog.exec_():
                return
            self.diagrams = dialog.selectedDiagrams()

        LOGGER.info(
            'Exporting selected diagrams in project %s in CSV format: %s',
            self.project.name, path)
        collection = {x: {} for x in self.Types}

        for diagram in self.diagrams:
            nodes = self.project.predicates(diagram=diagram)
            for node in nodes:
                if node.type() in collection:
                    if not node.text() in collection[node.type()]:
                        meta = self.project.meta(node.type(), node.text())
                        collection[node.type()][node.text()] = {
                            CsvExporter.KeyName:
                            node.text().replace('\n', ''),
                            CsvExporter.KeyType:
                            node.shortName,
                            CsvExporter.KeyDescription:
                            self.plainText(meta.get(K_DESCRIPTION, '')),
                            CsvExporter.KeyDiagrams:
                            DistinctList()
                        }
                    collection[node.type()][node.text()][self.KeyDiagrams] += [
                        node.diagram.name
                    ]

        buffer = io.StringIO()
        writer = csv.writer(buffer,
                            delimiter=',',
                            quotechar='"',
                            quoting=csv.QUOTE_ALL)
        writer.writerow((self.KeyName, self.KeyType, self.KeyDescription,
                         self.KeyDiagrams))
        for i, j in sorted(((v, k) for k in collection for v in collection[k]),
                           key=itemgetter(0)):
            writer.writerow((
                collection[j][i][self.KeyName],
                collection[j][i][self.KeyType],
                collection[j][i][self.KeyDescription],
                sorted(collection[j][i][self.KeyDiagrams]),
            ))

        fwrite(buffer.getvalue(), path)

        if self.open:
            openPath(path)
Example #2
0
    def run(self, path):
        """
        Perform CSV file generation.
        :type path: str
        """
        diagrams_selection_dialog = DiagramsSelectionDialog(
            self.project, self.session)
        diagrams_selection_dialog.exec_()
        self.selected_diagrams = diagrams_selection_dialog.diagrams_selected

        LOGGER.info(
            'Exporting selected diagrams in project %s in CSV format: %s',
            self.project.name, path)
        collection = {x: {} for x in self.Types}

        for diag in self.selected_diagrams:
            nodes = self.project.predicates(diagram=diag)
            for node in nodes:
                if node.type() in collection:
                    if not node.text() in collection[node.type()]:
                        meta = self.project.meta(node.type(), node.text())
                        collection[node.type()][node.text()] = {
                            #CsvExporter.KeyName: lstrip(OWLShortIRI('', node.text()), ':'),
                            CsvExporter.KeyName:
                            node.text().replace('\n', ''),
                            CsvExporter.KeyType:
                            node.shortName,
                            #CsvExporter.KeyDescription: meta.get(K_DESCRIPTION, ''),
                            CsvExporter.KeyDescription:
                            QtWidgets.QTextEdit(meta.get(K_DESCRIPTION,
                                                         '')).toPlainText(),
                            CsvExporter.KeyDiagrams:
                            DistinctList()
                        }
                    collection[node.type()][node.text()][self.KeyDiagrams] += [
                        node.diagram.name
                    ]

        buffer = io.StringIO()
        writer = csv.writer(buffer)
        writer.writerow((self.KeyName, self.KeyType, self.KeyDescription,
                         self.KeyDiagrams))
        for i, j in sorted(((v, k) for k in collection for v in collection[k]),
                           key=itemgetter(0)):
            writer.writerow((
                collection[j][i][self.KeyName],
                collection[j][i][self.KeyType],
                collection[j][i][self.KeyDescription],
                sorted(collection[j][i][self.KeyDiagrams]),
            ))

        fwrite(buffer.getvalue(), path)

        openPath(path)
Example #3
0
 def doExport(self):
     """
     Export the generated OWL and schema.
     """
     dialog = QtWidgets.QFileDialog(self)
     dialog.setFileMode(QtWidgets.QFileDialog.Directory)
     if dialog.exec_():
         directory = first(dialog.selectedFiles())
         owl = self.findChild(QtWidgets.QTextEdit, 'owl_text').toPlainText()
         fwrite(owl, os.path.join(directory, 'ontology.owl'))
         openPath(directory)
Example #4
0
 def createProjectFile(self):
     """
     Serialize a previously created QDomDocument to disk.
     """
     try:
         mkdir(self.project.path)
         filename = postfix(self.project.name, File.Graphol.extension)
         filepath = os.path.join(self.project.path, filename)
         fwrite(self.document.toString(2), filepath)
     except Exception as e:
         raise e
     else:
         LOGGER.info('Saved project %s to %s', self.project.name, self.project.path)
Example #5
0
 def createProjectFile(self):
     """
     Serialize a previously created QDomDocument to disk.
     """
     try:
         mkdir(self.project.path)
         filename = postfix(self.project.name, File.Graphol.extension)
         filepath = os.path.join(self.project.path, filename)
         fwrite(self.document.toString(2), filepath)
     except Exception as e:
         raise e
     else:
         LOGGER.info('Saved project %s to %s', self.project.name,
                     self.project.path)
Example #6
0
    def run(self, path):
        """
        Perform graph references document generation.
        :type path: str
        """
        # CREATE THE DOCUMENT
        self.document = QtXml.QDomDocument()
        instruction = self.document.createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8" standalone="no"')
        self.document.appendChild(instruction)

        # CREATE ROOT ELEMENT
        root = self.document.createElement('graphReferences')

        # GENERATE NODES
        for diagram in self.project.diagrams():
            for node in diagram.nodes():
                QtCore.QCoreApplication.processEvents()
                if node.isMeta():
                    iri = self.project.get_full_IRI(
                        self.project.get_iri_of_node(node), None, node.remaining_characters)
                    diagramElement = self.document.createElement('diagramName')
                    diagramElement.appendChild(self.document.createTextNode(diagram.name))
                    xElement = self.document.createElement('x')
                    xElement.appendChild(self.document.createTextNode(str(int(node.x()))))
                    yElement = self.document.createElement('y')
                    yElement.appendChild(self.document.createTextNode(str(int(node.y()))))
                    wElement = self.document.createElement('w')
                    wElement.appendChild(self.document.createTextNode(str(int(node.width()))))
                    hElement = self.document.createElement('h')
                    hElement.appendChild(self.document.createTextNode(str(int(node.height()))))
                    nodeElement = self.document.createElement(node.type().realName.replace(' node', ''))
                    nodeElement.setAttribute('name', iri)
                    nodeElement.appendChild(diagramElement)
                    nodeElement.appendChild(xElement)
                    nodeElement.appendChild(yElement)
                    nodeElement.appendChild(wElement)
                    nodeElement.appendChild(hElement)
                    root.appendChild(nodeElement)

        # APPEND THE GRAPH TO THE DOCUMENT
        self.document.appendChild(root)

        # GENERATE THE FILE
        fwrite(self.document.toString(2), path)
Example #7
0
    def run(self, path):
        """
        Perform CSV file generation.
        :type path: str
        """
        LOGGER.info('Exporting project %s in CSV format: %s',
                    self.project.name, path)
        collection = {x: {} for x in self.Types}

        for node in self.project.predicates():
            if node.type() in collection:
                if not node.text() in collection[node.type()]:
                    meta = self.project.meta(node.type(), node.text())
                    collection[node.type()][node.text()] = {
                        CsvExporter.KeyName:
                        lstrip(OWLShortIRI('', node.text()), ':'),
                        CsvExporter.KeyType:
                        node.shortName,
                        CsvExporter.KeyDescription:
                        meta.get(K_DESCRIPTION, ''),
                        CsvExporter.KeyDiagrams:
                        DistinctList()
                    }
                collection[node.type()][node.text()][self.KeyDiagrams] += [
                    node.diagram.name
                ]

        buffer = io.StringIO()
        writer = csv.writer(buffer)
        writer.writerow((self.KeyName, self.KeyType, self.KeyDescription,
                         self.KeyDiagrams))
        for i, j in sorted(((v, k) for k in collection for v in collection[k]),
                           key=itemgetter(0)):
            writer.writerow((
                collection[j][i][self.KeyName],
                collection[j][i][self.KeyType],
                collection[j][i][self.KeyDescription],
                sorted(collection[j][i][self.KeyDiagrams]),
            ))

        fwrite(buffer.getvalue(), path)

        openPath(path)
Example #8
0
 def createProjectFile(self):
     """
     Serialize a previously created QDomDocument to disk.
     """
     try:
         currPath = self.exportPath if self.exportPath else self.project.path
         if not fexists(currPath):
             folderPath = os.path.dirname(currPath)
             if not isdir(folderPath):
                 mkdir(folderPath)
             fd = os.open(currPath, os.O_CREAT)
             os.close(fd)
         #TODO filename = postfix(self.project.name, File.Graphol.extension)
         #TODO filepath = os.path.join(self.project.path, filename)
         #TODO fwrite(self.document.toString(2), filepath)
         fwrite(self.document.toString(2), currPath)
     except Exception as e:
         raise e
     else:
         LOGGER.info('Saved project %s to %s', self.project.name, currPath)
Example #9
0
    def export(self, path):
        """
        Perform CSV file generation.
        :type path: str
        """
        LOGGER.info('Exporting project %s in CSV format: %s', self.project.name, path)
        collection = {x: {} for x in self.Types}

        for node in self.project.predicates():
            if node.type() in collection:
                # If there is no data for this predicate node, create a new entry.
                if not node.text() in collection[node.type()]:
                    meta = self.project.meta(node.type(), node.text())
                    collection[node.type()][node.text()] = {
                        CsvExporter.KeyName: lstrip(OWLShortIRI('', node.text()), ':'),
                        CsvExporter.KeyType: node.shortName,
                        CsvExporter.KeyDescription: meta.get('description', ''),
                        CsvExporter.KeyDiagrams: DistinctList()}
                # Append the name of the diagram to the diagram list.
                collection[node.type()][node.text()][self.KeyDiagrams] += [node.diagram.name]

        # Collect data in a buffer.
        buffer = io.StringIO()
        writer = csv.writer(buffer)
        writer.writerow((self.KeyName, self.KeyType, self.KeyDescription, self.KeyDiagrams))
        for i, j in sorted(((v, k) for k in collection for v in collection[k]), key=itemgetter(0)):
            writer.writerow((
                collection[j][i][self.KeyName],
                collection[j][i][self.KeyType],
                collection[j][i][self.KeyDescription],
                sorted(collection[j][i][self.KeyDiagrams]),
            ))

        # Write to disk.
        fwrite(buffer.getvalue(), path)

        # Open the document.
        openPath(path)
Example #10
0
    def run(self,path):

        project = self.diagram.project

        # 1) CREATE THE DOCUMENT
        self.document = QtXml.QDomDocument()
        instruction = self.document.createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8" standalone="no"')
        self.document.appendChild(instruction)

        # 2) CREATE ROOT ELEMENT
        root = self.document.createElement('graphReferences')

        node_diagrams_dict = dict()

        for diagram in project.diagrams():
            for node in diagram.nodes():
                if node.isMeta():#if node.type() not in self.missing:

                    full_IRI = project.get_full_IRI(project.get_iri_of_node(node), None, node.remaining_characters)

                    if full_IRI not in node_diagrams_dict.keys():
                        node_diagrams_dict[full_IRI] = []

                        node_diagrams_dict[full_IRI].append(node.type().realName.replace(' node',''))

                    node_diagrams_dict[full_IRI].append(diagram.name)
                    node_diagrams_dict[full_IRI].append(str(int(node.pos().x())))
                    node_diagrams_dict[full_IRI].append(str(int(node.pos().y())))
                    node_diagrams_dict[full_IRI].append(str(int(node.width())))
                    node_diagrams_dict[full_IRI].append(str(int(node.height())))

        # 3) GENERATE NODES
        for node_full_text in node_diagrams_dict.keys():

            value = node_diagrams_dict[node_full_text]

            for i in range(1,len(value)-4,5):

                diag = value[i]
                x = value[i+1]
                y = value[i+2]
                w = value[i+3]
                h = value[i+4]

                diag_to_append = self.document.createElement('diagramName')
                diag_to_append.appendChild(self.document.createTextNode(diag))

                x_to_append = self.document.createElement('x')
                x_to_append.appendChild(self.document.createTextNode(x))

                y_to_append = self.document.createElement('y')
                y_to_append.appendChild(self.document.createTextNode(y))

                w_to_append = self.document.createElement('w')
                w_to_append.appendChild(self.document.createTextNode(w))

                h_to_append = self.document.createElement('h')
                h_to_append.appendChild(self.document.createTextNode(h))

                node_to_append = self.document.createElement(value[0])
                node_to_append.setAttribute('name', node_full_text)

                node_to_append.appendChild(diag_to_append)
                node_to_append.appendChild(x_to_append)
                node_to_append.appendChild(y_to_append)
                node_to_append.appendChild(w_to_append)
                node_to_append.appendChild(h_to_append)

                root.appendChild(node_to_append)

        # 4) APPEND THE GRAPH TO THE DOCUMENT
        self.document.appendChild(root)

        # 5) GENERATE THE FILE
        fwrite(self.document.toString(2), path)

        self.success = True
Example #11
0
    def run(self, path):
        """
        Perform GraphML document generation.
        :type path: str
        """
        LOGGER.info('Exporting diagram %s to %s', self.diagram.name, path)

        # 1) CREATE THE DOCUMENT
        self.document = QtXml.QDomDocument()
        instruction = self.document.createProcessingInstruction(
            'xml', 'version="1.0" encoding="UTF-8"')
        self.document.appendChild(instruction)

        # 2) CREATE ROOT ELEMENT
        root = self.document.createElement('graphml')
        root.setAttribute('xmlns', 'http://graphml.graphdrawing.org/xmlns')
        root.setAttribute('xmlns:xsi',
                          'http://www.w3.org/2001/XMLSchema-instance')
        root.setAttribute('xmlns:y', 'http://www.yworks.com/xml/graphml')
        root.setAttribute('xmlns:yed', 'http://www.yworks.com/xml/yed/3')
        root.setAttribute(
            'xsi:schemaLocation', 'http://graphml.graphdrawing.org/xmlns '
            'http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd')

        # 3) CREATE ELEMENT KEYS
        key = self.document.createElement('key')
        key.setAttribute('for', 'node')
        key.setAttribute('id', GraphMLDiagramExporter.KeyNode)
        key.setAttribute('yfiles.type', 'nodegraphics')
        root.appendChild(key)

        key = self.document.createElement('key')
        key.setAttribute('for', 'edge')
        key.setAttribute('id', GraphMLDiagramExporter.KeyEdge)
        key.setAttribute('yfiles.type', 'edgegraphics')
        root.appendChild(key)

        key = self.document.createElement('key')
        key.setAttribute('attr.name', K_URL)
        key.setAttribute('attr.type', 'string')
        key.setAttribute('for', 'node')
        key.setAttribute('id', GraphMLDiagramExporter.KeyUrl)
        root.appendChild(key)

        key = self.document.createElement('key')
        key.setAttribute('attr.name', K_DESCRIPTION)
        key.setAttribute('attr.type', 'string')
        key.setAttribute('for', 'node')
        key.setAttribute('id', GraphMLDiagramExporter.KeyDescription)
        root.appendChild(key)

        # 4) CREATE THE GRAPH NODE
        graph = self.document.createElement('graph')
        graph.setAttribute('edgedefault', 'directed')
        graph.setAttribute('id', 'G')

        # 5) GENERATE NODES
        for node in self.diagram.nodes():
            if node.type() not in self.missing:
                func = self.exportFuncForItem[node.type()]
                graph.appendChild(func(node))

        # 6) GENERATE EDGES
        for edge in self.diagram.edges():
            if edge.source.type() not in self.missing and edge.target.type(
            ) not in self.missing:
                func = self.exportFuncForItem[edge.type()]
                graph.appendChild(func(edge))

        # 7) APPEND THE GRAPH TO THE DOCUMENT
        self.document.appendChild(root)
        root.appendChild(graph)

        # 8) GENERATE THE FILE
        fwrite(self.document.toString(2), path)
Example #12
0
    def run(self, path):
        """
        Perform Graphml document generation.
        :type path: str
        """
        LOGGER.info('Exporting diagram %s to %s', self.diagram.name, path)

        # 1) CREATE THE DOCUMENT
        self.document = QtXml.QDomDocument()
        instruction = self.document.createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"')
        self.document.appendChild(instruction)

        # 2) CREATE ROOT ELEMENT
        root = self.document.createElement('graphml')
        root.setAttribute('xmlns', 'http://graphml.graphdrawing.org/xmlns')
        root.setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance')
        root.setAttribute('xmlns:y', 'http://www.yworks.com/xml/graphml')
        root.setAttribute('xmlns:yed', 'http://www.yworks.com/xml/yed/3')
        root.setAttribute('xsi:schemaLocation', 'http://graphml.graphdrawing.org/xmlns '
                                                'http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd')

        # 3) CREATE ELEMENT KEYS
        key = self.document.createElement('key')
        key.setAttribute('for', 'node')
        key.setAttribute('id', GraphMLDiagramExporter.KeyNode)
        key.setAttribute('yfiles.type', 'nodegraphics')
        root.appendChild(key)

        key = self.document.createElement('key')
        key.setAttribute('for', 'edge')
        key.setAttribute('id', GraphMLDiagramExporter.KeyEdge)
        key.setAttribute('yfiles.type', 'edgegraphics')
        root.appendChild(key)

        key = self.document.createElement('key')
        key.setAttribute('attr.name', 'url')
        key.setAttribute('attr.type', 'string')
        key.setAttribute('for', 'node')
        key.setAttribute('id', GraphMLDiagramExporter.KeyUrl)
        root.appendChild(key)

        key = self.document.createElement('key')
        key.setAttribute('attr.name', 'description')
        key.setAttribute('attr.type', 'string')
        key.setAttribute('for', 'node')
        key.setAttribute('id', GraphMLDiagramExporter.KeyDescription)
        root.appendChild(key)

        # 4) CREATE THE GRAPH NODE
        graph = self.document.createElement('graph')
        graph.setAttribute('edgedefault', 'directed')
        graph.setAttribute('id', 'G')

        # 5) GENERATE NODES
        for node in self.diagram.nodes():
            if node.type() not in self.missing:
                func = self.exportFuncForItem[node.type()]
                graph.appendChild(func(node))

        # 6) GENERATE EDGES
        for edge in self.diagram.edges():
            if edge.source.type() not in self.missing and edge.target.type() not in self.missing:
                func = self.exportFuncForItem[edge.type()]
                graph.appendChild(func(edge))

        # 7) APPEND THE GRAPH TO THE DOCUMENT
        self.document.appendChild(root)
        root.appendChild(graph)

        # 8) GENERATE THE FILE
        fwrite(self.document.toString(2), path)