Java
programming using SPARQL and Jena
Load the family ontology
you have defined Check the checkbox “with OWL inference”.
If you don’t
have a version of the family ontology you can use this family.owl.
Write and
execute SPARQL queries to response to the following:
OPTIONAL: if the result is empty, rewrite a more complex SPARQL query, or an SWRL rule to return non empty result if possible
Write and
execute SPARQL queries (several conditions in WHERE) to response to the
following:
-
Download
this version of Jena
-
Launch
Eclipse
-
Create
a new Java project
-
Create
a new folder called data
-
Create
the file owlrules.txt in the folder data (content is given below)
-
Create
the file rules.txt in the folder data (content is given below)
-
Create
the file query.txt in the folder data (content is given below)
-
Create
the file family.owl in the folder data
-
Create
a new package tools
-
Open
the menu Project/Properties/Java Build
Path. In the tab Libraries, click
on add external jars. Add all the lib
of
-
Create
a new class FileTool in tools
package
-
Create
a new class JenaEngine in tools
package
-
Create
a new package applications
-
Create
a new class Main
in application package
-
Execute
the Main class
@include <OWLMicro>. |
@prefix ns:
<http://www.owl-ontologies.com/unnamed.owl#>. @prefix rdf:
<http://www.w3.org/1999/02/22-rdf-syntax-ns#>. [rule1: (?per rdf:type ns:Person) (?per ns:age
?age) greaterThan(?age, 60)-> (?per rdf:type ns:PersonneAge)] |
PREFIX ns:
<http://www.owl-ontologies.com/unnamed.owl#> PREFIX rdf:
<http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX xsd:
<http://www.w3.org/2001/XMLSchema#> SELECT ?user ?age WHERE { ?user rdf:type ns:PersonneAge. ?user ns:age ?age. } |
-
Create
query files that correspond to query from Part1 of this lab. Modify the Main class
to refer to these query (one by one) and execute the Main program (compare the
results with the ones obtained in Part 1)
-
Add
a new functionality in the JenaEngine class that
allows to read the value of property of type ObjectType
(see the javadoc of the Jena API)
-
Add
a new functionality in the JenaEngine class that
allows to read the value of property of type DataType
(see the javadoc of the Jena API)
-
Create
a new class in the application
package that
a.
Read
a name of a person
b.
Display
his/her parents, brothers and sisters.
c.
If
this person is married, display the name and age of her husband/his wife
d.
If
this person is not married Display all the persons
§ whose gender is different,
§ whose age is close (+/- 5 years) and
§ is not married