Collect all nodes involved in a subgraph statement
979688
function collectNodeIds(stmt) {
  var ids = {},
      stack = [],
      curr;

  var push = stack.push.bind(stack);

  push(stmt);
  while(stack.length) {
    curr = stack.pop();
    switch(curr.type) {
      case "node": ids[curr.id] = true; break;
      case "edge": _.each(curr.elems, push); break;
      case "subgraph": _.each(curr.stmts, push); break;
    }
  }

  return _.keys(ids);
}
1338488
def _rdf_graph_from_ntriples_string(ntriples_string, graph=nil)
      graph ||= RDF::Graph.new
      RDF::Reader.for(:ntriples).new(ntriples_string) do |reader|
        reader.each_statement do |statement|
          graph << statement
        end
      end
      graph
    end
1150367
function nodes(){
    var nodeSet = {};
    Object.keys(edges).forEach(function (u){
      nodeSet[u] = true;
      edges[u].forEach(function (v){
        nodeSet[v] = true;
      });
    });
    return Object.keys(nodeSet);
  }
1314783
def get_nodes(graph: BELGraph, node_predicates: NodePredicates) -> Set[BaseEntity]:
    """"""
    return set(filter_nodes(graph, node_predicates=node_predicates))
599255
def get_subgraph_from_edge_list(graph, edge_list):
    """"""
    node_list = get_vertices_from_edge_list(graph, edge_list)
    subgraph = make_subgraph(graph, node_list, edge_list)

    return subgraph
257946
def full_subgraph(self, vertices):
        
        obj_map = {vertex.id: vertex for vertex in vertices}
        edges = [
            edge for vertex_id in obj_map
            for edge in self._out_edges[vertex_id]
            if edge.head in obj_map
        ]

        return AnnotatedGraph(
            vertices=obj_map.values(),
            edges=edges,
        )
135030
function collectSiblings(node, name, endNode) {
          var siblings = [];

          for (; node && node != endNode; node = node[name]) {
            siblings.push(node);
          }

          return siblings;
        }
1345553
private void populateGraph(final EntityGraph<?> graph, final Set<String> fetches)
	{
		Map<String, Subgraph<?>> created = new HashMap<>();

		for (String fetch : fetches)
		{
			final String[] parts = StringUtils.split(fetch, '.');

			// Starts of null (meaning parent is the root graph), updated as we go through path segments to refer to the last path segment
			Subgraph<?> parent = null;

			// Iterate over the path segments, adding attributes subgraphs
			for (int i = 0; i < parts.length; i++)
			{
				final String path = StringUtils.join(parts, '.', 0, i + 1);
				final boolean isLeaf = (i == parts.length - 1);

				final Subgraph<?> existing = created.get(path);

				if (existing == null)
				{
					if (parent == null)
					{
						try
						{
							// Relation under root
							graph.addAttributeNodes(parts[i]);

							// Only set up a subgraph if this is not a leaf node
							// This prevents us trying to add a Subgraph for a List of Embeddable
							if (!isLeaf)
								parent = graph.addSubgraph(parts[i]);
						}
						catch (IllegalArgumentException e)
						{
							throw new IllegalArgumentException("Error adding graph member " +
							                                   parts[i] +
							                                   " with isLeaf=" +
							                                   isLeaf +
							                                   " to root as part of " +
							                                   fetch, e);
						}
					}
					else
					{
						try
						{
							// Relation under parent
							parent.addAttributeNodes(parts[i]);

							// Only set up a subgraph if this is not a leaf node
							// This prevents us trying to add a Subgraph for a List of Embeddable
							if (!isLeaf)
								parent = parent.addSubgraph(parts[i]);
						}
						catch (IllegalArgumentException e)
						{
							throw new IllegalArgumentException("Error adding graph member " +
							                                   parts[i] +
							                                   " with isLeaf=" +
							                                   isLeaf +
							                                   " as part of " +
							                                   fetch +
							                                   " with parent.class=" +
							                                   parent.getClassType(), e);
						}
					}

					if (!isLeaf)
						created.put(path, parent);
				}
				else
				{
					// Already seen this graph node before
					parent = existing;
				}
			}
		}
	}
127867
def __get_segments_from_node(node, graph):
    """"""
    list_of_segments = []
    node_object = graph.get_node(node)
    for e in node_object['edges']:
        list_of_segments.append(e)
    return list_of_segments
741124
def get_all_nodes(self, addr, is_syscall=None, anyaddr=False):
        
        results = [ ]

        for cfg_node in self.graph.nodes():
            if cfg_node.addr == addr or (anyaddr and
                                         cfg_node.size is not None and
                                         cfg_node.addr <= addr < (cfg_node.addr + cfg_node.size)
                                         ):
                if is_syscall and cfg_node.is_syscall:
                    results.append(cfg_node)
                elif is_syscall is False and not cfg_node.is_syscall:
                    results.append(cfg_node)
                else:
                    results.append(cfg_node)

        return results
