Class: NlpToolz::Parser
- Inherits:
-
Object
- Object
- NlpToolz::Parser
- Includes:
- TmpFile
- Defined in:
- lib/nlp_toolz/parser.rb
Defined Under Namespace
Constant Summary collapse
- FileInputStream =
load java classes
Rjb::import('java.io.FileInputStream')
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#model ⇒ Object
Returns the value of attribute model.
-
#model_name ⇒ Object
Returns the value of attribute model_name.
-
#parse_hash ⇒ Object
Returns the value of attribute parse_hash.
-
#parsed ⇒ Object
readonly
Returns the value of attribute parsed.
Instance Method Summary collapse
- #has_model? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(input, lang = nil) ⇒ Parser
constructor
A new instance of Parser.
- #layer(level = nil) ⇒ Object
- #parse_text ⇒ Object
Methods included from TmpFile
delete_and_unlink_tmp_file, make_tmp_file_from
Constructor Details
#initialize(input, lang = nil) ⇒ Parser
Returns a new instance of Parser.
18 19 20 21 22 23 |
# File 'lib/nlp_toolz/parser.rb', line 18 def initialize(input, lang = nil) @input = input @lang = lang || NlpToolz::Language.get_language(input) @model_name = "#{@lang}-sm5.gr" get_model end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
16 17 18 |
# File 'lib/nlp_toolz/parser.rb', line 16 def input @input end |
#lang ⇒ Object
Returns the value of attribute lang.
16 17 18 |
# File 'lib/nlp_toolz/parser.rb', line 16 def lang @lang end |
#model ⇒ Object
Returns the value of attribute model.
16 17 18 |
# File 'lib/nlp_toolz/parser.rb', line 16 def model @model end |
#model_name ⇒ Object
Returns the value of attribute model_name.
16 17 18 |
# File 'lib/nlp_toolz/parser.rb', line 16 def model_name @model_name end |
#parse_hash ⇒ Object
Returns the value of attribute parse_hash.
16 17 18 |
# File 'lib/nlp_toolz/parser.rb', line 16 def parse_hash @parse_hash end |
#parsed ⇒ Object (readonly)
Returns the value of attribute parsed.
15 16 17 |
# File 'lib/nlp_toolz/parser.rb', line 15 def parsed @parsed end |
Instance Method Details
#has_model? ⇒ Boolean
41 42 43 |
# File 'lib/nlp_toolz/parser.rb', line 41 def has_model? @model end |
#hash ⇒ Object
49 50 51 |
# File 'lib/nlp_toolz/parser.rb', line 49 def hash @parse_hash end |
#layer(level = nil) ⇒ Object
45 46 47 |
# File 'lib/nlp_toolz/parser.rb', line 45 def layer(level = nil) @first_layer end |
#parse_text ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nlp_toolz/parser.rb', line 25 def parse_text parsed = nil if self.has_model? jar = "#{JARS}/BerkeleyParser-1.7.jar" in_file = make_tmp_file_from @input.clean_up out_file = make_tmp_file_from `java -Xmx4g -jar #{jar} -gr #{@model} -inputFile #{in_file.path} -outputFile #{out_file.path} -tokenize -maxLength 500`.chomp @parsed = File.open(out_file).gets(nil).chomp parse_output_to_hash delete_and_unlink_tmp_file in_file delete_and_unlink_tmp_file out_file end end |