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()));
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class SDBConnectionDesc method worker.
private static SDBConnectionDesc worker(Model m) {
Resource r = GraphUtils.getResourceByType(m, AssemblerVocab.SDBConnectionAssemblerType);
if (r == null)
throw new SDBException("Can't find connection description");
SDBConnectionDesc desc = (SDBConnectionDesc) AssemblerBase.general.open(r);
desc.initJDBC();
return desc;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class CmdDescAssembler method open.
/* This SPARQL query will process arguments
PREFIX acmd: <http://jena.hpl.hp.com/2007/sdb#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX list: <http://jena.apache.org/ARQ/list#>
SELECT ?name ?value
{ ?x rdf:type acmd:Cmd ;
acmd:args ?args .
{ ?args list:member [ acmd:name ?name ; acmd:value ?value ] }
UNION
{ ?args list:member ?e .
OPTIONAL { ?e acmd:name ?name }
FILTER (!bound(?name)) .
?e acmd:value ?value .
}
UNION
{ ?args list:member ?value . FILTER isLiteral(?value) }
}
*/
@Override
public Object open(Assembler a, Resource root, Mode mode) {
CmdDesc cd = new CmdDesc();
String main = GraphUtils.getStringValue(root, AssemblerVocab.pMain);
if (main == null)
main = GraphUtils.getStringValue(root, AssemblerVocab.pClassname);
cd.setCmd(main);
Resource x = GraphUtils.getResourceValue(root, AssemblerVocab.pArgs);
if (x != null) {
for (; !x.equals(RDF.nil); ) {
RDFNode e = x.getRequiredProperty(RDF.first).getObject();
// Move to next list item
x = x.getRequiredProperty(RDF.rest).getResource();
// Either : a literal or a named pair.
if (e.isLiteral()) {
cd.addPosn(((Literal) e).getString());
continue;
}
Resource entry = (Resource) e;
String name = GraphUtils.getStringValue(entry, AssemblerVocab.pArgName);
String value = GraphUtils.getStringValue(entry, AssemblerVocab.pArgValue);
if (value == null)
throw new CommandAssemblerException(entry, "Strange entry: " + entry);
if (name != null)
cd.addNamedArg(name, value);
else
cd.addPosn(value);
}
}
return cd;
}
Aggregations