ncbo_annotator 1.0.1 → 1.0.3
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.
- data/lib/ncbo_annotator/parser.rb +24 -13
 - data/lib/ncbo_annotator.rb +21 -5
 - metadata +3 -3
 
| 
         @@ -20,7 +20,6 @@ module NCBO 
     | 
|
| 
       20 
20 
     | 
    
         
             
                  def initialize(results)
         
     | 
| 
       21 
21 
     | 
    
         
             
                    @root = "/success/data/annotatorResultBean"
         
     | 
| 
       22 
22 
     | 
    
         
             
                    @results = parse_xml(results)
         
     | 
| 
       23 
     | 
    
         
            -
                    @result = AnnotatorResult.new
         
     | 
| 
       24 
23 
     | 
    
         
             
                  end
         
     | 
| 
       25 
24 
     | 
    
         | 
| 
       26 
25 
     | 
    
         
             
                  def self.parse_results(results)
         
     | 
| 
         @@ -28,6 +27,8 @@ module NCBO 
     | 
|
| 
       28 
27 
     | 
    
         
             
                  end
         
     | 
| 
       29 
28 
     | 
    
         | 
| 
       30 
29 
     | 
    
         
             
                  def parse_results
         
     | 
| 
      
 30 
     | 
    
         
            +
                    @result = AnnotatorResult.new
         
     | 
| 
      
 31 
     | 
    
         
            +
                    p @results
         
     | 
| 
       31 
32 
     | 
    
         
             
                    @result.id = @results.find_first(@root + "/resultID").content
         
     | 
| 
       32 
33 
     | 
    
         
             
                    @result.statistics = parse_statistics
         
     | 
| 
       33 
34 
     | 
    
         
             
                    @result.annotations = parse_annotations
         
     | 
| 
         @@ -35,6 +36,28 @@ module NCBO 
     | 
|
| 
       35 
36 
     | 
    
         
             
                    @result
         
     | 
| 
       36 
37 
     | 
    
         
             
                  end
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
      
 39 
     | 
    
         
            +
                  def self.parse_included_ontologies(ontologies)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    new(ontologies).parse_included_ontologies
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                    
         
     | 
| 
      
 43 
     | 
    
         
            +
                  def parse_included_ontologies
         
     | 
| 
      
 44 
     | 
    
         
            +
                    @root = "/success/data/list"
         
     | 
| 
      
 45 
     | 
    
         
            +
                    ontologies = parse_ontologies("ontologyBean")
         
     | 
| 
      
 46 
     | 
    
         
            +
                    ontologies
         
     | 
| 
      
 47 
     | 
    
         
            +
                  end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  private
         
     | 
| 
      
 50 
     | 
    
         
            +
                  
         
     | 
| 
      
 51 
     | 
    
         
            +
                  def parse_ontologies(ontology_location = "ontologies/ontologyUsedBean")
         
     | 
| 
      
 52 
     | 
    
         
            +
                    ontologies = []
         
     | 
| 
      
 53 
     | 
    
         
            +
                    @results.find(@root + "/#{ontology_location}").each do |ontology|
         
     | 
| 
      
 54 
     | 
    
         
            +
                      ont = {}
         
     | 
| 
      
 55 
     | 
    
         
            +
                      ontology.children.each {|child| ont[child.name.to_sym] = safe_to_i(child.content)}
         
     | 
| 
      
 56 
     | 
    
         
            +
                      ontologies << ont
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
                    ontologies
         
     | 
| 
      
 59 
     | 
    
         
            +
                  end
         
     | 
| 
      
 60 
     | 
    
         
            +
                  
         
     | 
| 
       38 
61 
     | 
    
         
             
                  def parse_statistics
         
     | 
| 
       39 
62 
     | 
    
         
             
                    statistics = {}
         
     | 
| 
       40 
63 
     | 
    
         
             
                    @results.find(@root + "/statistics/statisticsBean").each do |statistic|
         
     | 
| 
         @@ -55,18 +78,6 @@ module NCBO 
     | 
|
| 
       55 
78 
     | 
    
         
             
                    annotations
         
     | 
| 
       56 
79 
     | 
    
         
             
                  end
         
     | 
| 
       57 
80 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                  def parse_ontologies
         
     | 
| 
       59 
     | 
    
         
            -
                    ontologies = []
         
     | 
| 
       60 
     | 
    
         
            -
                    @results.find(@root + "/ontologies/ontologyUsedBean").each do |ontology|
         
     | 
| 
       61 
     | 
    
         
            -
                      ont = {}
         
     | 
| 
       62 
     | 
    
         
            -
                      ontology.children.each {|child| ont[child.name.to_sym] = safe_to_i(child.content)}
         
     | 
| 
       63 
     | 
    
         
            -
                      ontologies << ont
         
     | 
| 
       64 
     | 
    
         
            -
                    end
         
     | 
| 
       65 
     | 
    
         
            -
                    ontologies
         
     | 
| 
       66 
     | 
    
         
            -
                  end
         
     | 
| 
       67 
     | 
    
         
            -
                  
         
     | 
| 
       68 
     | 
    
         
            -
                  private
         
     | 
| 
       69 
     | 
    
         
            -
                  
         
     | 
| 
       70 
81 
     | 
    
         
             
                  def parse_concept(annotation, concept_location = "concept")
         
     | 
