class Arbetsformedlingen::API::OntologyClient
API
client for ontology @see ontologi.arbetsformedlingen.se/ontology/v1/?url=swagger.json
Constants
- BASE_URL
Base
API
URL- VALID_TYPES
Valid types
Attributes
Public Class Methods
Initialize client
# File lib/arbetsformedlingen/api/ontology_client.rb, line 17 def initialize(request: Request.new(base_url: BASE_URL)) @request = request end
Public Instance Methods
GET /concept/:uuid} - Fetch a concept given an uuid @return [Response]
# File lib/arbetsformedlingen/api/ontology_client.rb, line 31 def concept(uuid) request.get("/concept/#{uuid}") end
GET /concept/:uuid/related/:type - Fetches related concepts for the given uuid, returning only concepts of the given type @return [Response]
# File lib/arbetsformedlingen/api/ontology_client.rb, line 60 def concept_relations(concept_uuid, type, offset: nil, limit: nil) query = to_params(offset: offset, limit: limit) request.get("/concept/#{concept_uuid}/related/#{type}", query: query) end
GET /concept/:uuid/terms - Fetches the terms for the given uuid @return [Response]
# File lib/arbetsformedlingen/api/ontology_client.rb, line 51 def concept_terms(concept_uuid, offset: nil, limit: nil) query = to_params(offset: offset, limit: limit) request.get("/concept/#{concept_uuid}/terms", query: query) end
GET /concept - Fetches a list of concepts @return [Response]
# File lib/arbetsformedlingen/api/ontology_client.rb, line 23 def concepts(filter: nil, offset: nil, limit: nil, type: nil) query = to_params(filter: filter, offset: offset, limit: limit, type: type) request.get('/concept', query: query) end
GET /concept/related - Fetches related concepts for any number of concepts and/or uuids @return [Response]
# File lib/arbetsformedlingen/api/ontology_client.rb, line 38 def concepts_relations(uuids: [], names: [], limit: nil, type: nil) concepts = ( names.map { |name| ['concept', name] } + uuids.map { |name| ['uui', name] } ).reject(&:empty?) query = to_params(limit: limit, type: type).to_a.concat(concepts) request.get('/concept/related', query: query) end
GET /terms - Fetches a list of terms @return [Response]
# File lib/arbetsformedlingen/api/ontology_client.rb, line 68 def terms(filter: nil, offset: nil, limit: nil, type: nil) query = to_params(filter: filter, offset: offset, limit: limit, type: type) request.get('/terms', query: query) end
POST /text-to-structure - Analyzes a text and returns the concepts found @return [Response]
# File lib/arbetsformedlingen/api/ontology_client.rb, line 89 def text_to_structure(text) request.post('/text-to-structure', data: { text: text }) end
GET /:type/:description - Redirects to the concepts UUID @return [Response]
# File lib/arbetsformedlingen/api/ontology_client.rb, line 76 def type_description(type, description) request.get("/#{type}/#{description}") end
GET /:type/:description/related/:totype - Redirects to the concepts UUID related concepts @return [Response]
# File lib/arbetsformedlingen/api/ontology_client.rb, line 83 def type_description_relations(type, description, relation_type) request.get("/#{type}/#{description}/related/#{relation_type}") end
Private Instance Methods
# File lib/arbetsformedlingen/api/ontology_client.rb, line 95 def to_params(filter: nil, offset: nil, limit: nil, type: nil) if type && !VALID_TYPES.include?(type) raise(ArgumentError, "invalid type #{type}, valid types are #{VALID_TYPES.join(', ')}") # rubocop:disable Metrics/LineLength end { filter: filter, offset: offset, limit: limit, type: type, }.delete_if { |_k, v| v.nil? } end