Class: NCBO::Annotator

Inherits:
Object
  • Object
show all
Defined in:
lib/ncbo_annotator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Annotator

Returns a new instance of Annotator.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ncbo_annotator.rb', line 10

def initialize(args = {})
  @options = {}
  
  @options[:annotator_location] = "http://rest.bioontology.org/obs"
  @options[:filterNumber] = true
  @options[:isStopWordsCaseSensitive] = true
  @options[:isVirtualOntologyId] = true
  @options[:levelMax] = 0
  @options[:longestOnly] = false
  @options[:ontologiesToExpand] = []
  @options[:ontologiesToKeepInResult] = []
  @options[:mappingTypes] = []
  @options[:minTermSize] = 3
  @options[:scored] = true
  @options[:semanticTypes] = []
  @options[:stopWords] = []
  @options[:wholeWordOnly] = false
  @options[:withDefaultStopWords] = false
  @options[:withSynonyms] = true

  @options.merge!(args)
  
  @ontologies = nil
  
  # Check to make sure mappingTypes are capitalized
  fix_params

  raise ArgumentError, ":apikey is required, you can obtain one at http://bioportal.bioontology.org/accounts/new" if @options[:apikey].nil?
end

Class Method Details

.annotate(text, options = {}) ⇒ Object



40
41
42
43
# File 'lib/ncbo_annotator.rb', line 40

def self.annotate(text, options = {})
  options[:textToAnnotate] = text
  new(options).annotate
end

.ontologies(options) ⇒ Object



56
57
58
# File 'lib/ncbo_annotator.rb', line 56

def self.ontologies(options)
  new(options).ontologies
end

.semantic_types(options) ⇒ Object



69
70
71
# File 'lib/ncbo_annotator.rb', line 69

def self.semantic_types(options)
  new(options).semantic_types
end

Instance Method Details

#annotate(text = nil, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
53
54
# File 'lib/ncbo_annotator.rb', line 45

def annotate(text = nil, options = {})
  @options[:textToAnnotate] = text unless text.nil?
  @options.merge!(options) unless options.empty?
  fix_params
  
  raise ArgumentError, ":textToAnnotate must be included" if @options[:textToAnnotate].nil?
  
  result_xml = annotate_post
  Parser::Annotator.parse_results(result_xml)
end

#ontologiesObject



60
61
62
63
64
65
66
67
# File 'lib/ncbo_annotator.rb', line 60

def ontologies
  if @ontologies.nil?
    ontologies_xml = open("#{@options[:annotator_location]}/ontologies?apikey=#{@options[:apikey]}").read
    @ontologies = Parser::Annotator.parse_included_ontologies(ontologies_xml)
  else
    @ontologies
  end
end

#optionsObject



82
83
84
# File 'lib/ncbo_annotator.rb', line 82

def options
  @options
end

#semantic_typesObject



73
74
75
76
77
78
79
80
# File 'lib/ncbo_annotator.rb', line 73

def semantic_types
  if @semantic_types.nil?
    semantic_types_xml = open("#{@options[:annotator_location]}/semanticTypes?apikey=#{@options[:apikey]}").read
    @semantic_types = Parser::Annotator.parse_semantic_types(semantic_types_xml)
  else
    @semantic_types
  end
end