Search in sources :

Example 11 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.

the class TestOWLAPIInputSources method testOfflineSingleton.

/**
     * Loads a modified FOAF by resolving a URI from a resource directory.
     * 
     * @throws Exception
     */
@Test
public void testOfflineSingleton() throws Exception {
    URL url = getClass().getResource("/ontologies/mockfoaf.rdf");
    assertNotNull(url);
    OntologyInputSource<OWLOntology> coreSource = new RootOntologySource(IRI.create(url));
    assertNotNull(df);
    /*
         * To check it fetched the correct ontology, we look for a declaration of the bogus class foaf:Perzon
         * (added in the local FOAF)
         */
    OWLClass cPerzon = df.getOWLClass(IRI.create("http://xmlns.com/foaf/0.1/Perzon"));
    assertTrue(coreSource.getRootOntology().getClassesInSignature().contains(cPerzon));
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLClass(org.semanticweb.owlapi.model.OWLClass) URL(java.net.URL) Test(org.junit.Test)

Example 12 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.

the class RecipeListWriter method writeTo.

@Override
public void writeTo(RecipeList recipeList, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType mediaType, MultivaluedMap<String, Object> arg5, OutputStream out) throws IOException, WebApplicationException {
    Logger log = LoggerFactory.getLogger(getClass());
    log.debug("Rendering the list of recipes.");
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    OWLOntology ontology;
    try {
        ontology = manager.createOntology();
        String recipeClassURI = Symbols.Recipe.toString().replace("<", "").replace(">", "");
        IRI recipeClassIRI = IRI.create(recipeClassURI);
        OWLClass owlRecipeClass = factory.getOWLClass(recipeClassIRI);
        String descriptionURI = Symbols.description.toString().replace("<", "").replace(">", "");
        IRI descriptionIRI = IRI.create(descriptionURI);
        OWLDataProperty descriptionProperty = factory.getOWLDataProperty(descriptionIRI);
        if (recipeList != null) {
            log.info("Converting the recipe list to OWL.");
            for (Recipe recipe : recipeList) {
                String recipeURI = recipe.getRecipeID().toString().replace("<", "").replace(">", "");
                IRI recipeIRI = IRI.create(recipeURI);
                OWLIndividual recipeIndividual = factory.getOWLNamedIndividual(recipeIRI);
                OWLAxiom axiom = factory.getOWLClassAssertionAxiom(owlRecipeClass, recipeIndividual);
                manager.addAxiom(ontology, axiom);
                String description = recipe.getRecipeDescription();
                if (description != null) {
                    axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, recipeIndividual, description);
                    manager.addAxiom(ontology, axiom);
                }
            }
        }
        if (mediaType.toString().equals(KRFormat.RDF_XML)) {
            try {
                manager.saveOntology(ontology, new RDFXMLOntologyFormat(), out);
            } catch (OWLOntologyStorageException e) {
                log.error("Failed to store ontology for rendering.", e);
            }
        } else if (mediaType.toString().equals(KRFormat.OWL_XML)) {
            try {
                manager.saveOntology(ontology, new OWLXMLOntologyFormat(), out);
            } catch (OWLOntologyStorageException e) {
                log.error("Failed to store ontology for rendering.", e);
            }
        } else if (mediaType.toString().equals(KRFormat.MANCHESTER_OWL)) {
            try {
                manager.saveOntology(ontology, new ManchesterOWLSyntaxOntologyFormat(), out);
            } catch (OWLOntologyStorageException e) {
                log.error("Failed to store ontology for rendering.", e);
            }
        } else if (mediaType.toString().equals(KRFormat.FUNCTIONAL_OWL)) {
            try {
                manager.saveOntology(ontology, new OWLFunctionalSyntaxOntologyFormat(), out);
            } catch (OWLOntologyStorageException e) {
                log.error("Failed to store ontology for rendering.", e);
            }
        } else if (mediaType.toString().equals(KRFormat.TURTLE)) {
            try {
                manager.saveOntology(ontology, new TurtleOntologyFormat(), out);
            } catch (OWLOntologyStorageException e) {
                log.error("Failed to store ontology for rendering.", e);
            }
        } else if (mediaType.toString().equals(KRFormat.RDF_JSON)) {
            Graph mGraph = OWLAPIToClerezzaConverter.owlOntologyToClerezzaGraph(ontology);
            RdfJsonSerializingProvider provider = new RdfJsonSerializingProvider();
            provider.serialize(out, mGraph, SupportedFormat.RDF_JSON);
        }
    } catch (OWLOntologyCreationException e1) {
        log.error("An error occurred.", e1);
    }
    out.flush();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ManchesterOWLSyntaxOntologyFormat(org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat) TurtleOntologyFormat(org.coode.owlapi.turtle.TurtleOntologyFormat) Recipe(org.apache.stanbol.rules.base.api.Recipe) OWLFunctionalSyntaxOntologyFormat(org.semanticweb.owlapi.io.OWLFunctionalSyntaxOntologyFormat) RDFXMLOntologyFormat(org.semanticweb.owlapi.io.RDFXMLOntologyFormat) Logger(org.slf4j.Logger) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) Graph(org.apache.clerezza.commons.rdf.Graph) RdfJsonSerializingProvider(org.apache.clerezza.rdf.rdfjson.serializer.RdfJsonSerializingProvider) OWLXMLOntologyFormat(org.semanticweb.owlapi.io.OWLXMLOntologyFormat) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 13 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.

the class TestClerezzaSpaces method setup.

