Search in sources :

Example 1 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestLangTurtle method optionalDotInBase.

@Test
public void optionalDotInBase() {
    Model model = ModelFactory.createDefaultModel();
    StringReader reader = new StringReader("@base <http://example/> <x> <p> <o> .");
    RDFDataMgr.read(model, reader, null, RDFLanguages.TURTLE);
    assertEquals(1, model.size());
    Resource r = model.createResource("http://example/x");
    Property p = model.createProperty("http://example/p");
    assertTrue(model.contains(r, p));
}
Also used : Model(org.apache.jena.rdf.model.Model) StringReader(java.io.StringReader) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 2 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestUpdateOperations method insert_where_01.

@Test
public void insert_where_01() {
    Model m = ModelFactory.createDefaultModel();
    Resource anon = m.createResource();
    anon.addProperty(RDF.type, OWL.Thing);
    assertEquals(1, m.size());
    UpdateRequest req = UpdateFactory.create("INSERT { ?s ?p ?o } WHERE { ?o ?p ?s }");
    UpdateAction.execute(req, m);
    assertEquals(2, m.size());
    assertEquals(1, m.listStatements(anon, null, (RDFNode) null).toList().size());
    assertEquals(1, m.listStatements(null, null, anon).toList().size());
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 3 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class SomeValuesFromRestrictionImpl method getSomeValuesFrom.

/**
     * <p>Answer the resource characterising the constraint on at least one value of the restricted property. This may be
     * a class, the URI of a concrete datatype, a DataRange object or the URI rdfs:Literal.</p>
     * @return A resource, which will have been pre-converted to the appropriate Java value type
     *        ({@link OntClass} or {@link DataRange}) if appropriate.
     * @exception ProfileException If the {@link Profile#SOME_VALUES_FROM()} property is not supported in the current language profile.
     */
@Override
public Resource getSomeValuesFrom() {
    checkProfile(getProfile().SOME_VALUES_FROM(), "SOME_VALUES_FROM");
    Resource r = (Resource) getRequiredProperty(getProfile().SOME_VALUES_FROM()).getObject();
    boolean currentStrict = ((OntModel) getModel()).strictMode();
    ((OntModel) getModel()).setStrictMode(true);
    try {
        if (r.canAs(OntClass.class)) {
            // all values from a class
            return r.as(OntClass.class);
        } else if (r.canAs(DataRange.class)) {
            // all values from a given data range
            return r.as(DataRange.class);
        } else {
            // must be a datatype ID or rdfs:Literal
            return r;
        }
    } finally {
        ((OntModel) getModel()).setStrictMode(currentStrict);
    }
}
Also used : Resource(org.apache.jena.rdf.model.Resource)

Example 4 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class AllValuesFromRestrictionImpl method getAllValuesFrom.

/**
     * <p>Answer the resource characterising the constraint on all values of the restricted property. This may be
     * a class, the URI of a concrete datatype, a DataRange object or the URI rdfs:Literal.</p>
     * @return A resource, which will have been pre-converted to the appropriate Java value type
     *        ({@link OntClass} or {@link DataRange}) if appropriate.
     * @exception ProfileException If the {@link Profile#ALL_VALUES_FROM()} property is not supported in the current language profile.
     */
@Override
public Resource getAllValuesFrom() {
    checkProfile(getProfile().ALL_VALUES_FROM(), "ALL_VALUES_FROM");
    Resource r = (Resource) getRequiredProperty(getProfile().ALL_VALUES_FROM()).getObject();
    boolean currentStrict = ((OntModel) getModel()).strictMode();
    ((OntModel) getModel()).setStrictMode(true);
    try {
        if (r.canAs(OntClass.class)) {
            // all values from a class
            return r.as(OntClass.class);
        } else if (r.canAs(DataRange.class)) {
            // all values from a given data range
            return r.as(DataRange.class);
        } else {
            // must be a datatype ID or rdfs:Literal
            return r;
        }
    } finally {
        ((OntModel) getModel()).setStrictMode(currentStrict);
    }
}
Also used : Resource(org.apache.jena.rdf.model.Resource)

Example 5 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestGenericRuleReasonerConfig method testLoadsRulesViaRuleSetStrings.

private void testLoadsRulesViaRuleSetStrings(String ns) {
    String ruleA = "[R: (?x rdf:type eg:Thing) -> (?x eg:thing true)]";
    String ruleB = "[S: (?x rdf:type eg:Thung) -> (?x eg:thing false)]";
    Set<Rule> rules = rulesFromTwoStrings(ruleA, ruleB);
    String modelString = "x <ns>:ruleSet _x; _x <ns>:hasRule '<A>'; _x <ns>:hasRule '<B>'".replaceAll("<ns>", ns).replaceAll("<A>", ruleA.replaceAll(" ", "\\\\\\\\s")).replaceAll("<B>", ruleB.replaceAll(" ", "\\\\\\\\s"));
    Resource r = resourceInModel(modelString);
    GenericRuleReasoner grr = new GenericRuleReasoner(null, r);
    assertEquals(rules, new HashSet<>(grr.getRules()));
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Rule.parseRule(org.apache.jena.reasoner.rulesys.Rule.parseRule)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)178 Model (org.apache.jena.rdf.model.Model)86 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)34 RDFNode (org.apache.jena.rdf.model.RDFNode)24 Dataset (org.apache.jena.query.Dataset)20 Literal (org.apache.jena.rdf.model.Literal)17 BaseTest (org.apache.jena.atlas.junit.BaseTest)16 Node (org.apache.jena.graph.Node)16 Statement (org.apache.jena.rdf.model.Statement)14 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)9 InfModel (org.apache.jena.rdf.model.InfModel)9 Reader (java.io.Reader)8 ArrayList (java.util.ArrayList)8 JsonString (org.apache.jena.atlas.json.JsonString)8 Triple (org.apache.jena.graph.Triple)8 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5