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.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Analyzer.



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

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
  }.merge(opts)
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



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

def document
  @document
end

#latest_error_logObject (readonly)

Returns the value of attribute latest_error_log.



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

def latest_error_log
  @latest_error_log
end

Instance Method Details

#sentences(run_again = false) ⇒ Object



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

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



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

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