Jena Fuseki missed inference? - jena

I'm using Jena Fuseki 3.13.1 (with OWLFBRuleReasoner), and I have asserted (uploaded) the following triples:
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix f: <http://vleo.net/family#> .
f:Bob f:hasWife f:Alice .
f:Bob f:hasWife f:Alice2 .
f:Alice2 f:hasHusband f:Bob2 .
f:hasWife a owl:FunctionalProperty .
f:hasWife a owl:InverseFunctionalProperty .
f:hasHusband owl:inverseOf f:hasWife .
Now, If I query and ASK { f:Alice owl:sameAs f:Alice2 }, I get true.
However, If I ASK { f:Bob owl:sameAs f:Bob2 }, I get false! Loading the same triples on another reasoner (owl-rl), I get the triple f:Bob owl:sameAs f:Bob2 inferred.
What is happening here?

I have worked with jena reasoner following this doc:
https://jena.apache.org/documentation/inference/
I have many years of experience with jena, and had never used OWLFBRuleReasoner, and it does not appear in the indicated doc, which is curious for me.
Not all reasoners work with the same construct, and that is the reason why I check the doc, that means perhaps OWLFBRuleReasoner does not use the same owl construct as the another reasoner you used (owl-rl).
Another thing is that, as I understand your KB is inconsistent, because you are declaring:
f:hasWife a owl:FunctionalProperty
But, you are assigning 2 values to it, which must make your KB inconsistent.
Luis Ramos

A follow-up: as suggested by UninformedUser, I've asked this one on the Jena mailing list and got an answer from Dave.
Jena's implementation trades some reasoning completeness for performance, the solution in this case is to add explicitly the forward version of inverseOf to the owl-fb rules file:
[inverseOf2b: (?P owl:inverseOf ?Q), (?X ?P ?Y) -> (?Y ?Q ?X) ]
The details are in this thread.

Related

Notation3 rules using language tags

