bracket_notation 1.0.3
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/CHANGELOG +24 -0
- data/COPYING +674 -0
- data/Manifest +23 -0
- data/README.rdoc +11 -0
- data/Rakefile +42 -0
- data/bracket_notation.gemspec +33 -0
- data/init.rb +29 -0
- data/lib/bracket_notation.rb +34 -0
- data/lib/bracket_notation/evaluator.rb +99 -0
- data/lib/bracket_notation/expressions.rb +31 -0
- data/lib/bracket_notation/expressions/expression.rb +49 -0
- data/lib/bracket_notation/expressions/identifier.rb +62 -0
- data/lib/bracket_notation/expressions/terminal.rb +34 -0
- data/lib/bracket_notation/parser.rb +99 -0
- data/lib/bracket_notation/scanner.rb +129 -0
- data/lib/bracket_notation/token.rb +79 -0
- data/lib/bracket_notation/version.rb +40 -0
- data/test/functional/evaluator_test.rb +48 -0
- data/test/functional/parser_test.rb +79 -0
- data/test/functional/scanner_test.rb +48 -0
- data/test/integration/parsing_test.rb +50 -0
- data/test/test_helper.rb +32 -0
- data/test/unit/expression_test.rb +72 -0
- data/test/unit/token_test.rb +117 -0
- metadata +129 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
#--
|
2
|
+
# This file is part of BracketNotation.
|
3
|
+
#
|
4
|
+
# BracketNotation is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# BracketNotation is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with BracketNotation. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#++
|
17
|
+
# BracketNotation is a parser for generating syntax trees from sentences
|
18
|
+
# annotated with the kind of bracket notation that is commonly used by
|
19
|
+
# linguists. The result is a tree structure with nodes that describe the phrases
|
20
|
+
# and constituents of the sentence.
|
21
|
+
#
|
22
|
+
# BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.com/rsyntaxtree/],
|
23
|
+
# and small portions of his code have been incorporated in the parser.
|
24
|
+
#
|
25
|
+
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
+
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
27
|
+
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
|
+
|
29
|
+
require 'test/test_helper'
|
30
|
+
|
31
|
+
class ScannerTest < Test::Unit::TestCase
|
32
|
+
include BracketNotation
|
33
|
+
|
34
|
+
context "the scanner" do
|
35
|
+
setup do
|
36
|
+
@input = "[S[DP[D the][NP[N boy]]][VP[V ate][DP[D the][NP[N bread]]]]]"
|
37
|
+
@scanner = Scanner.new(@input)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "always generate at least one token" do
|
41
|
+
assert @scanner.scan.length > 0
|
42
|
+
end
|
43
|
+
|
44
|
+
should "always produce an EOL token as its last token" do
|
45
|
+
assert @scanner.scan.last == Token.EOL
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#--
|
2
|
+
# This file is part of BracketNotation.
|
3
|
+
#
|
4
|
+
# BracketNotation is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# BracketNotation is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with BracketNotation. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#++
|
17
|
+
# BracketNotation is a parser for generating syntax trees from sentences
|
18
|
+
# annotated with the kind of bracket notation that is commonly used by
|
19
|
+
# linguists. The result is a tree structure with nodes that describe the phrases
|
20
|
+
# and constituents of the sentence.
|
21
|
+
#
|
22
|
+
# BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.com/rsyntaxtree/],
|
23
|
+
# and small portions of his code have been incorporated in the parser.
|
24
|
+
#
|
25
|
+
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
+
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
27
|
+
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
|
+
|
29
|
+
require 'test/test_helper'
|
30
|
+
|
31
|
+
class ParsingTest < Test::Unit::TestCase
|
32
|
+
include BracketNotation
|
33
|
+
|
34
|
+
context "the parsing process" do
|
35
|
+
setup do
|
36
|
+
@input = "[S [DP [D the] [NP [N boy]]] [VP [V ate] [DP [D the] [NP [N bread]]]]]"
|
37
|
+
@parser = Parser.new(@input)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "not raise exceptions" do
|
41
|
+
assert_nothing_raised do
|
42
|
+
@parser.parse
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
should "produce an expression" do
|
47
|
+
assert_kind_of Expression, @parser.parse
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#--
|
2
|
+
# This file is part of BracketNotation.
|
3
|
+
#
|
4
|
+
# BracketNotation is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# BracketNotation is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with BracketNotation. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#++
|
17
|
+
# BracketNotation is a parser for generating syntax trees from sentences
|
18
|
+
# annotated with the kind of bracket notation that is commonly used by
|
19
|
+
# linguists. The result is a tree structure with nodes that describe the phrases
|
20
|
+
# and constituents of the sentence.
|
21
|
+
#
|
22
|
+
# BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.com/rsyntaxtree/],
|
23
|
+
# and small portions of his code have been incorporated in the parser.
|
24
|
+
#
|
25
|
+
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
+
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
27
|
+
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
|
+
|
29
|
+
require 'test/unit'
|
30
|
+
require 'rubygems'
|
31
|
+
require 'shoulda'
|
32
|
+
require 'lib/bracket_notation'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#--
|
2
|
+
# This file is part of BracketNotation.
|
3
|
+
#
|
4
|
+
# BracketNotation is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# BracketNotation is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with BracketNotation. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#++
|
17
|
+
# BracketNotation is a parser for generating syntax trees from sentences
|
18
|
+
# annotated with the kind of bracket notation that is commonly used by
|
19
|
+
# linguists. The result is a tree structure with nodes that describe the phrases
|
20
|
+
# and constituents of the sentence.
|
21
|
+
#
|
22
|
+
# BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.com/rsyntaxtree/],
|
23
|
+
# and small portions of his code have been incorporated in the parser.
|
24
|
+
#
|
25
|
+
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
+
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
27
|
+
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
|
+
|
29
|
+
require 'test/test_helper'
|
30
|
+
|
31
|
+
class ExpressionTest < Test::Unit::TestCase
|
32
|
+
include BracketNotation
|
33
|
+
|
34
|
+
context "an identifier expression" do
|
35
|
+
setup do
|
36
|
+
@identifier1 = Identifier.new("NP", 1)
|
37
|
+
@identifier2 = Identifier.new("VP")
|
38
|
+
end
|
39
|
+
|
40
|
+
should "have a value" do
|
41
|
+
assert_not_nil @identifier1.value
|
42
|
+
end
|
43
|
+
|
44
|
+
should "have a depth" do
|
45
|
+
assert_not_nil @identifier1.depth
|
46
|
+
end
|
47
|
+
|
48
|
+
should "make itself the parent of a new child" do
|
49
|
+
@identifier1.add_child(@identifier2)
|
50
|
+
assert_same @identifier1, @identifier2.parent
|
51
|
+
end
|
52
|
+
|
53
|
+
should "update the depth of a new child" do
|
54
|
+
@identifier1.add_child(@identifier2)
|
55
|
+
assert @identifier2.depth == @identifier1.depth + 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "a terminal expression" do
|
60
|
+
setup do
|
61
|
+
@expression = Terminal.new("NP")
|
62
|
+
end
|
63
|
+
|
64
|
+
should "have a value" do
|
65
|
+
assert_not_nil @expression.value
|
66
|
+
end
|
67
|
+
|
68
|
+
should "have a depth" do
|
69
|
+
assert_not_nil @expression.depth
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#--
|
2
|
+
# This file is part of BracketNotation.
|
3
|
+
#
|
4
|
+
# BracketNotation is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# BracketNotation is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with BracketNotation. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#++
|
17
|
+
# BracketNotation is a parser for generating syntax trees from sentences
|
18
|
+
# annotated with the kind of bracket notation that is commonly used by
|
19
|
+
# linguists. The result is a tree structure with nodes that describe the phrases
|
20
|
+
# and constituents of the sentence.
|
21
|
+
#
|
22
|
+
# BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.com/rsyntaxtree/],
|
23
|
+
# and small portions of his code have been incorporated in the parser.
|
24
|
+
#
|
25
|
+
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
+
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
27
|
+
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
|
+
|
29
|
+
require 'test/test_helper'
|
30
|
+
|
31
|
+
class TokenTest < Test::Unit::TestCase
|
32
|
+
include BracketNotation
|
33
|
+
|
34
|
+
context "a left bracket token" do
|
35
|
+
setup do
|
36
|
+
@lbracket = Token.LBRACKET
|
37
|
+
end
|
38
|
+
|
39
|
+
should "be of type #{Token::LBRACKET}" do
|
40
|
+
assert_equal Token::LBRACKET, @lbracket.type
|
41
|
+
end
|
42
|
+
|
43
|
+
should "not have a value" do
|
44
|
+
assert_nil @lbracket.value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "a right bracket token" do
|
49
|
+
setup do
|
50
|
+
@rbracket = Token.RBRACKET
|
51
|
+
end
|
52
|
+
|
53
|
+
should "be of type #{Token::RBRACKET}" do
|
54
|
+
assert_equal Token::RBRACKET, @rbracket.type
|
55
|
+
end
|
56
|
+
|
57
|
+
should "not have a value" do
|
58
|
+
assert_nil @rbracket.value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "a name token" do
|
63
|
+
setup do
|
64
|
+
@value = "string"
|
65
|
+
@name = Token.NAME(@value)
|
66
|
+
end
|
67
|
+
|
68
|
+
should "be of type #{Token::NAME}" do
|
69
|
+
assert_equal Token::NAME, @name.type
|
70
|
+
end
|
71
|
+
|
72
|
+
should "have a value" do
|
73
|
+
assert_not_nil @name.value
|
74
|
+
end
|
75
|
+
|
76
|
+
should "have a value equal to that which was given when initializing" do
|
77
|
+
assert_equal @value, @name.value
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "an end-of-line token" do
|
82
|
+
setup do
|
83
|
+
@eol = Token.EOL
|
84
|
+
end
|
85
|
+
|
86
|
+
should "be of type #{Token::EOL}" do
|
87
|
+
assert_equal Token::EOL, @eol.type
|
88
|
+
end
|
89
|
+
|
90
|
+
should "not have a value" do
|
91
|
+
assert_nil @eol.value
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "two tokens" do
|
96
|
+
setup do
|
97
|
+
@name1 = Token.NAME("name")
|
98
|
+
@name2 = Token.NAME("name")
|
99
|
+
@name3 = Token.NAME("other")
|
100
|
+
@bracket = Token.LBRACKET
|
101
|
+
@eol = Token.EOL
|
102
|
+
end
|
103
|
+
|
104
|
+
should "be equal if they have the same type and value" do
|
105
|
+
assert_equal @name1, @name2
|
106
|
+
assert_equal @bracket1, @bracket2
|
107
|
+
end
|
108
|
+
|
109
|
+
should "be unequal if they have different types" do
|
110
|
+
assert_not_equal @bracket, @eol
|
111
|
+
end
|
112
|
+
|
113
|
+
should "be unequal if they have different values" do
|
114
|
+
assert_not_equal @name1, @name3
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bracket_notation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Cody Brimhall
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-08 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 37
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 11
|
33
|
+
- 3
|
34
|
+
version: 2.11.3
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Generates a representation of a syntax tree using a string of bracket notation.
|
38
|
+
email: zbrimhall@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- CHANGELOG
|
45
|
+
- COPYING
|
46
|
+
- README.rdoc
|
47
|
+
- lib/bracket_notation.rb
|
48
|
+
- lib/bracket_notation/evaluator.rb
|
49
|
+
- lib/bracket_notation/expressions.rb
|
50
|
+
- lib/bracket_notation/expressions/expression.rb
|
51
|
+
- lib/bracket_notation/expressions/identifier.rb
|
52
|
+
- lib/bracket_notation/expressions/terminal.rb
|
53
|
+
- lib/bracket_notation/parser.rb
|
54
|
+
- lib/bracket_notation/scanner.rb
|
55
|
+
- lib/bracket_notation/token.rb
|
56
|
+
- lib/bracket_notation/version.rb
|
57
|
+
files:
|
58
|
+
- CHANGELOG
|
59
|
+
- COPYING
|
60
|
+
- README.rdoc
|
61
|
+
- Rakefile
|
62
|
+
- init.rb
|
63
|
+
- lib/bracket_notation.rb
|
64
|
+
- lib/bracket_notation/evaluator.rb
|
65
|
+
- lib/bracket_notation/expressions.rb
|
66
|
+
- lib/bracket_notation/expressions/expression.rb
|
67
|
+
- lib/bracket_notation/expressions/identifier.rb
|
68
|
+
- lib/bracket_notation/expressions/terminal.rb
|
69
|
+
- lib/bracket_notation/parser.rb
|
70
|
+
- lib/bracket_notation/scanner.rb
|
71
|
+
- lib/bracket_notation/token.rb
|
72
|
+
- lib/bracket_notation/version.rb
|
73
|
+
- test/functional/evaluator_test.rb
|
74
|
+
- test/functional/parser_test.rb
|
75
|
+
- test/functional/scanner_test.rb
|
76
|
+
- test/integration/parsing_test.rb
|
77
|
+
- test/test_helper.rb
|
78
|
+
- test/unit/expression_test.rb
|
79
|
+
- test/unit/token_test.rb
|
80
|
+
- Manifest
|
81
|
+
- bracket_notation.gemspec
|
82
|
+
has_rdoc: true
|
83
|
+
homepage: http://github.com/zbrimhall/bracket_notation
|
84
|
+
licenses: []
|
85
|
+
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options:
|
88
|
+
- --line-numbers
|
89
|
+
- --inline-source
|
90
|
+
- --title
|
91
|
+
- Bracket_notation
|
92
|
+
- --main
|
93
|
+
- README.rdoc
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 11
|
111
|
+
segments:
|
112
|
+
- 1
|
113
|
+
- 2
|
114
|
+
version: "1.2"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project: bracket_notation
|
118
|
+
rubygems_version: 1.4.2
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Provides a parser for strings that have been marked up with the bracket notation commonly used by syntacticians. The parser generates an abstract tree representation of the syntax of the string.
|
122
|
+
test_files:
|
123
|
+
- test/functional/evaluator_test.rb
|
124
|
+
- test/functional/parser_test.rb
|
125
|
+
- test/functional/scanner_test.rb
|
126
|
+
- test/integration/parsing_test.rb
|
127
|
+
- test/test_helper.rb
|
128
|
+
- test/unit/expression_test.rb
|
129
|
+
- test/unit/token_test.rb
|