def test_process_translate_owl(executable, qtbot, owlfilename, ntables):
    # GIVEN
    process = BlackbirdProcess(executable)
    nmanager = NetworkManager()
    basepath = os.path.join(os.path.dirname(__file__), os.pardir)
    owlfile = os.path.join(basepath, 'tests', 'test_export_owl_1', owlfilename)
    try:
        # WHEN
        with qtbot.waitSignal(process.sgnReady, timeout=3000):
            process.start()
        # THEN
        assert process.state() == QtCore.QProcess.Running
        # WHEN
        reply = nmanager.postSchema(fread(owlfile).encode('utf-8'))
        with qtbot.waitSignal(reply.finished, timeout=3000):
            pass
        # THEN
        assert reply.error() == QtNetwork.QNetworkReply.NoError
        # AND
        schema = json.loads(str(reply.readAll(), encoding='utf-8'))
        assert 'id' in schema
        assert 'schemaName' in schema
        assert 'tables' in schema
        assert ntables == len(schema['tables'])
        # WHEN
        with qtbot.waitSignal(process.sgnFinished, timeout=3000):
            process.terminate()
        # THEN
        assert process.state() == QtCore.QProcess.NotRunning
    finally:
        if process.state() != QtCore.QProcess.NotRunning:
            process.kill()
Esempio n. 2
0
    def find_spec(cls, file_or_directory):
        """
        Searches the given file or directory for a 'plugin.spec' file and tries to load it,
        or returns 'None' if no such file exists.

        :type file_or_directory: str
        :rtype: PluginSpec
        """
        file_or_directory = expandPath(file_or_directory)
        try:
            if os.path.exists(file_or_directory) and os.access(
                    file_or_directory, os.R_OK):
                # READ SPEC FILE FROM DIRECTORY
                if isdir(file_or_directory):
                    plugin_spec_path = os.path.join(file_or_directory,
                                                    'plugin.spec')
                    if fexists(plugin_spec_path):
                        return cls.spec(fread(plugin_spec_path))
                # READ SPEC FILE FROM ZIP ARCHIVE
                elif is_zipfile(file_or_directory):
                    zf = ZipFile(file_or_directory)
                    zf_name_list = zf.namelist()
                    if 'plugin.spec' in zf_name_list:
                        plugin_spec_content = zf.read('plugin.spec').decode(
                            'utf8')
                        return cls.spec(plugin_spec_content)
        except Exception as e:
            LOGGER.exception('Failed to load plugin spec: %s', e)
Esempio n. 3
0
 def import_plugin_from_directory(cls, directory):
     """
     Import a plugin from the given directory:
     * Lookup for the plugin .spec configuration file.
     * Search for the module where the plugin is implemented.
     * Search for the class implementing the plugin.
     * Import the plugin module.
     :type directory: str
     :rtype: tuple
     """
     if isdir(directory):
         plugin_spec_path = os.path.join(directory, 'plugin.spec')
         if fexists(plugin_spec_path):
             try:
                 #LOGGER.debug('Found plugin .spec: %s', plugin_spec_path)
                 plugin_spec = PluginManager.spec(fread(plugin_spec_path))
                 plugin_name = plugin_spec.get('plugin', 'id')
                 for extension in ('.pyc', '.pyo', '.py'):
                     plugin_path = os.path.join(directory, '%s%s' % (plugin_name, extension))
                     if fexists(plugin_path):
                         #LOGGER.debug('Found plugin module: %s', plugin_path)
                         plugin_module = SourceFileLoader(plugin_name, plugin_path).load_module()
                         plugin_class = PluginManager.find_class(plugin_module, plugin_name)
                         return plugin_spec, plugin_class
                 else:
                     raise PluginError('missing plugin module: %s.py(c|o)' % os.path.join(directory, plugin_name))
             except Exception as e:
                 LOGGER.exception('Failed to import plugin: %s', e)
Esempio n. 4
0
 def import_reasoner_from_directory(cls, directory):
     """
     Import a reasoner from the given directory:
     * Lookup for the reasoner .spec configuration file.
     * Search for the module where the reasoner is implemented.
     * Search for the class implementing the reasoner.
     * Import the reasoner module.
     :type directory: str
     :rtype: tuple
     """
     if isdir(directory):
         reasoner_spec_path = os.path.join(directory, 'reasoner.spec')
         if fexists(reasoner_spec_path):
             try:
                 #LOGGER.debug('Found reasoner .spec: %s', reasoner_spec_path)
                 reasoner_spec = ReasonerManager.spec(fread(reasoner_spec_path))
                 reasoner_name = reasoner_spec.get('reasoner', 'id')
                 for extension in ('.pyc', '.pyo', '.py'):
                     reasoner_path = os.path.join(directory, '%s%s' % (reasoner_name, extension))
                     if fexists(reasoner_path):
                         #LOGGER.debug('Found reasoner module: %s', reasoner_path)
                         reasoner_module = SourceFileLoader(reasoner_name, reasoner_path).load_module()
                         reasoner_class = ReasonerManager.find_class(reasoner_module, reasoner_name)
                         return reasoner_spec, reasoner_class
                 else:
                     raise ReasonerError('missing reasoner module: %s.py(c|o)' % os.path.join(directory, reasoner_name))
             except Exception as e:
                 LOGGER.exception('Failed to import reasoner: %s', e)
