Code Monkey home page Code Monkey logo

ontologies_api_ruby_client's Introduction

ontologies_api_client

Models and serializers for ontologies and related artifacts backed by an AllegroGraph or a 4store database. This library can be used for interacting with an AllegroGraph or a 4store instance that stores BioPortal ontology data. Models in the library are based on Graph Oriented Objects for Ruby (Goo). Serializers support RDF serialization as Rack Middleware and automatic generation of hypermedia links.

Install

gem install ontologies_api_client

Configuration

Configuration is provided by calling the config method

require 'ontologies_api_client'
LinkedData::Client.config do |config|
  config.rest_url   = "http://stagedata.bioontology.org"
  config.apikey     = "your_apikey"
  config.links_attr = "links"
  config.cache      = false
end

Usage

Once configured, you can utilize the existing resources that are defined (see lib/ontologies_api_client/models) to access a resource, its information, and related resources.

Retrieval

There are multiple ways to retrieve individual or groups of resources.

Find

To retrieve a single record by ID:

Category.find("http://data.bioontology.org/categories/all_organisms")

Where

To retrieve all records that match a particular in-code filter:

categories = Category.where do |ont|
  ont.name.include?("health")
end

The code is a block that should return a boolean that indicates whether or not the item should be included in the results.

Find By

Use shortcut methods to find by particular attribute/value pairs:

categories = Category.find_by_parentCategory("http://data.bioontology.org/categories/anatomy")

Attributes are named in the method and multiple can be provided by connecting them with 'and'.

Create / Update / Delete

Creates are done via HTTP POST, update via HTTP PATCH, and deletes using HTTP DELETE.

Create

