forked from timbl/rabel
-
Notifications
You must be signed in to change notification settings - Fork 5
/
rabel.js
executable file
·689 lines (626 loc) · 23.5 KB
/
rabel.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#!/usr/local/bin/node
// Utility Data conversion program.
//
// Test platform for parsers and serializers
//
//
var base = 'file://' + process.cwd() + '/'
var helpMessage =
'Utilty data converter for linked data\n' +
'\n' +
'Commands in unix option form are executed left to right, and include:\n' +
'\n' +
'-base=rrrr Set the current base URI (relative URI, default is ' + base + ')\n' +
'-clear Clear the current store\n' +
'-dump Serialize the current store in current content type\n' +
'-format=cccc Set the current content-type\n' +
'-help This message \n' +
'-in=uri Load a web resource or file\n' +
'-out=filename Output in eth current content type\n' +
'-report=file set the report file destination for future validation\n' +
'-size Give the current store\n' +
'-spray=base Write out linked data to lots of different linked files CAREFUL!\n' +
'-test=manifest Run tests as described in the test manifest\n' +
'-validate=shapeFile Run a SHACL validator on the data loaded by previous in=x\n' +
'-version Give the version of this program\n' +
'\n' +
'Formats are given as MIME types, such as text/turtle (default), application/rdf+xml, etc\n' +
'In input only, can parse application/xml, with smarts about IANA and GPX files.\n' +
'\n' + 'Default base URI: ' + base + '\n'
var $rdf = require('rdflib')
var fs = require('fs')
var ShapeChecker = require('./../shacl-check/src/shacl-check.js')
var kb = $rdf.graph()
var fetcher = $rdf.fetcher(kb)
const RDF = $rdf.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
const a = RDF('type')
const mf = $rdf.Namespace('http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#')
const sht = $rdf.Namespace('http://www.w3.org/ns/shacl/test-suite#')
var contentType = 'text/turtle'
var reportDocument, targetDocument
var testHandlers = []
var registerTest = function(klass, handler){
testHandlers[klass.uri || klass] = handler
}
var check = function (ok, message, status) {
if (!ok) {
console.log('Failed ' + status + ': ' + message)
process.exit(2)
}
}
var exitMessage = function (message) {
console.log(message)
process.exit(4)
}
var doNext = function (remaining) {
var loadDocument = function (right) {
var doc = $rdf.sym($rdf.uri.join(right, base))
targetDocument = targetDocument || doc // remember first doc
// console.log("Document is " + targetDocument)
if (contentType === 'application/xml') {
readXML(doc, {}, function (ok, body, xhr) {
check(ok, body, xhr ? xhr.status : undefined)
console.log('Loaded XML ' + targetDocument)
doNext(remaining)
}) // target, kb, base, contentType, callback
} else {
fetcher.nowOrWhenFetched(doc, {}, function (ok, body, xhr) {
check(ok, body, xhr ? xhr.status : undefined)
console.log('Loaded ' + doc)
doNext(remaining)
}) // target, kb, base, contentType, callback
}
}
// Writes the data we have in the store under targetDocument out to file doc
var writeDocument = function (targetDocument, doc) {
console.log(' writing ... ' + doc)
try {
var outText = $rdf.serialize(targetDocument, kb, targetDocument.uri, contentType)
} catch (e) {
exitMessage('Error in serializer: ' + e)
}
if (doc.uri.slice(0, 8) !== 'file:///') {
exitMessage('Can only write files just now, sorry: ' + doc.uri)
}
var fileName = doc.uri.slice(7) //
fs.writeFile(fileName, outText, function (err) {
if (err) {
exitMessage('Error writing file ' + doc + ' :' + err)
}
console.log('Written ' + doc)
doNext(remaining)
})
}
while (remaining.length) {
let arg = remaining.shift()
let command = arg.split('=')
let left = command[0]
let right = command[1]
if (left.slice(0, 1) !== '-') {
loadDocument(arg)
return
}
let doc
switch (left) {
case '-base':
base = $rdf.uri.join(right, base)
break
case '-clear':
kb = $rdf.graph()
break
case '-dump':
console.log('Serialize ' + targetDocument + ' as ' + contentType)
try {
var out = $rdf.serialize(targetDocument, kb, targetDocument.uri, contentType)
} catch (e) {
exitMessage('Error in serializer: ' + e)
}
console.log('Result: ' + out)
break
case '-format':
contentType = right
break
case '-report':
reportDocument = $rdf.sym($rdf.uri.join(right, base))
break
case '-validate':
if (!targetDocument) {
console.log('Load data to be validated before -validate=shapefile')
process.exit(1)
}
let shapeDoc = $rdf.sym($rdf.uri.join(right, base))
console.log('shapeDoc ' + shapeDoc)
fetcher.nowOrWhenFetched(shapeDoc, {}, function (ok, body, xhr) {
if (!ok) {
exitMessage("Error loading " + doc + ": " + body)
} else {
console.log("Loaded shape file " + shapeDoc)
let checker = new ShapeChecker(kb, shapeDoc, targetDocument, reportDocument)
checker.execute()
console.log('Validation done.')
targetDocument = reportDocument
writeDocument(reportDocument, reportDocument) // and move on to next command
}
})
return
case '-help':
console.log(helpMessage)
break
case '-in':
loadDocument(right)
return
case '-out':
doc = $rdf.sym($rdf.uri.join(right, base))
writeDocument(targetDocument, doc)
return
case '-spray':
var root = $rdf.sym($rdf.uri.join(right, base)) // go back to folder
if (root.uri.slice(0, 8) !== 'file:///') {
exitMessage('Can only write files just now, sorry: ' + doc.uri)
}
try {
spray(root.uri, targetDocument)
} catch (e) {
exitMessage('Error in spray: ' + e)
}
return
case '-size':
console.log(kb.statements.length + ' triples')
doNext(remaining)
break
case '-test':
doc = $rdf.sym($rdf.uri.join(right, base))
console.log("Loading " + doc)
fetcher.nowOrWhenFetched(doc, {}, function(ok, message){
if (!ok) exitMessage("Error loading tests " + doc + ": " + message)
runTests(doc).then(function(issues){
console.log("DONE ALL TESTS. Issue array length: " + issues.length)
issues.forEach(function(issue){
console.log(' Test: ' + issue.test)
})
doNext(remaining)
})
})
return
case '-version':
console.log('rdflib built: ' + $rdf.buildTime)
break
default:
console.log('Unknown command: ' + left)
console.log(helpMessage)
process.exit(1)
}
}
/*
(function wait () {
if (true) setTimeout(wait, 3000);
})();
*/
process.exit(0) // No!!! node must wait for stuff to finish
}
var statementsToTurtle = function (kb, statements, base) {
var sz = new $rdf.Serializer(kb)
sz.suggestNamespaces(kb.namespaces)
sz.setBase(base)
sz.setFlags('si') // Suppress = for sameAs and => for implies
return sz.statementsToN3(statements)
}
// Returns a promise of an issues list
var validationTest = function(test){
const indent = ' '
var forwardTree = function (x) {
var sts = []
var f = function (x) {
var s = kb.statementsMatching(x)
sts = sts.concat(s)
s.forEach(function (st) {
if (st.object.termType === 'BlankNode') {
f(st.object)
}
})
}
f(x)
return sts
}
console.log(indent + 'Validation test ' + test)
action = kb.the(test, mf('action'))
if (!action) throw new Error("Need action")
dataGraph = kb.the(action, sht('dataGraph'))
shapesGraph = kb.the(action, sht('shapesGraph')) // A doc
actualGraph = kb.sym(test.uri + '__results')
if (!dataGraph || !shapesGraph || !actualGraph) throw new Error("Need all params")
let opts = { noResultMessage: true } // must be excludded from tests
;(new ShapeChecker(kb, shapesGraph, dataGraph, actualGraph, opts)).execute()
expected = kb.the(test, mf('result')) // Node
var expectedDoc = kb.statementsMatching(expected)[0].graph // whare is that data anyway?
var base = expected.doc? expected.doc().uri : dataGraph.uri
let expectedStatements = forwardTree(expected)
console.log(indent + 'Expected statements: ' + expectedStatements.length)
let expectedString = statementsToTurtle(kb, expectedStatements, expectedDoc.uri)
let actualStatements = kb.statementsMatching(null, null, null, actualGraph)
console.log(indent + 'Actual statements: ' + actualStatements.length)
let actualString = statementsToTurtle(kb, actualStatements, actualGraph.uri)
let issues = []
if (expectedString === actualString) {
console.log(indent + ' Match -> passed')
} else {
console.log(indent + ' -> FAILED, expected:')
let ul = '\n__________________________________________________\n'
console.log(ul + expectedString + ul + actualString + ul)
issues.push({ test, expectedString, actualString, // generic
dataGraph, shapesGraph, actualGraph}) // test type specific
}
return Promise.resolve(issues)
}
registerTest(sht('Validate'), validationTest)
// Returns promise of issues array
var doAppropriateTest = function (test){
return new Promise(function(resolve, reject){
console.log(' -- Do approp test for ' + test)
var testDoc
if (test.uri.includes('#')){
testDoc = test.doc()
} else {
if (test.uri.endsWith('.ttl')) {
testDoc = test
} else {
testDoc = kb.sym(test.uri + '.ttl') /// needed for shacl tests in file space
}
}
console.log( "loading... " + testDoc)
fetcher.load(testDoc).then(function (xhr) {
var klasses = kb.each(test, a)
var ppp = []
for (let j=0; j<klasses.length; j++){
let handler = testHandlers[klasses[j].uri]
if (handler){
handler(test).then(function (issues) {
resolve(issues)
})
break
}
resolve(null)
}
})
.catch(function (e) {
const message = "Error in doAppropriateTest loading " + testDoc + ': ' + e
console.log(message)
console.log('stack: ' + e.stack.toString())
reject(new Error(message))
})
}) // promise
}
// See https://www.w3.org/TR/rdf11-testcases/
// Returns a promise of set of issues
var runTests = function (doc) {
const indent = ''
console.log("runTests " + doc)
return new Promise(function(resolve, reject){
kb.fetcher.load(doc).then(function (xhr) {
console.log(indent + 'Manifest loaded: ' + doc)
let comment = kb.anyValue(doc, kb.sym('http://www.w3.org/2000/01/rdf-schema#comment'))
if (comment) console.log(indent + comment)
var action, dataGraph, shapesGraph, expected, actualGraph
var testList = kb.any(doc, mf('entries'))
let promises = []
if (testList) {
testList = testList.elements
console.log("Entries " + testList.length)
promises = testList.map(doAppropriateTest)
}
let includes = kb.each(doc, mf('include'))
console.log(indent + ' includes: ' + includes.length + ' for ' + doc )
promises = promises.concat(includes.map(runTests))
Promise.all(promises).then(function(issues){
console.log('Done with ' + doc + ': ' + issues ? issues.length : "ISSUES ERROR @@@")
resolve(issues) // @@ mayeb have to concat subarrays
})
.catch(function (e) {
const message = "ERROR in runTests loading " + doc + ': ' + e
console.log(message)
console.log('stack: ' + e.strack.toString())
reject(new Error(message))
})
})
})
}
// Store linked data in separe files
//
// Caution: use with care! This will build a complete linked data
// database of linked files from master data
var spray = function (rootURI, original, doubleLinked) {
var docs = []
console.log('Spray: Root is ' + rootURI)
var docURI
var check = function (x) {
// console.log('check x= ' + x)
if (x.uri && x.uri.startsWith(rootURI)) {
var docURI = x.uri.split('#')[0]
if (docURI === original.uri) {
// console.log(' (ignoring original file) ' + docURI)
return
}
docs[docURI] = docs[docURI] || []
if (!docs[docURI][x.uri]) console.log('target ' + x)
docs[docURI][x.uri] = true
}
}
kb.statements.forEach(function (st) { check(st.subject); check(st.object) }) // Not predicates
for (docURI in docs) {
var sts = []
console.log('Document: ' + docURI)
for (var uri in docs[docURI]) {
var thing = $rdf.sym(uri)
console.log(' Thing: ' + thing)
var connected = kb.connectedStatements(thing)
console.log(' We have ' + connected.length + ' statements around ' + thing)
sts = sts.concat(connected)
}
console.log('We have ' + sts.length + ' total statements in document ' + docURI)
var fileName = docURI.slice(7) + '.ttl'
var out = statementsToTurtle(kb, sts, docURI)
console.log('To be written to ' + fileName + ':\n' + out + '\n')
var foo = function (fileName, out){
var f = fileName
fs.writeFile(f, out, function (err) {
if (err) {
exitMessage("***** Error writing file <" + f + "> :" + err)
}
console.log("Written ok: " + f)
})
}
foo(fileName, out)
}
}
// Read An XML file
//
// Contains namespace-trigged specials for IANA registry data
//
var readXML = function (targetDocument, options, callback) {
var uri = targetDocument.uri
var file = $rdf.Util.uri.refTo(base, uri)
var ignore = { 7: true }
fs.readFile(file, options.encoding || 'utf8', function (err, data) {
var defaultNamespace = null
if (err) {
console.log('File read FAIL, error: ' + err)
return callback(false, err)
}
console.log('File read ok, length: ' + data.length)
var local = $rdf.uri.join(file, base) + '#'
var ns = options.ns || local
var DOMParser = require('xmldom').DOMParser
var doc = new DOMParser().parseFromString(data)
var root = kb.sym(uri)
var nextId = 0
var justTextContent = function (ele) {
var ch = ele.childNodes
var text = ''
if (ch) {
for (let i = 0; i < ch.length; i++) {
if (ch[i].nodeType !== 3) {
if (ch.length > 1 && options.iana && ch[i].nodeType === 1 && ch[i].nodeName === 'xref') {
text += ' ' + ch[i].getAttribute('data') + ' '
} else {
return false
}
} else {
text += ch[i].nodeValue
}
}
}
if (ele.attributes && ele.attributes.length > 0) {
return false
}
if (!options.noTrim) {
text = text.trim()
}
return text
}
var randomNamedNode = function(){
return kb.sym(root.uri + '#n' + (nextId++))
}
// ///////////////////////// GPX SPECIAL
var GPX_predicateMap = {
time: { uri: 'http://www.w3.org/2003/01/geo/wgs84_pos#time',
type: 'http://www.w3.org/2001/XMLSchema#dateTime' },
lat: { uri: 'http://www.w3.org/2003/01/geo/wgs84_pos#lat' },
lon: { uri: 'http://www.w3.org/2003/01/geo/wgs84_pos#long' },
ele: { uri: 'http://www.w3.org/2003/01/geo/wgs84_pos#altitude' }
}
// ///////////////////////// IANA SPECIAL
var IANA_predicateMap = {
created: { uri: 'http://purl.org/dc/terms/created',
type: 'http://www.w3.org/2001/XMLSchema#date' }, // @@CHECK
date: { uri: 'http://purl.org/dc/terms/date',
type: 'http://www.w3.org/2001/XMLSchema#date' }, // @@CHECK
description: { uri: 'http://purl.org/dc/terms/description' }, // @@CHECK
title: { uri: 'http://purl.org/dc/terms/title' },
value: { uri: 'http://www.w3.org/2000/01/rdf-schema#label' },
note: { uri: 'http://www.w3.org/2000/01/rdf-schema#comment' }
}
/*
var magicIANAxref_Original = function (ele, local) {
var ch = ele.childNodes
if (ch.length === 1 && ch[0].nodeName === 'xref') {
var at = ch[0].attributes
var ty = at.getNamedItem('type').nodeValue
var data = at.getNamedItem('data').nodeValue
if (ty === 'uri') return kb.sym(data)
if (ty === 'rfc') return kb.sym('https://tools.ietf.org/html/' + data)
if (ty === 'draft') return kb.sym('https://tools.ietf.org/html/' + data)
if (ty === 'person') return kb.sym($rdf.uri.join('../person/', local) + data + '#')
// RFCs are at e.g. https://tools.ietf.org/html/rfc5005
// Internet Drafts are at e.g.
// https://tools.ietf.org/html/draft-ietf-httpbis-legally-restricted-status-04
}
return null
}
*/
var magicIANAxref = function (ele, local) {
if (ele.nodeName !== 'xref') return null
var at = ele.attributes
var ty = at.getNamedItem('type').nodeValue
if (ty === 'text') return $rdf.lit(justTextContent(ele)) // eg "ISO JTC-1"
var data = at.getNamedItem('data').nodeValue
if (ty === 'uri') return kb.sym(data)
if (ty === 'rfc') return kb.sym('https://tools.ietf.org/html/' + data)
if (ty === 'draft') return kb.sym('https://tools.ietf.org/html/' + data)
if (ty === 'person') return kb.sym($rdf.uri.join('../person/', local) + data + '#')
// RFCs are at e.g. https://tools.ietf.org/html/rfc5005
// Internet Drafts are at e.g.
// https://tools.ietf.org/html/draft-ietf-httpbis-legally-restricted-status-04
return null
}
var magicIANAsubject = function (ele, local) {
var ch = ele.childNodes
for (let i = 0; i < ch.length; i++) {
if (ch[i].nodeName === 'value') { // a value subelement gives a local URI
var localid = justTextContent(ch[i])
return kb.sym(local + localid)
}
}
/* Data looks like:
<record date="2016-08-12">
<name>vnd.ascii-art</name>
<xref type="person" data="Kim_Scarborough"/>
<file type="template">text/vnd.ascii-art</file>
</record>
*/
for (let i = 0; i < ch.length; i++) {
var child = ch[i]
if (child.nodeName === 'file' && child.attributes && child.getAttribute('type')) {
return kb.sym($rdf.uri.join(child.textContent, local) + '#Resource')
}
}
/* Data looks like:
<record>
<name>rfc822</name>
<xref type="rfc" data="rfc2045"/>
<xref type="rfc" data="rfc2046"/>
</record>
*/
let parent = ele.parentNode
// console.log('@@ 3 magicIANAsubject tag: ' + ele.tagName + ' parent: ' + parent.tagName )
if (ele.tagName === 'record' && parent.tagName === 'registry') {
for (let i = 0; i < ch.length; i++) {
var child = ch[i]
if (child.nodeName === 'name') {
return kb.sym($rdf.uri.join(parent.getAttribute('id') + '/' + child.textContent, local) + '#Resource')
}
}
}
return null
}
// ////////////////////////////////
var convert = function (ele, subject, indent) {
indent = indent || ''
var pred, obj, type
// console.log(indent + "nodeName: " + ele.nodeName + " type " + ele.nodeType)
console.log(indent + 'tagName: ' + ele.tagName)
if (ele.nodeType in ignore) { // PI
return
}
var setPred = function (id) {
pred = kb.sym(ns + id)
if (options.predicateMap && options.predicateMap[id]) {
var p = options.predicateMap[id]
// console.log(indent + "Mapping to " + p.uri)
if (p.uri) {
pred = kb.sym(p.uri)
}
if (p.type) {
type = kb.sym(p.type)
}
}
}
if (ele.attributes) {
var attrs = ele.attributes
var atr
// console.log(indent + 'attributes: ' + attrs.length)
for (var j = 0; j < attrs.length; j++) {
atr = attrs.item(j)
// console.log(indent + j + ") " +atr.nodeName + " = " + atr.nodeValue)
if (atr.nodeName === 'xmlns') {
defaultNamespace = atr.nodeValue
if (defaultNamespace === 'http://www.iana.org/assignments') {
options.iana = true
ns = 'https://www.w3.org/ns/assignments/reg#'
options.predicateMap = IANA_predicateMap
console.log('IANA MODE')
} else if (defaultNamespace === 'http://www.topografix.com/GPX/1/1') {
ns = 'http://hackdiary.com/ns/gps#' // @@@ u
options.predicateMap = GPX_predicateMap
console.log('GPX Mode')
}
continue
}
setPred(atr.nodeName)
kb.add(subject, pred, $rdf.lit(atr.nodeValue, undefined, type), targetDocument)
}
}
if (ele.childNodes) {
// console.log(indent + "children " +ele.childNodes.length)
for (var i = 0; i < ele.childNodes.length; i++) {
// console.log(indent + ' i ' + i)
var child = ele.childNodes[i]
type = null
setPred(child.nodeName)
if (child.nodeType === 3) { // text
obj = child.nodeValue.trim() // @@ optional
if (obj.length !== 0) {
// console.log($rdf.lit(obj, undefined, type))
kb.add(subject, kb.sym(ns + ele.nodeName), $rdf.lit(obj, undefined, type), targetDocument)
// console.log(indent + 'actual text ' + obj)
} else {
// console.log(indent + 'whitespace')
}
} else if (!(child.nodeType in ignore)) {
console.log(indent + '-> ' + child.tagName)
var txt = justTextContent(child)
if (txt !== false) {
if (txt.length > 0) {
kb.add(subject, pred, $rdf.lit(txt, undefined, type), targetDocument)
}
} else if (options.iana && magicIANAxref(child, local)) {
kb.add(subject, kb.sym(ns + child.nodeName), magicIANAxref(child, local), targetDocument)
console.log(indent + 'Magic IANA xref ' + child.nodeName + ': ' + magicIANAxref(child, local))
} else {
if (child.attributes && child.getAttribute('id')) {
if (options.iana && child.nodeName === 'person') {
let who = child.getAttribute('id')
if (!who) throw new Error("Person has no ID")
obj = kb.sym($rdf.uri.join('../person/', local) + who + '#')
console.log(indent + 'Person is ' + obj)
} else {
let who = child.getAttribute('id')
if (!who) throw new Error("Thing has no ID")
obj = kb.sym(local + child.getAttribute('id'))
console.log(indent + 'Local thing is ' + obj)
}
} else if (options.iana && magicIANAsubject(child, local)) {
obj = magicIANAsubject(child, local)
console.log(indent + 'Magic IANA URI ' + obj)
// kb.add(obj, RDF('type'), RDF('Property') , targetDocument)
} else {
if (options.iana && child.nodeName === 'uri'){
obj = kb.sym(justTextContent(child))
} else if (options.iana && child.nodeName === 'people') {
obj = randomNamedNode()
} else {
obj = kb.bnode()
}
}
kb.add(subject, pred, obj, targetDocument)
convert(child, obj, indent + ' ')
}
}
}
}
}
convert(doc, root)
callback(true)
})
}
doNext(process.argv.slice(2))
// ends