/** Given an Iterator that returns Iterator's, this creates an * Iterator over the next level values. * Similar to list splicing in lisp. */ public static <T> ExtendedIterator<T> createIteratorIterator( Iterator<Iterator<T>> it ) { ExtendedIterator<T> retval = NullIterator.instance(); while (it.hasNext()) { retval = retval.andThen(it.next()); } return retval; }
public ExtendedIterator<T> andThen(ClosableIterator<? extends T> other) { lazy(); return it.andThen(other); }
/** * {@inheritDoc} */ @Override protected ExtendedIterator<Triple> graphBaseFind(TripleMatch m) { ExtendedIterator<Triple> result = NullIterator.instance(); for (final Graph g : m_subGraphs) { result = result.andThen(g.find(m)); } return result; }
public Iterator<GraphNode> concatenateSiblings( Iterator<GraphNode> base ) { return WrappedIterator.create( base ).andThen( siblings.siblingIterator() ); }
public ExtendedIterator<Key> keyIterator( final NotifyEmpty container ) { showkeys(); final List<Key> movedKeys = new ArrayList<Key>(); ExtendedIterator<Key> basic = new BasicKeyIterator( changes, container, movedKeys ); ExtendedIterator<Key> leftovers = new MovedKeysIterator( changes, container, movedKeys ); return basic.andThen( leftovers ); }
@Override protected ExtendedIterator<Triple> _graphBaseFind( TripleMatch m ) { return L.find( m ) .andThen( R.find( m ) ); }
/** * <p>Answer an iterator over all of the ontology properties in this model, including * object properties, datatype properties, annotation properties, etc. This method * takes a different approach to calculating the set of property resources to return, * and is robust against the absence of a reasoner attached to the model (see note * in {@link #listOntProperties()} for explanation). However, the calculation used by * this method is potentially less efficient than the alternative <code>listOntProperties()</code>. * Users whose models have an attached reasoner are recommended to use * {@link #listOntProperties()}.</p> * @return An iterator over all available properties in a model, irrespective of * whether a reasoner is available to perform <code>rdf:type</code> entailments. * Each property will appear exactly once in the iterator. */ @Override public ExtendedIterator<OntProperty> listAllOntProperties() { ExtendedIterator<OntProperty> i = findByTypeAs( RDF.Property, OntProperty.class ) .andThen( listObjectProperties() ) .andThen( listDatatypeProperties() ) .andThen( listAnnotationProperties() ) .andThen( listFunctionalProperties() ) .andThen( listTransitiveProperties() ) .andThen( listSymmetricProperties() ); // we must filter for uniqueness return i.filterKeep( new UniqueFilter<OntProperty>()); }
@Override public ExtendedIterator<Triple> find(final KnowledgeBase kb, final PelletInfGraph pellet, final Node subj, final Node pred, Node obj) { ExtendedIterator<Triple> builtinTypes = WrappedIterator.create( new NestedIterator<Node,Triple>( Arrays.asList( BUILTIN_TYPES ) ) { @Override public Iterator<Triple> getInnerIterator(Node builtinType) { return findTriple( kb, pellet, subj, pred, builtinType ); } } ); ExtendedIterator<Triple> typeAssertions = WrappedIterator.create( new NestedIterator<ATermAppl,Triple>( kb.getAllClasses() ) { @Override public Iterator<Triple> getInnerIterator(ATermAppl cls) { return subjectFiller( kb.getInstances( cls ), pred, JenaUtils.makeGraphResource( cls ) ); } } ); return builtinTypes.andThen( typeAssertions ); } }
@Override public ExtendedIterator<Triple> find(final KnowledgeBase kb, final PelletInfGraph pellet, final Node s, final Node p, final Node o) { ExtendedIterator<Triple> builtinPredicates = NullIterator.instance(); if( !pellet.isSkipBuiltinPredicates() ) { for( Node pred : BUILTIN_PREDICATES ) { builtinPredicates = builtinPredicates.andThen( findTriple( kb, pellet, s, pred, o ) ); } } ExtendedIterator<Triple> propertyAssertions = WrappedIterator.create( new NestedIterator<ATermAppl,Triple>( kb.getProperties() ) { @Override public Iterator<Triple> getInnerIterator(ATermAppl prop) { Node p = JenaUtils.makeGraphNode( prop ); return findTriple( kb, pellet, s, p, o ); } } ); return builtinPredicates.andThen( propertyAssertions ); } }
/** * This fires a triple into the current RETE network. * This format of call is used in the unit testing but needs to be public * because the tester is in another package. */ public void testTripleInsert(Triple t) { Iterator<RETENode> i1 = clauseIndex.getAll(t.getPredicate()); Iterator<RETENode> i2 = clauseIndex.getAll(Node.ANY); Iterator<RETENode> i = WrappedIterator.create( i1 ).andThen( i2 ); while (i.hasNext()) { RETEClauseFilter cf = (RETEClauseFilter) i.next(); cf.fire(t, true); } }
/** * <p> * Answer an iterator over all of the resources that have * <code>rdf:type type</code>, or optionally, one of the alternative types. * </p> * * @param type The resource that is the value of <code>rdf:type</code> we * want to match * @param alternates An iterator over alternative types to search for, or null * @return An iterator over all triples <code>_x rdf:type t</code> where t * is <code>type</code> or one of the values from <code>types</code>. */ protected ExtendedIterator<Triple> findByType( Resource type, Iterator<Resource> alternates ) { ExtendedIterator<Triple> i = findByType( type ); // compose onto i the find iterators for the alternate types if (alternates != null) { while (alternates.hasNext()) { i = i.andThen( findByType( alternates.next() ) ); } } return i.filterKeep( new UniqueFilter<Triple>()); }
/** * Answer the concatenation of all the iterators from a-subGraph.find( t ). */ private ExtendedIterator<Triple> multiGraphFind(final TripleMatch t) { Set<Triple> seen = CollectionFactory.createHashedSet() ; ExtendedIterator<Triple> result = NullIterator.instance() ; boolean finished = false ; try { for (Iterator<Graph> graphs = m_subGraphs.iterator(); graphs.hasNext();) { ExtendedIterator<Triple> newTriples = recording(rejecting(graphs.next().find(t), seen), seen) ; result = result.andThen(newTriples) ; } finished = true ; return result ; } finally { // Throwable happened. if (!finished) result.close() ; } }
@Override public ExtendedIterator<Triple> find(final KnowledgeBase kb, final PelletInfGraph pellet, final Node s, final Node p, final Node o) { ExtendedIterator<Triple> builtinPredicates = NullIterator.instance(); if( !o.isLiteral() && !pellet.isSkipBuiltinPredicates() ) { for( Node pred : BUILTIN_PREDICATES ) { builtinPredicates = builtinPredicates.andThen( findTriple( kb, pellet, s, pred, o ) ); } } ExtendedIterator<Triple> propertyAssertions = WrappedIterator.create( new NestedIterator<ATermAppl,Triple>( kb.getProperties() ) { @Override public Iterator<Triple> getInnerIterator(ATermAppl prop) { Node p = JenaUtils.makeGraphNode( prop ); return findTriple( kb, pellet, s, p, o ); } } ); return builtinPredicates.andThen( propertyAssertions ); } }
/** * Inject a single triple into the RETE network */ private void inject(Triple t, boolean isAdd) { if (infGraph.shouldTrace()) { logger.debug((isAdd ? "Inserting" : "Deleting") + " triple: " + PrintUtil.print(t)); } Iterator<RETENode> i1 = clauseIndex.getAll(t.getPredicate()); Iterator<RETENode> i2 = clauseIndex.getAll(Node.ANY); Iterator<RETENode> i = WrappedIterator.create(i1).andThen( i2 ); while (i.hasNext()) { RETEClauseFilter cf = (RETEClauseFilter) i.next(); // firedRules guard in here? cf.fire(t, isAdd); } }
/** * Find all the base triples matching tm, exclude the ones that are deleted, * add the ones that have been added. */ @Override protected ExtendedIterator<Triple> _graphBaseFind(TripleMatch tm) { return base.find(tm).filterDrop(ifIn(GraphUtil.findAll(R))).andThen(L.find(tm)) ; }
/** To find in the union, find in the components, concatenate the results, and omit duplicates. That last is a performance penalty, but I see no way to remove it unless we know the graphs do not overlap. */ @Override protected ExtendedIterator<Triple> _graphBaseFind( final TripleMatch t ) { Set<Triple> seen = CollectionFactory.createHashedSet(); return recording( L.find( t ), seen ).andThen( rejecting( R.find( t ), seen ) ); // return L.find( t ) .andThen( rejecting( R.find( t ), L ) ); } }
/** * Extended find interface used in situations where the implementator * may or may not be able to answer the complete query. It will * attempt to answer the pattern but if its answers are not known * to be complete then it will also pass the request on to the nested * Finder to append more results. * @param pattern a TriplePattern to be matched against the data * @param continuation either a Finder or a normal Graph which * will be asked for additional match results if the implementor * may not have completely satisfied the query. */ @Override public ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder continuation) { if (graph == null) return new NullIterator<Triple>(); if (continuation == null) { return graph.find(pattern.asTripleMatch()); } else { return graph.find(pattern.asTripleMatch()).andThen(continuation.find(pattern)); } }
/** * Extended find interface used in situations where the implementator * may or may not be able to answer the complete query. It will * attempt to answer the pattern but if its answers are not known * to be complete then it will also pass the request on to the nested * Finder to append more results. * @param pattern a TriplePattern to be matched against the data * @param continuation either a Finder or a normal Graph which * will be asked for additional match results if the implementor * may not have completely satisfied the query. */ @Override public synchronized ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder continuation) { checkOpen(); this.requirePrepared(); ExtendedIterator<Triple> result = engine.find(pattern).filterKeep( new UniqueFilter<Triple>()); if (continuation != null) { result = result.andThen(continuation.find(pattern)); } return result.filterDrop(Functor.acceptFilter); }
@Override public ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder finder) { prepare(); Node subject = pattern.getSubject(); Node predicate = pattern.getPredicate(); Node object = pattern.getObject(); ExtendedIterator<Triple> i = GraphQueryHandler.findTriple( kb, this, subject, predicate, object ); // always look at asserted triples at the end if( finder != null ) { TriplePattern tp = new TriplePattern( subject, predicate, object ); i = i.andThen( finder.find( tp ) ); } // make sure we don't have duplicates return UniqueExtendedIterator.create( i ); }
@Override public ExtendedIterator<Triple> find(KnowledgeBase kb, PelletInfGraph pellet, final Node s, final Node p, Node o) { ExtendedIterator<Triple> result = NullIterator.instance(); ATermAppl subj = pellet.getLoader().node2term( s ); ATermAppl obj = pellet.getLoader().node2term( o ); if( kb.isIndividual( subj ) || kb.isIndividual( obj ) ) { if( kb.isIndividual( subj )) { List<ATermAppl> properties = kb.getProperties( pellet.getLoader().node2term( s ), pellet.getLoader().node2term( o ) ); result = propertyFiller( s, properties, o ); if(kb.isIndividual( obj ) ) { if( kb.isSameAs( subj, obj ) ) result = result.andThen( new SingletonIterator<Triple>( Triple.create( s, OWL.sameAs.asNode(), o ) ) ); if( kb.isDifferentFrom( subj, obj ) ) result = result.andThen( new SingletonIterator<Triple>( Triple.create( s, OWL.differentFrom.asNode(), o ) ) ); } } } else if( !pellet.isSkipBuiltinPredicates() ) { for( Node pred : BUILTIN_PREDICATES ) { result = result.andThen( findTriple( kb, pellet, s, pred, o ) ); } } return result; } }