FYI
-------- Forwarded Message --------
Subject: Re: What might cause a writeAll stack overflow?
Date: Thu, 12 Oct 2017 16:24:26 +0100
From: Andy Seaborne <[email protected]>
To: Steve Vestal <[email protected]>, Dave Reynolds
<[email protected]>
Steve,
Thanks for the update.
Could I ask you to send this to the users mailing list?
We may wish to provide model.write names "RDF/XML:plain" and
"RDF/XML:abbrev" to expose what's possible with RDFDataMgr to model.write.
A stacktrace for the NPE would be useful.
Andy
On 11/10/17 11:22, Steve Vestal wrote:
> Thanks for the help. This is FYI to let you know how your suggestions
> worked out, and in case you had any final advice for future reference.
> My take-away is that Jena is being clever in its RDF/XML formatter, but
> it may be lower risk to choose another format where suitable.
>
> As you won't recall, I was getting stack overflow on a
> myOntology.writeAll("RDF/XML") call.
>
> The following calls succeed:
>
> OntModel testOntology = ModelFactory.createOntologyModel(
> OntModelSpec.OWL_MEM); // And with OWL_MEM_RULE_INF
> testOntology.add(myOntology);
>
> myOntology.writeAll(out, "N-TRIPLE");
>
> RDFDataMgr.write(out, myOntology.getBaseModel(), RDFFormat.RDFXML_ABBREV );
>
> The following calls fail with stack overflow:
>
> myOntology.writeAll(out, "RDF/XML"); // Original issue
>
> RDFDataMgr.write(out, myOntology, RDFFormat.RDFXML_ABBREV );
>
> The following call fails by getting into an infinite loop when
> testOntology is OWL_MEM_RULE_INF and with a null pointer exception when
> testOntology is OWL_MEM:
>
> RDFDataMgr.write(out, testOntology, RDFFormat.RDFXML_ABBREV );
>
>
>
> On 10/6/2017 5:29 AM, Andy Seaborne wrote:
>> 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.
>>>>>>
>>>>>>
>>>
>
>