You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Tran Thai Binh <th...@gmail.com> on 2011/12/02 10:04:37 UTC
Re: How to get Pellet inference
Dear Dave,
Please show me how to use Pellet with my code. I am totally newbie, I try
many way but it it not right way. Please help me.
Thank you,
Binh
On Wed, Nov 30, 2011 at 4:53 PM, Dave Reynolds <da...@gmail.com>wrote:
> On Wed, 2011-11-30 at 12:15 +0100, Tran Thai Binh wrote:
> > Dear all,
> > I have a problem with inference value. I create two rdf files. One for
> > schema, one for data
> > For schema rdf file, I create subclass a2 of a1, and one dataproperty p1.
> > a2 have definition "a1 and p1 some float[>2]". For data rdf file, I
> create
> > some instant belongs to class a1 which have property p1.
> >
> > I want to run reasoner in Jena to get instant of class a2. I expect some
> > instant when I query for a2 but Jena returns nothing. I attach rdf files
> > and my code below. Could anyone help me to solve problem.
>
> As explained earlier on jena-dev you need OWL 2 reasoning for your
> specific example.
>
> > At the moment i want to use Pellet as a reasoner but I donnot know how to
> > join these two rdf files. Please help me.
>
> You don't need to "join" those files. You can simply use the Pellet
> Reasoner the same way you currently are (bindSchema).
>
> If you want to join those files in your program you can use Model.add,
> for example data.add( schema ).
>
> The other option is to use owl:imports in your source data document to
> import the ontology file and then use the OntModel machinery to handle
> the imports for you.
>
> Dave
>
> >
> > Thank in advance.
> > Binh
> >
> >
> >
> > *(1) for schema*
> >
> > <?xml version="1.0"?>
> > <!DOCTYPE rdf:RDF [
> > <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
> > <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
> > <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
> > <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
> > <!ENTITY Ontology1322586150669 "
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#"
> >
> > ]>
> > <rdf:RDF xmlns="
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#
> "
> > xml:base="
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl"
> > 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#"
> > xmlns:Ontology1322586150669="
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#
> ">
> > <owl:Ontology rdf:about="
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl
> "/>
> > <!--
> > //////////////////////////////
> > //////////////////////////////
> > ///////////////////////////
> > //
> > // Datatypes
> > //
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > -->
> > <!--
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > //
> > // Data properties
> > //
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > -->
> > <!--
> >
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#p1--
> >
> > <owl:DatatypeProperty rdf:about="&Ontology1322586150669;p1"/>
> > <!--
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > //
> > // Classes
> > //
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > -->
> > <!--
> >
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#a1--
> >
> > <owl:Class rdf:about="&Ontology1322586150669;a1"/>
> > <!--
> >
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#a2--
> >
> > <owl:Class rdf:about="&Ontology1322586150669;a2">
> > <rdfs:subClassOf>
> > <owl:Class>
> > <owl:intersectionOf rdf:parseType="Collection">
> > <rdf:Description
> rdf:about="&Ontology1322586150669;a1"/>
> > <owl:Restriction>
> > <owl:onProperty
> > rdf:resource="&Ontology1322586150669;p1"/>
> > <owl:someValuesFrom>
> > <rdfs:Datatype>
> > <owl:onDatatype
> rdf:resource="&xsd;float"/>
> > <owl:withRestrictions
> > rdf:parseType="Collection">
> > <rdf:Description>
> > <xsd:minExclusive
> > rdf:datatype="&xsd;integer">2</xsd:minExclusive>
> > </rdf:Description>
> > </owl:withRestrictions>
> > </rdfs:Datatype>
> > </owl:someValuesFrom>
> > </owl:Restriction>
> > </owl:intersectionOf>
> > </owl:Class>
> > </rdfs:subClassOf>
> > </owl:Class>
> > </rdf:RDF>
> > <!-- Generated by the OWL API (version 3.2.3.22702)
> > http://owlapi.sourceforge.net -->
> >
> > *(2) for data*
> > <?xml version="1.0"?>
> > <!DOCTYPE rdf:RDF [
> > <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
> > <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
> > <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
> > <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
> > <!ENTITY Ontology1322586150669 "
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#"
> >
> > ]>
> > <rdf:RDF xmlns="
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586466073.owl#
> "
> > xml:base="
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586466073.owl"
> > 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#"
> > xmlns:Ontology1322586150669="
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#
> ">
> > <owl:Ontology rdf:about="
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586466073.owl
> "/>
> > <!--
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > //
> > // Datatypes
> > //
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > -->
> > <!--
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > //
> > // Data properties
> > //
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > -->
> > <!--
> >
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#p1--
> >
> > <owl:DatatypeProperty rdf:about="&Ontology1322586150669;p1"/>
> > <!--
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > //
> > // Classes
> > //
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > -->
> > <!--
> >
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#a1--
> >
> > <owl:Class rdf:about="&Ontology1322586150669;a1"/>
> > <!--
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > //
> > // Individuals
> > //
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > -->
> > <!--
> >
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#c--
> >
> >
> > <owl:NamedIndividual rdf:about="&Ontology1322586150669;c">
> > <rdf:type rdf:resource="&Ontology1322586150669;a1"/>
> > <Ontology1322586150669:p1
> > rdf:datatype="&xsd;float">5</Ontology1322586150669:p1>
> > </owl:NamedIndividual>
> > <owl:NamedIndividual rdf:about="&Ontology1322586150669;q">
> > <rdf:type rdf:resource="&Ontology1322586150669;a1"/>
> > <Ontology1322586150669:p1
> > rdf:datatype="&xsd;float">1</Ontology1322586150669:p1>
> > </owl:NamedIndividual>
> > <!--
> >
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#rf--
> >
> > <owl:NamedIndividual rdf:about="&Ontology1322586150669;rf">
> > <rdf:type rdf:resource="&Ontology1322586150669;a1"/>
> > <Ontology1322586150669:p1
> > rdf:datatype="&xsd;float">16</Ontology1322586150669:p1>
> > </owl:NamedIndividual>
> > </rdf:RDF>
> > <!-- Generated by the OWL API (version 3.2.3.22702)
> > http://owlapi.sourceforge.net -->
> >
> > *This is my code in Jena*
> >
> > package query;
> > import com.hp.hpl.jena.query.*;
> > import com.hp.hpl.jena.rdf.model.*;
> > import com.hp.hpl.jena.reasoner.*;
> > import com.hp.hpl.jena.util.
> > FileManager;
> >
> > public class query {
> >
> > public static void main(String[] args) {
> >
> > Model schema = FileManager.get().loadModel("O1.owl");
> > Model data = FileManager.get().loadModel("O2.owl");
> >
> > Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
> > reasoner = reasoner.bindSchema(schema);
> > InfModel infmodel = ModelFactory.createInfModel(reasoner, data);
> >
> > String queryString =
> > "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+
> > "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
> > "PREFIX test: <
> > http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#
> >"+
> > "select ?data " +
> > "where {?data a test:a2}";
> >
> > Query query = QueryFactory.create(queryString);
> >
> > System.out.println("----------------------");
> > System.out.println("Query Result Sheet");
> > System.out.println("----------------------");
> > System.out.println("Direct&Indirect Descendants (inf)");
> > System.out.println("-------------------");
> >
> > // Execute the query and obtain results
> > QueryExecution qe = QueryExecutionFactory.create(query,
> > infmodel);
> > ResultSet results = qe.execSelect();
> >
> > // Output query results
> > ResultSetFormatter.out(System.out, results, query);
> >
> > qe.close();
> > System.out.println("----------------------");
> >
> >
> > }
> > }
> >
> >
>
>
>
>
--
Trần Thái Bình
GIS and Remote Sensing
thaibinhtran@gmail.com
ttbinh@vast-hcm.ac.vn
Phone: (848) 38247360
mobile:
- Việt Nam -
Re: How to get Pellet inference
Posted by Dave Reynolds <da...@gmail.com>.
Hi,
On Fri, 2011-12-02 at 12:31 +0100, Tran Thai Binh wrote:
> Dear Dave,
> I create a very simple code. It is still error. Sorry, if my question is
> stupid.
[snip]
> -----error----
> WARN [main] (OntDocumentManager.java:1078) - An error occurred while
> attempting to read from
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586466073.owl.
So this error message is telling you that there is something wrong with
the file at that URL and indeed when I try to go there it gives a 404.
> @prefix : <
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#> .
> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
> @prefix owl: <http://www.w3.org/2002/07/owl#> .
> @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
>
> <http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl>
> rdf:type owl:Ontology ;
> owl:imports <
> http://www.semanticweb.org/ontologies/2011/10/Ontology1322586466073.owl> .
This is the import statement which is causing the problem.
Since there's no reference to that in the rest of your ontology maybe
it's a spurious import and you can just drop the import.
If you do need to import it then you can use the OntDocumentManager to
set up a mapping from the URL in the import statement to a local file.
Dave
Re: How to get Pellet inference
Posted by Tran Thai Binh <th...@gmail.com>.
Dear Dave,
I create a very simple code. It is still error. Sorry, if my question is
stupid.
package query;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class Query {
public static void main(String[] args) {
OntModel model = ModelFactory.createOntologyModel(
org.mindswap.pellet.jena.PelletReasonerFactory.THE_SPEC);
model.read("file:O1.owl");
model.write(System.out, "Turtle");
}
}
-----error----
WARN [main] (OntDocumentManager.java:1078) - An error occurred while
attempting to read from
http://www.semanticweb.org/ontologies/2011/10/Ontology1322586466073.owl.
Msg was '
http://www.semanticweb.org/ontologies/2011/10/Ontology1322586466073.owl'.
com.hp.hpl.jena.shared.DoesNotExistException:
http://www.semanticweb.org/ontologies/2011/10/Ontology1322586466073.owl
at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:89)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:178)
at
com.hp.hpl.jena.util.FileManager.readModelWorker(FileManager.java:366)
at com.hp.hpl.jena.util.FileManager.readModel(FileManager.java:334)
at com.hp.hpl.jena.util.FileManager.readModel(FileManager.java:318)
at
com.hp.hpl.jena.ontology.OntDocumentManager.read(OntDocumentManager.java:1064)
at
com.hp.hpl.jena.ontology.OntDocumentManager$1.readModel(OntDocumentManager.java:1034)
at
com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl.getModel(ModelMakerImpl.java:78)
at
com.hp.hpl.jena.ontology.OntDocumentManager.fetchLoadedImportModel(OntDocumentManager.java:1031)
at
com.hp.hpl.jena.ontology.OntDocumentManager.fetchPossiblyCachedImportModel(OntDocumentManager.java:1004)
at
com.hp.hpl.jena.ontology.OntDocumentManager.loadImport(OntDocumentManager.java:977)
at
com.hp.hpl.jena.ontology.OntDocumentManager.loadImports(OntDocumentManager.java:771)
at
com.hp.hpl.jena.ontology.OntDocumentManager.loadImports(OntDocumentManager.java:709)
at
com.hp.hpl.jena.ontology.impl.OntModelImpl.loadImports(OntModelImpl.java:1887)
at
com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:2150)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:202)
at
com.hp.hpl.jena.ontology.impl.OntModelImpl.readDelegate(OntModelImpl.java:3024)
at
com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:2106)
at
com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:2022)
at query.Query.main(Query.java:19)
@prefix : <
http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://www.semanticweb.org/ontologies/2011/10/Ontology1322586150669.owl>
rdf:type owl:Ontology ;
owl:imports <
http://www.semanticweb.org/ontologies/2011/10/Ontology1322586466073.owl> .
:p1 rdf:type owl:DatatypeProperty .
:a1 rdf:type owl:Class .
:a2 rdf:type owl:Class ;
owl:equivalentClass
[ rdf:type owl:Class ;
owl:intersectionOf (:a1 [ rdf:type owl:Restriction ;
owl:onProperty :p1 ;
owl:someValuesFrom
[ rdf:type rdfs:Datatype ;
owl:onDatatype xsd:int ;
owl:withRestrictions
([ xsd:minExclusive 2
])
]
])
] .
Please tell me what is wrong.
Binh
On Fri, Dec 2, 2011 at 10:30 AM, Dave Reynolds <da...@gmail.com>wrote:
> Hi,
>
> On Fri, 2011-12-02 at 10:04 +0100, Tran Thai Binh wrote:
> > Dear Dave,
> > Please show me how to use Pellet with my code. I am totally newbie, I try
> > many way but it it not right way. Please help me.
>
> Try following http://clarkparsia.com/pellet/faq/using-pellet-in-jena/
>
> Dave
>
>
>
--
Trần Thái Bình
GIS and Remote Sensing
thaibinhtran@gmail.com
ttbinh@vast-hcm.ac.vn
Phone: (848) 38247360
mobile:
- Việt Nam -
Re: How to get Pellet inference
Posted by Dave Reynolds <da...@gmail.com>.
Hi,
On Fri, 2011-12-02 at 10:04 +0100, Tran Thai Binh wrote:
> Dear Dave,
> Please show me how to use Pellet with my code. I am totally newbie, I try
> many way but it it not right way. Please help me.
Try following http://clarkparsia.com/pellet/faq/using-pellet-in-jena/
Dave