简体   繁体   中英

How to get inference using Jena command line tool 'sparql'?

A |_P(p1,p2) | |_M(m1,m2) | B

I want to get the A's all instances.

my query is

SELECT ?x
    WHERE { 
            ?x rdf:type :A .} 

Output: A(p1,p2,m1,m2)

How to get this result using command line tool 'sparql'? . Means I want to get inference here.

My OWL file is here:

<rdf:RDF xmlns="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    <owl:Ontology rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11"/>

    <owl:Class rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#A">
    <owl:Class rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#B">
    <owl:Class rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#M">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#P"/>
    </owl:Class>

    <owl:Class rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#P">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#A"/>
    </owl:Class>

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#m1">
        <rdf:type rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#M"/>
    </owl:NamedIndividual>

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#m2">
        <rdf:type rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#M"/>
    </owl:NamedIndividual>

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#p1">
        <rdf:type rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#P"/>
    </owl:NamedIndividual>

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#p2">
        <rdf:type rdf:resource="http://www.semanticweb.org/chetan/ontologies/2014/5/untitled-ontology-11#P"/>
    </owl:NamedIndividual>
</rdf:RDF>

Reading your question it is not clear if you want to write some code for your problem or if you just want to use some tool - I'll try to give an answer for the alternative "writing code" as this fits best with stackoverflow:

Roughly speaken you have to load your owl file into a Jena OntModel using one of the methods available in the Jena API. ( http://jena.apache.org/documentation/javadoc/jena/ ) Don't forget to specify the type of reasoning you would like to have. Then, you could use the ARQ API ( http://jena.apache.org/documentation/javadoc/arq/ ) to execute your sparql queries against the OntModel. There should be some code examples on the Jena Homepage also.

If you just want to use some commandline tool provided by Jena, I'm not sure if this allows to specify some reasoning. I would start my search at the tutorial on the Jena documentation site ( http://jena.apache.org/tutorials/ )

Maybe this is still useful to some reader.

Jena line commands accept assembler description files as input. 'tarql' supports this with the --desc option , so it should be possible to describe a data set backed by an inference model and your data, and then run your query against it.

Another alternative, which is more general and can be applied to any existing endpoint, might be to run Fuseki on top of your data and with inference enabled (or any other triple store). Then use the SPARQL syntax to do federated queries .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM