Class: Ve::Provider::FreelingEn

Inherits:
Ve::Provider show all
Defined in:
lib/providers/freeling_en.rb

Constant Summary collapse

BIT_STOP =
'VeEnd'

Instance Method Summary collapse

Methods inherited from Ve::Provider

#provides

Constructor Details

#initialize(config = {}) ⇒ FreelingEn

TODO: Automatically set FREELINGSHARE if it’s not set?



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/providers/freeling_en.rb', line 15

def initialize(config = {})
  @config = {:app => 'analyzer',
             :path => '',
             :flags => ''}.merge(config)
    
  @config[:app] = `which #{@config[:app]}`.strip!
  local = @config[:app] =~ /local/ ? '/local' : ''
  @config[:flags] = "-f /usr#{local}/share/FreeLing/config/en.cfg --flush --nonumb --nodate"
  
  start!
end

Instance Method Details

#parse(text, options = {}) ⇒ Object

Talks to the app and returns a parse object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/providers/freeling_en.rb', line 34

def parse(text, options = {})
  start! if @stdin.nil?
  # Fix Unicode chars
  # TODO: These need to be converted back to the original char in the :literal attribute
  text = text.gsub('', "'")
  
  @stdin.puts "#{text}\n#{BIT_STOP}\n"
  output = []
  
  while line = @stdout.readline
    if line =~ /#{BIT_STOP}/x
      @stdout.readline
      break
    end
    output << line
  end

  Ve::Parse::FreelingEn.new(text, output)
rescue
  Ve::Parse::FreelingEn.new(text, [])
end

#works?Boolean

Interface methods

Returns:

  • (Boolean)


29
30
31
# File 'lib/providers/freeling_en.rb', line 29

def works?
  (["Wrote write VBD 1", ""] == parse('Wrote').tokens.collect { |t| t[:raw] })
end