Class: NlpToolz::Parser

Inherits:
Object
  • Object
show all
Includes:
TmpFile
Defined in:
lib/nlp_toolz/parser.rb

Defined Under Namespace

Classes: Leaf, Node

Constant Summary collapse

FileInputStream =

load java classes

Rjb::import('java.io.FileInputStream')

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#inputObject

Returns the value of attribute input.



16
17
18
# File 'lib/nlp_toolz/parser.rb', line 16

def input
  @input
end

#langObject

Returns the value of attribute lang.



16
17
18
# File 'lib/nlp_toolz/parser.rb', line 16

def lang
  @lang
end

#modelObject

Returns the value of attribute model.



16
17
18
# File 'lib/nlp_toolz/parser.rb', line 16

def model
  @model
end

#model_nameObject

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_hashObject

Returns the value of attribute parse_hash.



16
17
18
# File 'lib/nlp_toolz/parser.rb', line 16

def parse_hash
  @parse_hash
end

#parsedObject (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

Returns:

  • (Boolean)


41
42
43
# File 'lib/nlp_toolz/parser.rb', line 41

def has_model?
  @model
end

#hashObject



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_textObject



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