treebank 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +2 -1
 - data/lib/treebank.rb +5 -8
 - data/test/test_treebank.rb +12 -12
 - metadata +2 -2
 
    
        data/README
    CHANGED
    
    | 
         @@ -28,7 +28,7 @@ in a bracketed tree format. 
     | 
|
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
            Bracketed tree strings can be used to create Node trees.
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
               irb(main):006:0> t = Treebank::Node. 
     | 
| 
      
 31 
     | 
    
         
            +
               irb(main):006:0> t = Treebank::Node.from_s('(parent (child1) (child2))')
         
     | 
| 
       32 
32 
     | 
    
         
             
               => <Treebank::Node parent [child1 child2]>
         
     | 
| 
       33 
33 
     | 
    
         
             
               irb(main):007:0> puts t
         
     | 
| 
       34 
34 
     | 
    
         
             
               (parent (child1) (child2))
         
     | 
| 
         @@ -42,6 +42,7 @@ linguistic structure. 
     | 
|
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
            * 1-0-0 ... First release
         
     | 
| 
       44 
44 
     | 
    
         
             
            * 1-1-0 ... Removed unnecessary fsa dependency from gemspec
         
     | 
| 
      
 45 
     | 
    
         
            +
            * 2-0-0 ... Changed from_s initialization
         
     | 
| 
       45 
46 
     | 
    
         | 
| 
       46 
47 
     | 
    
         
             
            = See Also
         
     | 
| 
       47 
48 
     | 
    
         | 
    
        data/lib/treebank.rb
    CHANGED
    
    | 
         @@ -18,7 +18,7 @@ 
     | 
|
| 
       18 
18 
     | 
    
         
             
            # Treebank is the namespace that contains all tree-related functions.
         
     | 
| 
       19 
19 
     | 
    
         
             
            module Treebank
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
              VERSION = " 
     | 
| 
      
 21 
     | 
    
         
            +
              VERSION = "2.0.0"
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
              # An enumerable list of tokens in a string representation of a tree
         
     | 
| 
       24 
24 
     | 
    
         
             
              #
         
     | 
| 
         @@ -244,14 +244,11 @@ module Treebank 
     | 
|
| 
       244 
244 
     | 
    
         
             
                # * right ... right bracket symbol
         
     | 
| 
       245 
245 
     | 
    
         
             
                #
         
     | 
| 
       246 
246 
     | 
    
         
             
                # This function uses a Treebank::Parser object to create the tree from
         
     | 
| 
       247 
     | 
    
         
            -
                # _s_. 
     | 
| 
       248 
     | 
    
         
            -
                def from_s(s, left = '(', right = ')')
         
     | 
| 
       249 
     | 
    
         
            -
                   
     | 
| 
       250 
     | 
    
         
            -
                  nodes = Parser.new(TokenStream.new(s, left, right), self.class).collect
         
     | 
| 
      
 247 
     | 
    
         
            +
                # _s_.
         
     | 
| 
      
 248 
     | 
    
         
            +
                def Node.from_s(s, left = '(', right = ')')
         
     | 
| 
      
 249 
     | 
    
         
            +
                  nodes = Parser.new(TokenStream.new(s, left, right), self).collect
         
     | 
| 
       251 
250 
     | 
    
         
             
                  raise "#{s} defines multiple trees" if nodes.length != 1
         
     | 
| 
       252 
     | 
    
         
            -
                   
     | 
| 
       253 
     | 
    
         
            -
                  @children = nodes.first.collect
         
     | 
| 
       254 
     | 
    
         
            -
                  self
         
     | 
| 
      
 251 
     | 
    
         
            +
                  nodes.first
         
     | 
| 
       255 
252 
     | 
    
         
             
                end
         
     | 
| 
       256 
253 
     | 
    
         | 
| 
       257 
254 
     | 
    
         
             
                # Stringify
         
     | 
    
        data/test/test_treebank.rb
    CHANGED
    
    | 
         @@ -68,7 +68,7 @@ module ParseTreeMixin 
     | 
|
| 
       68 
68 
     | 
    
         
             
              def test_tree_parse
         
     | 
| 
       69 
69 
     | 
    
         
             
                p = Treebank::Parser.new(Treebank::TokenStream.new('(A) (B)'), @node_class)
         
     | 
| 
       70 
70 
     | 
    
         
             
                trees = p.collect
         
     | 
