add a dominance relation to this docgraph
481722
def _add_dominance_relation(self, source, target):
        """"""
        # TODO: fix #39, so we don't need to add nodes by hand
        self.add_node(target, layers={self.ns, self.ns+':unit'})
        self.add_edge(source, target,
                      layers={self.ns, self.ns+':discourse'},
                      edge_type=EdgeTypes.dominance_relation)
546451
def _parse_decour(self, tree):
        
        self._add_dominance_relation(self.root, 'intro')
        self._add_token_span_to_document(tree.find('/intro'))

        for turn in tree.iterfind('/turn'):
            turn_id = 'turn_{}'.format(turn.attrib['nrgen'])
            self._add_dominance_relation(self.root, turn_id)
            self.turns.append(turn_id)
            act = turn.find('./act')
            if act is not None:
                self._add_dominance_relation(turn_id,
                                             'act_{}'.format(self.act_count))
                self._add_token_span_to_document(act)

            for utter in turn.iterfind('./utterance'):
                    utter_id = 'utterance_{}'.format(utter.attrib['nrgen'])
                    self._add_dominance_relation(turn_id, utter_id)
                    self._add_utterance_to_document(utter)

        conclu = tree.find('/conclu')
        if conclu is not None:
            self._add_dominance_relation(self.root, 'conclu')
            self._add_token_span_to_document(conclu)
546386
def _find_relation(self, span_doc: doc, r: List) -> Dict:
        

        rule = r[1][0]
        span_pivot = 0
        relation = {}
        for e_id, element in enumerate(rule):
            if not span_doc[span_pivot:]:
                for extra_id, _, in enumerate(rule[e_id:]):
                    relation[e_id+extra_id] = None
                break
            new_doc = self._tokenizer.tokenize_to_spacy_doc(span_doc[span_pivot:].text)
            if "OP" not in element:
                relation[e_id] = (span_pivot, span_pivot+1)
                span_pivot += 1
            else:
                if e_id < len(rule)-1:
                    tmp_rule_1 = [rule[e_id]]
                    tmp_rule_2 = [rule[e_id+1]]
                    tmp_matcher = Matcher(self._nlp.vocab)
                    tmp_matcher.add(0, None, tmp_rule_1)
                    tmp_matcher.add(1, None, tmp_rule_2)
                    tmp_matches = sorted([x for x in tmp_matcher(new_doc) if x[1] != x[2]], key=lambda a: a[1])

                    if not tmp_matches:
                        relation[e_id] = None
                    else:
                        matches_1 = [x for x in tmp_matches if x[0] == 0 and x[1] == 0]
                        if not matches_1:
                            relation[e_id] = None
                        else:
                            _, s1, e1 = matches_1[0]
                            matches_2 = [x for x in tmp_matches if x[0] == 1]
                            if not matches_2:
                                relation[e_id] = (span_pivot, span_pivot + e1)
                                span_pivot += e1
                            else:
                                _, s2, e2 = matches_2[0]
                                if e1 <= s2:
                                    relation[e_id] = (span_pivot, span_pivot + e1)
                                    span_pivot += e1
                                else:
                                    relation[e_id] = (span_pivot, span_pivot + s2)
                                    span_pivot += s2
                else:
                    relation[e_id] = (span_pivot, len(span_doc))

        return relation
1075943
private void addToGraph(ClassDoc cd) {
	// avoid adding twice the same class, but don't rely on cg.getClassInfo
	// since there are other ways to add a classInfor than printing the class
	if (visited.contains(cd.toString()))
	    return;

	visited.add(cd.toString());
	cg.printClass(cd, false);
	cg.printRelations(cd);
	if (opt.inferRelationships)
	    cg.printInferredRelations(cd);
	if (opt.inferDependencies)
	    cg.printInferredDependencies(cd);
    }
