This repository has been archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWikidataScheme.js
53 lines (46 loc) · 1.79 KB
/
WikidataScheme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function wikidataScheme(OpenSearchSuggestions, SkosConceptSource, SkosConceptListSource) {
return {
name: 'Wikidata',
// look up a wikidata item by notation
getConcept: new SkosConceptSource({
url: "http://www.wikidata.org/w/api.php?" + [
"action=wbgetentities",
"ids={notation}",
"props=info|labels|descriptions|aliases",
"format=json"
].join('&'),
jsonp: true,
transform: function(item) {
var entity;
if (angular.isObject(item.entities)) {
angular.forEach(item.entities, function(value, key) {
if (key == value.title) {
entity = value;
}
});
}
if (!entity) return { };
var concept = {
uri: "http://wikidata.org/wiki/"+entity.title,
notation: [entity.title],
prefLabel: { },
altLabel: { },
note: { }
};
angular.forEach(entity.labels, function(s,language) {
concept.prefLabel[language] = s.value;
});
angular.forEach(entity.aliases, function(s,language) {
concept.altLabel[language] = s.map(function(v) {
return v.value;
});
});
angular.forEach(entity.descriptions, function(s,language) {
concept.note[language] = [s.value];
});
//console.log(concept);
return concept;
}
})
};
}