Пример #1
0
 def path(self):
     """
     Returns the path to the the reasoner (either a directory of a ZIP file).
     :rtype: str
     """
     path = lstrip(inspect.getfile(self.__class__), expandPath('@reasoners/'), expandPath('@home/reasoners/'))
     home = first(filter(None, path.split(os.path.sep)))
     root = expandPath('@reasoners/' if self.isBuiltIn() else '@home/reasoners/')
     return os.path.join(root, home)
Пример #2
0
 def path(self):
     """
     Returns the path to the the plugin (either a directory of a ZIP file).
     :rtype: str
     """
     path = lstrip(inspect.getfile(self.__class__), expandPath('@plugins/'), expandPath('@home/plugins/'))
     home = first(filter(None, path.split(os.path.sep)))
     root = expandPath('@plugins/' if self.isBuiltIn() else '@home/plugins/')
     return os.path.join(root, home)
Пример #3
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)
Пример #4
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)
Пример #5
0
 def test_lstrip(self):
     self.assertEqual('.graphol', lstrip('Pizza.graphol', 'Pizza'))
     self.assertEqual('graphol', lstrip('Family.graphol', 'Family', '.'))
     self.assertEqual(
         'Message', lstrip('ThisIsATestMessage', 'This', 'Is', 'A', 'Test'))
Пример #6
0
 def test_lstrip(self):
     self.assertEqual('.graphol', lstrip('Pizza.graphol', 'Pizza'))
     self.assertEqual('graphol', lstrip('Family.graphol', 'Family', '.'))
     self.assertEqual('Message', lstrip('ThisIsATestMessage', 'This', 'Is', 'A', 'Test'))
Пример #7
0
def test_lstrip():
    assert '.graphol' == lstrip('Pizza.graphol', 'Pizza')
    assert 'graphol' == lstrip('Family.graphol', 'Family', '.')
    assert 'Message' == lstrip('ThisIsATestMessage', 'This', 'Is', 'A', 'Test')