@Deprecated @Override public Iterator<Statement> match(Resource subj, IRI pred, Value obj, Resource... contexts) { return this.filter(subj, pred, obj, contexts).iterator(); }
@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(); }
public Iterator<Statement> iterator() { return getDelegate().iterator(); }
@Override public Iterator<Statement> iterator() { return getDelegate().filter(subj, pred, obj, contexts).iterator(); }
@Override public Iterator<Statement> iterator() { return getDelegate().filter(subj, pred, obj, contexts).iterator(); }
/** * Filters all triples from the specified graph that do not exist in the underlying data source * * @param theData the data to be filtered * @return a graph that contains only triples that already exist in the data source * @throws DataSourceException if querying the data source causes an error */ private Model existingTriples(Model theData) throws DataSourceException { Model aResult = Models2.newModel(); // TODO: is there a more efficient way to check that than triple-by-triple? // (for remote data sources this will cause one request for triple ...) for (Iterator<Statement> it = theData.iterator(); it.hasNext(); ) { Statement statement = it.next(); if (existsInDataSource(statement)) { aResult.add(statement); } } return aResult; }
private Resource getResource(Model model) { Iterator<Statement> st = model.iterator(); while (st.hasNext()) { Statement s = st.next(); if ((s.getPredicate().equals(RDF.TYPE))) { if (isRootElement(s)) { return s.getSubject(); } } } return null; }
/** * Filters all triples from the specified graph that already exist in the underlying data source * * @param theData the data to be filtered * @return a graph that contains only triples that do not exist in the data source * @throws DataSourceException if querying the data source causes an error */ private Model nonExistingTriples(Model theData) throws DataSourceException { Model aResult = Models2.newModel(); // TODO: is there a more efficient way to check that than triple-by-triple? // (for remote data sources this will cause one request for triple ...) for (Iterator<Statement> it = theData.iterator(); it.hasNext(); ) { Statement statement = it.next(); if (!existsInDataSource(statement)) { aResult.add(statement); } } return aResult; }
@Override public RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException { Model model = committed.filter(subj, pred, obj, contexts); CloseableIteration<Statement, RepositoryException> iter; iter = new CloseableIteratorIteration<>(model.iterator()); return new RepositoryResult<>(iter); }
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); }
private static Statement getIDStatement(Model model, String repositoryID) { Literal idLiteral = SimpleValueFactory.getInstance().createLiteral(repositoryID); Model idStatementList = model.filter(null, REPOSITORYID, idLiteral); if (idStatementList.size() == 1) { return idStatementList.iterator().next(); } else if (idStatementList.isEmpty()) { return null; } else { throw new RepositoryConfigException("Multiple ID-statements for repository ID " + repositoryID); } }
private static Statement getIDStatement(Model model, String repositoryID) { Literal idLiteral = SimpleValueFactory.getInstance().createLiteral(repositoryID); Model idStatementList = model.filter(null, REPOSITORYID, idLiteral); if (idStatementList.size() == 1) { return idStatementList.iterator().next(); } else if (idStatementList.isEmpty()) { return null; } else { throw new RepositoryConfigException("Multiple ID-statements for repository ID " + repositoryID); } }
@Test public void testGetListsSingleNullContext() { this.testRdfListUtilDefaults.addListAtNode( this.testSubjectUri1, this.testPredicateUri1, this.testValuesSingleUri, this.testGraph); assertEquals(3, this.testGraph.size()); // Find the head node that was generated by this method final Iterator<Statement> match = this.testGraph.filter(this.testSubjectUri1, this.testPredicateUri1, null).iterator(); assertTrue(match.hasNext()); final Statement matchedStatement = match.next(); assertNotNull(matchedStatement); assertFalse(match.hasNext()); assertTrue(matchedStatement.getObject() instanceof Resource); final Resource headNode = (Resource) matchedStatement.getObject(); final Set<Resource> heads = new HashSet<>(); heads.add(headNode); final Collection<List<Value>> lists = this.testRdfListUtilDefaults.getLists(heads, this.testGraph); assertEquals(1, lists.size()); Iterator<List<Value>> listIterator = lists.iterator(); assertTrue(listIterator.hasNext()); List<Value> nextList = listIterator.next(); assertEquals(1, nextList.size()); }
@Test public void testGetListsAfterAddListBNodeHeadSingleNullContext() { this.testRdfListUtilDefaults.addList(this.testListHeadBNode1, this.testValuesSingleUri, this.testGraph); assertEquals(2, this.testGraph.size()); // verify that the head statement was inserted final Iterator<Statement> match = this.testGraph.filter(this.testListHeadBNode1, null, null).iterator(); assertTrue(match.hasNext()); final Statement matchedStatement = match.next(); assertNotNull(matchedStatement); assertEquals(this.testListHeadBNode1, matchedStatement.getSubject()); Set<Resource> heads = new HashSet<>(1); heads.add(matchedStatement.getSubject()); final Collection<List<Value>> lists = this.testRdfListUtilDefaults .getLists(heads, this.testGraph); assertEquals(1, lists.size()); Iterator<List<Value>> listIterator = lists.iterator(); assertTrue(listIterator.hasNext()); List<Value> nextList = listIterator.next(); assertEquals(1, nextList.size()); }
@Test public void testGetListsAtNodeSingleNullContext() { this.testRdfListUtilDefaults.addListAtNode( this.testSubjectUri1, this.testPredicateUri1, this.testValuesSingleUri, this.testGraph); assertEquals(3, this.testGraph.size()); // verify that the head statement was inserted final Iterator<Statement> match = this.testGraph.filter(this.testSubjectUri1, this.testPredicateUri1, null).iterator(); assertTrue(match.hasNext()); final Statement matchedStatement = match.next(); assertNotNull(matchedStatement); assertFalse(match.hasNext()); assertTrue(matchedStatement.getObject() instanceof Resource); final Collection<List<Value>> lists = this.testRdfListUtilDefaults .getListsAtNode(this.testSubjectUri1, this.testPredicateUri1, this.testGraph, (Resource) null); assertEquals(1, lists.size()); Iterator<List<Value>> listIterator = lists.iterator(); assertTrue(listIterator.hasNext()); List<Value> nextList = listIterator.next(); assertEquals(1, nextList.size()); }
@Test public void testGetListAfterAddListAtNodeMultipleElementsNullContext() { this.testRdfListUtilDefaults.addListAtNode( this.testSubjectUri1, this.testPredicateUri1, this.testValuesMultipleElements, this.testGraph); assertEquals(7, this.testGraph.size()); // verify that the head statement was inserted and find the first pointer to use with // getList final Iterator<Statement> match = this.testGraph.filter(this.testSubjectUri1, this.testPredicateUri1, null).iterator(); assertTrue(match.hasNext()); final Statement matchedStatement = match.next(); assertNotNull(matchedStatement); assertFalse(match.hasNext()); assertTrue(matchedStatement.getObject() instanceof Resource); final List<Value> results = this.testRdfListUtilDefaults.getList( (BNode) matchedStatement.getObject(), this.testGraph, (Resource) null); assertEquals(3, results.size()); assertTrue(results.contains(this.testObjectBNode1)); assertTrue(results.contains(this.testObjectLiteral1)); assertTrue(results.contains(this.testObjectUri1)); }
@Test public void testGetListBNodeHeadAfterInvalidGraphOperation() { this.testRdfListUtilDefaults.addList(this.testListHeadBNode1, this.testValuesMultipleElements, this.testGraph); assertEquals(6, this.testGraph.size()); // Modify the graph in an invalid way to test getList final Iterator<Statement> matches = this.testGraph.filter(null, RDF.REST, RDF.NIL).iterator(); assertTrue(matches.hasNext()); final Statement matchedStatement = matches.next(); assertFalse(matches.hasNext()); assertTrue(this.testGraph.remove(matchedStatement)); assertFalse(this.testGraph.contains(matchedStatement)); try { final List<Value> results = this.testRdfListUtilDefaults.getList( this.testListHeadBNode1, this.testGraph, (Resource) null); assertEquals("Returned results from an invalid list structure", 0, results.size()); fail("Did not find expected exception"); } catch (final RuntimeException rex) { assertEquals("List structure was not complete", rex.getMessage()); } }
@Test public void testGetListURIHeadAfterInvalidGraphOperation() { this.testRdfListUtilDefaults.addList(this.testListHeadUri1, this.testValuesMultipleElements, this.testGraph); assertEquals(6, this.testGraph.size()); // Modify the graph in an invalid way to test getList final Iterator<Statement> matches = this.testGraph.filter(null, RDF.REST, RDF.NIL).iterator(); assertTrue(matches.hasNext()); final Statement matchedStatement = matches.next(); assertFalse(matches.hasNext()); assertTrue(this.testGraph.remove(matchedStatement)); assertFalse(this.testGraph.contains(matchedStatement)); try { final List<Value> results = this.testRdfListUtilDefaults.getList( this.testListHeadUri1, this.testGraph, (Resource) null); assertEquals("Returned results from an invalid list structure", 0, results.size()); fail("Did not find expected exception"); } catch (final RuntimeException rex) { assertEquals("List structure was not complete", rex.getMessage()); } }
@Test public void testGetListAtNodeAfterInvalidGraphOperation() { this.testRdfListUtilDefaults.addListAtNode( this.testSubjectUri1, this.testPredicateUri1, this.testValuesMultipleElements, this.testGraph); assertEquals(7, this.testGraph.size()); // Modify the graph in an invalid way to test getList final Iterator<Statement> matches = this.testGraph.filter(null, RDF.REST, RDF.NIL).iterator(); assertTrue(matches.hasNext()); final Statement matchedStatement = matches.next(); assertFalse(matches.hasNext()); assertTrue(this.testGraph.remove(matchedStatement)); assertFalse(this.testGraph.contains(matchedStatement)); try { final List<Value> results = this.testRdfListUtilDefaults.getListAtNode( this.testSubjectUri1, this.testPredicateUri1, this.testGraph, (Resource) null); assertEquals("Returned results from an invalid list structure", 0, results.size()); fail("Did not find expected exception"); } catch (final RuntimeException rex) { assertEquals("List structure was not complete", rex.getMessage()); } }