@Deprecated @Override public Iterator<Statement> match(Resource subj, IRI pred, Value obj, Resource... contexts) { return this.filter(subj, pred, obj, contexts).iterator(); }
public Iterator<Statement> iterator() { return getDelegate().iterator(); }
@Override public Iterator<Statement> iterator() { return getDelegate().filter(subj, pred, obj, contexts) .iterator(); } };
@Override public void removeAllNaturalText(String field, String... languages) throws IllegalArgumentException { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } ValueTypeFilter<Literal> vtf = new ValueTypeFilter<Literal>(languages); Iterator<Statement> statements = model.filter( subject, sesameFactory.createURI(field), null).iterator(); while(statements.hasNext()){ Statement statement = statements.next(); if(vtf.evaluate(statement.getObject())){ statements.remove(); } } }
@Override public void removeAllNaturalText(String field, String... languages) throws IllegalArgumentException { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } ValueTypeFilter<Literal> vtf = new ValueTypeFilter<Literal>(languages); Iterator<Statement> statements = model.filter( subject, sesameFactory.createURI(field), null).iterator(); while(statements.hasNext()){ Statement statement = statements.next(); if(vtf.evaluate(statement.getObject())){ statements.remove(); } } }
private CloseableIteration<? extends Statement, SailException> union( CloseableIteration<? extends Statement, SailException> result, Model included) { if (included.isEmpty()) { return result; } final Iterator<Statement> iter = included.iterator(); CloseableIteration<Statement, SailException> incl; incl = new CloseableIteratorIteration<Statement, SailException>(iter); return new UnionIteration<Statement, SailException>(incl, result); }
@Override @SuppressWarnings("unchecked") public Iterator<Reference> getReferences(String field) { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); return IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement new ValueTypeFilter<Reference>(Reference.class)), //filter references org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); //transform to Text instances }
@Override @SuppressWarnings("unchecked") public Iterator<Reference> getReferences(String field) { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); return IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement new ValueTypeFilter<Reference>(Reference.class)), //filter references org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); //transform to Text instances }
/** * Fetches a collection of generalized lists based on the given subject and * predicate, where lists are allowed to branch from head to tail. * * @param subject the subject of a statement pointing to the list * @param predicate the predicate of a statement pointing to the list * @param graphToSearch the Model from which the list is to be fetched * @param contexts the Model contexts from which the list is to be fetched * @return all matching lists. If no matching lists are found, an empty * collection is returned. */ public Collection<List<Value>> getListsAtNode( final Resource subject, final IRI predicate, final Model graphToSearch, final Resource... contexts) { OpenRDFUtil.verifyContextNotNull(contexts); Collection<List<Value>> results; final Iterator<Statement> headStatementMatches = graphToSearch.filter( subject, predicate, null, contexts).iterator(); final Set<Resource> heads = new HashSet<>(); while (headStatementMatches.hasNext()) { final Statement nextHeadStatement = headStatementMatches.next(); if (nextHeadStatement.getObject() instanceof Resource) { heads.add((Resource) nextHeadStatement.getObject()); } } results = this.getLists(heads, graphToSearch, contexts); return results; }
@Override @SuppressWarnings("unchecked") public <T> Iterator<T> get(String field, final Class<T> type) throws UnsupportedTypeException { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); //filter for values that are compatible with the parsed type Iterator<?> iterator = IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement new ValueTypeFilter<T>(type)); if(!Value.class.isAssignableFrom(type)){ //if the requested type is not a Sesame value, we need also to //transform results iterator = IteratorUtils.transformedIterator( iterator, // the already filtered values org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); // need to be transformed } return (Iterator<T>)iterator; }
@Override @SuppressWarnings("unchecked") public <T> Iterator<T> get(String field, final Class<T> type) throws UnsupportedTypeException { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); //filter for values that are compatible with the parsed type Iterator<?> iterator = IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement new ValueTypeFilter<T>(type)); if(!Value.class.isAssignableFrom(type)){ //if the requested type is not a Sesame value, we need also to //transform results iterator = IteratorUtils.transformedIterator( iterator, // the already filtered values org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); // need to be transformed } return (Iterator<T>)iterator; }
@Override @SuppressWarnings("unchecked") public Iterator<Object> get(String field) throws IllegalArgumentException { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); return IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement notPredicate(instanceofPredicate(BNode.class))), org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); // transform the values }
@Override @SuppressWarnings("unchecked") public Iterator<Object> get(String field) throws IllegalArgumentException { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); return IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement notPredicate(instanceofPredicate(BNode.class))), org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); // transform the values }
@Override @SuppressWarnings("unchecked") public Iterator<Text> get(String field, String...languages) { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); return IteratorUtils.transformedIterator( IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement new ValueTypeFilter<Text>(languages)), //filter languages org.apache.stanbol.entityhub.model.sesame.ModelUtils.STRING_LITERAL_TO_TEXT_TRANSFORMER), //transform strings to Text org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); //transform to Text instances }
@Override @SuppressWarnings("unchecked") public Iterator<Text> getText(String field) { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); return IteratorUtils.transformedIterator( IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement new ValueTypeFilter<Text>(Text.class)), //filter plain literals org.apache.stanbol.entityhub.model.sesame.ModelUtils.STRING_LITERAL_TO_TEXT_TRANSFORMER), org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); //transform to Text instances }
@Override @SuppressWarnings("unchecked") public Iterator<Text> get(String field, String...languages) { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); return IteratorUtils.transformedIterator( IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement new ValueTypeFilter<Text>(languages)), //filter languages org.apache.stanbol.entityhub.model.sesame.ModelUtils.STRING_LITERAL_TO_TEXT_TRANSFORMER), //transform strings to Text org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); //transform to Text instances }
@Override @SuppressWarnings("unchecked") public Iterator<Text> getText(String field) { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); return IteratorUtils.transformedIterator( IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement new ValueTypeFilter<Text>(Text.class)), //filter plain literals org.apache.stanbol.entityhub.model.sesame.ModelUtils.STRING_LITERAL_TO_TEXT_TRANSFORMER), org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); //transform to Text instances }
/** * Get the statements for the query pattern passed as arguments. In case the subject resource is acceptable for caching, * refreshes the cache for this resource and returns a merged query result together with the wrapped connection. * Otherwise, simply delegates to the wrapped connection. * * @param subj * @param pred * @param obj * @param includeInferred * @param contexts * @return * @throws SailException */ @Override public CloseableIteration<? extends Statement, SailException> getStatements(Resource subj, URI pred, Value obj, boolean includeInferred, Resource... contexts) throws SailException { if (accept(subj)) { log.debug("Refreshing resource: {}", subj.stringValue()); final Model cached = ldcache.get((URI)subj); // join the results of the cache connection and the wrapped connection in a single result return new UnionIteration<>( new CloseableIteratorIteration<Statement, SailException>(cached.iterator()), super.getStatements(subj, pred, obj, includeInferred, contexts) ); } else { return super.getStatements(subj, pred, obj, includeInferred, contexts); } }
@Override public CloseableIteration<BindingSet, QueryEvaluationException> evaluate( BindingSet bindings) throws QueryEvaluationException { if (this.bindings != null) { QueryBindingSet b = new QueryBindingSet(bindings); b.addAll(this.bindings); bindings = b; } CloseableIteration<? extends Statement, QueryEvaluationException> stIter = null; try { Resource[] contexts = contexts(sp, dataset, bindings); if (contexts == null) return new EmptyIteration<BindingSet, QueryEvaluationException>(); Iterator<Statement> iter = filter(model, bindings).iterator(); stIter = new CloseableIteratorIteration<Statement, QueryEvaluationException>(iter); if (contexts.length == 0 && sp.getScope() == Scope.NAMED_CONTEXTS) { stIter = new NamedContextCursor(stIter); } } catch (ClassCastException e) { // Invalid value type for subject, predicate and/or context return new EmptyIteration<BindingSet, QueryEvaluationException>(); } // The same variable might have been used multiple times in this // StatementPattern, verify value equality in those cases. stIter = new StatementPatternCursor(stIter, sp); // Return an iterator that converts the statements to var bindings return new StatementBindingSetCursor(stIter, sp, bindings); }