Class: Arbetsformedlingen::API::OntologyClient

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#requestObject (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

Returns:



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

Returns:



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

Returns:



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

Returns:



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

Returns:



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

Returns:



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

Returns:



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

Returns:



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

Returns:



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