use of org.apache.jena.ontology.OntModel in project jena by apache.
the class JenaOSGITest method testJenaCore.
@Test
public void testJenaCore() throws Exception {
Model model = makeModel();
Writer writer = new StringWriter();
model.write(writer, "N-Triples");
assertEquals("<http://example.com/alice> <http://xmlns.com/foaf/0.1/knows> <http://example.com/bob> .", writer.toString().trim());
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
ObjectProperty knowsObjProp = ontModel.createObjectProperty(knows.getURI());
ObjectProperty hasFriend = ontModel.createObjectProperty("http://example.com/has_friend");
hasFriend.addSuperProperty(knowsObjProp);
Individual aliceIndividual = ontModel.createIndividual(alice);
Individual bobIndividiual = ontModel.createIndividual(bob);
ontModel.add(aliceIndividual, hasFriend, bobIndividiual);
assertTrue(aliceIndividual.hasProperty(knowsObjProp, bobIndividiual));
}
use of org.apache.jena.ontology.OntModel in project ORCID-Source by ORCID.
the class RDFMessageBodyWriter method getOntModel.
protected OntModel getOntModel() {
OntModel ontModel = ModelFactory.createOntologyModel();
ontModel.setNsPrefix("foaf", FOAF.NS);
ontModel.setNsPrefix("prov", PROV.NS);
ontModel.setNsPrefix("pav", PAV.NS);
ontModel.setNsPrefix("gn", Geonames.NS);
// ontModel.getDocumentManager().loadImports(foaf.getOntModel());
return ontModel;
}
use of org.apache.jena.ontology.OntModel in project ORCID-Source by ORCID.
the class RDFMessageBodyWriter method getCountries.
protected OntModel getCountries() {
if (countries != null) {
// Check for a static cache
return countries;
}
// Load list of countries
InputStream countriesStream = getClass().getResourceAsStream(COUNTRIES_TTL);
if (countriesStream == null) {
throw new IllegalStateException("Can't find country resource on classpath: " + COUNTRIES_TTL);
}
OntModel ontModel = ModelFactory.createOntologyModel();
ontModel.read(countriesStream, "http://example.com/", "TURTLE");
// Note: We should not need to synchronize(this) to cache,
// as the odd concurrent duplicate load is not harmful
// and can be thrown away
countries = ontModel;
return countries;
}
use of org.apache.jena.ontology.OntModel in project jena by apache.
the class TDB method sync.
/** Sync a TDB-backed Model. Do nothing if not TDB-backed. */
public static void sync(Model model) {
if (model instanceof OntModelImpl) {
OntModelImpl ontModel = (OntModelImpl) model;
sync(ontModel.getBaseGraph());
return;
}
// This never happens (there is only one OntModel implementation)
if (model instanceof OntModel) {
OntModel ontModel = (OntModel) model;
sync(ontModel.getBaseModel());
return;
}
sync(model.getGraph());
}
use of org.apache.jena.ontology.OntModel in project jena by apache.
the class TestOWLMisc method doTestSameAsDifferentFrom.
/**
* Test sameAs/differentFrom interaction
*/
public void doTestSameAsDifferentFrom(OntModelSpec os) {
String test = "[ a owl:AllDifferent ; owl:distinctMembers ( :limited1 :limited2 :limited3 ) ] .\n" + ":limited4 owl:sameAs :limited1 .";
OntModel inf = ModelFactory.createOntologyModel(os, modelFromN3(test));
Resource l4 = inf.getResource(NS + "limited4");
Resource l2 = inf.getResource(NS + "limited2");
Resource l3 = inf.getResource(NS + "limited3");
assertTrue(inf.contains(l4, OWL.differentFrom, l2));
assertTrue(inf.contains(l4, OWL.differentFrom, l3));
}
Aggregations