Skip to content

Commit

Permalink
Add Shift+drop to attach node without creating enhanced dependency
Browse files Browse the repository at this point in the history
Fix stylesheet to display nodes without deps in cyan.
Add more details to the documentation.
  • Loading branch information
choroba committed May 16, 2024
1 parent 20707d0 commit 687e1b2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 35 deletions.
29 changes: 26 additions & 3 deletions README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,32 @@ ud - TrEd extension to display and edit Universal Dependencies

=head1 DESCRIPTION

Use mouse to change the tree structure. Drop a node with C<Ctrl> to add or
remove an enhanced dependency. Press C<d> to edit the current node's
C<deprel>.
=over 2

=item *

Dropping node C<a> on node C<b> attaches node C<a> to node C<b>. An enhanced
dependency is created together with the basic one, if an enhanced dependency
existed to the old or new parent, it is removed.

=item *

Dropping node C<a> on node C<b> while pressing C<Control> toggles existence of
an enhanced dependency of node C<a> on node C<b>. If a dependency was created,
the user is asked for its type. This works even when C<a> already is C<b>'s
parent.

=item *

Dropping node C<a> on node C<b> while pressing C<Shift> attaches node C<a> to
node C<b> without creating an enhanced dependency. If an enhanced dependency
existed to the old or new parent, it is removed.

=item *

Pressing C<d> opens a dialog box to edit the current node's dependency type.
If previously an enhanced dependency of the same type as the basic dependency
existed, it is changed together with it, otherwise, it stays unchanged.

=head1 INSTALLATION

Expand Down
13 changes: 8 additions & 5 deletions ud/contrib/ud/ud.inc
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,16 @@
} else {
return if $target == $parent;

my @deps = (_create_container(
$target->{ord}, $node->{deprel}),
grep $_->{func} ne $node->{deprel}
&& $_->content != $parent->{ord},
my $with_enhanced = ! (defined $mod && $mod eq 'Shift');
my @deps = ($with_enhanced
? _create_container($target->{ord},
$node->{deprel})
: (),
grep $_->content != $parent->{ord}
&& $_->content != $target->{ord},
ListV($node->{deps}));
delete $node->{deps};
$node->{deps} = List(@deps);
$node->{deps} = List(@deps) if @deps;
CutPaste($node, $target);
ChangingFile(1);
}
Expand Down
55 changes: 28 additions & 27 deletions ud/stylesheets/UD
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@ node: ${id}<? '#{grey}' if $${ord} =~ /\./ ?>${form}<? $${lemma} && $${lemma} ne
node: #{darkcyan}${upostag}<? $${id} ? "" : "." ?>#{blue}${deprel}

style: <?
if ($this->{deps}) {
my @deps = grep {
($_->content // 0) ne ($this->parent->{ord} // 0)
} ListV($this->{deps});

my $is_parent_in_deps = grep $_->content == $this->parent->{ord}
&& $_->{func} eq $this->{deprel},
ListV($this->{deps});

my $coords = join '&', 'n,n,p,p', map {
my ($parent, $func) = ($_->content, $_->{func});
my $expression = $parent ? "[ord=$parent]" : '[! $this->root !]';
"n,n,(x$expression+xn)/2,(y$expression+yn)/2.5,x$expression,y$expression"
} @deps;

my $arrows = join '&', 'none', ('last') x @deps;
my $colours = join '&', ($is_parent_in_deps ? 'grey' : 'cyan'), ('orange') x @deps;
my $widths = join '&', ($is_parent_in_deps ? '2' : '1'), ('1') x @deps;
my $smooth = join '&', '0', ('1') x @deps;
my $hints = join '&', "", map "$_->{func}", @deps;
my $deco = join '&', "", map "shape=text;font=SansSerif 9;fill=magenta;coords=n,n;start=20;text=$_->{func}", @deps;

"#{Line-coords:$coords}#{Line-fill:$colours}#{Line-arrow:$arrows}"
. "#{Line-width:$widths}#{Line-smooth:$smooth}#{Line-hint:$hints}"
. "#{Line-decoration:$deco}"
. ('#{Oval-fill:whitesmoke}#{CurrentOval-fill:pink}#{Oval-outline:cyan}' x $this->{ord} =~ /\./);
}
my @deps = grep {
($_->content // 0) ne ($this->parent->{ord} // 0)
} ListV($this->{deps});

my $is_parent_in_deps = grep $_->content == $this->parent->{ord}
&& $_->{func} eq $this->{deprel},
ListV($this->{deps});
warn $this->{ord}, ' ', $is_parent_in_deps ? 'yes' : 'no';

my $coords = join '&', 'n,n,p,p', map {
my ($parent, $func) = ($_->content, $_->{func});
my $expression = $parent ? "[ord=$parent]" : '[! $this->root !]';
"n,n,(x$expression+xn)/2,(y$expression+yn)/2.5,x$expression,y$expression"
} @deps;

my $arrows = join '&', 'none', ('last') x @deps;
my $colours = join '&', ($is_parent_in_deps ? 'grey' : 'cyan'), ('orange') x @deps;
my $widths = join '&', ($is_parent_in_deps ? '2' : '1'), ('1') x @deps;
my $smooth = join '&', '0', ('1') x @deps;
my $hints = join '&', "", map "$_->{func}", @deps;
my $deco = join '&', "", map "shape=text;font=SansSerif 9;fill=magenta;coords=n,n;start=20;text=$_->{func}", @deps;

warn "\t$colours | $widths";

"#{Line-coords:$coords}#{Line-fill:$colours}#{Line-arrow:$arrows}"
. "#{Line-width:$widths}#{Line-smooth:$smooth}#{Line-hint:$hints}"
. "#{Line-decoration:$deco}"
. ('#{Oval-fill:whitesmoke}#{CurrentOval-fill:pink}#{Oval-outline:cyan}' x $this->{ord} =~ /\./);

?>

0 comments on commit 687e1b2

Please sign in to comment.