Hello there,
I'm currently designing a system on top of Jena (or on top of semantic web
technologies in general) and I arrived at the point where I need to get
inference support for SPARQL queries up and running. I looked at
https://jena.apache.org/documentation/inference/ but I'm having problems to
understand how to exactly design what I need. I would welcome if someone could
look at my use case and tell me if it makes sense to design it this way in
general and how to tell Jena to do the inference support.
I think my use case can be described with the following two SPARQL queries:
prefix sd:<http://x.test/schema/Decl/0.1/>
prefix sc:<http://x.test/schema/Class/0.1/>
prefix c:<http://x.test/data/Class/0.1/>
prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>
prefix s:<http://schema.org/name>
insert data {
sc:name rdfs:subPropertyOf sd:name .
sc:name a s: .
sd:name a s: .
c:ClassName a sc: .
c:ClassName sc:name "ClassName" .
}
The purpose of the snippet above is to create an object of type
`http://x.test/schema/Class/0.1/` and give it a name. There is also the type
`http://x.test/schema/Decl/0.1/`, which is a super type of the previous type.
The types of the names are not important, the only thing that is important is
that `Class` shares all the properties that are also part of `Decl`. This query
works fine but the next one doesn't:
prefix sd:<http://x.test/schema/Decl/0.1/>
prefix sc:<http://x.test/schema/Class/0.1/>
select * where {
# This doesn't give back any results:
?s sd:name ?o .
# This would work fine:
# ?s sc:name ?o .
}
The purpose of this query is to select all names. Unfortunately at the moment
it only works when I ask for the name of the `Class`. If I ask for the name of
the `Decl` I don't get back anything because there is no relation between the
two different names yet. What I need here is basically a dynamic dispatch as it
exists for Java methods for example. I want to ask for the property that is
part of the supertype but I want to store it as a property of the subtype.
Now, there are two concrete questions:
- Does it make sense to design the system this way? I'm more or less mimicking
the typical inheritance model of object oriented languages here but I'm not
sure if that is the way to go. The two types `Class` and `Decl` can be created
independently from each other and the subtype relationship may be created by
another party.
- How to express the above relationship in Jena? I found Jenas
`GenericRuleReasoner` but this one doesn't seem to do what I need. It seems to
infer additional information based on a set of rules and stores this additional
information in the database. I don't think that the relationship I have should
be stored in the database. I think the moment when the second query is run,
Jena internally needs to find out about the relationship (based on a set of
rules) and find more information based on the rules.
Ultimately, I want that the SPARQL query is as easy as possible. I don't want
that users have to care about if something is stored as `Decl` name or as
`Class` name.
Simon