ontologies_api_client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c736724165de5f33538c13e206ac5150c63c7981
4
+ data.tar.gz: a6798c4a65ed2d0ffda6d2be3ceb880e964060d8
5
+ SHA512:
6
+ metadata.gz: 9517548f936421e34a71a4a7cf775ef761dfe6e0895f61816b02eefe8ebbb40971eb1dbe40627ebe8cedbdbf1e69c94db468ef38a16ea8e5a4e5db48c6db6492
7
+ data.tar.gz: bd418bc224d2e499704d29bcf81685185c3124eaea9f5f86357368ba34ec3968d27d849b626cb7e9732b61f4cebe49e0922ea3c6f76747098456421fbc0d47b3
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+
2
+ config/config.rb
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ontologies_api_client (0.0.2)
5
+ faraday
6
+ multi_json
7
+ oj
8
+ typhoeus
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ coderay (1.0.9)
14
+ ethon (0.5.11)
15
+ ffi (>= 1.3.0)
16
+ mime-types (~> 1.18)
17
+ faraday (0.8.7)
18
+ multipart-post (~> 1.1)
19
+ ffi (1.7.0)
20
+ method_source (0.8.1)
21
+ mime-types (1.22)
22
+ multi_json (1.7.2)
23
+ multipart-post (1.2.0)
24
+ oj (2.0.11)
25
+ pry (0.9.12.1)
26
+ coderay (~> 1.0.5)
27
+ method_source (~> 0.8)
28
+ slop (~> 3.4)
29
+ rake (10.0.4)
30
+ slop (3.4.4)
31
+ typhoeus (0.6.3)
32
+ ethon (~> 0.5.11)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ ontologies_api_client!
39
+ pry
40
+ rake
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # NCBO Ontologies API Client
2
+
3
+ ## Install
4
+
5
+ gem install ontologies_api_client
6
+
7
+ ## Usage
8
+
9
+ The client is designed to consume resources from the [NCBO Ontologies API](https://github.com/ncbo/ontologies_api).
10
+ Resources are defined in the client using media types that we know about and
11
+ providing attribute names that we want to retreive for each media type.
12
+
13
+ For example:
14
+
15
+ class Category < LinkedData::Client::Base
16
+ include LinkedData::Client::Collection
17
+ @media_type = "http://data.bioontology.org/metadata/Category"
18
+ end
19
+
20
+ ### Retrieval
21
+
22
+ There are multiple ways to retrieve individual or groups of resources.
23
+
24
+ #### Find
25
+
26
+ To retrieve a single record by id: <code>Category.find("http://data.bioontology.org/categories/all_organisms")</code>
27
+
28
+ #### Where
29
+
30
+ To retrieve all records that match a particular an in-code filter. The code is a block that should return a
31
+ boolean that indicates whether or not the item should be included in the results.
32
+
33
+ categories = Category.where do |ont|
34
+ ont.name.include?("health")
35
+ end
36
+
37
+ #### Find By
38
+
39
+ You can use shortcut methods to find by particular attribute/value pairs
40
+ (attributes are named in the method and multiple can be provided by connecting them with 'and').
41
+
42
+ categories = Category.find_by_parentCategory("http://data.bioontology.org/categories/anatomy")
43
+
44
+ ## Questions
45
+
46
+ For questions please email [support@bioontology.org](support@bioontology.org.)
47
+
48
+ ## License
49
+
50
+ Copyright (c) 2013, The Board of Trustees of Leland Stanford Junior University All rights reserved.
51
+
52
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
53
+
54
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
55
+
56
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
57
+
58
+ THIS SOFTWARE IS PROVIDED BY THE BOARD OF TRUSTEES OF LELAND STANFORD JUNIOR UNIVERSITY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL The Board of Trustees of Leland Stanford Junior University OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
+
60
+ The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of The Board of Trustees of Leland Stanford Junior University.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs = []
5
+ t.test_files = FileList['test/**/test*.rb']
6
+ end
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.libs = []
10
+ t.name = "test:models"
11
+ t.test_files = FileList['test/models/test*.rb']
12
+ end
13
+
@@ -0,0 +1,16 @@
1
+ require 'oj'
2
+ require 'multi_json'
3
+ require 'typhoeus'
4
+ require 'faraday'
5
+ require 'typhoeus/adapters/faraday'
6
+
7
+ require_relative 'ontologies_api_client/config'
8
+ require_relative 'ontologies_api_client/http'
9
+ require_relative 'ontologies_api_client/link_explorer'
10
+ require_relative 'ontologies_api_client/base'
11
+ require_relative 'ontologies_api_client/collection'
12
+ require_relative 'ontologies_api_client/read_write'
13
+
14
+ # Models
15
+ curr_dir = File.expand_path("../ontologies_api_client", __FILE__)
16
+ Dir.glob("#{curr_dir}/models/*.rb").each {|f| require_relative f }
@@ -0,0 +1,51 @@
1
+ module LinkedData
2
+ module Client
3
+ class Base
4
+ HTTP = LinkedData::Client::HTTP
5
+ attr_writer :instance_values
6
+ attr_accessor :context, :links
7
+
8
+ class << self
9
+ attr_accessor :media_type, :include_attrs
10
+ end
11
+
12
+ def self.class_for_type(media_type)
13
+ classes = LinkedData::Client::Models.constants
14
+ classes.each do |cls|
15
+ media_type_cls = LinkedData::Client::Models.const_get(cls)
16
+ return media_type_cls if media_type_cls.media_type.eql?(media_type)
17
+ end
18
+ nil
19
+ end
20
+
21
+ def initialize(values = nil)
22
+ @instance_values = values
23
+ end
24
+
25
+ def method_missing(meth, *args, &block)
26
+ if @instance_values && @instance_values.respond_to?(meth)
27
+ @instance_values.send(meth, *args, &block)
28
+ else
29
+ super
30
+ end
31
+ end
32
+
33
+ def respond_to?(meth)
34
+ if @instance_values && @instance_values.respond_to?(meth)
35
+ return true
36
+ else
37
+ super
38
+ end
39
+ end
40
+
41
+ def explore
42
+ LinkedData::Client::LinkExplorer.new(@links)
43
+ end
44
+
45
+ def id
46
+ @instance_values["@id"]
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,92 @@
1
+ require_relative 'config'
2
+ require_relative 'http'
3
+
4
+ module LinkedData
5
+ module Client
6
+ module Collection
7
+
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ end
11
+
12
+ module ClassMethods
13
+ ##
14
+ # Allows for arbitrary find_by methods. For example:
15
+ # Ontology.find_by_acronym("BRO")
16
+ # Ontology.find_by_group_and_category("UMLS", "Anatomy")
17
+ def method_missing(meth, *args, &block)
18
+ if meth.to_s =~ /^find_by_(.+)$/
19
+ find_by($1, *args, &block)
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ ##
26
+ # Get all top-level links for the API
27
+ def top_level_links
28
+ HTTP.get(LinkedData::Client.settings.rest_url)
29
+ end
30
+
31
+ ##
32
+ # Return a link given an object (with links) and a media type
33
+ def uri_from_context(object, media_type)
34
+ object.links.each do |type, link|
35
+ return link if link.media_type && link.media_type.downcase.eql?(media_type.downcase)
36
+ end
37
+ end
38
+
39
+ ##
40
+ # Get the first collection of resources for a given type
41
+ def entry_point(media_type)
42
+ HTTP.get(uri_from_context(top_level_links, media_type), include: @include_attrs)
43
+ end
44
+
45
+ ##
46
+ # Get all resources from the base collection for a resource
47
+ def all(*args)
48
+ entry_point(@media_type)
49
+ end
50
+
51
+ ##
52
+ # Find certain resources from the collection by passing a block that filters results
53
+ def where(params = {}, &block)
54
+ if block_given?
55
+ return all.select {|e| block.call(e)}
56
+ else
57
+ raise ArgumentException("Must provide a block to find ontologies")
58
+ end
59
+ end
60
+
61
+ ##
62
+ # Find a resource by id
63
+ def find(id, params = {})
64
+ found = where do |obj|
65
+ obj.send("@id").eql?(id)
66
+ end
67
+ found.first
68
+ end
69
+
70
+ ##
71
+ # Find a resource by a combination of attributes
72
+ def find_by(attrs, *args)
73
+ attributes = attrs.split("_and_")
74
+ where do |obj|
75
+ bools = []
76
+ attributes.each_with_index do |attr, index|
77
+ if obj.respond_to?(attr)
78
+ value = obj.send(attr)
79
+ if value.is_a?(Enumerable)
80
+ bools << value.include?(args[index])
81
+ else
82
+ bools << (value == args[index])
83
+ end
84
+ end
85
+ end
86
+ bools.all?
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,48 @@
1
+ require 'ostruct'
2
+ require 'faraday'
3
+ require 'typhoeus'
4
+ require 'logger'
5
+
6
+ module LinkedData
7
+ module Client
8
+ extend self
9
+ attr_reader :settings
10
+
11
+ @settings = OpenStruct.new
12
+ @settings_run = false
13
+
14
+ def config(&block)
15
+ return if @settings_run
16
+ @settings_run = true
17
+
18
+ yield @settings if block_given?
19
+
20
+ # Set defaults
21
+ @settings.rest_url ||= "http://stagedata.bioontology.org/"
22
+ @settings.apikey ||= "4ea81d74-8960-4525-810b-fa1baab576ff"
23
+ @settings.links_attr ||= "links"
24
+ @settings.cache ||= false
25
+
26
+ @settings.conn = Faraday.new(@settings.rest_url) do |faraday|
27
+ faraday.request :url_encoded
28
+ faraday.request :multipart
29
+ faraday.adapter :typhoeus
30
+ if @settings.cache
31
+ begin
32
+ require 'faraday-http-cache'
33
+ faraday.use :http_cache
34
+ rescue LoadError
35
+ puts "faraday-http-cache gem is not available, caching disabled"
36
+ end
37
+ end
38
+ faraday.headers = {
39
+ "Accept" => "application/json",
40
+ "Authorization" => "apikey token=#{@settings.apikey}",
41
+ "User-Agent" => "NCBO API Ruby Client v0.1.0"
42
+ }
43
+ end
44
+
45
+ @settings_run = true
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,108 @@
1
+ require 'oj'
2
+ require 'multi_json'
3
+ require 'digest'
4
+
5
+ module LinkedData
6
+ module Client
7
+ module HTTP
8
+ class Link < String; attr_accessor :media_type; end
9
+
10
+ OBJ_CACHE = {}
11
+ GET_CACHE = {}
12
+ ENABLE_CACHE = true
13
+
14
+ def self.conn
15
+ LinkedData::Client.settings.conn
16
+ end
17
+
18
+ def self.get(path, params = {})
19
+ params = params.delete_if {|k,v| v == nil || v.to_s.empty?}
20
+
21
+ if ENABLE_CACHE && GET_CACHE[[path, params].hash]
22
+ obj = GET_CACHE[[path, params].hash]
23
+ else
24
+ response = conn.get path, params
25
+ body = response.body
26
+ obj = rucursive_struct(load_json(body))
27
+ GET_CACHE[[path, params].hash] = obj if response.status < 400 && ENABLE_CACHE
28
+ end
29
+ obj
30
+ end
31
+
32
+ def self.get_batch(paths)
33
+ responses = []
34
+ conn.in_parallel do
35
+ paths.each {|p| responses << conn.get(p[0], p[1]) }
36
+ end
37
+ return *responses
38
+ end
39
+
40
+ def self.post
41
+ end
42
+
43
+ def self.put
44
+ end
45
+
46
+ def self.patch
47
+ end
48
+
49
+ def self.delete
50
+ end
51
+
52
+ private
53
+
54
+ def self.rucursive_struct(json_obj)
55
+ # TODO: Convert dates to date objects
56
+ if json_obj.is_a?(Hash)
57
+ value_cls = LinkedData::Client::Base.class_for_type(json_obj["@type"])
58
+ links = prep_links(json_obj)
59
+ context = json_obj.delete("@context")
60
+ obj_cls = cls_for_keys(json_obj.keys.map {|k| k.to_sym})
61
+ values = []
62
+ json_obj.each do |key, value|
63
+ values << rucursive_struct(value)
64
+ end
65
+ new_values = obj_cls.new(*values)
66
+ obj = value_cls ? value_cls.new(new_values) : new_values
67
+ obj.links = links if links
68
+ obj.context = context if context
69
+ elsif json_obj.is_a?(Array)
70
+ obj = []
71
+ json_obj.each do |value|
72
+ obj << rucursive_struct(value)
73
+ end
74
+ else
75
+ obj = value_cls ? value_cls.new(json_obj) : json_obj
76
+ end
77
+ obj
78
+ end
79
+
80
+ def self.prep_links(obj)
81
+ links = obj.delete(LinkedData::Client.settings.links_attr)
82
+ return if links.nil?
83
+
84
+ context = links.delete("@context")
85
+ return if context.nil?
86
+ links.keys.each do |link_type|
87
+ link = Link.new(links[link_type])
88
+ link.media_type = context[link_type]
89
+ links[link_type] = link
90
+ end
91
+ links
92
+ end
93
+
94
+ def self.cls_for_keys(keys)
95
+ keys = keys + [:links, :context]
96
+ OBJ_CACHE[keys.hash] ||= Struct.new(*keys)
97
+ end
98
+
99
+ def self.load_json(json)
100
+ MultiJson.load(json)
101
+ end
102
+
103
+ def self.dump_json(json)
104
+ MultiJson.dump(json)
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,52 @@
1
+ require 'cgi'
2
+ require_relative 'http'
3
+
4
+ module LinkedData
5
+ module Client
6
+ class LinkExplorer
7
+ HTTP = LinkedData::Client::HTTP
8
+
9
+ def initialize(links)
10
+ @links = links
11
+ end
12
+
13
+ def method_missing(meth, *args, &block)
14
+ if @links.key?(meth.to_s)
15
+ explore_link(meth, *args)
16
+ elsif meth == :batch
17
+ explore_links(*args)
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ def respond_to?(meth)
24
+ if @links.key?(meth.to_s) || meth == :batch
25
+ return true
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ def explore_link(*args)
32
+ link = @links[args.shift.to_s]
33
+ url = replace_template_elements(link.to_s, args)
34
+ value_cls = LinkedData::Client::Base.class_for_type(link.media_type)
35
+ params = {includes: value_cls.include_attrs}
36
+ HTTP.get(url, params)
37
+ end
38
+
39
+ def replace_template_elements(url, values = [])
40
+ return url if values.empty?
41
+ return url.gsub(/(\{.*?\})/) do
42
+ CGI.escape(values.shift)
43
+ end
44
+ end
45
+
46
+ def explore_links(*args)
47
+ paths = args.each.map {|p| [p.to_s, p.media_type]}
48
+ HTTP.batch_get(args)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "../base"
2
+
3
+ module LinkedData
4
+ module Client
5
+ module Models
6
+ class Category < LinkedData::Client::Base
7
+ include LinkedData::Client::Collection
8
+ @media_type = "http://data.bioontology.org/metadata/Category"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ require_relative "../base"
2
+
3
+ module LinkedData
4
+ module Client
5
+ module Models
6
+ class Class < LinkedData::Client::Base
7
+ require 'cgi'
8
+ HTTP = LinkedData::Client::HTTP
9
+ @media_type = "http://www.w3.org/2002/07/owl#Class"
10
+ @include_attrs = "prefLabel,definition,synonym,properties,childrenCount,children"
11
+
12
+ attr_accessor :parent
13
+ alias :fullId :id
14
+
15
+ # TODO: Implement properly
16
+ def obsolete?; false; end
17
+ def relation_icon; ""; end
18
+
19
+ def self.find(id, ontology, params = {})
20
+ ontology = HTTP.get(ontology, params)
21
+ ontology.explore.class(CGI.escape(id))
22
+ end
23
+
24
+ def expanded?
25
+ !children.nil? && children.length > 0
26
+ end
27
+
28
+ def children
29
+ # if @children.nil?
30
+ # return self.explore.children.collection
31
+ # end
32
+ @children
33
+ end
34
+
35
+ def children=(children)
36
+ @children = children
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "../base"
2
+
3
+ module LinkedData
4
+ module Client
5
+ module Models
6
+ class Group < LinkedData::Client::Base
7
+ include LinkedData::Client::Collection
8
+ @media_type = "http://data.bioontology.org/metadata/Group"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ require 'cgi'
2
+ require_relative "../base"
3
+
4
+ module LinkedData
5
+ module Client
6
+ module Models
7
+ class Ontology < LinkedData::Client::Base
8
+ include LinkedData::Client::Collection
9
+
10
+ @media_type = "http://data.bioontology.org/metadata/Ontology"
11
+ @include_attrs = "all"
12
+
13
+ #TODO: Implement actual methods
14
+ def private?; false; end
15
+ def licensed?; false; end
16
+ def viewing_restricted?; false; end
17
+ def admin?(user); false; end
18
+ def flat?; false; end
19
+
20
+ def purl
21
+ "PURL not implemented"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "../base"
2
+
3
+ module LinkedData
4
+ module Client
5
+ module Models
6
+ class OntologySubmission < LinkedData::Client::Base
7
+ include LinkedData::Client::Collection
8
+ @media_type = "http://data.bioontology.org/metadata/OntologySubmission"
9
+ @include_attrs = "all"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "../base"
2
+
3
+ module LinkedData
4
+ module Client
5
+ module Models
6
+ class Project < LinkedData::Client::Base
7
+ include LinkedData::Client::Collection
8
+ @media_type = "http://data.bioontology.org/metadata/Project"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "../base"
2
+
3
+ module LinkedData
4
+ module Client
5
+ module Models
6
+ class Review < LinkedData::Client::Base
7
+ include LinkedData::Client::Collection
8
+ @media_type = "http://data.bioontology.org/metadata/Review"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "../base"
2
+
3
+ module LinkedData
4
+ module Client
5
+ module Models
6
+ class User < LinkedData::Client::Base
7
+ include LinkedData::Client::Collection
8
+ @media_type = "http://data.bioontology.org/metadata/User"
9
+ @include_attrs = "all"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module LinkedData
2
+ module Client
3
+ module ReadWrite
4
+ def save
5
+ end
6
+
7
+ def update
8
+ end
9
+
10
+ def delete
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.authors = ["Paul R Alexander"]
3
+ gem.email = ["palexander@stanford.edu"]
4
+ gem.description = %q{Models and serializers for ontologies and related artifacts backed by 4store}
5
+ gem.summary = %q{This library can be used for interacting with a 4store instance that stores NCBO-based ontology information. Models in the library are based on Goo. Serializers support RDF serialization as Rack Middleware and automatic generation of hypermedia links.}
6
+ gem.homepage = "https://github.com/ncbo/ontologies_api_ruby_client"
7
+
8
+ gem.files = `git ls-files`.split($\)
9
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
10
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
11
+ gem.name = "ontologies_api_client"
12
+ gem.require_paths = ["lib"]
13
+ gem.version = "0.0.2"
14
+
15
+ gem.add_dependency('multi_json')
16
+ gem.add_dependency('oj')
17
+ gem.add_dependency('faraday')
18
+ gem.add_dependency('typhoeus')
19
+
20
+ # gem.executables = %w()
21
+ end
@@ -0,0 +1,41 @@
1
+ require 'benchmark'
2
+
3
+ require_relative '../../lib/ontologies_api_client'
4
+ LinkedData::Client.config
5
+
6
+ module LinkedData
7
+ module Client
8
+ class Benchmark
9
+
10
+ def test_all_ontologies
11
+ 10.times {LinkedData::Client::Models::Ontology.all}
12
+ end
13
+
14
+ def test_explore_ontologies
15
+ onts = LinkedData::Client::Models::Ontology.all
16
+ onts.each do |ont|
17
+ ont.explore.projects
18
+ ont.explore.groups
19
+ ont.explore.categories
20
+ ont.explore.reviews
21
+ end
22
+ end
23
+
24
+ def test_batch_explore_ontologies
25
+ # onts = LinkedData::Client::Models::Ontology.all
26
+ # onts.each do |ont|
27
+ # projects, groups, categories = LinkedData::Client::HTTP.get_batch([ont.links["projects"], ont.links["groups"], ont.links["categories"]])
28
+ # end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+
35
+ benchmark = LinkedData::Client::Benchmark.new
36
+ benchmark.public_methods(false).each do |method|
37
+ time = ::Benchmark.realtime do
38
+ benchmark.send(method)
39
+ end
40
+ puts "#{method}: #{time*1000}ms"
41
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../test_case'
2
+
3
+ class TestOntology < LinkedData::Client::Base
4
+ include LinkedData::Client::Collection
5
+ include LinkedData::Client::ReadWrite
6
+
7
+ @media_type = "http://data.bioontology.org/metadata/Ontology"
8
+ @include_attrs = "all"
9
+ end
10
+
11
+ class CollectionTest < LinkedData::Client::TestCase
12
+ def test_all
13
+ onts = LinkedData::Client::Models::Ontology.all
14
+ assert onts.length > 350
15
+ end
16
+
17
+ def test_class_for_type
18
+ media_type = "http://data.bioontology.org/metadata/Category"
19
+ type_cls = LinkedData::Client::Base.class_for_type(media_type)
20
+ assert type_cls == LinkedData::Client::Models::Category
21
+ end
22
+
23
+ def test_find_by
24
+ bro = TestOntology.find_by_acronym("BRO")
25
+ assert bro.length >= 1
26
+ assert bro.any? {|o| o.acronym.eql?("BRO")}
27
+
28
+ onts = TestOntology.find_by_hasDomain_and_doNotUpdate("http://data.bioontology.org/categories/health", true)
29
+ assert onts.length >= 1
30
+
31
+ onts = TestOntology.find_by_hasDomain_and_hasDomain("http://data.bioontology.org/categories/phenotype", "http://data.bioontology.org/categories/human")
32
+ assert onts.length >= 1
33
+ end
34
+
35
+ def test_where
36
+ onts = TestOntology.where {|o| o.name.downcase.start_with?("c")}
37
+ assert onts.length >= 1
38
+ end
39
+
40
+ def test_find
41
+ ont = TestOntology.find("http://data.bioontology.org/ontologies/CAMRQ")
42
+ assert !ont.nil?
43
+ end
44
+ end
data/test/test_case.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require_relative '../lib/ontologies_api_client'
3
+ require_relative '../config/config.rb'
4
+
5
+ module LinkedData
6
+ module Client
7
+ class TestCase < Test::Unit::TestCase
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ontologies_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Paul R Alexander
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: typhoeus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Models and serializers for ontologies and related artifacts backed by
70
+ 4store
71
+ email:
72
+ - palexander@stanford.edu
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - README.md
81
+ - Rakefile
82
+ - lib/ontologies_api_client.rb
83
+ - lib/ontologies_api_client/base.rb
84
+ - lib/ontologies_api_client/collection.rb
85
+ - lib/ontologies_api_client/config.rb
86
+ - lib/ontologies_api_client/http.rb
87
+ - lib/ontologies_api_client/link_explorer.rb
88
+ - lib/ontologies_api_client/models/category.rb
89
+ - lib/ontologies_api_client/models/class.rb
90
+ - lib/ontologies_api_client/models/group.rb
91
+ - lib/ontologies_api_client/models/ontology.rb
92
+ - lib/ontologies_api_client/models/ontology_submission.rb
93
+ - lib/ontologies_api_client/models/project.rb
94
+ - lib/ontologies_api_client/models/review.rb
95
+ - lib/ontologies_api_client/models/user.rb
96
+ - lib/ontologies_api_client/read_write.rb
97
+ - ontologies_api_client.gemspec
98
+ - test/benchmark/http.rb
99
+ - test/models/test_collection.rb
100
+ - test/test_case.rb
101
+ homepage: https://github.com/ncbo/ontologies_api_ruby_client
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.0
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: This library can be used for interacting with a 4store instance that stores
124
+ NCBO-based ontology information. Models in the library are based on Goo. Serializers
125
+ support RDF serialization as Rack Middleware and automatic generation of hypermedia
126
+ links.
127
+ test_files:
128
+ - test/benchmark/http.rb
129
+ - test/models/test_collection.rb
130
+ - test/test_case.rb
131
+ has_rdoc: