Collect a stream of Triples into a Graph
@return a graph
175953
public static Collector<Triple, ?, Graph> toGraph() {
        return of(rdf::createGraph, Graph::add, (left, right) -> {
            right.iterate().forEach(left::add);
            return left;
        }, UNORDERED);
    }
902554
public static Iterable<GraphObject> map(final Iterable<Object> src) {

		return Iterables.map((Object t) -> {

			if (t instanceof GraphObject) {
				return (GraphObject)t;
			} else if (t instanceof Map) {
				return Function.toGraphObjectMap((Map)t);
			} else {

				return (GraphObject)UiFunction.toGraphObject(t, 1);
			}

		}, src);

	}
1075858
public static <T> Stream<T> streamC(T root, Function<? super T, ? extends Collection<T>> edges)
    {
        return StreamSupport.stream(spliterator(root, (y)->edges.apply(y).stream()), false);
    }
1303060
function () {
      var s, triples = [];
      if (this.union === undefined) {
        triples = this.tripleStore;
      } else {
        $.each(this.union, function (i, databank) {
          triples = triples.concat(databank.triples().get());
        });
        triples = unique(triples);
      }
      return $(triples);
    }
1368100
public static final <T> Stream<T> diGraph(T root, Function<? super T, ? extends Stream<T>> edges)
    {
        return DiGraphIterator.stream(root, edges);
    }
1280701
public static <V> Set<V> getIncomingVertices(DirectedGraph<V, DefaultEdge> graph, V target) {
        Set<DefaultEdge> edges = graph.incomingEdgesOf(target);
        Set<V> sources = new LinkedHashSet<V>();
        for (DefaultEdge edge : edges) {
            sources.add(graph.getEdgeSource(edge));
        }
        return sources;
    }
1364226
def rdf2dot( g, stream, opts={} ):
    

    accept_lang = set( opts.get('lang',[]) )
    do_literal = opts.get('literal')
    nodes = {}
    links = []

    def node_id(x):
        if x not in nodes:
            nodes[x] = "node%d" % len(nodes)
        return nodes[x]

    def qname(x, g):
        try:
            q = g.compute_qname(x)
            return q[0] + ":" + q[2]
        except:
            return x

    def accept( node ):
        if isinstance( node, (rdflib.URIRef,rdflib.BNode) ):
            return True
        if not do_literal:
            return False
        return (not accept_lang) or (node.language in accept_lang)


    stream.write( u'digraph { \n node [ fontname="DejaVu Sans,Tahoma,Geneva,sans-serif" ] ; \n' )

    # Write all edges. In the process make a list of all nodes
    for s, p, o in g:
        # skip triples for labels
        if p == rdflib.RDFS.label:
            continue

        # Create a link if both objects are graph nodes
        # (or, if literals are also included, if their languages match)
        if not (accept(s) and accept(o)):
            continue

        # add the nodes to the list
        sn = node_id(s)
        on = node_id(o)

        # add the link
        q = qname(p,g)
        if isinstance(p, rdflib.URIRef):
            opstr = u'\t%s -> %s [ arrowhead="open", color="#9FC9E560", fontsize=9, fontcolor="#204080", label="%s", href="%s", target="_other" ] ;\n' % (sn,on,q,p)
        else:
            opstr = u'\t%s -> %s [ arrowhead="open", color="#9FC9E560", fontsize=9, fontcolor="#204080", label="%s" ] ;\n'%(sn,on,q)
        stream.write( opstr )

    # Write all nodes
    for u, n in nodes.items():
        lbl = escape( label(u,g,accept_lang), True )
        if isinstance(u, rdflib.URIRef):
            opstr = u'%s [ shape=none, fontsize=10, fontcolor=%s, label="%s", href="%s", target=_other ] \n' % (n, 'blue', lbl, u )
        else:
            opstr = u'%s [ shape=none, fontsize=10, fontcolor=%s, label="%s" ] \n' % (n, 'black', lbl )
        stream.write( u"# %s %s\n" % (u, n) )
        stream.write( opstr )

    stream.write(u'}\n')