Esempio n. 5
0
 def import_plugin_from_directory(self, directory):
     """
     Import a plugin from the given directory:
     * Lookup for the plugin .spec configuration file.
     * Search for the module where the plugin is implemented.
     * Search for the class implementing the plugin.
     * Import the plugin module.
     :type directory: str
     :rtype: tuple
     """
     if isdir(directory):
         plugin_spec_path = os.path.join(directory, 'plugin.spec')
         if fexists(plugin_spec_path):
             try:
                 LOGGER.debug('Found plugin .spec: %s', plugin_spec_path)
                 plugin_spec = self.spec(fread(plugin_spec_path))
                 plugin_name = plugin_spec.get('plugin', 'id')
                 for extension in ('.pyc', '.pyo', '.py'):
                     plugin_path = os.path.join(directory, '%s%s' % (plugin_name, extension))
                     if fexists(plugin_path):
                         LOGGER.debug('Found plugin module: %s', plugin_path)
                         plugin_module = SourceFileLoader(plugin_name, plugin_path).load_module()
                         plugin_class = self.find_class(plugin_module, plugin_name)
                         return plugin_spec, plugin_class
                 else:
                     raise PluginError('missing plugin module: %s.py(c|o)' % os.path.join(directory, plugin_name))
             except Exception as e:
                 LOGGER.exception('Failed to import plugin: %s', e)
Esempio n. 6
0
 def stylesheet(self):
     """
     Returns the stylesheet for this proxystyle.
     :rtype: str
     """
     if not self._stylesheet:
         if hasattr(sys, 'frozen'):
             resources = expandPath('@resources/styles/')
             if isdir(resources):
                 self._stylesheet = fread(os.path.join(resources, 'default.qss'))
         else:
             self._stylesheet = pkgutil.get_data(__name__, 'default.qss').decode('utf-8')
     return self._stylesheet
Esempio n. 7
0
def test_check_for_update_no_update_available(qtbot):
    # GIVEN
    response_content = fread(expandPath('@tests/test_resources/network/no_update_available.json')).encode('utf-8')
    response_data = b'application/json'
    update_provider = UpdateContentProvider(response_content, response_data)
    nmanager = NetworkManagerMock(None, content_provider=update_provider)
    # WHEN
    with qtbot.waitSignals([nmanager.sgnNoUpdateAvailable]) as blocker, \
            qtbot.assertNotEmitted(nmanager.sgnNoUpdateDataAvailable), \
            qtbot.assertNotEmitted(nmanager.sgnUpdateAvailable):
        nmanager.checkForUpdate(Channel.Stable, '1.0.0')
    # THEN
    assert 1 == len(blocker.all_signals_and_args)
Esempio n. 8
0
    def createDomDocument(self):
        """
        Create the QDomDocument from where to parse information.
        """
        QtWidgets.QApplication.processEvents()

        LOGGER.info('Loading diagram: %s', self.path)

        if not fexists(self.path):
            raise DiagramNotFoundError('diagram not found: {0}'.format(self.path))

        self.document = QtXml.QDomDocument()
        if not self.document.setContent(fread(self.path)):
            raise DiagramNotValidError('could not parse diagram from {0}'.format(self.path))
