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