| 
       71 
82 
     | 
    
         
             
                    a = {}
         
     | 
| 
       72 
83 
     | 
    
         
             
                    annotation.find("#{concept_location}/*").each {|child| a[child.name.to_sym] = safe_to_i(child.content) if !child.first.nil? && !child.first.children?}
         
     | 
    
        data/lib/ncbo_annotator.rb
    CHANGED
    
    | 
         @@ -2,6 +2,7 @@ require 'rubygems' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'net/http'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'xml'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'uri'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'open-uri'
         
     | 
| 
       5 
6 
     | 
    
         
             
            require 'ncbo_annotator/parser'
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
            module NCBO
         
     | 
| 
         @@ -10,7 +11,7 @@ module NCBO 
     | 
|
| 
       10 
11 
     | 
    
         
             
                def initialize(args = {})
         
     | 
| 
       11 
12 
     | 
    
         
             
                  @options = {}
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                  @options[:annotator_location] = "http://rest.bioontology.org/obs 
     | 
| 
      
 14 
     | 
    
         
            +
                  @options[:annotator_location] = "http://rest.bioontology.org/obs"
         
     | 
| 
       14 
15 
     | 
    
         
             
                  @options[:filterNumber] = true
         
     | 
| 
       15 
16 
     | 
    
         
             
                  @options[:isStopWordsCaseSensitive] = false
         
     | 
| 
       16 
17 
     | 
    
         
             
                  @options[:isVirtualOntologyId] = true
         
     | 
| 
         @@ -28,6 +29,8 @@ module NCBO 
     | 
|
| 
       28 
29 
     | 
    
         
             
                  @options[:withSynonyms] = true
         
     | 
| 
       29 
30 
     | 
    
         | 
| 
       30 
31 
     | 
    
         
             
                  @options.merge!(args)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @ontologies = nil
         
     | 
| 
       31 
34 
     | 
    
         | 
| 
       32 
35 
     | 
    
         
             
                  raise ArgumentError, ":apikey is required, you can obtain one at http://bioportal.bioontology.org/accounts/new" if @options[:apikey].nil?
         
     | 
| 
       33 
36 
     | 
    
         
             
                end
         
     | 
| 
         @@ -43,18 +46,31 @@ module NCBO 
     | 
|
| 
       43 
46 
     | 
    
         | 
| 
       44 
47 
     | 
    
         
             
                  raise ArgumentError, ":textToAnnotate must be included" if @options[:textToAnnotate].nil?
         
     | 
| 
       45 
48 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                  result_xml =  
     | 
| 
      
 49 
     | 
    
         
            +
                  result_xml = annotate_post
         
     | 
| 
       47 
50 
     | 
    
         
             
                  Parser::Annotator.parse_results(result_xml)
         
     | 
| 
       48 
51 
     | 
    
         
             
                end
         
     | 
| 
       49 
52 
     | 
    
         | 
| 
      
 53 
     | 
    
         
            +
                def self.ontologies(options)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  new(options).ontologies
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
                
         
     | 
| 
      
 57 
     | 
    
         
            +
                def ontologies
         
     | 
| 
      
 58 
     | 
    
         
            +
                  if @ontologies.nil?
         
     | 
| 
      
 59 
     | 
    
         
            +
                    ontologies_xml = open("#{@options[:annotator_location]}/ontologies?apikey=#{@options[:apikey]}").read
         
     | 
| 
      
 60 
     | 
    
         
            +
                    @ontologies = Parser::Annotator.parse_included_ontologies(ontologies_xml)
         
     | 
| 
      
 61 
     | 
    
         
            +
                  else
         
     | 
| 
      
 62 
     | 
    
         
            +
                    @ontologies
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
                
         
     | 
| 
       50 
66 
     | 
    
         
             
                def options
         
     | 
| 
       51 
67 
     | 
    
         
             
                  @options
         
     | 
| 
       52 
68 
     | 
    
         
             
                end
         
     | 
| 
       53 
69 
     | 
    
         | 
| 
       54 
70 
     | 
    
         
             
                private
         
     | 
| 
       55 
71 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
                def  
     | 
| 
       57 
     | 
    
         
            -
                  url = @options[:annotator_location]
         
     | 
| 
      
 72 
     | 
    
         
            +
                def annotate_post
         
     | 
| 
      
 73 
     | 
    
         
            +
                  url = @options[:annotator_location] + "/annotator"
         
     | 
| 
       58 
74 
     | 
    
         
             
                  options = @options.clone
         
     | 
| 
       59 
75 
     | 
    
         
             
                  options.each do |k,v|
         
     | 
| 
       60 
76 
     | 
    
         
             
                    if v.kind_of?(Array)
         
     | 
| 
         @@ -65,4 +81,4 @@ module NCBO 
     | 
|
| 
       65 
81 
     | 
    
         
             
                  return res.body
         
     | 
| 
       66 
82 
     | 
    
         
             
                end
         
     | 
| 
       67 
83 
     | 
    
         
             
              end # end Annotator class
         
     | 
| 
       68 
     | 
    
         
            -
            end # end NCBO module
         
     | 
| 
      
 84 
     | 
    
         
            +
            end # end NCBO module
         
     | 
    
        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:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 17
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 1
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 3
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 1.0.3
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Paul R Alexander
         
     |