Transform the features into a more graph-like structure by
    appropriately splitting LineString features into two-point
    "edges" that connect Point "nodes".
15886
def features_node_edge_graph(obj):
    
    points = {}
    features = obj['features']
    for feature in tqdm(obj['features']):
        for (lon, lat) in geojson.utils.coords(feature):
            points.setdefault((lon, lat), 0)
            points[(lon, lat)] += 1
    points = [p for (p, c) in points.items() if c > 1]
    features = [geojson.Point(p) for p in points]

    # For each feature, split it into "edge" features
    # that occur between every point.
    for f in tqdm(obj['features']):
        seqs = []
        seq = []
        for point in geojson.utils.coords(f):
            if len(seq) > 0:
                seq.append(point)
            if point in points:
                seq.append(point)
                if len(seq) > 1 and seq[0] in points:
                    seqs.append(seq)
                    seq = [point]
        for seq in seqs:
            features.append(geojson.Feature(geometry={"coordinates":seq, "type":f['geometry']['type']}, properties=f['properties'], type=f['type']))

    obj['features'] = features
    return obj
1200590
def add_graph(patterns, G):
    """"""
    if not patterns:
        patterns.append([G])
        return
    for i, graphs in enumerate(patterns):
        if networkx.is_isomorphic(graphs[0], G, node_match=type_match,
                                  edge_match=type_match):
            patterns[i].append(G)
            return
    patterns.append([G])
954056
def build_edges(self):
        
        self.edges = [
            edge if isinstance(edge, Edge) else Edge(*edge)
            for node in self.nodes.values()
            for edge in getattr(node, "edges", [])
            if edge[0] in self.nodes and edge[1] in self.nodes
        ]
        return self
899867
def add_edge(edges, edge_points, coords, i, j):
    
    if (i, j) in edges or (j, i) in edges:
        # already added
        return( edges.add((i, j)), edge_points.append(coords[[i, j]]))
1368475
def build_pattern(body, features):
    '''
    '''
    line_patterns = apply_features(body, features)
    return reduce(lambda x, y: [i + j for i, j in zip(x, y)], line_patterns)
300036
def from_edges(edges, source_key='source', target_key='target', weight_key='weight', directed=True):
    
    raw = list(map(lambda x: [x[source_key], x[target_key], int(x[weight_key])], edges))
    g = IGraph.TupleList(raw, weights=True, directed=directed)
    g.vs['indegree'] = g.degree(mode="in")
    g.vs['outdegree'] = g.degree(mode="out")
    g.vs['label'] = g.vs['name']
    if 'group' not in g.vs.attributes():
        g.vs['group'] = labels_to_groups(g.vs['label'])
    return g
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
1280609
def coupling(corpus_or_featureset, featureset_name=None,
             min_weight=1, filter=lambda f, v, c, dc: True,
             node_attrs=[]):
    

    featureset = _get_featureset(corpus_or_featureset, featureset_name)

    c = lambda f: featureset.count(f)           # Overall count.
    dc = lambda f: featureset.documentCount(f)  # Document count.
    f = lambda elem: featureset.index[elem]
    v = lambda p, f: featureset.features[p].value(f)

    select = lambda p, elem: filter(f(elem), v(p, f(elem)), c(f(elem)), dc(f(elem)))

    pairs = defaultdict(list)
    for elem, papers in featureset.with_feature.iteritems():
        selected = [p for p in papers if select(p, elem)]
        for combo in combinations(selected, 2):
            combo = tuple(sorted(combo))
            pairs[combo].append(featureset.index[elem])

    graph = nx.Graph()
    for combo, features in pairs.iteritems():
        count = len(features)
        if count >= min_weight:
            graph.add_edge(combo[0], combo[1], features=features, weight=count)

    # Add node attributes.
    for attr in node_attrs:
        for node in graph.nodes():
            value = ''
            if node in corpus_or_featureset:
                paper = corpus_or_featureset[node]
                if hasattr(paper, attr):
                    value = getattr(paper, attr)
                    if value is None:
                        value = ''
                    elif callable(value):
                        value = value()
            graph.node[node][attr] = value

    return graph
1358079
def _stmt_graph_annotate_edges(self, edges_to_annotate, **new_labels):
        

        graph = self.graph

        for src, dst in edges_to_annotate:

            if src not in graph:
                continue
            if dst not in graph[src]:
                continue

            data = graph[src][dst]

            for k, v in new_labels.items():
                if k in data:
                    if v not in data[k]:
                        data[k] = data[k] + (v,)
                else:
                    # Construct a tuple
                    data[k] = (v,)
211456
def merge(polylines, mx_dist=4):
    
    l = len(polylines)
    to_remove = set()
    for n in range(l - 1, -1, -1):
        if n not in to_remove:
            c = polylines[n]
            for p0, p1 in zip(c[:-1], c[1:]):
                # create a line from any subsegment:
                l0 = p0[0], p0[1], p1[0], p1[1]

                # for every other polyline:
                for m in range(l - 1, -1, -1):
                    if m not in to_remove:
                        if n == m:
                            continue
                        remove = False
                        cc = polylines[m]
                        ind = np.zeros(shape=cc.shape[0], dtype=bool)

                        # for every point p in this polyline:
                        for o in range(len(cc) - 1, -1, -1):
                            p = cc[o]

                            if line.segmentDistance(l0, p) < mx_dist:
                                remove = True
                                ind[o] = True

                        if remove:
                            polylines[n] = np.append(c, cc[ind], axis=0)
                            ind = ~ind
                            s = ind.sum()
                            if s < 2:
                                to_remove.add(m)
                            else:
                                polylines[m] = cc[ind]

    to_remove = sorted(to_remove)
    to_remove.reverse()
    for i in to_remove:
        polylines.pop(i)
