Both sides previous revision
Previous revision
|
Next revision
Both sides next revision
|
external:tectomt:tutorial [2009/01/21 11:06] kravalova |
external:tectomt:tutorial [2009/01/21 11:08] kravalova |
This block illustrates some of the most common methods for accessing objects: | This block illustrates some of the most common methods for accessing objects: |
| |
* ''my @bundles = $document->get_bundles()'' - an array of bundles contained in the document | * ''my @bundles = $document<nowiki>-></nowiki>get_bundles()'' - an array of bundles contained in the document |
* ''my $root_node = $bundle->get_tree($layer_name);'' - the root node of the tree of the given type in the given bundle | * ''my $root_node = $bundle<nowiki>-></nowiki>get_tree($layer_name);'' - the root node of the tree of the given type in the given bundle |
* ''my @children = $node->get_children();'' - array of the node's children | * ''my @children = $node<nowiki>-></nowiki>get_children();'' - array of the node's children |
* ''my @descendants = $node->get_descendants();'' - array of the node's children and their children and children of their children ... | * ''my @descendants = $node<nowiki>-></nowiki>get_descendants();'' - array of the node's children and their children and children of their children ... |
* ''my $parent = $node->get_parent();'' - parent node of the given node, or undef for root | * ''my $parent = $node<nowiki>-></nowiki>get_parent();'' - parent node of the given node, or undef for root |
* ''my $root_node = $node->get_root();'' - the root node of the tree into which the node belongs | * ''my $root_node = $node<nowiki>-></nowiki>get_root();'' - the root node of the tree into which the node belongs |
| |
Attributes of documents, bundles or nodes can be accessed by attribute getters and setters, for example: | Attributes of documents, bundles or nodes can be accessed by attribute getters and setters, for example: |
* ''$node->get_attr($attr_name);'' | * ''$node<nowiki>-></nowiki>get_attr($attr_name);'' |
* ''$node->set_attr($attr_name, $attr_value);'' | * ''$node<nowiki>-></nowiki>set_attr($attr_name, $attr_value);'' |
| |
Our tutorial block ''Print_node_info.pm'' is ready to use. You only need to add this block to our scenario, e.g. as a new Makefile target: | Our tutorial block ''Print_node_info.pm'' is ready to use. You only need to add this block to our scenario, e.g. as a new Makefile target: |
**Instructions**: | **Instructions**: |
| |
* To find an object to a verb, look for objects among effective children of a verb (''$child->get_attr('afun') eq 'Obj' ''). That implies working on analytical layer. | * To find an object to a verb, look for objects among effective children of a verb (''$child<nowiki>-></nowiki>get_attr('afun') eq 'Obj' ''). That implies working on analytical layer. |
* For debugging, a method returning surface word order of a node is useful: ''$node->get_attr('ord')''. It can be used to print out nodes sorted by attribute ''ord''. | * For debugging, a method returning surface word order of a node is useful: ''$node<nowiki>-></nowiki>get_attr('ord')''. It can be used to print out nodes sorted by attribute ''ord''. |
* Once you have node ''$object'' and node ''$verb'', use method ''$object->shift_before_node($verb)''. This method takes the whole subtree under node ''$object'' and counts the attributes ''ord'' (surface word order) so that all nodes in subtree under ''$object'' have smaller ''ord'' than ''$verb''. That is, the method rearranges the surface word order from VO to OV. | * Once you have node ''$object'' and node ''$verb'', use method ''$object<nowiki>-></nowiki>shift_before_node($verb)''. This method takes the whole subtree under node ''$object'' and counts the attributes ''ord'' (surface word order) so that all nodes in subtree under ''$object'' have smaller ''ord'' than ''$verb''. That is, the method rearranges the surface word order from VO to OV. |
| |
| |
| |
You are going to need these new methods: | You are going to need these new methods: |
* ''my @children = $node->get_children'' | * ''my @children = $node<nowiki>-></nowiki>get_children'' |
* ''my $parent = $node->get_parent'' | * ''my $parent = $node<nowiki>-></nowiki>get_parent'' |
* ''$node->set_parent($parent)'' | * ''$node<nowiki>-></nowiki>set_parent($parent)'' |
| |
//Hint//: | //Hint//: |
* On analytical layer, you can use this test to recognize prepositions: ''$node->get_attr('afun') eq 'AuxP' '' | * On analytical layer, you can use this test to recognize prepositions: ''$node<nowiki>-></nowiki>get_attr('afun') eq 'AuxP' '' |
* You can use block template in ''libs/blocks/BlockTemplate.pm''. To see the results, you can again use TrEd (''tmttred sample.tmt'') | * You can use block template in ''libs/blocks/BlockTemplate.pm''. To see the results, you can again use TrEd (''tmttred sample.tmt'') |
| |