ncbo_annotator 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,7 @@ module NCBO
23
23
  @options[:scored] = true
24
24
  @options[:semanticTypes] = []
25
25
  @options[:stopWords] = []
26
- @options[:wholeWordOnly] = true
26
+ @options[:wholeWordOnly] = false
27
27
  @options[:withDefaultStopWords] = false
28
28
  @options[:withSynonyms] = true
29
29
 
@@ -84,13 +84,14 @@ module NCBO
84
84
  def annotate_post
85
85
  url = @options[:annotator_location] + "/annotator"
86
86
  options = @options.clone
87
+ options.delete_if {|k,v| v.kind_of?(Array) && v.empty?}
87
88
  options.each do |k,v|
88
89
  if v.kind_of?(Array)
89
90
  options[k] = v.join(",")
90
91
  end
91
92
  end
92
93
  res = Net::HTTP.post_form(URI.parse(url), options)
93
- return res.body
94
+ res.body
94
95
  end
95
96
  end # end Annotator class
96
97
  end # end NCBO module
@@ -50,14 +50,7 @@ module NCBO
50
50
  end
51
51
 
52
52
  def parse_semantic_types
53
- @root = "/success/data/list"
54
- semantic_types = []
55
- @results.find(@root + "/semanticTypeBean").each do |semantic_type_bean|
56
- semantic_type = {}
57
- semantic_type_bean.children.each { |child| semantic_type[child.name.to_sym] = safe_to_i(child.content) }
58
- semantic_types << semantic_type
59
- end
60
- semantic_types
53
+ _parse_semantic_types(@results.find_first("/success/data/list"))
61
54
  end
62
55
 
63
56
  private
@@ -94,16 +87,28 @@ module NCBO
94
87
 
95
88
  def parse_concept(annotation, concept_location = "concept")
96
89
  a = {}
90
+
97
91
  annotation.find("#{concept_location}/*").each {|child| a[child.name.to_sym] = safe_to_i(child.content) if !child.first.nil? && !child.first.children?}
98
-
99
92
  a[:synonyms] = annotation.find("#{concept_location}/synonyms/string").map {|syn| safe_to_i(syn.content)}
100
93
 
101
- semantic_types = {}
102
- annotation.find("#{concept_location}/semanticTypes/semanticTypeBean/*").each {|child| semantic_types[child.name.to_sym] = safe_to_i(child.content)}
94
+ semantic_types = []
95
+ semantic_types = _parse_semantic_types(annotation.find_first("#{concept_location}/semanticTypes"))
103
96
  a[:semantic_types] = semantic_types
104
-
97
+
105
98
  a
106
99
  end
100
+
101
+ def _parse_semantic_types(semantic_types_xml)
102
+ return Array.new if semantic_types_xml.nil?
103
+
104
+ semantic_types = []
105
+ semantic_types_xml.each do |semantic_type_bean|
106
+ semantic_type = {}
107
+ semantic_type_bean.children.each { |child| semantic_type[child.name.to_sym] = safe_to_i(child.content) }
108
+ semantic_types << semantic_type
109
+ end
110
+ semantic_types
111
+ end
107
112
 
108
113
  def parse_context(annotation)
109
114
  a = {}
@@ -112,9 +117,7 @@ module NCBO
112
117
  if a[:contextName].downcase.include?("mapping")
113
118
  a[:mappedConcept] = parse_concept(annotation.find_first("context"), "mappedConcept")
114
119
  elsif a[:contextName].downcase.include?("mgrep")
115
- term = {}
116
- annotation.find("context/term/*").each {|trm| term[trm.name.to_sym] = safe_to_i(trm.content)}
117
- a[:term] = term
120
+ a[:term] = parse_concept(annotation.find_first("context/term/concept"))
118
121
  elsif a[:contextName].downcase.include?("closure")
119
122
  a[:concept] = parse_concept(annotation.find_first("context"))
120
123
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncbo_annotator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 6
10
- version: 1.0.6
9
+ - 7
10
+ version: 1.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul R Alexander