Class: Ve::Provider::FreelingEn
- Inherits:
-
Ve::Provider
- Object
- Ve::Provider
- Ve::Provider::FreelingEn
- Defined in:
- lib/providers/freeling_en.rb
Constant Summary collapse
- BIT_STOP =
FIX: This class isn’t tested
'VeEnd'
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ FreelingEn
constructor
TODO: Automatically set FREELINGSHARE if it’s not set?.
-
#parse(text, options = {}) ⇒ Object
Talks to the app and returns a parse object.
-
#works? ⇒ Boolean
Interface methods.
Methods inherited from Ve::Provider
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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/providers/freeling_en.rb', line 35 def parse(text, = {}) 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 puts line 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
29 30 31 32 |
# File 'lib/providers/freeling_en.rb', line 29 def works? p = parse('Wrote') ["Wrote write VBD 1", ""] == p.tokens.collect { |t| t[:raw] } end |