1152539
function addImportToGraph(importId, parentId, graph, visited) {
  const siblingsId = parentId + '_' + 'siblings'
  const visitedId = parentId + '_' + importId

  if (visited[visitedId] !== VISITED_MARKER) {
    if (!Array.isArray(visited[siblingsId])) visited[siblingsId] = []

    const siblings = visited[siblingsId]

    if (Array.isArray(graph[importId]))
      graph[importId] = graph[importId].concat(siblings)
    else graph[importId] = siblings.slice()

    visited[visitedId] = VISITED_MARKER
    siblings.push(importId)
  }
}
77407
def _handle_relation(self, tokens: ParseResults) -> str:
        """"""
        subject_node_dsl = self.ensure_node(tokens[SUBJECT])
        object_node_dsl = self.ensure_node(tokens[OBJECT])

        subject_modifier = modifier_po_to_dict(tokens[SUBJECT])
        object_modifier = modifier_po_to_dict(tokens[OBJECT])

        annotations = {
            annotation_name: (
                {
                    ae: True
                    for ae in annotation_entry
                }
                if isinstance(annotation_entry, set) else
                {
                    annotation_entry: True
                }
            )
            for annotation_name, annotation_entry in self.control_parser.annotations.items()
        }

        return self._add_qualified_edge(
            subject_node_dsl,
            object_node_dsl,
            relation=tokens[RELATION],
            annotations=annotations,
            subject_modifier=subject_modifier,
            object_modifier=object_modifier,
        )
583085
def get_child_nodes(docgraph, parent_node_id, data=False):
    """"""
    return select_neighbors_by_edge_attribute(
        docgraph=docgraph,
        source=parent_node_id,
        attribute='edge_type',
        value=[EdgeTypes.dominance_relation],
        data=data)
831061
def add_precedence_relations(self):
        
        assert len(self.tokens) > 1, \
            "There are no tokens to add precedence relations to."
        self.add_edge(self.root, self.tokens[0],
                      layers={self.ns, self.ns+':precedence'},
                      edge_type=EdgeTypes.precedence_relation)
        for i, token_node_id in enumerate(self.tokens[1:]):
            # edge from token_n to token_n+1
            self.add_edge(self.tokens[i], token_node_id,
                          layers={self.ns, self.ns+':precedence'},
                          edge_type=EdgeTypes.precedence_relation)
1310506
def __add_span_tier(self, tier):
        
        tier_id = tier.attrib['id']
        # add the tier's root node with an inbound edge from the document root
        self.add_node(
            tier_id, layers={self.ns, self.ns+':tier'},
            attr_dict={self.ns+':category': tier.attrib['category'],
                       self.ns+':type': tier.attrib['type'],
                       self.ns+':display-name': tier.attrib['display-name']})
        self.add_edge(self.root, tier_id, edge_type=EdgeTypes.dominance_relation)

        # add a node for each span, containing an annotation.
        # add an edge from the tier root to each span and an edge from each
        # span to the tokens it represents
        for i, event in enumerate(tier.iter('event')):
            span_id = '{}_{}'.format(tier_id, i)
            span_tokens = self.gen_token_range(event.attrib['start'], event.attrib['end'])
            annotation = event.text if event.text else ''
            self.add_node(
                span_id, layers={self.ns, self.ns+':span'},
                attr_dict={self.ns+':annotation': annotation,
                           'label': annotation})
            self.add_edge(tier_id, span_id, edge_type=EdgeTypes.dominance_relation)

            for token_id in span_tokens:
                self.add_edge(span_id, token_id,
                              edge_type=EdgeTypes.spanning_relation)
641771
def _add_two_way_unqualified_edge(self, u: BaseEntity, v: BaseEntity, relation: str) -> str:
        """"""
        self.add_unqualified_edge(v, u, relation)
        return self.add_unqualified_edge(u, v, relation)
989360
protected function leadingRelations()
    {
        foreach ($this->relations as $relation) {
            if ($relation instanceof RelationInterface && $relation->isLeading()) {
                yield $relation;
            }
        }
    }
1149386
def _add_constraints(self, relation):
        

        expression = relation.expression
        constr_count = sum(True for _ in expression.value_sets())
        if constr_count == 0:
            return []

        row_indices = count(swiglpk.glp_add_rows(self._p, constr_count))

        names = []
        for i, value_set in zip(row_indices, expression.value_sets()):
            value_set = list(value_set)
            var_indices = swiglpk.intArray(1 + len(value_set))
            var_values = swiglpk.doubleArray(1 + len(value_set))
            for j, (variable, coeff) in enumerate(value_set):
                var_indices[1 + j] = self._variables[variable]
                var_values[1 + j] = float(coeff)

            swiglpk.glp_set_mat_row(
                self._p, i, len(value_set), var_indices, var_values)

            if relation.sense == RelationSense.Greater:
                swiglpk.glp_set_row_bnds(
                    self._p, i, swiglpk.GLP_LO, -float(expression.offset), 0)
            elif relation.sense == RelationSense.Less:
                swiglpk.glp_set_row_bnds(
                    self._p, i, swiglpk.GLP_UP, 0, -float(expression.offset))
            else:
                swiglpk.glp_set_row_bnds(
                    self._p, i, swiglpk.GLP_FX, -float(expression.offset), 0)

            names.append(i)

        self._do_presolve = True

        return names
