gbv / cocoda-sdk

SDK for Cocoda and coli-conc services
https://gbv.github.io/cocoda-sdk/
MIT License
5 stars 1 forks source link

SkosmosApi failing when getting a single concept #10

Closed nichtich closed 4 years ago

nichtich commented 4 years ago

Tested with

const ysa = {
  "uri": "http://bartoc.org/de/node/372",
  "VOCID": "ysa"
}

const fintoSubsetConfig = {
  "provider": "SkosmosApi",
  "api": "http://api.finto.fi/rest/v1/",
  "uri": "http://example.org/finto",
  "schemes": [ ysa ]
} 

const providers = require("../providers")
const finto = new providers.SkosmosApi({ registry: fintoSubsetConfig })

let uri = "http://www.yso.fi/onto/ysa/Y109755"
let concepts = [ { uri, inScheme: [ ysa ] } ]
finto.getConcepts({ concepts }).then(console.log)

Fails because at https://github.com/gbv/cocoda-sdk/blob/c70fea4e5ee7dcfea1e4741237bd9ddefa7e3470/providers/skosmos-api-provider.js#L90 the prefLabel field is an object instead an array. Same issue in line 114.

stefandesu commented 4 years ago

Well, the issue is actually that the Skosmos API doesn't seem to be well-defined when it comes to the prefLabel field. If you have multiple languages, it actually returns an array:

https://zbw.eu/beta/skosmos/rest/v1/stw/data?uri=http://zbw.eu/stw/descriptor/10025-6&format=application/json

But in your example, there is only one language, and instead of an array with one object, it returns an object:

https://api.finto.fi/rest/v1/data?uri=http://www.yso.fi/onto/ysa/Y109755&format=application/json

I will add a check whether the field is an array and if not, wrap it in an array, so that both options are supported.

stefandesu commented 4 years ago

Fun fact: The same check was already included for altLabel because the same thing happens there, but apparently I did not realize that it can happen with prefLabel as well.