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).
Related
I have a set of multiple files that store time series data.
The time series data is stored as a CSV file with multiple large columns.
E.g.:
Time
Force
1
0.1
2
0.2
3
0.2
4
0.3
...
...
I would like to make this data accessible using RDF without conversion of the actual data into RDF. The columns in the file should be related to ontology individuals.
I know I can create a json-ld file that stores the meta information of the file. I read that this file is usually stored together with the csv file as "-metadata.json" file.
I made a minimal example for my table:
{
"#context":[
"http://www.w3.org/ns/csvw"
],
"url":"PATH-TO-URL",
"dialect":{
"delimiter":"\t",
"skipRows":4,
"headerRowCount":2,
"encoding":"ISO-8859-1"
},
"tableSchema":{
"columns":[
{
"titles":"Time",
"#id":"Time",
"#type":"Column"
},
{
"titles":"Force",
"#id":"Force",
"#type":"Column"
}
]
}
}
Now I also have an ontology, with individuals representing time and force of a specific experiment (F1 and T1). This ontology is stored in a tripplestore.
E.g.:
#prefix : <http://www.semanticweb.org/example#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix xml: <http://www.w3.org/XML/1998/namespace> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#base <http://www.semanticweb.org/example> .
<http://www.semanticweb.org/example> rdf:type owl:Ontology .
#################################################################
# Object Properties
#################################################################
### http://www.semanticweb.org/example#hasDataReference
:hasDataReference rdf:type owl:ObjectProperty .
#################################################################
# Classes
#################################################################
### http://www.semanticweb.org/example#Force
:Force rdf:type owl:Class .
### http://www.semanticweb.org/example#Time
:Time rdf:type owl:Class .
#################################################################
# Individuals
#################################################################
### http://www.semanticweb.org/example#F1
:F1 rdf:type owl:NamedIndividual ,
:Force .
### http://www.semanticweb.org/example#T1
:T1 rdf:type owl:NamedIndividual ,
:Time .
I would like to relate these individuals to the columns stored in the "-metadata.json" file. So that the user can locate the specific column by following the graph from the individuals.
What would be the correct way to link the individuals with the column location ? Do I need to convert the json-ld to ttl, add it to the tripplestore and then add a relation to the column, e.g. using my "hasDataReference" relation?
I think the file itself could be made accessible using an ontology like dcat.
In general, I am looking for the recommended way to make csv data (e.g. the columns and rows) available via an ontology-based graph.
I do not want to load the entire column in the tripplestore only the location of the column in the file, so that the user can extract the column if needed.
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.
May I know if Apahe JENA supports OWL 2 syntax in Java? It does mentioned that in the documentation (https://jena.apache.org/documentation/ontology/) it only provide limited cardinality restrictions. I would like to confirm this from the experts.
Apache Jena does not support OWL2, only OWL11 through org.apache.jena.ontology.OntModel interface. See also documentation.
But you still can work with OWL2 in Jena using some external jena-based APIs and tools, e.g. ONT-API, that is OWL-API-api(v5) impl over Jena.
In ONT-API there are two main OWL2 view of data, which encapsulate the same RDF Graph: com.github.owlcs.ontapi.jena.model.OntModel and com.github.owlcs.ontapi.Ontology (in older versions (ONT-API:v1.x.x) these classes have names ru.avicomp.ontapi.jena.model.OntGraphModel and ru.avicomp.ontapi.OntologyModel respectively).
The com.github.owlcs.ontapi.jena.model.OntModel view is a full analogue of Jena org.apache.jena.ontology.OntModel, it is the facility to work with triples.
And the com.github.owlcs.ontapi.Ontology view is an extended org.semanticweb.owlapi.model.OWLOntology, the facility to work with axiomatic data, that is backed by the com.github.owlcs.ontapi.jena.model.OntModel view and vice-versa.
For example, the following snippet:
String uri = "https://stackoverflow.com/questions/54049750";
String ns = uri + "#";
OntModel m = OntModelFactory.createModel()
.setNsPrefixes(OntModelFactory.STANDARD).setNsPrefix("q", ns);
m.setID(uri);
OntClass c = m.createOntClass(ns + "c");
OntObjectProperty p = m.createObjectProperty(ns + "p");
OntIndividual i = c.createIndividual(ns + "i");
m.createObjectComplementOf(m.createObjectUnionOf(c, m.getOWLThing(),
m.createObjectSomeValuesFrom(p, m.createObjectOneOf(i))));
m.write(System.out, "ttl");
will produce the following ontology:
#prefix q: <https://stackoverflow.com/questions/54049750#> .
#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#> .
<https://stackoverflow.com/questions/54049750>
a owl:Ontology .
q:c a owl:Class .
q:p a owl:ObjectProperty .
q:i a owl:NamedIndividual , q:c .
[ a owl:Class ;
owl:complementOf [ a owl:Class ;
owl:unionOf ( q:c owl:Thing
[ a owl:Restriction ;
owl:onProperty q:p ;
owl:someValuesFrom [ a owl:Class ;
owl:oneOf ( q:i )
]
]
)
]
] .
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 .
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.