BracketNotation
BracketNotation is a parser for generating syntax trees from sentences annotated with the kind of bracket notation that is commonly used by linguists. The result is a tree structure with nodes that describe the phrases and constituents of the sentence.
BracketNotation was inspired by Yoichiro Hasebe’s RSyntaxTree, and small portions of his code have been incorporated in the parser.
- Author
-
Cody Brimhall ([email protected])
- Copyright
-
Copyright © 2010 Cody Brimhall
- License
-
Distributed under the terms of the GNU General Public License, v. 3
Using BracketNotation
To use BracketNotation, simply initialize a Parser instance with the string you want to parse, and call the #parse method. Parser performs some basic validation before attempting to evaluate the string. If validation fails, Parser raises a ValidationError. If the evaluator encounters a syntax error in the string, it raises an EvaluationError.
require 'bracket_notation'
include BracketNotation
input = "[S [NP colorless green ideas] [VP [V sleep] [Adv furiously]]]"
begin
parser = Parser.new(input)
tree = parser.parse
puts tree.pretty_print # => S
# -- NP
# ---- colorless
# ---- green
# ---- ideas
# -- VP
# ---- V
# ------ sleep
# ---- Adv
# ------ furiously
rescue ValidationError
puts "Validation failed: #{$!}"
rescue EvaluationError
puts "Evaluation failed: #{$!}"
end
Bugs, Feature Requests, Et Cetera
If you have any bugs, feature requests, or glowing praise, you can find this project on GitHub.