[
https://issues.apache.org/jira/browse/JENA-1026?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14742432#comment-14742432
]
Dave Reynolds commented on JENA-1026:
-------------------------------------
I tried to reply to this on the dev list but my reply didn't seem to get
through so I can't point to the entry in the email archive. So for reference
here it is:
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!
> listIndividuals (and listClasses) performance issue
> ---------------------------------------------------
>
> Key: JENA-1026
> URL: https://issues.apache.org/jira/browse/JENA-1026
> Project: Apache Jena
> Issue Type: Bug
> Components: Ontology API
> Affects Versions: Jena 3.0.0
> Environment: Verified on Jena 3.0.1-SNAPSHOT (2015-09-13) w/ Ubuntu
> 14.04/x64, 4 cores i7-3520M, 16G ram, SSD disk, Open JDK 1.8.0_45-internal
> Reporter: Stian Soiland-Reyes
> Priority: Minor
> Attachments: OntologiaDeAlimentos.owl,
> lpb-trace-of-not-much-food.txt, not-much-food.ttl, onto.java
>
>
> As [reported by Maria Clementina
> Latanzi|http://mail-archives.apache.org/mod_mbox/jena-dev/201509.mbox/%3CCAMOD-YqMEmXqTGnHCEinZb9DSruOnhhDZxXUU%2BvX1m_0%3DKJnEg%40mail.gmail.com%3E]
> on dev@jena 2015-09-12:
> {quote}
> 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.
> {quote}
> {code}
> package testOnto;
> import java.io.InputStream;
> import java.util.ArrayList;
> import java.util.Iterator;
> import com.hp.hpl.jena.ontology.Individual;
> import com.hp.hpl.jena.ontology.OntClass;
> import com.hp.hpl.jena.ontology.OntModel;
> import com.hp.hpl.jena.rdf.model.ModelFactory;
> import com.hp.hpl.jena.rdf.model.Resource;
> import com.hp.hpl.jena.rdf.model.Property;
> import com.hp.hpl.jena.rdf.model.StmtIterator;
> import com.hp.hpl.jena.rdf.model.impl.StatementImpl;
> import com.hp.hpl.jena.shared.JenaException;
> import com.hp.hpl.jena.util.FileManager;
> import com.hp.hpl.jena.util.iterator.ExtendedIterator;
> public class onto {
> static String Ontofile =
> "C:/Users/Sig/Clemen/OntologiasArchivos/OntologiaIngesta.owl";
> public static void main(String[] args) {
> //crea ontologia
> OntModel m = ModelFactory.createOntologyModel();
> try {
> InputStream in =
> FileManager.get().open("C:/Users/Sig/Clemen/OntologiasArchivosOntologiaDeAlimentos.owl");
> if (in ==null) {
> System.out.println("ERROR abriendo archivo" + Ontofile);
> return;
> }
> else { m.read(in, "RDF/XML");
> System.out.println("archivo" + Ontofile + "leido
> exitosamente" );
> }
> } catch (JenaException je) {
> System.out.println("ERROR leyendo archivo" + je.getMessage());
> je.printStackTrace();
> System.exit(0);
> }
> long startMilC = System.currentTimeMillis();
> System.out.println("Start list classes: " + startMilC);
> ExtendedIterator classes = m.listClasses();
> long endMilC = System.currentTimeMillis();
> System.out.println("Duration ListIndividuals: " + (endMilC
> -startMilC));
> long startMil = System.currentTimeMillis();
> System.out.println("Start ListIndividuals: " + startMil);
> ExtendedIterator individuos = m.listIndividuals();
> long endMil = System.currentTimeMillis();
> System.out.println("Duration ListIndividuals: " + (endMil -
> startMil));
> }
> }
> {code}
> See attached ontology and test case.
> Verified against current 3.0.1-SNAPSHOT.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)