Search in sources :

Example 26 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 27 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 28 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)

Example 29 with Resource

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;
}
Also used : SDBException(org.apache.jena.sdb.SDBException) Resource(org.apache.jena.rdf.model.Resource)

Example 30 with Resource

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;
}
Also used : Resource(org.apache.jena.rdf.model.Resource) CommandAssemblerException(org.apache.jena.sdb.assembler.CommandAssemblerException) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)179 Model (org.apache.jena.rdf.model.Model)87 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)35 RDFNode (org.apache.jena.rdf.model.RDFNode)25 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)15 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)9 Triple (org.apache.jena.graph.Triple)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 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5