| 
       71 
     | 
    
         
            -
                assert_equal [@node_class. 
     | 
| 
      
 71 
     | 
    
         
            +
                assert_equal [@node_class.from_s('(A)'), @node_class.from_s('(B)')], trees
         
     | 
| 
       72 
72 
     | 
    
         
             
                assert_kind_of @node_class, trees[0]
         
     | 
| 
       73 
73 
     | 
    
         
             
                assert_kind_of @node_class, trees[1]
         
     | 
| 
       74 
74 
     | 
    
         
             
                t = Treebank::Parser.new(Treebank::TokenStream.new('(A (B) (C))'), @node_class).collect.first
         
     | 
| 
         @@ -79,7 +79,7 @@ module ParseTreeMixin 
     | 
|
| 
       79 
79 
     | 
    
         
             
              end
         
     | 
| 
       80 
80 
     | 
    
         | 
| 
       81 
81 
     | 
    
         
             
              def test_string_in_constructor
         
     | 
| 
       82 
     | 
    
         
            -
                assert_equal [@node_class. 
     | 
| 
      
 82 
     | 
    
         
            +
                assert_equal [@node_class.from_s('(A)'), @node_class.from_s('(B)')], Treebank::Parser.new('(A) (B)', @node_class).collect
         
     | 
| 
       83 
83 
     | 
    
         
             
              end
         
     | 
| 
       84 
84 
     | 
    
         | 
| 
       85 
85 
     | 
    
         
             
            end
         
     | 
| 
         @@ -133,7 +133,7 @@ module NodeTestMixin 
     | 
|
| 
       133 
133 
     | 
    
         
             
              # Test adding children in the constructor
         
     | 
| 
       134 
134 
     | 
    
         
             
              def test_constructor_children
         
     | 
| 
       135 
135 
     | 
    
         
             
                t = @node_class.new('a', ['b', 'c', 'd'])
         
     | 
| 
       136 
     | 
    
         
            -
                assert_equal @node_class. 
     | 
| 
      
 136 
     | 
    
         
            +
                assert_equal @node_class.from_s('(a (b) (c) (d) )'), t, 'Children in constructor'
         
     | 
| 
       137 
137 
     | 
    
         
             
              end
         
     | 
| 
       138 
138 
     | 
    
         | 
| 
       139 
139 
     | 
    
         
             
              # Add children
         
     | 
| 
         @@ -163,17 +163,17 @@ module NodeTestMixin 
     | 
|
| 
       163 
163 
     | 
    
         
             
                    (N (boy)))
         
     | 
| 
       164 
164 
     | 
    
         
             
                 (VP
         
     | 
| 
       165 
165 
     | 
    
         
             
                    (V (ran))))'
         
     | 
| 
       166 
     | 
    
         
            -
                t = @node_class. 
     | 
| 
      
 166 
     | 
    
         
            +
                t = @node_class.from_s(s)
         
     | 
| 
       167 
167 
     | 
    
         
             
                assert_kind_of @node_class, t, 'from_s'
         
     | 
| 
       168 
168 
     | 
    
         
             
                assert_equal s, "#{t}", 'to_s'
         
     | 
| 
       169 
     | 
    
         
            -
                m = @node_class. 
     | 
| 
      
 169 
     | 
    
         
            +
                m = @node_class.from_s(multiline_s)
         
     | 
| 
       170 
170 
     | 
    
         
             
                assert_equal t, m, 'Single-/multi-line equal'
         
     | 
| 
       171 
171 
     | 
    
         
             
              end
         
     | 
| 
       172 
172 
     | 
    
         | 
| 
       173 
173 
     | 
    
         
             
              # Simple enumeration
         
     | 
| 
       174 
174 
     | 
    
         
             
              def test_enumeration
         
     | 
| 
       175 
175 
     | 
    
         
             
                # Enumerate all children.
         
     | 
| 
       176 
     | 
    
         
            -
                t = @node_class. 
     | 
| 
      
 176 
     | 
    
         
            +
                t = @node_class.from_s('(a (b (R) (S) ) (c (T) (U)) )')
         
     | 
| 
       177 
177 
     | 
    
         
             
                assert_equal ['a', 'b', 'c', 'R', 'S', 'T', 'U'], t.each_breadth_first.collect {|node| node.label}, 'Full breadth first'
         
     | 
| 
       178 
178 
     | 
    
         
             
                assert_equal ['a', 'b', 'R', 'S', 'c', 'T', 'U'], t.each_depth_first.collect {|node| node.label}, 'Full depth first'
         
     | 
| 
       179 
