Class: OpenNlp::Parser::Parse
- Inherits:
-
Object
- Object
- OpenNlp::Parser::Parse
- Includes:
- JavaClass
- Defined in:
- lib/open_nlp/parser/parse.rb
Instance Attribute Summary collapse
-
#j_instance ⇒ Object
readonly
Returns the value of attribute j_instance.
Instance Method Summary collapse
- #code_tree ⇒ Object
-
#initialize(java_instance) ⇒ Parse
constructor
A new instance of Parse.
- #tree_bank_string ⇒ Object
Methods included from JavaClass
Constructor Details
#initialize(java_instance) ⇒ Parse
Returns a new instance of Parse.
9 10 11 12 13 |
# File 'lib/open_nlp/parser/parse.rb', line 9 def initialize(java_instance) raise ArgumentError, "java_instance must be an instance of #{self.class.java_class.name}" unless java_instance.is_a?(self.class.java_class) @j_instance = java_instance end |
Instance Attribute Details
#j_instance ⇒ Object (readonly)
Returns the value of attribute j_instance.
5 6 7 |
# File 'lib/open_nlp/parser/parse.rb', line 5 def j_instance @j_instance end |
Instance Method Details
#code_tree ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/open_nlp/parser/parse.rb', line 34 def code_tree kids = j_instance.getChildren kids.each_with_object([]) do |kid, acc| data = { :type => kid.getType, :parent_type => self.j_instance.getType, :token => kid.toString } subtree = self.class.new(kid).code_tree data[:children] = subtree unless subtree.empty? acc << data end end |
#tree_bank_string ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/open_nlp/parser/parse.rb', line 15 def tree_bank_string span, text, type, res = j_instance.getSpan, j_instance.getText, j_instance.getType, '' start = span.getStart res << "(#{type} " if type != Java::opennlp.tools.parser.AbstractBottomUpParser::TOK_NODE j_instance.getChildren.each do |child| child_span = child.span res << text[start..child_span.getStart-1] if start < child_span.getStart res << self.class.new(child).tree_bank_string start = child_span.getEnd end res << text[start..span.getEnd-1] if start < span.getEnd res << ")" if type != Java::opennlp.tools.parser.AbstractBottomUpParser::TOK_NODE res end |