Java Code Examples for org.apache.jena.ontology.OntModel#setNsPrefix()
The following examples show how to use
org.apache.jena.ontology.OntModel#setNsPrefix() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ROEvoSerializer.java From incubator-taverna-language with Apache License 2.0 | 6 votes |
public void workflowHistory(Workflow mainWorkflow, OutputStream output) throws WriterException { OntModel model = ModelFactory.createOntologyModel(); Revision revision = mainWorkflow.getCurrentRevision(); Revision previous = revision.getPreviousRevision(); addRevision(model, revision); while (previous != null) { addRevision(model, previous); addPrevious(model, revision, previous); revision = previous; previous = revision.getPreviousRevision(); } java.net.URI baseURI = Workflow.WORKFLOW_ROOT; model.setNsPrefix("roevo", "http://purl.org/wf4ever/roevo#"); model.setNsPrefix("prov", "http://www.w3.org/ns/prov#"); model.setNsPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); model.write(output, "Turtle", baseURI.toASCIIString()); // throw new WriterException("Can't write to output", e); }
Example 2
Source File: RDFToManifest.java From incubator-taverna-language with Apache License 2.0 | 5 votes |
protected OntModel getOntModel() { OntModel ontModel = createOntologyModel(OWL_DL_MEM_RULE_INF); ontModel.setNsPrefix("foaf", foaf.NS); ontModel.setNsPrefix("prov", prov.NS); ontModel.setNsPrefix("ore", ore.NS); ontModel.setNsPrefix("pav", pav.NS); ontModel.setNsPrefix("dct", DCTerms.NS); // ontModel.getDocumentManager().loadImports(foaf.getOntModel()); return ontModel; }
Example 3
Source File: WfdescSerialiser.java From incubator-taverna-language with Apache License 2.0 | 5 votes |
public void save(WorkflowBundle wfBundle, OutputStream output) throws WriterException { OntModel model; final URI baseURI; if (wfBundle.getMainWorkflow() != null) { Workflow mainWorkflow = wfBundle.getMainWorkflow(); baseURI = uriTools.uriForBean(mainWorkflow); model = save(wfBundle); } else { throw new WriterException("wfdesc format requires a main workflow"); } model.setNsPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#"); model.setNsPrefix("owl", "http://www.w3.org/2002/07/owl#"); model.setNsPrefix("prov", "http://www.w3.org/ns/prov#"); model.setNsPrefix("wfdesc", "http://purl.org/wf4ever/wfdesc#"); model.setNsPrefix("wf4ever", "http://purl.org/wf4ever/wf4ever#"); model.setNsPrefix("roterms", "http://purl.org/wf4ever/roterms#"); model.setNsPrefix("dc", "http://purl.org/dc/elements/1.1/"); model.setNsPrefix("dcterms", "http://purl.org/dc/terms/"); model.setNsPrefix("comp", "http://purl.org/DP/components#"); model.setNsPrefix("dep", "http://scape.keep.pt/vocab/dependencies#"); model.setNsPrefix("biocat", "http://biocatalogue.org/attribute/"); model.setNsPrefix("", "#"); try { model.write(output, Lang.TURTLE.getName(), baseURI.toString()); } catch (RiotException e) { throw new WriterException("Can't write to output", e); } }
Example 4
Source File: AbstractRdfDocumentGraphConsumer.java From baleen with Apache License 2.0 | 5 votes |
@Override protected void processGraph(String documentSourceName, Graph graph) throws AnalysisEngineProcessException { OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, documentOntology); model.setNsPrefix("baleen", namespace); GraphTraversalSource traversal = graph.traversal(); traversal.V().forEachRemaining(v -> addNodeToModel(model, v)); traversal.E().forEachRemaining(e -> addRelationToModel(model, e)); outputModel(documentSourceName, model); }
Example 5
Source File: AbstractRdfEntityGraphConsumer.java From baleen with Apache License 2.0 | 5 votes |
@Override protected void processGraph(String documentSourceName, Graph graph) throws AnalysisEngineProcessException { OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, documentOntology); model.setNsPrefix("baleen", namespace); GraphTraversalSource traversal = graph.traversal(); traversal.V().forEachRemaining(v -> addNodeToModel(model, v)); traversal.E().forEachRemaining(e -> addRelationToModel(model, e)); outputModel(documentSourceName, model); }
Example 6
Source File: OwlSchemaFactoryTest.java From baleen with Apache License 2.0 | 4 votes |
@Test public void canGenerateDocumentSchema() throws CASRuntimeException, UIMAException { String ns = "http://baleen.dstl.gov.uk/document/"; OwlSchemaFactory owlTypeSystem = new OwlSchemaFactory(ns, typeSystem, ImmutableList.of("internalId")); OntModel model = owlTypeSystem.createDocumentOntology(); model.setNsPrefix("baleen", ns); try { assertNotNull(model); assertNotNull(model.getOntClass(ns + Document.class.getSimpleName())); assertNotNull(model.getOntClass(ns + ReferenceTarget.class.getSimpleName())); assertNotNull(model.getOntClass(ns + Relation.class.getSimpleName())); OntClass entity = model.getOntClass(ns + Entity.class.getSimpleName()); assertNotNull(entity); assertEquals( "Type to represent named entities - values that are assigned a semantic type.", entity.getComment("EN")); assertNotNull(entity.getSuperClass()); assertEquals(getEntityChildrenCount(), Streams.stream(entity.listSubClasses()).count()); OntClass location = model.getOntClass(ns + Location.class.getSimpleName()); assertEquals(entity, location.getSuperClass()); assertEquals(1, Streams.stream(location.listSubClasses()).count()); OntClass person = model.getOntClass(ns + Person.class.getSimpleName()); assertEquals(entity, person.getSuperClass()); assertEquals(0, Streams.stream(person.listSubClasses()).count()); assertEquals(2, Streams.stream(person.listDeclaredProperties(true)).count()); assertEquals(13, Streams.stream(person.listDeclaredProperties()).count()); Optional<OntProperty> findFirst = Streams.stream(person.listDeclaredProperties(true)) .filter(p -> "gender".equals(p.getLocalName())) .findFirst(); assertTrue(findFirst.isPresent()); assertEquals(XSD.xstring, findFirst.get().getRange()); Optional<OntProperty> mentionOf = Streams.stream(person.listDeclaredProperties()) .filter(p -> DocumentGraphFactory.MENTION_OF.equals(p.getLocalName())) .findFirst(); assertTrue(mentionOf.isPresent()); assertEquals( ReferenceTarget.class.getSimpleName(), mentionOf.get().getRange().getLocalName()); } finally { writeToConsole(model); } }
Example 7
Source File: OwlSchemaFactoryTest.java From baleen with Apache License 2.0 | 4 votes |
@Test public void canGenerateEntitySchema() throws ResourceInitializationException { String ns = "http://baleen.dstl.gov.uk/entity/"; OwlSchemaFactory owlTypeSystem = new OwlSchemaFactory(ns, typeSystem, ImmutableList.of("isNormalised", "internalId")); OntModel model = owlTypeSystem.createEntityOntology(); model.setNsPrefix("baleen", ns); try { assertNotNull(model); assertNull(model.getOntClass(ns + Document.class.getSimpleName())); assertNull(model.getOntClass(ns + ReferenceTarget.class.getSimpleName())); assertNull(model.getOntClass(ns + Relation.class.getSimpleName())); OntClass entity = model.getOntClass(ns + Entity.class.getSimpleName()); assertNotNull(entity); assertEquals( "Type to represent named entities - values that are assigned a semantic type.", entity.getComment("EN")); assertNull(entity.getSuperClass()); assertEquals(17, Streams.stream(entity.listSubClasses()).count()); OntClass location = model.getOntClass(ns + Location.class.getSimpleName()); assertEquals(entity, location.getSuperClass()); assertEquals(1, Streams.stream(location.listSubClasses()).count()); OntClass person = model.getOntClass(ns + Person.class.getSimpleName()); assertEquals(entity, person.getSuperClass()); assertEquals(0, Streams.stream(person.listSubClasses()).count()); assertEquals(2, Streams.stream(person.listDeclaredProperties(true)).count()); assertEquals(12, Streams.stream(person.listDeclaredProperties()).count()); Optional<OntProperty> findFirst = Streams.stream(person.listDeclaredProperties(true)) .filter(p -> "gender".equals(p.getLocalName())) .findFirst(); Optional<OntProperty> mentions = Streams.stream(person.listDeclaredProperties()) .filter(p -> "mentions".equals(p.getLocalName())) .findFirst(); assertTrue(mentions.isPresent()); assertEquals(XSD.xstring, findFirst.get().getRange()); Optional<OntProperty> relation = Streams.stream(person.listDeclaredProperties()) .filter(p -> DocumentGraphFactory.RELATION.equals(p.getLocalName())) .findFirst(); assertTrue(relation.isPresent()); assertEquals(Entity.class.getSimpleName(), relation.get().getRange().getLocalName()); assertEquals(Entity.class.getSimpleName(), relation.get().getDomain().getLocalName()); } finally { writeToConsole(model); } }