Esempio n. 9
0
def test_export_project_to_owl_with_normalization(session, tmpdir):
    #TODO ADD DATATYPE RESTRICTION WITH FACET TO TEST ONTOLOGY AND VERIFY TRANSLATION
    # WHEN
    owlfile = tmpdir.join('test_project_3_1.owl')
    project = session.project
    worker = OWLOntologyExporterWorker_v3(project,
                                          str(owlfile),
                                          axioms={x
                                                  for x in OWLAxiom},
                                          normalize=True,
                                          syntax=OWLSyntax.Functional)
    worker.run()
    # THEN
    assert os.path.isfile(str(owlfile))
    # WHEN
    content = list(filter(None, fread(str(owlfile)).split('\n')))
    # THEN
    assert 'Prefix(owl:=<http://www.w3.org/2002/07/owl#>)' in content
    assert 'Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)' in content
    assert 'Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)' in content
    assert 'Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)' in content
    assert 'Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)' in content
    assert 'Prefix(test:=<http://www.dis.uniroma1.it/~graphol/test_project/>)' in content
    assert 'Ontology(<http://www.dis.uniroma1.it/~graphol/test_project/>' in content
    assert 'Declaration(Class(test:Vegetable))' in content
    assert 'Declaration(Class(test:Person))' in content
    assert 'Declaration(Class(test:Male))' in content
    assert 'Declaration(Class(test:Female))' in content
    assert 'Declaration(Class(test:Mother))' in content
    assert 'Declaration(Class(test:Father))' in content
    assert 'Declaration(Class(test:Underage))' in content
    assert 'Declaration(Class(test:Adult))' in content
    assert 'Declaration(Class(test:Vehicle))' in content
    assert 'Declaration(Class(test:Less_than_50_cc))' in content
    assert 'Declaration(Class(test:Over_50_cc))' in content
    assert 'Declaration(NamedIndividual(test:Bob))' in content
    assert 'Declaration(NamedIndividual(test:Alice))' in content
    assert 'Declaration(NamedIndividual(test:Trudy))' in content
    assert 'Declaration(ObjectProperty(test:hasAncestor))' in content
    assert 'Declaration(ObjectProperty(test:hasParent))' in content
    assert 'Declaration(ObjectProperty(test:hasFather))' in content
    assert 'Declaration(ObjectProperty(test:hasMother))' in content
    assert 'Declaration(ObjectProperty(test:isAncestorOf))' in content
    assert 'Declaration(ObjectProperty(test:drives))' in content
    assert 'Declaration(DataProperty(test:name))' in content
    assert 'Declaration(Datatype(xsd:string))' in content
    assert 'AnnotationAssertion(rdfs:comment test:Person "A human being")' in content
    assert 'SubClassOf(test:Person ObjectSomeValuesFrom(test:hasAncestor owl:Thing))' in content
    assert 'SubClassOf(test:Father test:Male)' in content
    assert 'SubClassOf(test:Mother test:Female)' in content
    assert 'SubClassOf(test:Person DataSomeValuesFrom(test:name rdfs:Literal))' in content
    assert 'SubClassOf(test:Female test:Person)' in content
    assert 'SubClassOf(test:Male test:Person)' in content
    assert 'SubClassOf(test:Underage test:Person)' in content
    assert 'SubClassOf(test:Adult test:Person)' in content
    assert 'SubClassOf(test:Less_than_50_cc test:Vehicle)' in content
    assert 'SubClassOf(test:Over_50_cc test:Vehicle)' in content
    assert 'SubClassOf(test:Underage ObjectAllValuesFrom(test:drives test:Less_than_50_cc))' in content
    assert 'SubClassOf(test:Person ObjectAllValuesFrom(test:drives owl:Thing))' in content
    assert 'SubClassOf(ObjectAllValuesFrom(test:drives owl:Thing) test:Person)' in content
    assert 'SubObjectPropertyOf(test:hasParent test:hasAncestor)' in content
    assert 'SubObjectPropertyOf(test:hasFather test:hasParent)' in content
    assert 'SubObjectPropertyOf(test:hasMother test:hasParent)' in content
    assert 'FunctionalObjectProperty(test:hasFather)' in content
    assert 'FunctionalObjectProperty(test:hasMother)' in content
    assert 'DataPropertyRange(test:name xsd:string)' in content
    assert 'DataPropertyDomain(test:name test:Person)' in content

    assert any([
        line in content for line in [
            'SubObjectPropertyOf(test:hasAncestor ObjectInverseOf(test:isAncestorOf))',
            'SubObjectPropertyOf(ObjectInverseOf(test:hasAncestor) test:isAncestorOf)',
            'InverseObjectProperties(test:hasAncestor test:isAncestorOf)',
            'InverseObjectProperties(test:isAncestorOf test:hasAncestor)'
        ]
    ])

    assert any([
        line in content for line in [
            'SubObjectPropertyOf(test:isAncestorOf ObjectInverseOf(test:hasAncestor))',
            'SubObjectPropertyOf(ObjectInverseOf(test:isAncestorOf) test:hasAncestor)',
            'InverseObjectProperties(test:hasAncestor test:isAncestorOf)',
            'InverseObjectProperties(test:isAncestorOf test:hasAncestor)'
        ]
    ])

    assert 'ObjectPropertyAssertion(test:isAncestorOf test:Bob test:Alice)' in content
    assert 'ObjectPropertyRange(test:hasAncestor test:Person)' in content
    assert 'ObjectPropertyRange(test:hasFather test:Father)' in content
    assert 'ObjectPropertyRange(test:hasMother test:Mother)' in content
    assert 'ObjectPropertyRange(test:drives test:Vehicle)' in content
    assert 'NegativeObjectPropertyAssertion(test:isAncestorOf test:Bob test:Trudy)' in content
    assert ')' in content
    # AND
    assert 'SubClassOf(ObjectSomeValuesFrom(ObjectInverseOf(test:hasAncestor) owl:Thing) test:Person)' not in content
    assert 'SubClassOf(ObjectSomeValuesFrom(ObjectInverseOf(test:hasMother) owl:Thing) test:Mother)' not in content
    assert 'SubClassOf(ObjectSomeValuesFrom(ObjectInverseOf(test:hasFather) owl:Thing) test:Father)' not in content
    assert 'SubClassOf(DataSomeValuesFrom(test:name rdfs:Literal) test:Person)' not in content
    # AND
    assert any([
        line in content for line in [
            'SubClassOf(test:Person ObjectUnionOf(test:Underage test:Adult))',
            'SubClassOf(test:Person ObjectUnionOf(test:Adult test:Underage))'
        ]
    ])
    assert any([
        line in content for line in [
            'SubClassOf(test:Person ObjectUnionOf(test:Female test:Male))',
            'SubClassOf(ObjectUnionOf(test:Female test:Male) test:Person)'
        ]
    ])
    assert any([
        line in content for line in [
            'SubClassOf(test:Vehicle ObjectUnionOf(test:Less_than_50_cc test:Over_50_cc))',
            'SubClassOf(test:Vehicle ObjectUnionOf(test:Over_50_cc test:Less_than_50_cc))'
        ]
    ])
    assert any([
        line in content for line in [
            'DisjointClasses(test:Female test:Male)',
            'DisjointClasses(test:Male test:Female)'
        ]
    ])
    assert any([
        line in content for line in [
            'DisjointClasses(test:Person test:Vegetable)',
            'DisjointClasses(test:Vegetable test:Person)'
        ]
    ])
    assert any([
        line in content for line in [
            'DisjointClasses(test:Underage test:Adult)',
            'DisjointClasses(test:Adult test:Underage)'
        ]
    ])
    assert any([
        line in content for line in [
            'DisjointClasses(test:Less_than_50_cc test:Over_50_cc)',
            'DisjointClasses(test:Over_50_cc test:Less_than_50_cc)'
        ]
    ])

    assert 'AnnotationAssertion(rdfs:label test:drives "drives")' in content
    assert 'AnnotationAssertion(rdfs:label test:hasAncestor "hasAncestor")' in content
    assert 'AnnotationAssertion(rdfs:label test:hasFather "hasFather")' in content
    assert 'AnnotationAssertion(rdfs:label test:hasMother "hasMother")' in content
    assert 'AnnotationAssertion(rdfs:label test:hasParent "hasParent")' in content
    assert 'AnnotationAssertion(rdfs:label test:isAncestorOf "isAncestorOf")' in content
    assert 'AnnotationAssertion(rdfs:label test:name "name")' in content
    assert 'AnnotationAssertion(rdfs:label test:Adult "Adult")' in content
    assert 'AnnotationAssertion(rdfs:label test:Father "Father")' in content
    assert 'AnnotationAssertion(rdfs:label test:Female "Female")' in content
    assert 'AnnotationAssertion(rdfs:label test:Less_than_50_cc "Less_than_50_cc")' in content
    assert 'AnnotationAssertion(rdfs:label test:Male "Male")' in content
    assert 'AnnotationAssertion(rdfs:label test:Mother "Mother")' in content
    assert 'AnnotationAssertion(rdfs:label test:Over_50_cc "Over_50_cc")' in content
    assert 'AnnotationAssertion(rdfs:label test:Person "Person")' in content
    assert 'AnnotationAssertion(rdfs:label test:Underage "Underage")' in content
    assert 'AnnotationAssertion(rdfs:label test:Vegetable "Vegetable")' in content
    assert 'AnnotationAssertion(rdfs:label test:Vehicle "Vehicle")' in content
    assert 'AnnotationAssertion(rdfs:label test:Alice "Alice")' in content
    assert 'AnnotationAssertion(rdfs:label test:Bob "Bob")' in content
    assert 'AnnotationAssertion(rdfs:label test:Trudy "Trudy")' in content

    # AND
    assert len(content) == 89
