⬆️ Top

Howto change an edge label

The goal of this page is to show a few ways Grew can be used to change the label of an edge in a graph.

In all examples above, we suppose that we want to change the UD-style label obj:lvc into the SUD-style one comp:obj@lvc.

 UD  SUD
take_a_walk_UD sud_take_a_walk

Below, we show just one rule application, in real usage, such a rule should be used in a strategy Onf to deal with graph with zero on more then on occurrences of the obj:lvc relation.

Remove and add

One way to code the transformation is to remove the old edge and add a new one with the new label. The two rules above make this transformation whithout naming the old edge in the first case and with naming in the second.

rule del_add {
  pattern { X -[obj:lvc]-> Y } 
  commands { 
    del_edge X -[obj:lvc]-> Y;      % remove the edge matched by the request
    add_edge X -[comp:obj@lvc]-> Y  % add a new edge with the new label
  }
}

rule del_add_with_name {
  pattern { e: X -[obj:lvc]-> Y }   % name 'e' the matched edge
  commands { 
    del_edge e;                     % remove the edge 'e'
    add_edge X -[comp:obj@lvc]-> Y  % add a new edge with the new label
  }
}

Modify the existing edge

Another way to encode the transformation is to keep the existing edge and to change its label. The rule above does this with a command e.label = "…" which update the whole label.

rule change_whole_label {
  pattern { e: X -[obj:lvc]-> Y } % name 'e' the edge to change
  commands {
    e.label = "comp:obj@lvc";     % set a new value to the "label" of 'e'
  }
}

NB: the quote around comp:obj@lvc are required because of the special characters : and @.

Using the fact that edge labels are encoded as feature structures (see here), the edge label updating can be done by changing features. The rule above makes the expected changes in three steps, changing features 1, 2 and deep successively.

rule change_features {
  pattern { e: X -[obj:lvc]-> Y } 
  commands {
    e.1 = comp;    % change the edge feature '1' 
    e.2 = obj;     % change the edge feature '2'
    e.deep = lvc;  % change the edge feature 'deep'
  }
}

NB In order to have the expected behavior in the last example, the config must be set to sud (with the argument -config sud on the command line or with grewpy.set_config ("sud") in Python).