On 12/09/15 19:33, Maria Clementina Latanzi wrote:
Hi all,
I'm working with Jena. I have an ontology with no more than 50
individuals, and I use Jena to
get individuals from Ontology by
calling*listIndividual*(/*com.hp.hpl.jena.ontology.OntModel.listIndividuals*/).
When I call this method, it's taking a lot of time up to 20 seconds.
When debugging, it takes more than 1 minute to return. Other methods
like *listClass *return instantly.
I found a stackoverflow question relevant to my problem but there was no
answer. This makes me think that the problem might be general for other
people and not just an issue with my ontology. Here's the link:
http://stackoverflow.com/questions/27645110/method-listindividual-takes-more-than-15-mins-with-dbpedia-2014-owl-2mb-siz#
I'm wondering if you could help me figure out why does it take so long
to run. Any ideas? Is this normal and expected behavior because of the
size of the ontology?
Short answer:
Use an explicit OntModelSpec when you create the ontology and use either
OWL_MEM (if you don't need any inference) or OWL_MEM_MICRO_RULE_INF (if
you do). On your example I get:
No OntModelSpec: 1800ms
OWL_MEM 11ms
OWL_MEM_MICRO_RULE_INF: 1ms
[I'm running on Java 7, with Jena2.]
Long answer:
listIndividuals is quite tricky for a tool like Jena which is quite RDF
centric but does support OWL.
If we know the ontology is supposed to be OWL *and* we are working with
a sufficiently capable reasoner then we can just list the things of type
owl:Thing and trust the reasoner to figure things out. That's the place
where listIndividuals makes sense.
If we are or might be in RDFS land then testing whether a resource is a
individual is tricky because there is no such separation. In order to be
useful listIndividuals/isIndividual tries to eliminate things that are
explicitly classes or properties, and then looks for things which are
instances of known types. That's a useful heuristic approach which
people find useful though it has no formal justification - in RDFS
everything is an individual. However, it's expensive. There was a time
when listIndividuals tried to improve things but it proved too costly to
maintain so these days listIndividuals takes the brute force approach of
applying the isIndividual test to every resource.
The problem is that the default OntModelSpec if you create an ontology
with no explicit spec has RDFS inference. That is a good default choice
for a wide range of uses but a real problem for listIndividuals. It
tells us we can't rely on there being an owl:Thing-aware reasoner, so we
have to use the expensive heuristic. But is also means there is an
actual reasoner there which slows things down.
Hence the more efficient alternatives are to either have no reasoner or
to have an OWL reasoner. Or, if you really want RDFS, then don't use
listIndividuals in the first place!
[Aside: this is probably a question for the users list rather that the
dev list.]
Dave