contrib documentation

Table of contents


contrib.mac

ToC

contrib/contrib.mac - the file responsible for loading other macro files

DESCRIPTION

This file is included by default in tred.mac and serves as a wrapper for other contributed macro package inclusions.

Besides it provides file_opened_hook and file_resumed_hook in the package TredMacros. These hooks should not be overriden by other macro packages. See below how to plug context-specific code in.

Context Guessing

ToC

@TredMacro::AUTO_CONTEXT_GUESSING

This global variable can be used by contributed TrEd macro packages to plug-in their custom context guessing functions. The purpose of such a function is to detect whether the current file is suitable for the macro package and if so, to indicate the correct binding context.

The function must return name of the context to switch to or undef if the current file does not suit.

The synopsis for a package named 'Foo' is as follows:

  #binding-context Foo
  package Foo;
  BEGIN { import TredMacro; }
  context_guessing {
    my ($hook)=@_;
    if (PML::SchemaName() eq 'foo-data') { # some test that the file suites the macro package
      if ($hook eq 'file_opened_hook') {
         # some open-specific code
      } elsif ($hook eq 'file_resumed_hook') {
         # some resume-specific code
      }
      return 'Foo'; # return name of the macro package (context) to use
    }
    return;
  };

node_groups.mak

ToC

TrEd::NodeGroups - macros for visualizing groups of nodes