I have facts expressed in Turtle/Notation3 syntax that use language tags for localization of strings, e.g.
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
#prefix ex: <http://www.example.org/#>.
ex:A rdfs:label "example"#en;
rdfs:label "beispiel"#de.
Is it possible and if so, how could one define rules specific to a given language tag?
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
#prefix ex: <http://www.example.org/#>.
{
?s rdfs:label ?v#en. # a mechanism is needed here to select for 'en' lang tag
}
=>
{
?s a ex:EnglishLabeledThing.
}.
Thanks for your help ;)
I tried various variations of the above syntax, accessing properties of langString or LocalizableString but did not came up with a solution. Also I could not find any explanation in the N3 specs. I'm using EYE v2.3.0.
For future reference, I came up with a solution by using func (http://www.w3.org/2007/rif-builtin-function#):
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
#prefix ex: <http://www.example.org/#>.
#prefix func: <http://www.w3.org/2007/rif-builtin-function#>.
{
?s rdfs:label ?v.
(?v) func:lang-from-PlainLiteral ?l.
(?l "en") func:compare 0.
}
=>
{
?s a ex:EnglishLabeledThing.
}.
results in ex:A a ex:EnglishLabeledThing. as expected, however I also came across the pred:matches-language-range which might be a better fit here.

why Jena fuseki has no response to owl reasoning?

I want to use Jena Fuseki to construct a SPARQL endpoint for some ontology file.
and my fuseki config as follow:
#prefix fuseki: <http://jena.apache.org/fuseki#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
#prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
<#service1> rdf:type fuseki:Service ;
fuseki:name "ds" ; # http://host:port/ds
fuseki:serviceQuery "sparql" ; # SPARQL query service
fuseki:serviceQuery "query" ; # SPARQL query service (alt name)
fuseki:serviceUpdate "update" ; # SPARQL update service
fuseki:serviceUpload "upload" ; # Non-SPARQL upload service
fuseki:serviceReadWriteGraphStore "data" ; # SPARQL Graph store protocol (read and write)
# A separate read-only graph store endpoint:
fuseki:serviceReadGraphStore "get" ; # SPARQL Graph store protocol (read only)
fuseki:dataset <#dataset> ;
.
<#dataset> rdf:type ja:RDFDataset ;
ja:defaultGraph <#inf_model> ;
.
<#mv_data_model> a ja:MemoryModel;
ja:content[ja:externalContent <file://D:/Program%20Files/d2rq-0.8.1/movie.nt>] ;
ja:content[ja:externalContent <file://D:/Program%20Files/apache-jena-fuseki-3.13.1/run/ontology.ttl>]
.
<#inf_model> a ja:InfModel ;
ja:baseModel <#mv_data_model>;
ja:reasoner [ja:reasonerURL <http://jena.hpl.hp.com/2003/OWLFBRuleReasoner>] ;
#ja:reasoner [
# ja:reasonerURL <http://jena.hpl.hp.com/2003/GenericRuleReasoner> ;
# ja:rulesFrom <file://D:/Program%20Files/apache-jena-fuseki-3.13.1/run/rule.ttl>; ]
.
I run fuseki as a Standalone Server.when I close the OWL reasoner it works well.But once the OWL reasoner is enabled,the server has no response for the query,even the query like
SELECT ?s ?p ?o
WHERE {
?s ?p ?o
}
limit 10
has no response, and then throw a Exception: java.lang.OutOfMemoryError. However,the RuleReasoner works well.
And my ttl file has about 1500000 triples, is the data scale is too large for the OWL Reasoner to have a inference?
All work is done on my pc,can any friend offer me a help? Thanks
In fuseki, when running a Reasoner over a too big DataSet, the inferences will be applied to All Graph in query execution time. Besides that, all inferences will be materialized in Fuseki TDB case reasoner applies forward reasoning. It will burden the system, cause the graph will be to big to materialize and reason using RAM memory.
We have alredy crashed a machine dedicating 1 TD RAM to Fuseki.
A possible solution is to split your dataset into independent parts for tunning the queries.
For more information, look at hadoop and AllegroGraph solution for high-perfomance with Clusters
https://allegrograph.com/hadoop-and-allegrograph-the-semantic-data-lake-for-analytics/
It depends on your demand. In an unlimited scale, cluster solution seems to be the best, but maybe locally increasing the dedicated RAM memory to JVM solve your problem.

How to create user defined datatypes in Apache Jena?

I'm creating an ontology using Apache Jena. However, I can't find a way of creating custom datatypes as in the following example:
'has value' some xsd:float[>= 0.0f , <= 15.0f].
Do you have any ideas?
It seems what you need is DatatypeRestriction with two facet restrictions: xsd:minInclusive and xsd:maxInclusive.
It is OWL2 constructions.
org.apache.jena.ontology.OntModel does not support OWL2, only OWL1.1 partially (see documentation), and, therefore, there are no builtin methods for creating such data-ranges (there is only DataOneOf data range expression, see OntModel#createDataRange(RDFList)).
So you have to create a desired datatype manually, triple by triple, using the general org.apache.jena.rdf.model.Model interface.
In RDF, it would look like this:
_:x rdf:type rdfs:Datatype.
_:x owl:onDatatype DN.
_:x owl:withRestrictions (_:x1 ... _:xn).
See also owl2-quick-guide.
Or, to build such an ontology, you can use some external utilities or APIs.
For example, in ONT-API (v. 2.x.x) the following snippet
String ns = "https://stackoverflow.com/questions/54131709#";
OntModel m = OntModelFactory.createModel()
.setNsPrefixes(OntModelFactory.STANDARD).setNsPrefix("q", ns);
OntDataRange.Named floatDT = m.getDatatype(XSD.xfloat);
OntFacetRestriction min = m.createFacetRestriction(OntFacetRestriction.MinInclusive.class,
floatDT.createLiteral("0.0"));
OntFacetRestriction max = m.createFacetRestriction(OntFacetRestriction.MaxInclusive.class,
floatDT.createLiteral("15.0"));
OntDataRange.Named myDT = m.createDatatype(ns + "MyDatatype");
myDT.addEquivalentClass(m.createDataRestriction(floatDT, min, max));
m.createResource().addProperty(m.createDataProperty(ns + "someProperty"),
myDT.createLiteral("2.2"));
m.write(System.out, "ttl");
will produce the following ontology:
#prefix q: <https://stackoverflow.com/questions/54131709#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
[ q:someProperty "2.2"^^q:MyDatatype ] .
q:MyDatatype a rdfs:Datatype ;
owl:equivalentClass [ a rdfs:Datatype ;
owl:onDatatype xsd:float ;
owl:withRestrictions ( [ xsd:minInclusive "0.0"^^xsd:float ]
[ xsd:maxInclusive "15.0"^^xsd:float ]
)
] .
q:someProperty a owl:DatatypeProperty .

Sesame won't open Turtle file created by Jena

A Turtle file created by Jena is not opening in Sesame. On a closer analysis, I found that Jena uses namespace prefixes but Sesame uses the compete namespace. How can I resolve this?
This is what Sesame uses:
<http://rdf.freebase.com/ns/m.0_2c> <http://rdf.freebase.com/ns/type.object.key> <http://rdf.freebase.com/ns/wikipedia.it_title.Alexanderplatz> , <http://rdf.freebase.com/ns/wikipedia.ar.apjvik0623apjvik0644apjvik0643apjvik0633apjvik0627apjvik0646apjvik062Fapjvik0631_apjvik0628apjvik0644apjvik0627apjvik062Aapjvik0632> , <http://rdf.freebase.com/ns/wikipedia.ar_title.apjvik0645apjvik064Aapjvik062Fapjvik0627apjvik0646_apjvik0623apjvik0644apjvik0643apjvik0633apjvik0646apjvik062Fapjvik0631> , <http://rdf.freebase.com/ns/wikipedia.pl_title.Alexanderplatz> ;
<http://rdf.freebase.com/ns/type.object.type> <http://rdf.freebase.com/ns/location.location> ;
<http://rdf.freebase.com/ns/type.object.key> <http://rdf.freebase.com/ns/wikipedia.nl_id.429277> , <http://rdf.freebase.com/ns/wikipedia.ca.Alexanderplatz> , <http://rdf.freebase.com/ns/wikipedia.en_id.2511> , <http://rdf.freebase.com/ns/wikipedia.nl_title.Alexanderplatz> , <http://rdf.freebase.com/ns/wikipedia.fr_id.749899> , <http://rdf.freebase.com/ns/wikipedia.fa.apjvik0627apjvik0644apjvik0643apjvik0633apjvik0627apjvik0646apjvik062Fapjvik0631apjvik067Eapjvik0644apjvik0627apjvik062Aapjvik0633> , <http://rdf.freebase.com/ns/wikipedia.ru.apjvik0410apjvik043Bapjvik0435apjvik043Aapjvik0441apjvik0430apjvik043Dapjvik0434apjvik0435apjvik0440apjvik043Fapjvik043Bapjvik0430apjvik0446> , <http://rdf.freebase.com/ns/wikipedia.zh-tw.apjvik4E9Aapjvik5386apjvik5C71apjvik5927apjvik5E7Fapjvik573A> , <http://rdf.freebase.com/ns/wikipedia.th_title.apjvik0E2Dapjvik0E40apjvik0E25apjvik0E47apjvik0E01apjvik0E0Bapjvik0E32apjvik0E19apjvik0E40apjvik0E14apjvik0E2Dapjvik0E23apjvik0E4Capjvik0E1Eapjvik0E25apjvik0E32apjvik0E17apjvik0E0Bapjvik0E4C> , <http://rdf.freebase.com/ns/wikipedia.it.Haus_des_Reisens> , <http://rdf.freebase.com/ns/wikipedia.fr.Alexanderplatz> , <http://rdf.freebase.com/ns/wikipedia.en.Alexander_Platz> , <http://rdf.freebase.com/ns/wikipedia.cs_title.Alexanderplatz> , <http://rdf.freebase.com/ns/user.avh.ellerdale.0099-a6ea> ;
<http://rdf.freebase.com/ns/type.object.type> <http://rdf.freebase.com/ns/common.topic> ;
This is what Jena uses:
#prefix key: <http://rdf.freebase.com/key/>.
#prefix ns: <http://rdf.freebase.com/ns/>.
#prefix owl: <http://www.w3.org/2002/07/owl#>.
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
#prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
ns:m.0_2c
ns:common.topic.alias "Alexanderplatz, Berlin"#en;
I had a closer look: the cause is actually that the Turtle file produced by Jena contains a '.' in the localname part of a prefixed name (the m.02_c bit, and the common.topic.alias bit). This is allowed by the current W3C REC Turtle grammar, but Sesame does not yet fully implement this version of Turtle. This is a known issue (SES-1862).
Sesame is scheduled to be brought up to date with the latest Turtle spec for its next major release, 2.8. In the meantime, a workaround is to use a different syntax format when exporting from Jena (e.g. N-Triples).

Jena tdbloader assembler

How to load TDB storage with inference via tdbloader.bat (windows, Jena 2.7.3)?
I used this assembler file:
#prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
#prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
tdb:DatasetTDB rdfs:subClassOf ja:RDFDataset .
tdb:GraphTDB rdfs:subClassOf ja:Model .
<#dataset> rdf:type ja:RDFDataset ;
ja:defaultGraph <#infModel> .
<#infModel> a ja:InfModel ;
ja:baseModel <#tdbGraph>;
ja:reasoner
[ ja:reasonerURL <http://jena.hpl.hp.com/2003/OWLFBRuleReasoner> ].
<#tdbGraph> rdf:type tdb:GraphTDB ;
tdb:location "DB";
.
My command:
c:\apache-jena-2.7.3\bat>tdbloader --tdb=test.ttl C:\apache-jena-2.7.3\Lubm10\*
I got an exception:
java.lang.ClassCastException: com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph cannot be cast to com.hp.hpl.jena.tdb.store.GraphTDB
What is wrong?
(removing semicolon after "DB" - does not help)
It's not clear what you are trying to achieve. tdbloader is a tool for loading triples into a TDB store, prior to processing those triples via your app or SPARQL end-point. Separately, from your app code, you can construct a Jena model which uses the inference engine over a base model from a TDB graph. But I can't see why you are using an inference model at load time. If you look at the exception you are getting:
FBRuleInfGraph cannot be cast to com.hp.hpl.jena.tdb.store.GraphTDB
it confirms that you can't use an inference graph at that stage of the process, and I'm not sure why you would. Unless, of course, you are trying to statically compute the inference closure over the base model and store that in TDB, saving the need for inference computation at runtime. However, if you are trying to do that, I don't believe that can currently be done via the Jena assembler. You'll have to write custom code to do that at the moment.
Bottom line: separate the concerns. Use a plain graph description for tdbloader, use the inference graph at run time.

Resources