Class: Ve::Provider::FreelingEn

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

Constant Summary collapse

BIT_STOP =

FIX: This class isn’t tested

'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
26
27
# 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' : ''
  share_dir = "/usr#{local}/share"
  @config[:freeling_dir_name] = Dir.exist?("#{share_dir}/FreeLing") ? 'FreeLing' : 'freeling'
  @config[:flags] = "-f #{share_dir}/#{@config[:freeling_dir_name]}/config/en.cfg --flush --nonumb --nodate"

  start!
end

Instance Method Details

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

Talks to the app and returns a parse object



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

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)


31
32
33
34
# File 'lib/providers/freeling_en.rb', line 31

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