Class: OSCAR4
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from NER
Class Method Details
.init ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rbbt/ner/oscar4.rb', line 11 def self.init # There is an incompatibility between the OpenNLP version in OSCAR4 and the # one used for other matters in Rbbt, which is the most recent. We remove # the standalone jars from the CLASSPATH 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, type = nil) ⇒ 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 53 54 55 |
# File 'lib/rbbt/ner/oscar4.rb', line 28 def self.match(text, type = nil) self.init return [] if text.nil? or text.strip.empty? oscar = tagger #entities = oscar.findAndResolveNamedEntities(text); entities = oscar.findNamedEntities(text); it = entities.iterator result = [] while it.hasNext entity = it.next mention = entity.getSurface #inchi = entity.getFirstChemicalStructure(@@FormatType.INCHI) #inchi = inchi.getValue() unless inchi.nil? inchi = nil next unless entity.getType.toString == type unless type.nil? NamedEntity.setup mention, entity.getStart, entity.getType, inchi, entity.getConfidence result << mention end result end |
.tagger ⇒ Object
24 25 26 |
# File 'lib/rbbt/ner/oscar4.rb', line 24 def self.tagger @@tagger ||= @@OSCAR.new() end |