Another possibility:

The RDF/XML pretty writer can use a lot of stack if it encounters certain data patterns where there are choices of how to write the top-most level tags. The solution is to either find the formatting rule that causes the problem or write using the plain writer.

Nowadays, "RDF/XML" is the same as "RDFX/XML-ABBREV" (and the number of questions here and on StackOveflow about RDF/XML format went down).

You can control choice of RDF/XML output with either:

RDFDataMgr.write(System.out, ontmodel, RDFFormat.RDFXML_PLAIN );
or
RDFDataMgr.write(System.out, ontmodel, RDFFormat.RDFXML_ABBREV );

(That's a "writeAll" - use ontmodel.getBaseModel() to get the effect of OntModel.write)

    Andy

>>>>      .......

That's the important bit.

On 06/10/17 07:26, Dave Reynolds wrote:
If your myOntology object is an OntModel and has reasoning enabled then writeAll will ask it to create the entire closure of the model before (well as part of) writing it out. The closure of the model can be a *lot* bigger than the model.

Technically the closure can be infinite but part of the reason the rule sets offer only incomplete OWL and RDFS reasoning fragments is to avoid the infinite cases as best they can.

That said, there's no evidence of a reasoner in your example stack trace.

WriteAll will also include the imported ontologies. If you have very large imports then that would both blow up the reasoning and increase the output size.

Apart from just turning off reasoning then one way to investigate this is to separate the steps.

First create a new in-memory model add add your OntModel to it (model#add). That will materialize all the closure. If that completes successfully then you both have a simple model you can write out but you also know the size of the closure.

If that does complete successfully but write as RDF/XML still fails then try with RDF/XML-ABBREV.

Dave

On 06/10/17 02:40, Steve Vestal wrote:
64m, enough to hold the entire model several times over.


On 10/5/2017 8:32 PM, David Jordan wrote:
Recursion.

Try increasing the stack size of your JVM when you run it.


On Thu, Oct 5, 2017 at 9:18 PM, Steve Vestal <[email protected]
wrote:
What might cause

             myOntology.writeAll(outStream, "RDF/XML");

(where myOntology is an OntModel) to get a stack overflow

java.lang.StackOverflowError
     at java.util.regex.Pattern$GroupHead.match(Unknown Source)
     at java.util.regex.Pattern$BmpCharProperty.match(Unknown Source)
     .......
     at org.apache.jena.iri.impl.Parser.<init>(Parser.java:90)
     at org.apache.jena.iri.impl.IRIImpl.<init>(IRIImpl.java:65)
     at
org.apache.jena.iri.impl.AbsIRIFactoryImpl.create(
AbsIRIFactoryImpl.java:40)
     at
org.apache.jena.iri.impl.IRIFactoryImpl.create(IRIFactoryImpl.java:264)
     at org.apache.jena.riot.system.PrefixMapStd.add(PrefixMapStd.java:69)
     at java.util.HashMap.forEach(Unknown Source)
     at
org.apache.jena.riot.system.PrefixMapBase.putAll(PrefixMapBase.java:76)

Changing "writeAll" to "write" works fine.



Reply via email to