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));
}
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());
}
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);
}
}
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);
}
}
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()));
}
Aggregations