-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_ld.js
57 lines (50 loc) · 1.68 KB
/
test_ld.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
54
55
56
var LD = require('../js/ld')
var source = [
{
"@id": "http://example.org/vocab#Thing",
"@type": "http://www.w3.org/2000/01/rdf-schema#Class",
"http://www.w3.org/2000/01/rdf-schema#label": [{"@value": "Thing", "@language": "en"}]
},
{
"@id": "http://example.org/vocab#Item",
"@type": "http://www.w3.org/2000/01/rdf-schema#Class",
"http://www.w3.org/2000/01/rdf-schema#label": [{"@value": "Item", "@language": "en"}],
"http://www.w3.org/2000/01/rdf-schema#subClassOf": [{"@id": "http://example.org/vocab#Thing"}]
}
]
var ctx = {
rdfs: "http://www.w3.org/2000/01/rdf-schema#",
iri: "@id",
type: "@type",
Class: "rdfs:Class",
subClassOf: {"@id": "rdfs:subClassOf", "@container": "@set"},
label: "rdfs:label",
"@language": "en",
//all: {"@id": "@graph", "@container": "@id"},
byType: {"@id": "@graph", "@container": "@type"},
//rev: "@rev",
//instances: {"@rev": "type"},
subclasses: {"@rev": "subClassOf"}
}
var data = LD.connect(source, ctx)
console.log("\n## Compact usage ##")
//data.all.Class.instances.forEach(function (cls) {
//data.all.Class.via.type.forEach(function (cls) {
data.byType.Class.forEach(function (cls) {
console.log("class: " + cls.iri)
console.log(" label: " + cls.label)
if (cls.subClassOf) {
cls.subClassOf.forEach(function (sup) {
console.log(" subClassOf: " + sup.label)
})
}
if (cls.subclasses) {
console.log(" subclasses: " + cls.subclasses.map(
function (it) { return it.label }).join(", "))
}
})
//data.add(cls, 'subClassOf', sup)
//data.remove(cls, 'subClassOf', sup)
//data.add(cls, '@type', 'owl:Class')
console.log("\n## Serializing ##")
console.log(JSON.stringify(data, null, 2))