Class: NlpToolz::Parser
- Inherits:
-
Object
- Object
- NlpToolz::Parser
- 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
Methods included from Lang
#alternative_langs, #get_language
Methods included from UrlHandler
Constructor Details
#initialize(input, lang = nil) ⇒ Parser
Returns a new instance of Parser.
19 20 21 22 23 24 |
# File 'lib/nlp_toolz/parser.rb', line 19 def initialize(input, lang = nil) @input = input @lang = lang || get_language @model_name = "#{@lang}-sm5.gr" get_model end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
17 18 19 |
# File 'lib/nlp_toolz/parser.rb', line 17 def input @input end |
#lang ⇒ Object
Returns the value of attribute lang.
17 18 19 |
# File 'lib/nlp_toolz/parser.rb', line 17 def lang @lang end |
#model ⇒ Object
Returns the value of attribute model.
17 18 19 |
# File 'lib/nlp_toolz/parser.rb', line 17 def model @model end |
#model_name ⇒ Object
Returns the value of attribute model_name.
17 18 19 |
# File 'lib/nlp_toolz/parser.rb', line 17 def model_name @model_name end |
#parse_hash ⇒ Object
Returns the value of attribute parse_hash.
17 18 19 |
# File 'lib/nlp_toolz/parser.rb', line 17 def parse_hash @parse_hash end |
#parsed ⇒ Object (readonly)
Returns the value of attribute parsed.
16 17 18 |
# File 'lib/nlp_toolz/parser.rb', line 16 def parsed @parsed end |
Instance Method Details
#has_model? ⇒ Boolean
42 43 44 |
# File 'lib/nlp_toolz/parser.rb', line 42 def has_model? @model end |
#hash ⇒ Object
50 51 52 |
# File 'lib/nlp_toolz/parser.rb', line 50 def hash @parse_hash end |
#layer(level = nil) ⇒ Object
46 47 48 |
# File 'lib/nlp_toolz/parser.rb', line 46 def layer(level = nil) @first_layer end |
#parse_text ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nlp_toolz/parser.rb', line 26 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 |