705449
public GrammaticalRelation getGrammaticalRelation(int govIndex, int depIndex) {
    TreeGraphNode gov = getNodeByIndex(govIndex);
    TreeGraphNode dep = getNodeByIndex(depIndex);
    return getGrammaticalRelation(gov, dep);
  }
191439
def dominance_frontier(start_node = self.enter, dom_tree)
      vertices.inject(Hash.new { |h, k| h[k] = Set.new }) do |result, b|
        preds = b.real_predecessors
        if preds.size >= 2
          preds.each do |p|
            b_dominator = dom_tree[b].successors.first
            break unless b_dominator
            runner = dom_tree[p]
            while runner && runner != b_dominator
              result[runner] << b
              runner = runner.successors.first
            end
          end
        end
        result
      end
    end
1183684
def node2bracket(docgraph, node_id, child_str=''):
    """"""
    node_attrs = docgraph.node[node_id]
    if istoken(docgraph, node_id):
        pos_str = node_attrs.get(docgraph.ns+':pos', '')
        token_str = node_attrs[docgraph.ns+':token']
        return u"({pos}{space1}{token}{space2}{child})".format(
            pos=pos_str, space1=bool(pos_str)*' ', token=token_str,
            space2=bool(child_str)*' ', child=child_str)

    #else: node is not a token
    label_str = node_attrs.get('label', '')
    return u"({label}{space}{child})".format(
        label=label_str, space=bool(label_str and child_str)*' ',
        child=child_str)
649180
def __add_document_structure(self, docgraph,
                                 remove_redundant_layers=True):
        """"""
        E = self.E
        root = self.__create_document_header()

        body = E('basic-body')
        timeline = E('common-timeline')

        # for n tokens we need to create n+1 timeline indices
        for i in xrange(len(docgraph.tokens)+1):
            idx = str(i)
            # example: <tli id="T0" time="0"/>
            timeline.append(E('tli', {'id': 'T'+idx, 'time': idx}))

        body.append(timeline)
        body = self.__add_token_tiers(docgraph, body)

        annotation_layers = get_annotation_layers(docgraph)
        for layer in annotation_layers:
            if not remove_redundant_layers:  # add all layers
                self.__add_annotation_tier(docgraph, body, layer)
            elif is_informative(layer):  # only add informative layers
                self.__add_annotation_tier(docgraph, body, layer)

        self.__add_coreference_chain_tiers(docgraph, body)
        root.append(body)
        return root
782288
def merge_graphs(self, other_docgraph, verbose=False):
        
        # keep track of all merged/old root nodes in case we need to
        # delete them or their attributes (e.g. 'metadata')
        if hasattr(self, 'merged_rootnodes'):
            self.merged_rootnodes.append(other_docgraph.root)
        else:
            self.merged_rootnodes = [other_docgraph.root]

        # renaming the tokens of the other graph to match this one
        rename_tokens(other_docgraph, self, verbose=verbose)
        self.add_nodes_from(other_docgraph.nodes(data=True))

        # copy token node attributes to the current namespace
        for node_id, node_attrs in other_docgraph.nodes(data=True):
            if istoken(other_docgraph, node_id) and \
                self.ns+':token' not in self.node[node_id]:
                    self.node[node_id].update({self.ns+':token': other_docgraph.get_token(node_id)})
        self.add_edges_from(other_docgraph.edges(data=True))

        # workaround for issues #89 and #96
        # copy the token node IDs / sentence node IDs from the other graph,
        # if this graph doesn't have such lists, yet
        if other_docgraph.name and not self.name:
            self.name = other_docgraph.name
        if other_docgraph.tokens and not self.tokens:
            self.tokens = other_docgraph.tokens
        if other_docgraph.sentences and not self.sentences:
            self.sentences = other_docgraph.sentences

        # there should be no dangling, unused root nodes in a merged graph
        self.merge_rootnodes(other_docgraph)