public static <T> Stream<T> asStream(Iterator<T> iterator) { return asStream(iterator, false); }
public static <T> Stream<T> asStream(Iterator<T> iterator) { return asStream(iterator, false); }
/** Find matches in the notional union of all named graphs - return as triples. * No duplicates - the union graph is a <em>set</em> of triples. * See {@link #findInAnyNamedGraphs}, where there may be duplicates. * <p> * Implementations are encouraged to override this method. For example, it * may be possible to avoid "distinct". */ private Stream<Triple> findUnionGraphTriples(Node s, Node p , Node o) { return Iter.asStream(findInAnyNamedGraphs(s,p,o)).map(Quad::asTriple).distinct() ; }
/** * Get the number of child resources associated with the arg 'subject' as specified by the triple found in the arg * 'graph' with the predicate RdfLexicon.HAS_CHILD_COUNT. * * @param graph of triples * @param subject for which child resources is sought * @return number of child resources */ public int getNumChildren(final Graph graph, final Node subject) { LOGGER.trace("Getting number of children: s:{}, g:{}", subject, graph); return (int) asStream(listObjects(graph, subject, CONTAINS.asNode())).count(); }
@Override public Stream<? extends Triple> stream() { final JenaRDF factory = new JenaRDF(salt); return Iter.asStream(graph.find(null, null, null), true).map(factory::asTriple); }
@Override public Stream<? extends Quad> stream() { final JenaRDF factory = new JenaRDF(salt); return Iter.asStream(datasetGraph.find(ANY, ANY, ANY, ANY), true).map(factory::asQuad); }
@Override public Iterable<Quad> iterate() { final JenaRDF factory = new JenaRDF(salt); return Iter.asStream(datasetGraph.find(), false).map(q -> (Quad) factory.asQuad(q))::iterator; }
@Override public Stream<BlankNodeOrIRI> getGraphNames() { final JenaRDF factory = new JenaRDF(salt); return Iter.asStream(datasetGraph.listGraphNodes()).map(node -> (BlankNodeOrIRI) factory.asRDFTerm(node)); }
static List<Triple> quadsToDistinctTriples(Iterator<Quad> iter) { return asStream(iter).map(Quad::asTriple).distinct().collect(Collectors.toList()) ; }
@Override public long size() { final long quads = Iter.asStream(datasetGraph.listGraphNodes()) .map(datasetGraph::getGraph) .collect(Collectors.summingLong(org.apache.jena.graph.Graph::size)); return quads + datasetGraph.getDefaultGraph().size(); }
private Set<String> getObjectsOfProperty(final Model model, final String subject, final String property) { final InfModel infModel = createInfModel(getOWLMicroReasoner(), createDefaultModel()); infModel.add(model.listStatements()); infModel.add(oreModel.listStatements()); return asStream(infModel.listObjectsOfProperty(createResource(subject), createProperty(property))) .filter(RDFNode::isURIResource).map(RDFNode::asResource).map(Resource::getURI).collect(toSet()); } }
private Set<String> getObjectsOfProperty(final Model model, final String subject, final String property) { final InfModel infModel = createInfModel(getOWLMicroReasoner(), createDefaultModel()); infModel.add(model.listStatements()); infModel.add(pcdmModel.listStatements()); return asStream(infModel.listObjectsOfProperty(createResource(subject), createProperty(property))) .filter(RDFNode::isURIResource).map(RDFNode::asResource).map(Resource::getURI).collect(toSet()); } }
@Override public Stream<? extends Triple> stream(final BlankNodeOrIRI s, final IRI p, final RDFTerm o) { final JenaRDF factory = new JenaRDF(salt); return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true).map(factory::asTriple); }
@Override public Stream<? extends Quad> stream(final Optional<BlankNodeOrIRI> g, final BlankNodeOrIRI s, final IRI p, final RDFTerm o) { final JenaRDF factory = new JenaRDF(salt); return Iter.asStream(datasetGraph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true) .map(factory::asQuad); }
private Set<Node> gsp(RDFConnection conn, String graphName) { Set<Node> results = new HashSet<>(); Model model = graphName == null ? conn.fetch() : conn.fetch(graphName); // Extract subjects. Set<Node> seen = SetUtils.toSet( Iter.asStream(model.listSubjects()) .map(Resource::asNode) ); return seen; }
private Set<Node> gsp(RDFConnection conn, String graphName) { Set<Node> results = new HashSet<>(); Model model = graphName == null ? conn.fetch() : conn.fetch(graphName); // Extract subjects. Set<Node> seen = SetUtils.toSet( Iter.asStream(model.listSubjects()) .map(Resource::asNode) ); return seen; }
private Set<Node> dataset(RDFConnection conn) { Dataset ds = conn.fetchDataset(); Set<Node> seen = SetUtils.toSet( Iter.asStream(ds.asDatasetGraph().find()) .map(Quad::getSubject) ); return seen; }
private Set<Node> dataset(RDFConnection conn) { Dataset ds = conn.fetchDataset(); Set<Node> seen = SetUtils.toSet( Iter.asStream(ds.asDatasetGraph().find()) .map(Quad::getSubject) ); return seen; }
private Set<Node> gsp(String user, String password, String graphName) { Set<Node> results = new HashSet<>(); try (RDFConnection conn = RDFConnectionFactory.connectPW(baseUrl, user, password)) { Model model = graphName == null ? conn.fetch() : conn.fetch(graphName); // Extract subjects. Set<Node> seen = SetUtils.toSet( Iter.asStream(model.listSubjects()) .map(r->r.asNode()) ); return seen; } }
private Set<Node> gsp(String user, String password, String graphName) { Set<Node> results = new HashSet<>(); try (RDFConnection conn = RDFConnectionFactory.connectPW(baseUrl, user, password)) { Model model = graphName == null ? conn.fetch() : conn.fetch(graphName); // Extract subjects. Set<Node> seen = SetUtils.toSet( Iter.asStream(model.listSubjects()) .map(r->r.asNode()) ); return seen; } }