179 
     | 
    
         
             
                # Enumerate children beneath a node.
         
     | 
| 
         @@ -188,10 +188,10 @@ module NodeTestMixin 
     | 
|
| 
       188 
188 
     | 
    
         | 
| 
       189 
189 
     | 
    
         
             
              # Tree equivalence
         
     | 
| 
       190 
190 
     | 
    
         
             
              def test_equivalence
         
     | 
| 
       191 
     | 
    
         
            -
                t1 = @node_class. 
     | 
| 
       192 
     | 
    
         
            -
                t2 = @node_class. 
     | 
| 
       193 
     | 
    
         
            -
                s1 = @node_class. 
     | 
| 
       194 
     | 
    
         
            -
                s2 = @node_class. 
     | 
| 
      
 191 
     | 
    
         
            +
                t1 = @node_class.from_s('(a (b (R) (S) ) (c (T) (U)) )')
         
     | 
| 
      
 192 
     | 
    
         
            +
                t2 = @node_class.from_s('(a (b (R) (S) ) (c (T) (U)) )')
         
     | 
| 
      
 193 
     | 
    
         
            +
                s1 = @node_class.from_s('(a (b (R) (S) ) (c (T) ) )')
         
     | 
| 
      
 194 
     | 
    
         
            +
                s2 = @node_class.from_s('(a (c (R) (S) ) (b (T) (U) ) )')
         
     | 
| 
       195 
195 
     | 
    
         
             
                assert_equal t1, t2, 'Tree equivalence'
         
     | 
| 
       196 
196 
     | 
    
         
             
                assert_not_equal t1, s1, 'Tree non-equivalence: different terminals'
         
     | 
| 
       197 
197 
     | 
    
         
             
                assert_not_equal t1, s2, 'Tree non-equivalence: reversed non-terminal labels'
         
     | 
| 
         @@ -199,7 +199,7 @@ module NodeTestMixin 
     | 
|
| 
       199 
199 
     | 
    
         
             
              end
         
     | 
| 
       200 
200 
     | 
    
         | 
| 
       201 
201 
     | 
    
         
             
              def test_leaves
         
     | 
| 
       202 
     | 
    
         
            -
                t = @node_class. 
     | 
| 
      
 202 
     | 
    
         
            +
                t = @node_class.from_s('(a (b c) (d e))')
         
     | 
| 
       203 
203 
     | 
    
         
             
                leaves = t.each_depth_first.collect
         
     | 
| 
       204 
204 
     | 
    
         
             
                c = leaves[2]
         
     | 
| 
       205 
205 
     | 
    
         
             
                e = leaves[4]
         
     | 
| 
         @@ -229,7 +229,7 @@ class ParentedNodeTest < Test::Unit::TestCase 
     | 
|
| 
       229 
229 
     | 
    
         
             
              end
         
     | 
| 
       230 
230 
     | 
    
         | 
| 
       231 
231 
     | 
    
         
             
              def test_ancestor_enumeration
         
     | 
| 
       232 
     | 
    
         
            -
                t = @node_class. 
     | 
| 
      
 232 
     | 
    
         
            +
                t = @node_class.from_s('(a (b (R) (S) ) (c (T) (U)) )')
         
     | 
| 
       233 
233 
     | 
    
         
             
                assert_equal [t], t.each_parent.collect, 'Ancestors from head'
         
     | 
| 
       234 
234 
     | 
    
         
             
                u = t.each_depth_first.find {|node| node.label == 'U'}
         
     | 
| 
       235 
235 
     | 
    
         
             
                assert_equal ['U', 'c', 'a'], u.each_parent.collect {|node| node.label}, 'Ancestors from leaf'
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -3,8 +3,8 @@ rubygems_version: 0.8.11 
     | 
|
| 
       3 
3 
     | 
    
         
             
            specification_version: 1
         
     | 
| 
       4 
4 
     | 
    
         
             
            name: treebank
         
     | 
| 
       5 
5 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       6 
     | 
    
         
            -
              version:  
     | 
| 
       7 
     | 
    
         
            -
            date:  
     | 
| 
      
 6 
     | 
    
         
            +
              version: 2.0.0
         
     | 
| 
      
 7 
     | 
    
         
            +
            date: 2007-01-12 00:00:00 -08:00
         
     | 
| 
       8 
8 
     | 
    
         
             
            summary: Treebank implements support for ordered n-ary branching tree structures
         
     | 
| 
       9 
9 
     | 
    
         
             
            require_paths: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            - lib
         
     |