You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Steve Vestal <st...@adventiumlabs.com> on 2017/10/06 01:18:50 UTC
What might cause a writeAll stack overflow?
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.
Re: What might cause a writeAll stack overflow?
Posted by Andy Seaborne <an...@apache.org>.
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
>>> <steve.vestal@adventiumlabs.com
>>>> 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.
>>>>
>>>>
>
Re: What might cause a writeAll stack overflow?
Posted by Dave Reynolds <da...@gmail.com>.
On 06/10/17 18:46, Steve Vestal wrote:
> I do have reasoning enabled, but it seems to have done its job by the
> time I'm ready for output.
No, unless you are using your own rules then only the forward rules will
have run. The backward rules are run in response to queries. A writeAll
in RDF/XML format effective turns into a huge load of queries each of
which will trigger lots of backward rule firing.
> Is there a way to turn it off before the write?
Not really. Among your options are:
1. If you want the whole closure then try materializing everything first
as I explained below. That can be more efficient but also gives you control.
2. If you only want whatever the forward rules have done but none of the
rest then create a union of the baseModel and deductionsModel and write
that.
3. If you want selective inference results then get those by issuing the
corresponding queries and copy the results in a working model before
writing that out.
Dave
>
> On 10/6/2017 1:26 AM, 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
>>>> <steve.vestal@adventiumlabs.com
>>>>> 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.
>>>>>
>>>>>
>>
>
Re: What might cause a writeAll stack overflow?
Posted by Dave Reynolds <da...@gmail.com>.
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 <steve.vestal@adventiumlabs.com
>>> 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.
>>>
>>>
Re: What might cause a writeAll stack overflow?
Posted by Steve Vestal <st...@adventiumlabs.com>.
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 <steve.vestal@adventiumlabs.com
>> 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.
>>
>>
Re: What might cause a writeAll stack overflow?
Posted by David Jordan <jd...@gmail.com>.
Recursion.
Try increasing the stack size of your JVM when you run it.
On Thu, Oct 5, 2017 at 9:18 PM, Steve Vestal <steve.vestal@adventiumlabs.com
> 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.
>
>