USAGE

  package MyMacros;
  use strict;
  BEGIN{ import TredMacro };

  sub after_redraw_hook {
    my @nodes = GetDisplayedNodes();
    my $group1 = [ $nodes[0..$#$nodes/2] ];
    my $group2 = [ $nodes[$#$nodes/2..$#$nodes] ];
    my $group3 = [ $nodes[$#$nodes/3..2*$#$nodes/3] ];
    TrEd::NodeGroups::draw_groups(
      $grp,
      [$group1,$group2,$group3],
      { colors => [qw(red orange pink)],
        # stipples => [qw(dense1 dense2 ... dense6)],
        # stipples => [qw(dash1 dash2 ... dash6)], # default
        # group_line_width => 30, # default
      }
    );
  }

PML

ToC

PML.mak - Miscelaneous macros of general use in Prague Dependency Treebank (PDT) 2.0

USAGE

  #include <contrib/pml/PML.mak>

MACROS

The following macros (functions) are provided by this package:

PML::SchemaName()

Return name of the root element of a PML instance as specified in the PML schema associated with the current file. PDT uses root element named adata for analytical layer annotation and tdata for tectogrammatical layer annotation.

PML::SchemaDescription()

Return the content of the element description of the PML schema associated with the current file.

PML::Schema($object?)

For a Treex::PML::Node object returns PML schema associated with that object. If the object is a Treex::PML::Document, return PML schema associated with the given file. If no object is given, the current Treex::PML::Document is used.

The PML schema is returned in form of a Treex::PML::Schema object.

PML::GetNodeByID($id_or_ref,$fsfile?)

Looks up a node from the current file (or given fsfile) by its ID (or PMLREF - i.e. the ID preceded by a file prefix of the form xy#).

PML::DeleteFromNodeHash($id,$fsfile?)

Deletes a given ID from a node HASH of the current or specified Treex::PML::Document The node previously hashed under the given ID is returned.

PML::AddToNodeHash($id,$node,$fsfile?)

Adds a node to the node hash (of the given or current Treex::PML::Document) using given ID as the hash key.

PML::SearchForNodeById($id)

Searches for node with given id. Returns the node and the number of the tree.

PML::GetNodeHash($fsfile?)

Return a reference to a hash indexing nodes in a given file (or the current file if no argument is given). If such a hash was not yet created, it is built upon the first call to this function (or other functions calling it, such as GetNodeByID. Use clearNodeHash to clear the hash.

PML::ClearNodesHash($fsfile?)

Clear the internal hash indexing nodes of a given file (or the current file if called without an argument).

PML::GotoTree()

Ask user for sentence or node identificator (tree number or id) and go to the sentence.

PML::NonProjEdges($node,$ord?,$filterNode?,$returnParents?,$subord?,$filterGap?)

DEPRECATED, use non_proj_edges from <contrib/support/non_projectivity.mak> instead.

arrows.inc

ToC

This file provides generic support for drawing custom arrows that can be used in any macro context.

USAGE

Add these lines to your macro context:

  #include <contrib/support/arrows.inc>
  #include <contrib/pml/PML.mak>

  sub root_style_hook {
    DrawArrows_init();
    # ...
  }
  sub after_redraw_hook {
    DrawArrows_cleanup();
    # ...
  }
  sub node_style_hook {
     my ($node,$styles) = @_;
     DrawArrows($node,$styles,
       [ {
           # an arrow with a target
           -target => PML::GetNodeByID($node->{ref}),
           # other options: -tag -arrow -arrowshape -width -smooth -fill -dash
         },
         {
           # an arrow without a target
           -deltax => 10,
           -deltay => '(yn-yp)/2',
           # ...
         },
         {
           # an arrow with modified origin
           -originx => 'xn+10',
           -originy => 'yn+10',
           # ...
         },
      ],
      {
        # options common to all edges
      });
    #...
  }

DESCRIPTION

This file provides a function DrawArrows which can be called from the node_style_hook to extra arrows from the current node to some other nodes (or relative coordinates). The USAGE section above shows a full example.

In the macros for your annotation context, you have to:

1.

include <contrib/support/arrows.inc>

2.

define the root_style_hook which calls DrawArrow_init() to initialize caches.

3.

define an after_redraw_hook which calls DrawArrow_cleanup() to clean-up caches.

4.

define a node_style_hook which calls DrawArrows with the following arguments

  DrawArrows($node,$styles,\@arrow_definitions,\%common_arrow_options)

The first two arguments ($node and $styles) are the first two arguments passed to the node_style_hook by TrEd. The third argument, \@arrow_definitions, is an ARRAY reference containing definitions of the arrows to draw. Each arrow definition is a HASH reference defining the target node or target coordinates for the other end of the arrow and style options. Style options common to all arrows can be also passed in the optional HASH reference passed as the last argument \%common_arrow_options.

Arrow definitions and styles

Eeach arrow definition (passed in the \@rrow_definitions list to the DrawArrows) is a HASH reference consisting of some arrow options. With the exception of -target, -originx, -originy, -deltax, -deltay, these options can also be passed as \%common_arrow_options to DrawArrows.

-target

the target node.

If no target is specified, the target coordinates default to the coordinates of the current node and the flags -deltax and -deltay must be used to specify the target coordinates.

-originx

the x-coordinate of the origin (defaults to 'xn' - the x-coordinate of the current node)

-originy

the y-coordinate of the origin (defaults to 'yn' - the y-coordinate of the current node)

-deltax

value to add to the x-coordinate of the target

-deltay

value to add to the y-coordinate of the target

-smooth

1 to make the arrow a smoothed curve (see also -raise and -frac)

-frac

Defaults to 0.12. When a curved arrow is drawn (i.e. -smooth => 1 was given), this value defines the 'lift' of the arrow as a fraction of the length of the straight line connecting the start and end of the arrow. 0 means no lift (straight line). The signum of the value decides the orientation of the lift.

-raise

Defaults to 25. An absolute value added to the 'lift' of an arrow.

-arrow

one of 'first', 'last', 'both', 'none' (where to put the the arrow head)

-arrowshape

a comma-separated list of three integers defining the shape of the arrow head (see Tk::Canvas manual)

-dash

a comma-separated list of integers (even number) specifying the lengths of dashes and spaces between them

-width

width of the line

-fill

color of the line (either the color name or a '#rrggbb' hex code)

-hint

a tooltip that is displayed when the user hovers mouse over the arrow

-tag

a comma-separated list of tags associated with the arrow on the canvas; tags can be used for varius purposes, e.g. to raise or lower objects on the Tk::Canvas (see the stackOrder instruction in http://ufal.mff.cuni.cz/~pajas/tred/ar01s10.html). they are also used as classes when exporting to SVG.

-decoration

decoration of the arrow (see description of the Line-decoration style instruction in http://ufal.mff.cuni.cz/~pajas/tred/ar01s10.html).

fold_subtree.inc

ToC

This file can add support for folding (collapsing) subtrees to any macro context.

USAGE

1. Add these lines to your macro context:

  #include <contrib/support/fold_subtree.inc>
  #bind fold_subtree_toggle to SOME_KEY  menu Fold/unfold current subtree (toggle)

and possibly

  #bind fold_subtree_unfold_all to OTHER_KEY menu Unfold all in the current subtree

replacing SOME_KEY and OTHER_KEY with suitable key bindings.

2. Add the following lines to your stylesheet:

  style:<? "#{Node-hide:1}" if FileUserData('hide')->{$this}; ?>
  style:<? "#{Oval-fill:blue}#{Node-shape:rectangle}"
              if FileUserData('fold')->{$this} ?>

The fist line does the folding, the second defines the visual style for the root of a folded subtree (blue rectangle in this case). Adjust it as you need.

move_nodes_freely.inc

ToC

This file provides generic support for manual repositioning of nodes on the canvas.

USAGE

Add this line to your macro context:

  #include <contrib/support/move_nodes_freely.inc>

And these to your stylesheet:

style:<? my ($x,$y)=($this->{'.xadj'}||0,$this->{'.yadj'}||0); qq(#{Node-xadj:$x}#{Node-yadj:$y}) ?>

Then you can drag nodes over the canvas. When releasing the node with Shift pressed, the node (and its labels and edge-ends) move to the given position; if Control is pressed, then the complete subtree is moved in this way.

CUSTOMIZING

You may modify these default bindings by setting e.g.:

  $move_nodes_freely{subtree}='Alt'; # default is Control
  $move_nodes_freely{node}='Meta'; # default is Shift

WRAPPING

If you want to wrap this code into a more complex hook, you can do it by using a class:

  package MyContext::MoveSupport;
  import TredMacro;
  #include <contrib/support/move_nodes_freely.inc>

  package MyContext;
  import TredMacro;
  # ...
  sub node_release_hook {
    my (@args)=@_;
    if (MyContext::MoveSupport::node_release_hook(@args) eq 'subtree') {
       # the hook moved a subtree
    } else (MyContext::MoveSupport::node_release_hook(@args) eq 'node') {
       # the hook moved a node
    } else {
       # the hook moved nothing
    }
  }

A FINAL NOTE

This implementation adds the attributes .xadj and .yadj to the moved nodes. These may be preserved by some I/O backends, e.g. Storable.

non_projectivity.mak

ToC

An efficient algorighm for finding non-projectivity edges in ordered trees.

USAGE

  #include <contrib/support/non_projectivity.mak>

  non_proj_edges($root);

MACROS

The following macros (functions) are provided by this package:

non_proj_edges($node,$only_visible?,$ord?,$filterNode?,$returnParents?,$subord?,$filterGap?)

Returns hash-ref containing all non-projective edges in the subtree rooted in $node. Values of the hash are references to arrays containing the non-projective edges (the arrays contain the lower and upper nodes representing the edge, and then the nodes causing the non-projectivity of the edge), keys are concatenations of stringified references to lower and upper nodes of non-projective edges. Description of the arguments is as follows: $node specifies the root of a subtree to be checked for non-projective edges; $only_visible set to true confines the subtree to visible nodes; $ord specifies the ordering attribute to be used; a subroutine accepting one argument passed as sub-ref in $filterNode can be used to filter the edges taken into account (by specifying the lower nodes of the edges); sub-ref $returnParents accepting one argument returns an array of upper nodes of the edges to be taken into account; sub-ref $subord accepting two arguments returns 1 iff the first one is subordinated to the second one; sub-ref $filterGap accepting one argument can be used to filter nodes causing non-projectivity. Defaults are: all nodes, the default ordering attribute, all nodes, parent (in the technical representation), subordination in the technical sense, all nodes.

AUTHOR

Jiri Havelka

unbind_edit.inc

ToC

Disable default TredMacro key-bindings that modify trees.

USAGE

  #include <common/support/unbind_edit.inc>

DESCRIPTION

Include this macro in your binding context if you want to disable all default TredMacro key-bindings that modify trees, such as copy/paste, etc.