| 1 | # Before `make install' is performed this script should be runnable with | ||
| 2 | # `make test'. After `make install' it should work as `perl 1.t' | ||
| 3 | |||
| 4 | ######################### | ||
| 5 | |||
| 6 | # change 'tests => 1' to 'tests => last_test_to_print'; | ||
| 7 | |||
| 8 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use Test::More tests => 51; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | BEGIN { use_ok('Lingua::Treebank::Const') }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | ######################### | ||
| 13 | |||
| 14 | # Insert your test code below, the Test::More module is use()ed here so read | ||
| 15 | # its man page ( perldoc Test::More ) for help writing this test script. | ||
| 16 | |||
| 17 | 1 | ▶ | use constant PACK => 'Lingua::Treebank::Const'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 1 | my %examples; | |
| 19 | my %words; | ||
| 20 | 1 | can_ok(PACK, | |
| 21 | qw{ root }, | ||
| 22 | qw{ path_up_to }, | ||
| 23 | qw( get_all_terminals ), | ||
| 24 | # qw{ find_common_ancestor }, | ||
| 25 | # qw{ equiv_to }, | ||
| 26 | # qw{ depth_from depth }, | ||
| 27 | # qw{ height }, | ||
| 28 | # qw{ get_index }, | ||
| 29 | ); | ||
| 30 | |||
| 31 | 1 | my $d = PACK->new(); | |
| 32 | |||
| 33 | 1 | ok( defined $d, "new() returned something" ); | |
| 34 | |||
| 35 | 1 | isa_ok($d, PACK, 'root node'); | |
| 36 | |||
| 37 | 1 | $examples{ex1} = <<EOEX1; | |
| 38 | (S | ||
| 39 | (NP | ||
| 40 | (NNP Joe) | ||
| 41 | ) | ||
| 42 | (VP | ||
| 43 | (VB likes) | ||
| 44 | (NP | ||
| 45 | (NNP Bach) | ||
| 46 | ) | ||
| 47 | ) | ||
| 48 | (. .) | ||
| 49 | ) | ||
| 50 | EOEX1 | ||
| 51 | |||
| 52 | 1 | $d->from_penn_string($examples{ex1}); | |
| 53 | |||
| 54 | #05 | ||
| 55 | 1 | ok(1, "passed from_penn_string"); | |
| 56 | |||
| 57 | 1 | my $ll = $d->left_leaf(); | |
| 58 | |||
| 59 | 1 | isa_ok($ll, PACK, 'leftleaf'); | |
| 60 | |||
| 61 | 1 | is( $ll->root(), $d, 'root of leftleaf is orig root'); | |
| 62 | |||
| 63 | 1 | my @lineage = $ll->path_up_to($d); | |
| 64 | |||
| 65 | 1 | cmp_ok(scalar @lineage, '==', 3, '3 elements in lineage of "Joe"'); | |
| 66 | |||
| 67 | 1 | is( (join '-', map { $_->tag() } @lineage), 'NNP-NP-S', 'NNP-NP-S'); | |
| 68 | |||
| 69 | |||
| 70 | 1 | my @lterms = $ll->get_all_terminals(); | |
| 71 | |||
| 72 | #10 | ||
| 73 | 1 | cmp_ok(scalar @lterms, '==', 1); | |
| 74 | |||
| 75 | 1 | is($lterms[0], $ll, 'll is own terminal'); | |
| 76 | |||
| 77 | 1 | my @words = $d->get_all_terminals(); | |
| 78 | |||
| 79 | 1 | cmp_ok(scalar @words, '==', 4, '4 terminal words under root'); | |
| 80 | |||
| 81 | 1 | my $string = ''; | |
| 82 | #13->20 (4x2 tests) | ||
| 83 | 1 | foreach (@words) { | |
| 84 | 4 | isa_ok($_, PACK); | |
| 85 | 4 | ok( $_->is_terminal() ); | |
| 86 | 4 | $string .= ' '; | |
| 87 | 4 | $string .= $_->word(); | |
| 88 | } | ||
| 89 | |||
| 90 | 1 | is($string, ' Joe likes Bach .', "'Joe likes Bach .'"); | |
| 91 | |||
| 92 | 1 | $examples{ex30} = <<EOEX30; | |
| 93 | (NP-PRD (-NONE- *?*) ) | ||
| 94 | EOEX30 | ||
| 95 | 1 | $words{ex30} = ""; | |
| 96 | |||
| 97 | 1 | $examples{ex31} = <<EOEX31; | |
| 98 | (SQ (VBZ is) (RB n't) | ||
| 99 | (NP-SBJ (RB there) ) | ||
| 100 | (NP-PRD (-NONE- *?*) ) ) | ||
| 101 | EOEX31 | ||
| 102 | 1 | $words{ex31} = "is n't there"; | |
| 103 | |||
| 104 | 1 | $examples{ex32} = <<'EOEX32'; | |
| 105 | (SQ | ||
| 106 | (SQ (VBZ is) (RB n't) | ||
| 107 | (NP-SBJ (RB there) ) | ||
| 108 | (NP-PRD (-NONE- *?*) ) ) | ||
| 109 | (. .) (-DFL- E_S) | ||
| 110 | ) | ||
| 111 | EOEX32 | ||
| 112 | 1 | $words{ex32} = "is n't there . E_S"; | |
| 113 | |||
| 114 | 1 | $examples{ex33} = <<EOEX33; | |
| 115 | (SQ | ||
| 116 | (S | ||
| 117 | (INTJ (UH Uh) ) | ||
| 118 | (, ,) | ||
| 119 | (NP-SBJ (EX there) ) | ||
| 120 | (VP (BES 's) | ||
| 121 | (ADVP (RB really) ) | ||
| 122 | (NP-PRD (DT a) (NN lot) ))) | ||
| 123 | (, ,) | ||
| 124 | (SQ (VBZ is) (RB n't) | ||
| 125 | (NP-SBJ (RB there) ) | ||
| 126 | (NP-PRD (-NONE- *?*) )) | ||
| 127 | (. .) (-DFL- E_S) ) | ||
| 128 | EOEX33 | ||
| 129 | 1 | $words{ex33} = "Uh , there 's really a lot , is n't there . E_S"; | |
| 130 | |||
| 131 | 1 | $examples{ex40} = <<EOEX40; | |
| 132 | (S | ||
| 133 | (NP-SBJ (EX there) ) | ||
| 134 | (ADVP (RB really) ) | ||
| 135 | (VP (VBZ is) | ||
| 136 | (NP-PRD (-NONE- *?*) ))) | ||
| 137 | EOEX40 | ||
| 138 | 1 | $words{ex40} = "there really is"; | |
| 139 | |||
| 140 | 1 | $examples{ex41} = <<EOEX41; | |
| 141 | (SBAR (-NONE- 0) ) | ||
| 142 | EOEX41 | ||
| 143 | 1 | $words{ex41} = ""; | |
| 144 | |||
| 145 | 1 | $examples{ex42} = <<EOEX42; | |
| 146 | (SBAR (-NONE- 0) | ||
| 147 | (S | ||
| 148 | (NP-SBJ (EX there) ) | ||
| 149 | (ADVP (RB really) ) | ||
| 150 | (VP (VBZ is) | ||
| 151 | (NP-PRD (-NONE- *?*) )))) | ||
| 152 | EOEX42 | ||
| 153 | 1 | $words{ex42} = "there really is"; | |
| 154 | |||
| 155 | 1 | $examples{ex43} = <<EOEX43; | |
| 156 | (VP (VBP think) | ||
| 157 | (SBAR (-NONE- 0) | ||
| 158 | (S | ||
| 159 | (NP-SBJ (EX there) ) | ||
| 160 | (ADVP (RB really) ) | ||
| 161 | (VP (VBZ is) | ||
| 162 | (NP-PRD (-NONE- *?*) ))))) | ||
| 163 | EOEX43 | ||
| 164 | 1 | $words{ex43} = "think there really is"; | |
| 165 | |||
| 166 | |||
| 167 | 1 | $examples{ex44} = <<EOEX44; | |
| 168 | (S | ||
| 169 | (NP-SBJ (PRP I) ) | ||
| 170 | (VP (VBP think) | ||
| 171 | (SBAR (-NONE- 0) | ||
| 172 | (S | ||
| 173 | (NP-SBJ (EX there) ) | ||
| 174 | (ADVP (RB really) ) | ||
| 175 | (VP (VBZ is) | ||
| 176 | (NP-PRD (-NONE- *?*) ))))) | ||
| 177 | (. .) (-DFL- E_S) ) | ||
| 178 | EOEX44 | ||
| 179 | 1 | $words{ex44} = "I think there really is . E_S"; | |
| 180 | |||
| 181 | 1 | $examples{ex45} = <<EOEX45; | |
| 182 | ( (S | ||
| 183 | (NP-SBJ (PRP I) ) | ||
| 184 | (VP (VBP think) | ||
| 185 | (SBAR (-NONE- 0) | ||
| 186 | (S | ||
| 187 | (NP-SBJ (EX there) ) | ||
| 188 | (ADVP (RB really) ) | ||
| 189 | (VP (VBZ is) | ||
| 190 | (NP-PRD (-NONE- *?*) ))))) | ||
| 191 | (. .) (-DFL- E_S) )) | ||
| 192 | EOEX45 | ||
| 193 | 1 | $words{ex45} = "I think there really is . E_S"; | |
| 194 | |||
| 195 | #22->61 (10 ex * 3 tests each) | ||
| 196 | 1 | foreach ( qw{ ex30 ex31 ex32 ex33 }, | |
| 197 | qw{ ex40 ex41 ex42 ex43 ex44 ex45 } ) { | ||
| 198 | 10 | my $funky = PACK->new(); | |
| 199 | |||
| 200 | 10 | isa_ok($funky, PACK, $_); | |
| 201 | |||
| 202 | 10 | $funky->from_penn_string($examples{$_}); | |
| 203 | 10 | ok(1, "able to read in '$_' string"); | |
| 204 | |||
| 205 | 10 | my @leaflist = $funky->get_all_terminals(); | |
| 206 | # is( $words{$_}, join (" ", map {$_->word()} @leaflist), "$_ words match"); | ||
| 207 | |||
| 208 | 10 | is($funky->text(), $words{$_}, "$_ text match"); | |
| 209 | } | ||
| 210 | |||
| 211 | |||