Esempio n. 10
0
 def test_export_project_to_owl_without_normalization(self):
     # WHEN
     worker = OWLProjectExporterWorker(self.project, '@tests/.tests/test_project_1.owl',
         axioms={x for x in OWLAxiom},
         normalize=False,
         syntax=OWLSyntax.Functional)
     worker.run()
     # THEN
     self.assertFileExists('@tests/.tests/test_project_1.owl')
     # WHEN
     content = list(filter(None, fread('@tests/.tests/test_project_1.owl').split('\n')))
     # THEN
     self.assertIn('Prefix(:=<http://www.dis.uniroma1.it/~graphol/test_project#>)', content)
     self.assertIn('Prefix(owl:=<http://www.w3.org/2002/07/owl#>)', content)
     self.assertIn('Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)', content)
     self.assertIn('Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)', content)
     self.assertIn('Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)', content)
     self.assertIn('Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)', content)
     self.assertIn('Prefix(test:=<http://www.dis.uniroma1.it/~graphol/test_project#>)', content)
     self.assertIn('Ontology(<http://www.dis.uniroma1.it/~graphol/test_project>', content)
     self.assertIn('Declaration(Class(test:Vegetable))', content)
     self.assertIn('Declaration(Class(test:Person))', content)
     self.assertIn('Declaration(Class(test:Male))', content)
     self.assertIn('Declaration(Class(test:Female))', content)
     self.assertIn('Declaration(Class(test:Mother))', content)
     self.assertIn('Declaration(Class(test:Father))', content)
     self.assertIn('Declaration(Class(test:Underage))', content)
     self.assertIn('Declaration(Class(test:Adult))', content)
     self.assertIn('Declaration(Class(test:Vehicle))', content)
     self.assertIn('Declaration(Class(test:Less_than_50_cc))', content)
     self.assertIn('Declaration(Class(test:Over_50_cc))', content)
     self.assertIn('Declaration(NamedIndividual(test:Bob))', content)
     self.assertIn('Declaration(NamedIndividual(test:Alice))', content)
     self.assertIn('Declaration(NamedIndividual(test:Trudy))', content)
     self.assertIn('Declaration(ObjectProperty(test:hasAncestor))', content)
     self.assertIn('Declaration(ObjectProperty(test:hasParent))', content)
     self.assertIn('Declaration(ObjectProperty(test:hasFather))', content)
     self.assertIn('Declaration(ObjectProperty(test:hasMother))', content)
     self.assertIn('Declaration(ObjectProperty(test:isAncestorOf))', content)
     self.assertIn('Declaration(ObjectProperty(test:drives))', content)
     self.assertIn('Declaration(DataProperty(test:name))', content)
     self.assertIn('Declaration(Datatype(xsd:string))', content)
     self.assertIn('Declaration(AnnotationProperty(<rdfs:comment>))', content)
     self.assertIn('AnnotationAssertion(<rdfs:comment> test:Person "a human being"^^xsd:string)', content)
     self.assertIn('SubClassOf(test:Person ObjectSomeValuesFrom(test:hasAncestor owl:Thing))', content)
     self.assertIn('SubClassOf(test:Father test:Male)', content)
     self.assertIn('SubClassOf(test:Mother test:Female)', content)
     self.assertIn('SubClassOf(test:Underage ObjectAllValuesFrom(test:drives test:Less_than_50_cc))', content)
     self.assertIn('SubObjectPropertyOf(test:hasParent test:hasAncestor)', content)
     self.assertIn('SubObjectPropertyOf(test:hasFather test:hasParent)', content)
     self.assertIn('SubObjectPropertyOf(test:hasMother test:hasParent)', content)
     self.assertIn('FunctionalObjectProperty(test:hasFather)', content)
     self.assertIn('FunctionalObjectProperty(test:hasMother)', content)
     self.assertIn('DataPropertyRange(test:name xsd:string)', content)
     self.assertIn('DataPropertyDomain(test:name test:Person)', content)
     self.assertIn('InverseObjectProperties(test:hasAncestor test:isAncestorOf)', content)
     self.assertIn('ObjectPropertyAssertion(test:isAncestorOf test:Bob test:Alice)', content)
     self.assertIn('ObjectPropertyRange(test:hasAncestor test:Person)', content)
     self.assertIn('ObjectPropertyRange(test:hasFather test:Father)', content)
     self.assertIn('ObjectPropertyRange(test:hasMother test:Mother)', content)
     self.assertIn('ObjectPropertyRange(test:drives test:Vehicle)', content)
     self.assertIn('NegativeObjectPropertyAssertion(test:isAncestorOf test:Bob test:Trudy)', content)
     self.assertIn(')', content)
     # AND
     self.assertNotIn('SubClassOf(ObjectSomeValuesFrom(ObjectInverseOf(test:hasAncestor) owl:Thing) test:Person)', content)
     self.assertNotIn('SubClassOf(ObjectSomeValuesFrom(ObjectInverseOf(test:hasMother) owl:Thing) test:Mother)', content)
     self.assertNotIn('SubClassOf(ObjectSomeValuesFrom(ObjectInverseOf(test:hasFather) owl:Thing) test:Father)', content)
     # AND
     self.assertAnyIn(['EquivalentClasses(test:Person ObjectUnionOf(test:Underage test:Adult))',
                       'EquivalentClasses(test:Person ObjectUnionOf(test:Adult test:Underage))',
                       'EquivalentClasses(ObjectUnionOf(test:Underage test:Adult) test:Person)',
                       'EquivalentClasses(ObjectUnionOf(test:Adult test:Person) test:Person)'], content)
     self.assertAnyIn(['EquivalentClasses(test:Person DataSomeValuesFrom(test:name rdfs:Literal))',
                       'EquivalentClasses(DataSomeValuesFrom(test:name rdfs:Literal) test:Person)'], content)
     self.assertAnyIn(['EquivalentClasses(test:Person ObjectUnionOf(test:Female test:Male))',
                       'EquivalentClasses(test:Person ObjectUnionOf(test:Male test:Female))',
                       'EquivalentClasses(ObjectUnionOf(test:Female test:Male) test:Person)',
                       'EquivalentClasses(ObjectUnionOf(test:Male test:Female) test:Person)'], content)
     self.assertAnyIn(['EquivalentClasses(test:Vehicle ObjectUnionOf(test:Less_than_50_cc test:Over_50_cc))',
                       'EquivalentClasses(test:Vehicle ObjectUnionOf(test:Over_50_cc test:Less_than_50_cc))',
                       'EquivalentClasses(ObjectUnionOf(test:Less_than_50_cc test:Over_50_cc) test:Vehicle)',
                       'EquivalentClasses(ObjectUnionOf(test:Over_50_cc test:Less_than_50_cc) test:Vehicle)'], content)
     self.assertAnyIn(['EquivalentClasses(test:Person ObjectAllValuesFrom(test:drives owl:Thing))',
                       'EquivalentClasses(ObjectAllValuesFrom(test:drives owl:Thing) test:Person)',], content)
     self.assertAnyIn(['DisjointClasses(test:Female test:Male)',
                       'DisjointClasses(test:Male test:Female)'], content)
     self.assertAnyIn(['DisjointClasses(test:Person test:Vegetable)',
                       'DisjointClasses(test:Vegetable test:Person)'], content)
     self.assertAnyIn(['DisjointClasses(test:Underage test:Adult)',
                       'DisjointClasses(test:Adult test:Underage)'], content)
     self.assertAnyIn(['DisjointClasses(test:Less_than_50_cc test:Over_50_cc)',
                       'DisjointClasses(test:Over_50_cc test:Less_than_50_cc)'], content)
     # AND
     self.assertLen(60, content)