@BeforeClass
public static void setup() throws Exception {
    offline = new OfflineConfigurationImpl(new Hashtable<String, Object>());
    ScopeRegistry reg = new ScopeRegistryImpl();
    // This one is created from scratch
    Graph ont2 = ClerezzaOWLUtils.createOntology(baseIri2.toString());
    minorSrc = new GraphSource(ont2.getImmutableGraph());
    dropSrc = getLocalSource("/ontologies/droppedcharacters.owl");
    nonexSrc = getLocalSource("/ontologies/nonexistentcharacters.owl");
    inMemorySrc = new ParentPathInputSource(new File(TestClerezzaSpaces.class.getResource("/ontologies/maincharacters.owl").toURI()));
    OWLDataFactory df = OWLManager.getOWLDataFactory();
    OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing));
    OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus));
    linusIsHuman = df.getOWLClassAssertionAxiom(cHuman, iLinus);
    factory = new ClerezzaCollectorFactory(new ClerezzaOntologyProvider(tcManager, offline, parser), new Hashtable<String, Object>());
    factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
}
Also used : Hashtable(java.util.Hashtable) OfflineConfigurationImpl(org.apache.stanbol.ontologymanager.core.OfflineConfigurationImpl) ClerezzaOntologyProvider(org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider) Graph(org.apache.clerezza.commons.rdf.Graph) ScopeRegistryImpl(org.apache.stanbol.ontologymanager.core.scope.ScopeRegistryImpl) GraphSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphSource) ParentPathInputSource(org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) File(java.io.File) ScopeRegistry(org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeRegistry) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) ClerezzaCollectorFactory(org.apache.stanbol.ontologymanager.multiplexer.clerezza.collector.ClerezzaCollectorFactory) BeforeClass(org.junit.BeforeClass)

Example 14 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.

the class ConversionTester method testModelJenaToOwlConvert.

public void testModelJenaToOwlConvert() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OntModel model = ModelFactory.createOntologyModel();
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = mgr.getOWLDataFactory();
    String dul = "http://www.loa-cnr.it/ontologies/DUL.owl";
    OWLOntology owl = null;
    try {
        model.read(dul, RDFXML);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Could not load ontology");
    }
    try {
        owl = j2o.ModelJenaToOwlConvert(model, RDFXML);
        if (owl == null) {
            fail("Some errors occur");
        } else {
            ExtendedIterator<OntClass> jenaclass = model.listNamedClasses();
            int jenaclassset = jenaclass.toSet().size();
            jenaclass = model.listNamedClasses();
            Set<OWLClass> owlclass = owl.getClassesInSignature();
            int countclass = 0;
            while (jenaclass.hasNext()) if (owlclass.contains(factory.getOWLClass(IRI.create(jenaclass.next().getURI()))))
                countclass++;
            if (countclass == jenaclassset)
                assertEquals(countclass, jenaclassset);
            else
                fail("Error in number of classes");
            ExtendedIterator<ObjectProperty> jenaprop = model.listObjectProperties();
            int jenapropset = jenaprop.toSet().size();
            jenaprop = model.listObjectProperties();
            Set<OWLObjectProperty> owlprop = owl.getObjectPropertiesInSignature();
            int countprop = 0;
            while (jenaprop.hasNext()) if (owlprop.contains(factory.getOWLObjectProperty(IRI.create(jenaprop.next().getURI()))))
                countprop++;
            if (countprop == jenapropset)
                assertEquals(countprop, jenapropset);
            else
                fail("Error in number of object properties");
            ExtendedIterator<DatatypeProperty> jenadata = model.listDatatypeProperties();
            int jenadataset = jenadata.toSet().size();
            jenadata = model.listDatatypeProperties();
            Set<OWLDataProperty> owldata = owl.getDataPropertiesInSignature();
            int countdata = 0;
            while (jenadata.hasNext()) if (owldata.contains(factory.getOWLDataProperty(IRI.create(jenadata.next().getURI()))))
                countdata++;
            if (countdata == jenadataset)
                assertEquals(countdata, jenadataset);
            else
                fail("Error in number of data properties");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caugth");
    } finally {
        assertNotNull(owl);
    }
}
Also used : OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) ObjectProperty(com.hp.hpl.jena.ontology.ObjectProperty) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OntClass(com.hp.hpl.jena.ontology.OntClass) DatatypeProperty(com.hp.hpl.jena.ontology.DatatypeProperty)

Example 15 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.

the class ConversionTester method testClassJenaToOwl.

public void testClassJenaToOwl() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OntModel model = ModelFactory.createOntologyModel();
    OntClass jc = model.createClass(CLAZZ.toString());
    OWLClass wc = null;
    try {
        wc = j2o.ClassJenaToOwl(jc, RDFXML);
        if (wc == null)
            fail("Some problems accours");
        else {
            assertEquals(wc.getIRI().toURI().toString(), jc.getURI());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caugth");
    } finally {
        assertNotNull(wc);
    }
}
Also used : OntModel(com.hp.hpl.jena.ontology.OntModel) OWLClass(org.semanticweb.owlapi.model.OWLClass) OntClass(com.hp.hpl.jena.ontology.OntClass) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException)

Aggregations

OWLClass (org.semanticweb.owlapi.model.OWLClass)30 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)14 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)13 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)13 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)13 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)11 IRI (org.semanticweb.owlapi.model.IRI)10 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)10 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)9 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)8 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)6 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)6 AddAxiom (org.semanticweb.owlapi.model.AddAxiom)5 OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)5 OWLDataPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom)5 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)5 OWLObjectPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom)5 OntClass (com.hp.hpl.jena.ontology.OntClass)4 OntModel (com.hp.hpl.jena.ontology.OntModel)4 OWLAnnotation (org.semanticweb.owlapi.model.OWLAnnotation)4