863478
def graph(self):
        
        g = networkx.MultiDiGraph()
        edge_list = [(x.knob_helix, x.hole_helix, x.id, {'kih': x}) for x in self.get_monomers()]
        g.add_edges_from(edge_list)
        return g
1122387
@SafeVarargs
    @SuppressWarnings("unchecked")
    public static <T> Stream<T> stream(Iterable<T>... iterables) {
        List<Iterator<T>> iterators = Arrays.stream(iterables)
            .map(Iterable::iterator)
            .collect(Collectors.toList());

        return stream(iterators.toArray(new Iterator[iterables.length]));
    }
1072959
private StreamGraph generateInternal(List<StreamTransformation<?>> transformations) {
		for (StreamTransformation<?> transformation: transformations) {
			transform(transformation);
		}
		return streamGraph;
	}
891255
@SuppressWarnings("rawtypes")
    public Stream<Link> stream() {
        return links.values()
                .stream()
                .map(obj -> {
                    if (obj instanceof List) {
                        return (List) obj;
                    } else {
                        return singletonList(obj);
                    }
                })
                .flatMap(Collection::stream);
    }
876271
public Vector<Graph<UserStub>> generateAllNodeDataTypeGraphCombinationsOfMaxLength(int length) {
        Vector<Graph<UserStub>> graphs = super.generateAllNodeDataTypeGraphCombinationsOfMaxLength(length);

        if (WRITE_STRUCTURES_IN_PARALLEL) {
            // Left as an exercise to the student.
            throw new NotImplementedError();
        } else {
            int i = 0;
            for (Iterator<Graph<UserStub>> iter = graphs.toIterator(); iter.hasNext();) {
                Graph<UserStub> graph = iter.next();
                graph.setGraphId("S_" + ++i + "_" + graph.allNodes().size());
                graph.writeDotFile(outDir + graph.graphId() + ".gv", false, ALSO_WRITE_AS_PNG);
            }
            System.out.println("Wrote " + i + " graph files in DOT format to " + outDir + "");
        }

        return graphs;
    }
209810
def _get_triplet_value_list(self, graph, identity, rdf_type):
        
        values = []
        for elem in graph.objects(identity, rdf_type):
            values.append(elem.toPython())
        return values
1260955
private <T> GraphRequest<T> graph(String object, JavaType type, Param... params) {
		this.checkForBatchExecution();
		
		// The data is transformed through a chain of wrappers
		GraphRequest<T> req =
			new GraphRequest<T>(object, params, this.mapper, this.<T>createMappingChain(type));
		
		this.graphRequests.add(req);
		return req;
	}
39134
private Triple getLocalizedTriple(Triple triple) {
        try {
            return _connector.getElementFactory().createTriple(
                    getLocalizedResource(triple.getSubject()),
                    getLocalizedResource(triple.getPredicate()),
                    getLocalizedObject(triple.getObject()));
        } catch (GraphElementFactoryException e) {
            throw new RuntimeException("Error localizing triple", e);
        }
    }
641583
public static <T> Spliterator<T> spliterator(T root, Function<? super T, ? extends Stream<T>> edges)
    {
        DiGraphIterator dgi = new DiGraphIterator(root, edges);
        return Spliterators.spliteratorUnknownSize(dgi, 0);
    }
616738
function saveGraphSONSync(graph, filename) {
        var FileOutputStream = Tinkerpop.autoImport('FileOutputStream');
        var stream = new FileOutputStream(filename);
        var builder = Tinkerpop.GraphSONWriter.build();
        var mapper = _newGraphSONMapperSync();
        builder.mapper(mapper);
        var writer = builder.create();
        writer.writeGraph(stream, graph);
        return graph;
    }