ontology_values = {
  acronym: "MY_ONT",
  name: "My Ontology",
  administeredBy: [http://data.bioontology.org/users/my_user]
}
ontology = LinkedData::Client::Models::Ontology.new(values: ontology_values)
response = ontology.save
puts ontology_saved.errors

Update

new_values = {
  administeredBy: [http://data.bioontology.org/users/my_other_user]
}
ontology = LinkedData::Client::Models::Ontology.find_by_acronym("MY_ONT")
ontology.update_from_params(params[:ontology])
response = ontology.update
puts response.errors

Delete

ontology = LinkedData::Client::Models::Ontology.find_by_acronym("MY_ONT")
response = ontology.delete

Hypermedia Navigation

All resources have a collection of hypermedia links, available by calling the 'links' method. These links can be navigated by calling the 'explore' method and chaining the link:

ontology = Category.find("http://data.bioontology.org/categories/all_organisms")
classes = ontology.explore.classes

Links may contain a URI template. In this case, the template can be populated by passing in ordered values for the template tokens:

cls = ontology.explore.single_class("http://my.class.id/class1")

Defining Resources

The client is designed to consume resources from the NCBO Ontologies API. Resources are defined in the client using media types that we know about and providing attribute names that we want to retreive for each media type.

For example:

class Category < LinkedData::Client::Base
  include LinkedData::Client::Collection
  @media_type = "http://data.bioontology.org/metadata/Category"
end

Collections

Resources that are available via collections should include the Collection mixin (LinkedData::Client::Collection). By 'collection', we mean that the all resources are available at a single endpoint. For example, 'Ontology' is a resource with collections because you can see all ontologgies at the "/ontologies" URL.

Read/Write

Resources that should have save, update, and delete methods will need to include the ReadWrite mixin (LinkedData::Client::ReadWrite).

Questions

For questions please email [email protected]

License

Copyright (c) 2024, The Board of Trustees of Leland Stanford Junior University All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

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.

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.

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.

ontologies_api_ruby_client's People

Contributors

alexskr avatar dependabot[bot] avatar jvendetti avatar mdorf avatar palexander avatar syphax-bouazzouni avatar twktheainur avatar vemonet avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ontologies_api_ruby_client's Issues

Faraday multipart middleware moved out

Hi,

I don't know if you had already saw this issue.

The issue

At Agroportal, we are using the tag 2.0.2 (as you, i think) and recently when we did a bundle update we got the last version of faraday 2.1.0 where the multipart middleware (that is used here) is no more present (so causing a runtime error, see screenshot below ), it was moved to a separate gem called faraday-multipart.

image

More infos here : https://github.com/lostisland/faraday/blob/main/UPGRADING.md#bundled-middleware-moved-out

The fix for tag 2.0.2

For the tag 2.0.2 (used in production), we solved it by fixing the faraday version in the gemspec to 1.4.3

Gem::Specification.new do |gem|
  gem.authors       = ["Paul R Alexander"]
  gem.email         = ["[email protected]"]
  gem.description   = %q{Models and serializers for ontologies and related artifacts backed by 4store}
  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.}
  gem.homepage      = "https://github.com/ncbo/ontologies_api_ruby_client"

  gem.files         = `git ls-files`.split($\)
  gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
  gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
  gem.name          = "ontologies_api_client"
  gem.require_paths = ["lib"]
  gem.version       = "2.0.2"

  gem.add_dependency('activesupport', '~> 5.2.6')
  gem.add_dependency('excon')
  gem.add_dependency('faraday', '1.4.3')
  gem.add_dependency('lz4-ruby')
  gem.add_dependency('multi_json')
  gem.add_dependency('oj')
  gem.add_dependency('spawnling', '2.1.5')

  # gem.executables = %w()
end

The fix for tag 2.0.3

The fix for the last tag is to add the faraday-multipart gem as a dependency in the gemspec.

Updating ontology metadata sometimes fails with Faraday::TimeoutError

Received a complaint on the support list from a user that tried to remove an administrator from their ontology via the "Edit Ontology Information" form in the BioPortal UI, and received a 500 error. This form is accessed in the UI by going to any ontology summary page, e.g., http://bioportal.bioontology.org/ontologies/ECSO, and clicking the "Edit ontology information" link.

The production log file shows a Faraday::Timeout error:

I, [2017-04-05T10:47:07.646950 #21412]  INFO -- : Completed 500 Internal Server Error in 60274ms (ActiveRecord: 0.0ms)
F, [2017-04-05T10:47:07.649109 #21412] FATAL -- :
Faraday::TimeoutError (read timeout reached):
  app/controllers/ontologies_controller.rb:398:in `update'

I, [2017-04-05T10:47:07.650174 #21412]  INFO -- : Processing by ErrorsController#internal_server_error as HTML
I, [2017-04-05T10:47:07.650307 #21412]  INFO -- :   Parameters: {"utf8"=>"โœ“", "authenticity_token"=>"", "ontology"=>{"name"=>"The Ecosystem Ontology", "administeredBy"=>["", "http://data.bioontology.org/users/brycemecum", "http://data.bioontology.org/users/mobb", "http://data.bioontology.org/users/schild"], "viewingRestriction"=>"public", "acl"=>["", "http://data.bioontology.org/users/cjones", "http://data.bioontology.org/users/mobb", "http://data.bioontology.org/users/schild", "http://data.bioontology.org/users/sophisticus", "http://data.bioontology.org/users/xixiluo"], "hasDomain"=>["", "", "http://data.bioontology.org/categories/Other"], "isView"=>"0", "subscribe_notifications"=>"1"}, "commit"=>"Save ontology", "id"=>"ECSO"}
I, [2017-04-05T10:47:07.655224 #21412]  INFO -- :   Rendered errors/internal_server_error.html.erb within layouts/ontology (2.0ms)
I, [2017-04-05T10:47:07.658264 #21412]  INFO -- :   Rendered layouts/_topnav.html.haml (1.8ms)
I, [2017-04-05T10:47:07.658598 #21412]  INFO -- :   Rendered layouts/_notices.html.erb (0.2ms)
I, [2017-04-05T10:47:07.658686 #21412]  INFO -- :   Rendered layouts/_header.html.erb (3.2ms)
I, [2017-04-05T10:47:07.659514 #21412]  INFO -- :   Rendered layouts/_footer.html.erb (0.7ms)
I, [2017-04-05T10:47:07.659725 #21412]  INFO -- : Completed 500 Internal Server Error in 9ms (Views: 7.5ms | ActiveRecord: 0.0ms)

Just FYI - I removed the value of the authenticity token in the parameter list above.

Calling the update method in this project on an ontology object results in a read timeout. I wasn't able to reproduce this behavior after several attempts. We'll need to investigate under what circumstances the timeouts occur.

purl method generates URLs that result in 404 Not Found

The purl method is generating URLs that result in 404 Not Found. Some examples:

osteochondrosis (from RADLEX)
PURL: http://purl.bioontology.org/ontology/RADLEX?conceptid=http%3A%2F%2Fradlex.org%2FRID%2FRID5369

Abnormal Cell (from NCIT)
PURL: http://purl.bioontology.org/ontology/NCIT?conceptid=http%3A%2F%2Fncicb.nci.nih.gov%2Fxml%2Fowl%2FEVS%2FThesaurus.owl%23C12913

The PURLs will resolve properly if the conceptid parameter's value isn't URL encoded.

gemspec file is outdated

It appears that the gemspec file in this project hasn't been actively maintained, i.e.:

  • Since we're using this code in production, the version number should be (at least) 1.0.0.
  • We haven't been bumping the version number with code changes.
  • The email and summary fields should be updated with more current information.

find method on LinkedData::Client::Models::Class throws argument error

I couldn't find any functionality in the BioPortal RoR application that triggers a call to find on LinkedData::Client::Models::Class, nor do we have any unit tests that exercise that particular method.

If you attempt to call the method in a debugging environment, e.g.:

LinkedData::Client::Models::Class.find(
  'http://purl.bioontology.org/ontology/STY/T047', 
  'https://data.bioontology.org/ontologies/STY'
)

... the library throws an ArgumentError:

ArgumentError: wrong number of arguments (given 1, expected 0)

The method attempts to explore a non-existent type of hypermedia link on an ontology object (i.e., 'class' instead of 'single_class').

Validate API key before running unit tests

Unit tests fail with a confusing and unhelpful error when it is run with an invalid API key. A new unit test should be added to verify that the provided API key validates before proceeding to other unit tests.

relates to #14

Cache not invalidated after new submissions are processed

We've had several reports from the developers of the EDAM ontology where they upload a new ontology submission and the user interface only shows the submission status as uploaded. After waiting (sometimes as long as 24 hours), they're never able to see the status as anything other than uploaded, i.e., the data for the new submission never becomes visible.

I've reproduced this behavior in our production environment on two separate occasions, and observed the following:

  • It doesn't matter if you are logged in our out. The new submission shows as "uploaded" for both cases.
  • Clearing the browser cache has no effect.
  • Manually clearing BioPortal's goo and HTTP caches from the administrative page has no effect.

The only way I was able to get the new data to become visible in the UI was to click the "Flush UI Cache" button on the administrative page, which clears the front end in-memory cache (memcached).

I've also verified (by looking at the production parsing logs), that the EDAM ontology is relatively small and the system has no difficulty during the parsing process. From start to finish, we process the ontology in roughly 12 minutes.

URI.escape is obsolete warnings after Ruby 2.7 upgrade

After upgrading to Ruby 2.7, the log files for the BioPortal RoR application are full of URI.escape is obsolete warnings, originating from this library, e.g.:

Started GET "/ajax/classes/label?ontology=NIFSTD&concept=http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FUBERON_0000019" for 127.0.0.1 at 2022-12-19 11:34:52 -0800
Processing by ConceptsController#show_label as */*
  Parameters: {"ontology"=>"NIFSTD", "concept"=>"http://purl.obolibrary.org/obo/UBERON_0000019"}
/Users/vendetti/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/bundler/gems/ontologies_api_ruby_client-ca18863efae6/lib/ontologies_api_client/link_explorer.rb:64: warning: URI.escape is obsolete
  Rendering text template
  Rendered text template (Duration: 0.0ms | Allocations: 6)
Completed 200 OK in 362ms (Views: 0.3ms | ActiveRecord: 0.0ms | Allocations: 548234)

API calls in refresh_cache method intermittently failing

I'm testing the BioPortal Rails application against Ruby 3.0.6, and the staging version of the BioPortal REST API, which is currently running on the AllegroGraph database. In my local dev environment, I'm seeing intermittent failures from two of the API calls inside of the refresh_cache method:

def refresh_cache
  Spawnling.new do
    LinkedData::Client::Models::Ontology.all
    LinkedData::Client::Models::OntologySubmission.all
    LinkedData::Client::Models::User.all
    exit
  end
end

The call to fetch all OntologySubmission objects results in an empty array, or a Faraday::TimeoutError. The call to fetch all users sometimes returns user data, and sometimes results in the same Faraday::TimeoutError.

The responses of these calls are never examined/logged, so they essentially appear to be silent failures. @mdorf is looking into why the /submissions endpoint returns an emtpy array from an AllegroGraph database (see ncbo/ontologies_api#117).

We may want to consider - at a minimum - logging error responses from these calls, so that we're at least aware when they occur.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.