Esempio n. 11
0
    def configure(self, options):
        """
        Perform initial configuration tasks for Eddy to work properly.
        :type options: Namespace
        """
        #############################################
        # DRAW THE SPLASH SCREEN
        #################################

        splash = None
        if not options.nosplash:
            splash = Splash(mtime=4)
            splash.show()

        #############################################
        # CONFIGURE RECENT PROJECTS
        #################################

        settings = QtCore.QSettings(ORGANIZATION, APPNAME)
        examples = [
            expandPath('@examples/Animals'),
            expandPath('@examples/Diet'),
            expandPath('@examples/Family'),
            expandPath('@examples/LUBM'),
            expandPath('@examples/Pizza'),
        ]

        if not settings.contains('project/recent'):
            # From PyQt5 documentation: if the value of the setting is a container (corresponding
            # to either QVariantList, QVariantMap or QVariantHash) then the type is applied to the
            # contents of the container. So we can't use an empty list as default value because
            # PyQt5 needs to know the type of the contents added to the collection: we avoid
            # this problem by placing the list of example projects as recent project list.
            settings.setValue('project/recent', examples)
        else:
            # If we have some projects in our recent list, check whether they exists on the
            # filesystem. If they do not exists we remove them from our recent list.
            projects = []
            for path in map(expandPath, settings.value('project/recent')):
                if isdir(path) and path not in projects:
                    projects.append(path)
            settings.setValue('project/recent', projects or examples)
            settings.sync()

        #############################################
        # CONFIGURE FONTS
        #################################

        fontDB = QtGui.QFontDatabase()
        fontDB.addApplicationFont(':/fonts/Roboto-Black')
        fontDB.addApplicationFont(':/fonts/Roboto-BlackItalic')
        fontDB.addApplicationFont(':/fonts/Roboto-Bold')
        fontDB.addApplicationFont(':/fonts/Roboto-BoldItalic')
        fontDB.addApplicationFont(':/fonts/Roboto-Italic')
        fontDB.addApplicationFont(':/fonts/Roboto-Light')
        fontDB.addApplicationFont(':/fonts/Roboto-LightItalic')
        fontDB.addApplicationFont(':/fonts/Roboto-Medium')
        fontDB.addApplicationFont(':/fonts/Roboto-MediumItalic')
        fontDB.addApplicationFont(':/fonts/Roboto-Regular')
        fontDB.addApplicationFont(':/fonts/Roboto-Thin')
        fontDB.addApplicationFont(':/fonts/Roboto-ThinItalic')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-Bold')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-BoldItalic')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-Italic')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-Light')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-LightItalic')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-Regular')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Bold')
        fontDB.addApplicationFont(':/fonts/RobotoMono-BoldItalic')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Italic')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Light')
        fontDB.addApplicationFont(':/fonts/RobotoMono-LightItalic')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Medium')
        fontDB.addApplicationFont(':/fonts/RobotoMono-MediumItalic')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Regular')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Thin')
        fontDB.addApplicationFont(':/fonts/RobotoMono-ThinItalic')

        self.setFont(Font('Roboto', 12))

        #############################################
        # CONFIGURE LAYOUT
        #################################

        buffer = ''
        resources = expandPath('@resources/styles/')
        for name in os.listdir(resources):
            path = os.path.join(resources, name)
            if fexists(path) and File.forPath(path) is File.Qss:
                buffer += fread(path)
        self.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
        self.setStyle(EddyProxyStyle('Fusion'))
        self.setStyleSheet(buffer)

        #############################################
        # LOOKUP PLUGINS
        #################################

        PluginManager.scan('@plugins/', '@home/plugins/')

        #############################################
        # CLOSE THE SPLASH SCREEN
        #################################

        if splash and not options.nosplash:
            splash.sleep()
            splash.close()

        #############################################
        # CONFIGURE THE WORKSPACE
        #################################

        workspace = expandPath(settings.value('workspace/home', WORKSPACE,
                                              str))
        if not isdir(workspace):
            window = WorkspaceDialog()
            if window.exec_() == WorkspaceDialog.Rejected:
                raise SystemExit
