gpt4 book ai didi

java - 耶拿;迭代父类(super class)时出现java堆空间错误

转载 作者:行者123 更新时间:2023-12-02 05:03:25 25 4
gpt4 key购买 nike

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

Here是我正在使用的本体。

我的代码通常在第 8 次迭代或更少的 if 迭代后失败。谁能告诉我原因或该怎么办?我知道这个本体有点大,但是发生的事情符合逻辑吗? (当我使用 OntModelSpec 而不使用推理器“例如 OWL_DL_MEM ”时,一切正常)。

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;
}

最佳答案

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

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)

看起来这是耶拿规则推理器中的某种错误,或者至少是意外行为。有几件事可能是罪魁祸首:

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

关于java - 耶拿;迭代父类(super class)时出现java堆空间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28034276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com