Class: Arbetsformedlingen::API::OntologyClient
- Inherits:
-
Object
- Object
- Arbetsformedlingen::API::OntologyClient
- Defined in:
- lib/arbetsformedlingen/api/ontology_client.rb
Overview
API client for ontology
Constant Summary collapse
- BASE_URL =
Base API URL
'http://ontologi.arbetsformedlingen.se/ontology/v1'
- VALID_TYPES =
Valid types
%w[skill occupation trait].freeze
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#concept(uuid) ⇒ Response
GET /concept/:uuid} - Fetch a concept given an uuid.
-
#concept_relations(concept_uuid, type, offset: nil, limit: nil) ⇒ Response
GET /concept/:uuid/related/:type - Fetches related concepts for the given uuid, returning only concepts of the given type.
-
#concept_terms(concept_uuid, offset: nil, limit: nil) ⇒ Response
GET /concept/:uuid/terms - Fetches the terms for the given uuid.
-
#concepts(filter: nil, offset: nil, limit: nil, type: nil) ⇒ Response
GET /concept - Fetches a list of concepts.
-
#concepts_relations(uuids: [], names: [], limit: nil, type: nil) ⇒ Response
GET /concept/related - Fetches related concepts for any number of concepts and/or uuids.
-
#initialize(request: Request.new(base_url: BASE_URL)) ⇒ OntologyClient
constructor
Initialize client.
-
#terms(filter: nil, offset: nil, limit: nil, type: nil) ⇒ Response
GET /terms - Fetches a list of terms.
-
#text_to_structure(text) ⇒ Response
POST /text-to-structure - Analyzes a text and returns the concepts found.
-
#type_description(type, description) ⇒ Response
GET /:type/:description - Redirects to the concepts UUID.
-
#type_description_relations(type, description, relation_type) ⇒ Response
GET /:type/:description/related/:totype - Redirects to the concepts UUID related concepts.
Constructor Details
#initialize(request: Request.new(base_url: BASE_URL)) ⇒ OntologyClient
Initialize client
17 18 19 |
# File 'lib/arbetsformedlingen/api/ontology_client.rb', line 17 def initialize(request: Request.new(base_url: BASE_URL)) @request = request end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/arbetsformedlingen/api/ontology_client.rb', line 8 def request @request end |
Instance Method Details
#concept(uuid) ⇒ Response
GET /concept/:uuid} - Fetch a concept given an uuid
31 32 33 |
# File 'lib/arbetsformedlingen/api/ontology_client.rb', line 31 def concept(uuid) request.get("/concept/#{uuid}") end |
#concept_relations(concept_uuid, type, offset: nil, limit: nil) ⇒ Response
GET /concept/:uuid/related/:type - Fetches related concepts for the given uuid, returning only concepts of the given type
60 61 62 63 64 |
# 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 |
#concept_terms(concept_uuid, offset: nil, limit: nil) ⇒ Response
GET /concept/:uuid/terms - Fetches the terms for the given uuid
51 52 53 54 55 |
# 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 |
#concepts(filter: nil, offset: nil, limit: nil, type: nil) ⇒ Response
GET /concept - Fetches a list of concepts
23 24 25 26 27 |
# 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 |
#concepts_relations(uuids: [], names: [], limit: nil, type: nil) ⇒ Response
GET /concept/related - Fetches related concepts for any number of concepts and/or uuids
38 39 40 41 42 43 44 45 46 47 |
# 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 |
#terms(filter: nil, offset: nil, limit: nil, type: nil) ⇒ Response
GET /terms - Fetches a list of terms
68 69 70 71 72 |
# 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 |
#text_to_structure(text) ⇒ Response
POST /text-to-structure - Analyzes a text and returns the concepts found
89 90 91 |
# File 'lib/arbetsformedlingen/api/ontology_client.rb', line 89 def text_to_structure(text) request.post('/text-to-structure', data: { text: text }) end |
#type_description(type, description) ⇒ Response
GET /:type/:description - Redirects to the concepts UUID
76 77 78 |
# File 'lib/arbetsformedlingen/api/ontology_client.rb', line 76 def type_description(type, description) request.get("/#{type}/#{description}") end |
#type_description_relations(type, description, relation_type) ⇒ Response
GET /:type/:description/related/:totype - Redirects to the concepts UUID related concepts
83 84 85 |
# 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 |