You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Dick & Hannah <da...@gmail.com> on 2012/03/30 11:28:39 UTC
Filtering a model.
Hello all.
I need to filter a model i.e. all statements howsoever returned need to be checked and possibly one or more discarded.
Having viewed the model and graph I found the filter and caveats around the final methods with regards to reification. Is it simply a case of subclassing the Filter and passing it to a constructor or is there a base iterator?
Is what I require achievable? If so what's the best way to achieve it?
Regards
Dick Murray
Technology Specialist
UNIT4 Business Software
www.unit4.com
+44 1275 377359
+44 7884 111729
Re: Filtering a model.
Posted by Chris Dollin <eh...@electrichedgehog.net>.
On Friday 30 March 2012, Dick & Hannah wrote:
> I need to filter a model i.e. all statements howsoever returned need
> to be checked and possibly one or more discarded.
>
> Having viewed the model and graph I found the filter and caveats
> around the final methods with regards to reification. Is it simply
> a case of subclassing the Filter and passing it to a constructor
> or is there a base iterator?
>
> Is what I require achievable? If so what's the best way to achieve it?
I would
-- use listStatements() to get an ExtendedIterator over the model
-- use FilterKeep(F) or FilterDrop(F) to select only those items you
want to discard, writing an implemention F of Filter that does the
selection
-- use toList to turn the iterator into a list
-- then remove the list from the model
Something like this:
m.remove( m.listStatements().filterDrop(badStatement).toList() )
[split up to taste]
where BadStatement is a Filter that recognises the statements you
want to discard. (Or of course filterKeep(goodStatement).)
Note that it is IMPORTANT to make up the complete list and then
remove it from the model, because you're not allowed to update
a model while you're iterating through it.
I wouldn't worry about reification unless what you're doing is
something abiout reification, in which case, you need to say
what that is.
Chris
--
Far-Fetched Hedgehog
"The path to the web becomes deeper and wider" - October Project