637727
private List<String> getAllTokens(SStructuredNode n, String name, TComponenttype c, long cnr, String namespace)
  {
    List<String> result = null;
    if (!visitedNodes.contains(n.getId()))
    {
      result = new LinkedList<String>();
      visitedNodes.add(n.getId());
      if (tokensOfNode.containsKey(n.getId()))
      {
        for (String t : tokensOfNode.get(n.getId()))
        {
          result.add(t);
          if (componentOfToken.get(t) == null)
          {
            List<Long> newlist = new LinkedList<Long>();
            newlist.add(cnr);
            componentOfToken.put(t, newlist);
          }
          else
          {
            if (!componentOfToken.get(t).contains(cnr))
            {
              componentOfToken.get(t).add(cnr);
            }
          }
        }
      }
      else
      {
        result = searchTokens(n, cnr);
        if (result != null)
        {
          tokensOfNode.put(n.getId(), result);
        }
      }
      //get "P"-Edges!
      List<SRelation<SNode,SNode>> outEdges = n.getGraph().getOutRelations(n.getId());
      if(outEdges != null)
      {
        for (SRelation<? extends SNode,? extends SNode> e : outEdges)
        {
          if(includeEdge(e, namespace))
          {
            SPointingRelation rel = (SPointingRelation) e;
            if (name.equals(componentNameForRelation(rel))
              && !visitedNodes.contains(rel.getTarget().getId()))
            {
              c.nodeList.add(rel.getTarget().getId());
              List<String> Med = getAllTokens(rel.getTarget(), 
                name, c, cnr, namespace);
              for (String l : Med)
              {
                if (result != null && !result.contains(l))
                {
                  result.add(l);
                }
              }
            }
          }
        }
      }
      List<SRelation<SNode,SNode>> inEdges = n.getGraph().getInRelations(n.getId());
      if(inEdges != null)
      {
        for (SRelation<? extends SNode,? extends SNode> e : inEdges)
        {
          if(includeEdge(e, namespace))
          {
            SPointingRelation rel = (SPointingRelation) e;
            if (name.equals(componentNameForRelation(rel))
              && !visitedNodes.contains(rel.getSource().getId()))
            {
              c.nodeList.add(rel.getSource().getId());
              List<String> Med = getAllTokens(rel.getSource(), name, c, cnr, namespace);
              for (String s : Med)
              {
                if (result != null && !result.contains(s))
                {
                  result.add(s);
                }
              }
            }
          }
        }
      }
    }
    return result;
  }
799252
def getSubgraphList(self, parent_name):
        
        if not self.isMultigraph:
            raise AttributeError("Simple Munin Plugins cannot have subgraphs.")
        if self._graphDict.has_key(parent_name):
            return self._subgraphNames[parent_name] or []
        else:
            raise AttributeError("Invalid parent graph name %s."
                                 % (parent_name,))
855638
def filter_nodes(graph: BELGraph, node_predicates: NodePredicates) -> Iterable[BaseEntity]:
    """"""
    concatenated_predicate = concatenate_node_predicates(node_predicates=node_predicates)
    for node in graph:
        if concatenated_predicate(graph, node):
            yield node
843970
def predicates(graph):
    
    seen = set()

    def _traverse(binding):
        if binding.path in seen:
            return
        seen.add(binding.path)

        if binding.is_object:
            for prop in binding.properties:
                yield (binding.path, prop.name, tuple(prop.types))
                for pred in _traverse(prop):
                    yield pred
        elif binding.is_array:
            for item in binding.items:
                for pred in _traverse(item):
                    yield pred

    schemas = graph.aliases.values()
    schemas.extend(graph.resolver.store)
    for schema_uri in graph.aliases.values():
        binding = graph.get_binding(schema_uri, None)
        for pred in _traverse(binding):
            if pred not in seen:
                yield pred
                seen.add(pred)
463768
def get_children(self,node):
    
    if self.find_cycle() or self.__directionless:
      sys.stderr.write("ERROR: do cannot find a branch when there are cycles in the graph\n")
      sys.exit()
    v = self.__get_children(node.id)
    return [self.__nodes[i] for i in v]
753659
def _process_graph(self):
        
        all_nodes = [x.name for x in self.graph.as_graph_def().node]
        nodes = [x for x in all_nodes if x in self.possible_output_nodes]
        logger.info('List of nodes to export for brain :' + self.brain.brain_name)
        for n in nodes:
            logger.info('\t' + n)
        return nodes
526892
def all_nodes
      collection = connection[nodes_collection]
      collection.find.batch_size(999).projection(_id: 1).map { |k| k[:_id] }
    end