Search in sources :

Example 1 with ObjectProperty

use of org.apache.jena.ontology.ObjectProperty 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));
}
Also used : ObjectProperty(org.apache.jena.ontology.ObjectProperty) StringWriter(java.io.StringWriter) Individual(org.apache.jena.ontology.Individual) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) OntModel(org.apache.jena.ontology.OntModel) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Aggregations

StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Individual (org.apache.jena.ontology.Individual)1 ObjectProperty (org.apache.jena.ontology.ObjectProperty)1 OntModel (org.apache.jena.ontology.OntModel)1 Model (org.apache.jena.rdf.model.Model)1 Test (org.junit.Test)1