Class: Finder::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/rbbt/ner/finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, open_options = {}) ⇒ Instance

Returns a new instance of Instance.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rbbt/ner/finder.rb', line 18

def initialize(path, open_options = {})
  case path
  when TSV 
    @namespace = path.namespace 
    @format = path.key_field
    @normalizer = Normalizer.new(path)
  when Hash
    @namespace = open_options[:namespace]
    @format = nil
    @normalizer = RegExpNER.new(path)
  else
    open_options = Misc.add_defaults open_options, :type => :flat
    tsv = TSV.open(path, open_options)
    @namespace = tsv.namespace 
    @format = tsv.key_field
    @normalizer = Normalizer.new(tsv)
  end
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



17
18
19
# File 'lib/rbbt/ner/finder.rb', line 17

def format
  @format
end

#namespaceObject

Returns the value of attribute namespace.



17
18
19
# File 'lib/rbbt/ner/finder.rb', line 17

def namespace
  @namespace
end

#normalizerObject

Returns the value of attribute normalizer.



17
18
19
# File 'lib/rbbt/ner/finder.rb', line 17

def normalizer
  @normalizer
end

Instance Method Details

#find(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/rbbt/ner/finder.rb', line 37

def find(name)
  candidates = @normalizer.match(name)
  if defined? Finder::Match
    candidates.collect{|c|
      Finder::Match.setup(c.dup, @format, @namespace, @normalizer.token_score(c, name))
    }
  else
    candidates
  end
end