Class: OSCAR4
- Inherits:
-
NER
show all
- Defined in:
- lib/rbbt/ner/oscar4.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from NER
#entities, #extract, #initialize
Constructor Details
This class inherits a constructor from NER
Class Method Details
.init ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/rbbt/ner/oscar4.rb', line 10
def self.init
ENV["CLASSPATH"] = ENV["CLASSPATH"].split(":").select{|p| p !~ /opennlp/} * ":"
Rjb::load(nil, jvmargs = ['-Xms1G','-Xmx2G']) unless Rjb.loaded?
@@OSCAR ||= Rjb::import('uk.ac.cam.ch.wwmm.oscar.Oscar')
@@FormatType ||= Rjb::import('uk.ac.cam.ch.wwmm.oscar.chemnamedict.entities.FormatType')
end
|
.match(text, protect = false, type = nil) ⇒ Object
27
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
53
54
|
# File 'lib/rbbt/ner/oscar4.rb', line 27
def self.match(text, protect = false, type = nil)
self.init
return [] if text.nil? or text.strip.empty?
oscar = tagger
entities = oscar.findNamedEntities(text);
it = entities.iterator
result = []
while it.hasNext
entity = it.next
mention = entity.getSurface
inchi = nil
next unless entity.getType.toString == type unless type.nil?
NamedEntity.setup mention, :offset => entity.getStart, :entity_type => entity.getType, :code => inchi, :score => entity.getConfidence
result << mention
end
result
end
|
.tagger ⇒ Object
23
24
25
|
# File 'lib/rbbt/ner/oscar4.rb', line 23
def self.tagger
@@tagger ||= @@OSCAR.new()
end
|
Instance Method Details
#match(*args) ⇒ Object
56
57
58
|
# File 'lib/rbbt/ner/oscar4.rb', line 56
def match(*args)
OSCAR4.match *args
end
|