25356
def edges
      vertices.map { |vert| vert.successors.map { |succ| [vert, succ] }}.flatten 1
    end
1004417
function splitPolygon(a, b) {
       var a2 = new Node(a.i, a.x, a.y),
           b2 = new Node(b.i, b.x, b.y),
           an = a.next,
           bp = b.prev;

       a.next = b;
       b.prev = a;

       a2.next = an;
       an.prev = a2;

       b2.next = a2;
       a2.prev = b2;

       bp.next = b2;
       b2.prev = bp;

       return b2;
   }
662579
def prevnode(edges, component):
    """"""
    e = edges
    c = component
    n2c = [(a, b) for a, b in e if type(a) == tuple]
    c2n = [(a, b) for a, b in e if type(b) == tuple]
    node2cs = [(a, b) for a, b in e if b == c]
    c2nodes = []
    for node2c in node2cs:
        c2node = [(a, b) for a, b in c2n if b == node2c[0]]
        if len(c2node) == 0:
            # return []
            c2nodes = []
            break
        c2nodes.append(c2node[0])
    cs = [a for a, b in c2nodes]
    # test for connections that have no nodes
    # filter for no nodes
    nonodes = [(a, b) for a, b in e if type(a) != tuple and type(b) != tuple]
    for a, b in nonodes:
        if b == component:
            cs.append(a)
    return cs
165275
def split_if_nodes(graph):
    
    node_map = {n: n for n in graph}
    to_update = set()
    for node in graph.nodes[:]:
        if node.type.is_cond:
            if len(node.get_ins()) > 1:
                pre_ins = node.get_ins()[:-1]
                last_ins = node.get_ins()[-1]
                pre_node = StatementBlock('%s-pre' % node.name, pre_ins)
                cond_node = CondBlock('%s-cond' % node.name, [last_ins])
                node_map[node] = pre_node
                node_map[pre_node] = pre_node
                node_map[cond_node] = cond_node

                pre_node.copy_from(node)
                cond_node.copy_from(node)
                for var in node.var_to_declare:
                    pre_node.add_variable_declaration(var)
                pre_node.type.is_stmt = True
                cond_node.true = node.true
                cond_node.false = node.false

                for pred in graph.all_preds(node):
                    pred_node = node_map[pred]
                    # Verify that the link is not an exception link
                    if node not in graph.sucs(pred):
                        graph.add_catch_edge(pred_node, pre_node)
                        continue
                    if pred is node:
                        pred_node = cond_node
                    if pred.type.is_cond:  # and not (pred is node):
                        if pred.true is node:
                            pred_node.true = pre_node
                        if pred.false is node:
                            pred_node.false = pre_node
                    graph.add_edge(pred_node, pre_node)
                for suc in graph.sucs(node):
                    graph.add_edge(cond_node, node_map[suc])

                # We link all the exceptions to the pre node instead of the
                # condition node, which should not trigger any of them.
                for suc in graph.catch_edges.get(node, []):
                    graph.add_catch_edge(pre_node, node_map[suc])

                if node is graph.entry:
                    graph.entry = pre_node

                graph.add_node(pre_node)
                graph.add_node(cond_node)
                graph.add_edge(pre_node, cond_node)
                pre_node.update_attribute_with(node_map)
                cond_node.update_attribute_with(node_map)
                graph.remove_node(node)
        else:
            to_update.add(node)
    for node in to_update:
        node.update_attribute_with(node_map)
1085646
def make_subgraph(graph, vertices, edges):
    """"""
    # Copy the entire graph
    local_graph = copy.deepcopy(graph)

    # Remove all the edges that aren't in the list
    edges_to_delete = [x for x in local_graph.get_all_edge_ids() if x not in edges]
    for e in edges_to_delete:
        local_graph.delete_edge_by_id(e)

    # Remove all the vertices that aren't in the list
    nodes_to_delete = [x for x in local_graph.get_all_node_ids() if x not in vertices]
    for n in nodes_to_delete:
        local_graph.delete_node(n)

    return local_graph
1234586
def edge_node(name, points):
    
    line = []
    for point in points:
        line.append(point.longitude)
        line.append(point.latitude)
        line.append(point.depth)
    pos = Node('gml:posList', {}, line)
    node = Node(name, nodes=[Node('gml:LineString', nodes=[pos])])
    return node
1095862
def split(nodeShape, jobShape, wallTime):
    
    return (Shape(wallTime,
                  nodeShape.memory - jobShape.memory,
                  nodeShape.cores - jobShape.cores,
                  nodeShape.disk - jobShape.disk,
                  nodeShape.preemptable),
            NodeReservation(Shape(nodeShape.wallTime - wallTime,
                                  nodeShape.memory,
                                  nodeShape.cores,
                                  nodeShape.disk,
                                  nodeShape.preemptable)))