耶拿;迭代超类时java堆空间错误

时间:2015-01-19 22:03:22

标签: java jena owl

在Eclipse平台中使用Jena,我正在为给定的类编写一段代码,获取所有超类。我知道常见的Java堆空间问题,并且我已经为完成任务分配了1 G.B内存,但它触发了:java.lang.OutOfMemoryError: Java heap space at java.util.ArrayList.<init>(Unknown Source)exception.

Here是我正在使用的本体。

我的代码通常在第8次迭代后失败,或者更少在if上失败。任何人都可以告诉我这个或做什么的原因?我知道这个本体有点大但是发生了什么逻辑? (当我在没有推理者的情况下使用OntModelSpec时,例如OWL_DL_MEM&#39;,一切正常。)

ModelFactory model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
    this.model.read(convertPathToURI("some-path", "eu-car-rental.rdf"), "RDF/XML");     

    ExtendedIterator<OntClass> classes = getClassByURI("RentalAgreement").listSuperClasses();
    while (classes.hasNext()){
        OntClass oc = classes.next();
        System.out.println("something");
    }
    System.out.println("----finished----");

这是函数getClassByURI

public OntClass getClassByURI (String classURI)
{
    String myNS = model.getNsPrefixURI("");
    Resource r = model.getResource(myNS + classURI );       
    OntClass cls = (OntClass) r.as( OntClass.class );
    //System.out.println("++++++++++++  " + cls.getURI());
    //List<OntProperty> exItr = getClassProperties(cls,2, true);            
    return cls;
}

1 个答案:

答案 0 :(得分:2)

我可以重现你的问题。将来,请提供完整,简约,实用的示例。下面的代码是很好的例子;任何人都可以复制并运行它。代码:

import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class OWLSuperclassExample {
    public static void main(String[] args) {
        OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
        model.read("http://www.lsi.upc.edu/~%20oromero/EUCarRental.owl");
        OntClass rentalAgreement = 
            model.getOntClass("http://www.owl-ontologies.com/unnamed.owl#RentalAgreement");
        ExtendedIterator<OntClass> classes = rentalAgreement.listSuperClasses();
        while ( classes.hasNext() ) {
            System.out.println( "Superclass: " + classes.next() );
        }
        System.out.println("Completed.");
    }
}
Superclass: http://www.w3.org/2000/01/rdf-schema#Resource
Superclass: 75bdf39:14b07a39a79:-7f4c
Superclass: 75bdf39:14b07a39a79:-7f4b
Superclass: 75bdf39:14b07a39a79:-7f46
Superclass: 75bdf39:14b07a39a79:-7f4a
Superclass: 75bdf39:14b07a39a79:-7f4f
Superclass: http://www.w3.org/2002/07/owl#Thing
Superclass: 75bdf39:14b07a39a79:-7f4d
Superclass: 75bdf39:14b07a39a79:-7f47
Superclass: 75bdf39:14b07a39a79:-7f48
Superclass: 75bdf39:14b07a39a79:-7f50
Superclass: 75bdf39:14b07a39a79:-7f4e
Superclass: 75bdf39:14b07a39a79:-7f51
Superclass: 75bdf39:14b07a39a79:-7f49
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 92463104 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/taylorj/tmp/workspace/taylorj-jena-examples/hs_err_pid21802.log
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000deee4000, 92463104, 0) failed; error='Cannot allocate memory' (errno=12)

在Jena规则推理器中,它看起来像某种错误,或者至少是意外的行为。有一些事情可能是罪魁祸首:

  1. Jena的OWL reasoners 逻辑上不完整设计。这意味着他们不会产生合法的OWL合法结论。这是设计原因,因为使用基于规则的推理无法完全实现OWL语义。
  2. Jena的OWL reasoners适用于 OWL1 。如果这个本体具有OWL2的一部分,则可能会产生干扰。
  3. Jena的OWL reasoners用于某种OWL Full,它对三元组出现的限制比OWL DL更少。可能会出现这样的情况:规则正在应用于您不希望出现的情况,这可能会产生干扰。