Esempio n. 12
0
 def test_export_project_to_owl_without_normalization(self):
     # WHEN
     worker = OWLOntologyExporterWorker(self.project,
                                        '@tests/.tests/test_project_1.owl',
                                        axioms={x
                                                for x in OWLAxiom},
                                        normalize=False,
                                        syntax=OWLSyntax.Functional)
     worker.run()
     # THEN
     self.assertFileExists('@tests/.tests/test_project_1.owl')
     # WHEN
     content = list(
         filter(None,
                fread('@tests/.tests/test_project_1.owl').split('\n')))
     # THEN
     self.assertIn(
         'Prefix(:=<http://www.dis.uniroma1.it/~graphol/test_project#>)',
         content)
     self.assertIn('Prefix(owl:=<http://www.w3.org/2002/07/owl#>)', content)
     self.assertIn(
         'Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)',
         content)
     self.assertIn('Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)',
                   content)
     self.assertIn('Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)',
                   content)
     self.assertIn('Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)',
                   content)
     self.assertIn(
         'Prefix(test:=<http://www.dis.uniroma1.it/~graphol/test_project#>)',
         content)
     self.assertIn(
         'Ontology(<http://www.dis.uniroma1.it/~graphol/test_project>',
         content)
     self.assertIn('Declaration(Class(test:Vegetable))', content)
     self.assertIn('Declaration(Class(test:Person))', content)
     self.assertIn('Declaration(Class(test:Male))', content)
     self.assertIn('Declaration(Class(test:Female))', content)
     self.assertIn('Declaration(Class(test:Mother))', content)
     self.assertIn('Declaration(Class(test:Father))', content)
     self.assertIn('Declaration(Class(test:Underage))', content)
     self.assertIn('Declaration(Class(test:Adult))', content)
     self.assertIn('Declaration(Class(test:Vehicle))', content)
     self.assertIn('Declaration(Class(test:Less_than_50_cc))', content)
     self.assertIn('Declaration(Class(test:Over_50_cc))', content)
     self.assertIn('Declaration(NamedIndividual(test:Bob))', content)
     self.assertIn('Declaration(NamedIndividual(test:Alice))', content)
     self.assertIn('Declaration(NamedIndividual(test:Trudy))', content)
     self.assertIn('Declaration(ObjectProperty(test:hasAncestor))', content)
     self.assertIn('Declaration(ObjectProperty(test:hasParent))', content)
     self.assertIn('Declaration(ObjectProperty(test:hasFather))', content)
     self.assertIn('Declaration(ObjectProperty(test:hasMother))', content)
     self.assertIn('Declaration(ObjectProperty(test:isAncestorOf))',
                   content)
     self.assertIn('Declaration(ObjectProperty(test:drives))', content)
     self.assertIn('Declaration(DataProperty(test:name))', content)
     self.assertIn('Declaration(Datatype(xsd:string))', content)
     self.assertIn('Declaration(AnnotationProperty(<rdfs:comment>))',
                   content)
     self.assertIn(
         'AnnotationAssertion(<rdfs:comment> test:Person "A human being"^^xsd:string)',
         content)
     self.assertIn(
         'SubClassOf(test:Person ObjectSomeValuesFrom(test:hasAncestor owl:Thing))',
         content)
     self.assertIn('SubClassOf(test:Father test:Male)', content)
     self.assertIn('SubClassOf(test:Mother test:Female)', content)
     self.assertIn(
         'SubClassOf(test:Underage ObjectAllValuesFrom(test:drives test:Less_than_50_cc))',
         content)
     self.assertIn('SubObjectPropertyOf(test:hasParent test:hasAncestor)',
                   content)
     self.assertIn('SubObjectPropertyOf(test:hasFather test:hasParent)',
                   content)
     self.assertIn('SubObjectPropertyOf(test:hasMother test:hasParent)',
                   content)
     self.assertIn('FunctionalObjectProperty(test:hasFather)', content)
     self.assertIn('FunctionalObjectProperty(test:hasMother)', content)
     self.assertIn('DataPropertyRange(test:name xsd:string)', content)
     self.assertIn('DataPropertyDomain(test:name test:Person)', content)
     self.assertIn(
         'InverseObjectProperties(test:hasAncestor test:isAncestorOf)',
         content)
     self.assertIn(
         'ObjectPropertyAssertion(test:isAncestorOf test:Bob test:Alice)',
         content)
     self.assertIn('ObjectPropertyRange(test:hasAncestor test:Person)',
                   content)
     self.assertIn('ObjectPropertyRange(test:hasFather test:Father)',
                   content)
     self.assertIn('ObjectPropertyRange(test:hasMother test:Mother)',
                   content)
     self.assertIn('ObjectPropertyRange(test:drives test:Vehicle)', content)
     self.assertIn(
         'NegativeObjectPropertyAssertion(test:isAncestorOf test:Bob test:Trudy)',
         content)
     self.assertIn(')', content)
     # AND
     self.assertNotIn(
         'SubClassOf(ObjectSomeValuesFrom(ObjectInverseOf(test:hasAncestor) owl:Thing) test:Person)',
         content)
     self.assertNotIn(
         'SubClassOf(ObjectSomeValuesFrom(ObjectInverseOf(test:hasMother) owl:Thing) test:Mother)',
         content)
     self.assertNotIn(
         'SubClassOf(ObjectSomeValuesFrom(ObjectInverseOf(test:hasFather) owl:Thing) test:Father)',
         content)
     # AND
     self.assertAnyIn([
         'EquivalentClasses(test:Person ObjectUnionOf(test:Underage test:Adult))',
         'EquivalentClasses(test:Person ObjectUnionOf(test:Adult test:Underage))',
         'EquivalentClasses(ObjectUnionOf(test:Underage test:Adult) test:Person)',
         'EquivalentClasses(ObjectUnionOf(test:Adult test:Person) test:Person)'
     ], content)
     self.assertAnyIn([
         'EquivalentClasses(test:Person DataSomeValuesFrom(test:name rdfs:Literal))',
         'EquivalentClasses(DataSomeValuesFrom(test:name rdfs:Literal) test:Person)'
     ], content)
     self.assertAnyIn([
         'EquivalentClasses(test:Person ObjectUnionOf(test:Female test:Male))',
         'EquivalentClasses(test:Person ObjectUnionOf(test:Male test:Female))',
         'EquivalentClasses(ObjectUnionOf(test:Female test:Male) test:Person)',
         'EquivalentClasses(ObjectUnionOf(test:Male test:Female) test:Person)'
     ], content)
     self.assertAnyIn([
         'EquivalentClasses(test:Vehicle ObjectUnionOf(test:Less_than_50_cc test:Over_50_cc))',
         'EquivalentClasses(test:Vehicle ObjectUnionOf(test:Over_50_cc test:Less_than_50_cc))',
         'EquivalentClasses(ObjectUnionOf(test:Less_than_50_cc test:Over_50_cc) test:Vehicle)',
         'EquivalentClasses(ObjectUnionOf(test:Over_50_cc test:Less_than_50_cc) test:Vehicle)'
     ], content)
     self.assertAnyIn([
         'EquivalentClasses(test:Person ObjectAllValuesFrom(test:drives owl:Thing))',
         'EquivalentClasses(ObjectAllValuesFrom(test:drives owl:Thing) test:Person)',
     ], content)
     self.assertAnyIn([
         'DisjointClasses(test:Female test:Male)',
         'DisjointClasses(test:Male test:Female)'
     ], content)
     self.assertAnyIn([
         'DisjointClasses(test:Person test:Vegetable)',
         'DisjointClasses(test:Vegetable test:Person)'
     ], content)
     self.assertAnyIn([
         'DisjointClasses(test:Underage test:Adult)',
         'DisjointClasses(test:Adult test:Underage)'
     ], content)
     self.assertAnyIn([
         'DisjointClasses(test:Less_than_50_cc test:Over_50_cc)',
         'DisjointClasses(test:Over_50_cc test:Less_than_50_cc)'
     ], content)
     # AND
     self.assertLen(61, content)
