Class: FreeLing::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/freeling/analyzer.rb,
lib/freeling/analyzer/version.rb,
lib/freeling/analyzer/process_wrapper.rb,
lib/freeling/analyzer/freeling_default.rb

Defined Under Namespace

Classes: FreelingDefault, ProcessWrapper

Constant Summary collapse

Token =
Class.new(Hashie::Mash)
VERSION =
"0.1.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, opts = {}) ⇒ Analyzer

Returns a new instance of Analyzer.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/freeling/analyzer.rb', line 13

def initialize(document, opts={})
  @document = document

  @options = {
    :share_path          => freeling_path,
    :analyze_path        => analyzer_path,
    :input_format        => :plain,
    :output_format       => :tagged,
    :memoize             => true,
    :language            => :es,
    :server_host         => nil,
    :analyze_client_path => analyzer_client_path
  }.merge(opts)
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



9
10
11
# File 'lib/freeling/analyzer.rb', line 9

def document
  @document
end

#latest_error_logObject (readonly)

Returns the value of attribute latest_error_log.



9
10
11
# File 'lib/freeling/analyzer.rb', line 9

def latest_error_log
  @latest_error_log
end

Instance Method Details

#sentences(run_again = false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/freeling/analyzer.rb', line 28

def sentences(run_again=false)
  if @options[:output_format] == :token
    raise "Sentence splitter is not available with output format set to 'token'"
  end

  if not run_again and @sentences
    return @sentences.to_enum
  end

  Enumerator.new do |yielder|
    tokens = []
    read_tokens.each do |token|
      if token
        tokens << token
      else
        yielder << tokens
        if @options[:memoize]
          @sentences ||= []
          @sentences << tokens
        end
        tokens = []
      end
    end
  end
end

#tokens(run_again = false) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/freeling/analyzer.rb', line 54

def tokens(run_again=false)
  if not run_again and @tokens
    return @tokens.to_enum
  end

  if @sentences
    @tokens ||= @sentences.flatten
    return @tokens.to_enum
  end

  Enumerator.new do |yielder|
    read_tokens.each do |token|
      if token
        yielder << token
        if @options[:memoize]
          @tokens ||= []
          @tokens << token
        end
      end
    end
  end
end