Esempio n. 13
0
def spec():
    """
    Yields an instance of the PluginSpec.
    """
    basepath = os.path.join(os.path.dirname(__file__), os.pardir)
    yield PluginManager.spec(fread(os.path.join(basepath, 'plugin.spec')))
Esempio n. 14
0
    def configure(self, options):
        """
        Perform initial configuration tasks for Eddy to work properly.
        :type options: Namespace
        """
        #############################################
        # DRAW THE SPLASH SCREEN
        #################################

        splash = None
        if not options.nosplash:
            splash = Splash(mtime=4)
            splash.show()

        #############################################
        # CONFIGURE RECENT PROJECTS
        #################################

        settings = QtCore.QSettings(ORGANIZATION, APPNAME)
        examples = [
            expandPath('@examples/Animals'),
            expandPath('@examples/Diet'),
            expandPath('@examples/Family'),
            expandPath('@examples/LUBM'),
            expandPath('@examples/Pizza'),
        ]

        if not settings.contains('project/recent'):
            # From PyQt5 documentation: if the value of the setting is a container (corresponding
            # to either QVariantList, QVariantMap or QVariantHash) then the type is applied to the
            # contents of the container. So we can't use an empty list as default value because
            # PyQt5 needs to know the type of the contents added to the collection: we avoid
            # this problem by placing the list of example projects as recent project list.
            settings.setValue('project/recent', examples)
        else:
            # If we have some projects in our recent list, check whether they exists on the
            # filesystem. If they do not exists we remove them from our recent list.
            projects = []
            for path in map(expandPath, settings.value('project/recent')):
                if isdir(path) and path not in projects:
                    projects.append(path)
            settings.setValue('project/recent', projects or examples)
            settings.sync()

        #############################################
        # CONFIGURE FONTS
        #################################

        fontDB = QtGui.QFontDatabase()
        fontDB.addApplicationFont(':/fonts/Roboto-Black')
        fontDB.addApplicationFont(':/fonts/Roboto-BlackItalic')
        fontDB.addApplicationFont(':/fonts/Roboto-Bold')
        fontDB.addApplicationFont(':/fonts/Roboto-BoldItalic')
        fontDB.addApplicationFont(':/fonts/Roboto-Italic')
        fontDB.addApplicationFont(':/fonts/Roboto-Light')
        fontDB.addApplicationFont(':/fonts/Roboto-LightItalic')
        fontDB.addApplicationFont(':/fonts/Roboto-Medium')
        fontDB.addApplicationFont(':/fonts/Roboto-MediumItalic')
        fontDB.addApplicationFont(':/fonts/Roboto-Regular')
        fontDB.addApplicationFont(':/fonts/Roboto-Thin')
        fontDB.addApplicationFont(':/fonts/Roboto-ThinItalic')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-Bold')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-BoldItalic')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-Italic')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-Light')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-LightItalic')
        fontDB.addApplicationFont(':/fonts/RobotoCondensed-Regular')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Bold')
        fontDB.addApplicationFont(':/fonts/RobotoMono-BoldItalic')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Italic')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Light')
        fontDB.addApplicationFont(':/fonts/RobotoMono-LightItalic')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Medium')
        fontDB.addApplicationFont(':/fonts/RobotoMono-MediumItalic')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Regular')
        fontDB.addApplicationFont(':/fonts/RobotoMono-Thin')
        fontDB.addApplicationFont(':/fonts/RobotoMono-ThinItalic')

        self.setFont(Font('Roboto', 12))

        #############################################
        # CONFIGURE LAYOUT
        #################################

        buffer = ''
        resources = expandPath('@resources/styles/')
        for name in os.listdir(resources):
            path = os.path.join(resources, name)
            if fexists(path) and File.forPath(path) is File.Qss:
                buffer += fread(path)
        self.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
        self.setStyle(EddyProxyStyle('Fusion'))
        self.setStyleSheet(buffer)

        #############################################
        # CLOSE THE SPLASH SCREEN
        #################################

        if splash and not options.nosplash:
            splash.sleep()
            splash.close()

        #############################################
        # CONFIGURE THE WORKSPACE
        #################################

        workspace = expandPath(settings.value('workspace/home', WORKSPACE, str))
        if not isdir(workspace):
            window = WorkspaceDialog()
            if window.exec_() == WorkspaceDialog.Rejected:
                raise SystemExit