@@ -350,7 +350,7 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
350
350
if ( typedNode ) {
351
351
const type : RDF . NamedNode = this . uriToNamedNode ( tag . uri + tag . local ) ;
352
352
this . emitTriple ( activeTag . subject , this . dataFactory . namedNode ( RdfXmlParser . RDF + 'type' ) ,
353
- type , parentTag ? parentTag . reifiedStatementId : null , activeTag . childrenTripleTerms ) ;
353
+ type , parentTag ? parentTag . reifiedStatementId : null , activeTag . childrenTripleTerms , activeTag . reifier ) ;
354
354
}
355
355
356
356
if ( parentTag ) {
@@ -359,29 +359,30 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
359
359
if ( parentTag . childrenCollectionSubject ) {
360
360
// RDF:List-based properties
361
361
const linkTerm : RDF . BlankNode = this . dataFactory . blankNode ( ) ;
362
+ const restTerm = this . dataFactory . namedNode ( RdfXmlParser . RDF + 'rest' ) ;
362
363
363
364
// Emit <x> <p> <current-chain> OR <previous-chain> <rdf:rest> <current-chain>
364
365
this . emitTriple ( parentTag . childrenCollectionSubject ,
365
- parentTag . childrenCollectionPredicate , linkTerm , parentTag . reifiedStatementId , parentTag . childrenTripleTerms ) ;
366
+ parentTag . childrenCollectionPredicate , linkTerm , parentTag . reifiedStatementId , parentTag . childrenTripleTerms , parentTag . childrenCollectionPredicate . equals ( restTerm ) ? null : parentTag . reifier ) ;
366
367
367
368
// Emit <current-chain> <rdf:first> value
368
369
this . emitTriple ( linkTerm , this . dataFactory . namedNode ( RdfXmlParser . RDF + 'first' ) ,
369
370
activeTag . subject , activeTag . reifiedStatementId , activeTag . childrenTripleTerms ) ;
370
371
371
372
// Store <current-chain> in the parent node
372
373
parentTag . childrenCollectionSubject = linkTerm ;
373
- parentTag . childrenCollectionPredicate = this . dataFactory . namedNode ( RdfXmlParser . RDF + 'rest' ) ;
374
+ parentTag . childrenCollectionPredicate = restTerm ;
374
375
} else { // !parentTag.predicateEmitted
375
376
// Set-based properties
376
377
if ( ! parentTag . childrenTagsToTripleTerms ) {
377
- this . emitTriple ( parentTag . subject , parentTag . predicate , activeTag . subject , parentTag . reifiedStatementId , parentTag . childrenTripleTerms ) ;
378
+ this . emitTriple ( parentTag . subject , parentTag . predicate , activeTag . subject , parentTag . reifiedStatementId , parentTag . childrenTripleTerms , parentTag . reifier ) ;
378
379
parentTag . predicateEmitted = true ;
379
380
}
380
381
381
382
// Emit pending properties on the parent tag that had no defined subject yet.
382
383
for ( let i = 0 ; i < parentTag . predicateSubPredicates . length ; i ++ ) {
383
384
this . emitTriple ( activeTag . subject , parentTag . predicateSubPredicates [ i ] ,
384
- parentTag . predicateSubObjects [ i ] , null , parentTag . childrenTripleTerms ) ;
385
+ parentTag . predicateSubObjects [ i ] , null , parentTag . childrenTripleTerms , parentTag . reifier ) ;
385
386
}
386
387
387
388
// Cleanup so we don't emit them again when the parent tag is closed
@@ -393,12 +394,12 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
393
394
// Emit all collected triples
394
395
for ( let i = 0 ; i < predicates . length ; i ++ ) {
395
396
const object : RDF . Term = this . createLiteral ( objects [ i ] , activeTag ) ;
396
- this . emitTriple ( activeTag . subject , predicates [ i ] , object , parentTag . reifiedStatementId , parentTag . childrenTripleTerms ) ;
397
+ this . emitTriple ( activeTag . subject , predicates [ i ] , object , parentTag . reifiedStatementId , parentTag . childrenTripleTerms , parentTag . reifier ) ;
397
398
}
398
399
// Emit the rdf:type as named node instead of literal
399
400
if ( explicitType ) {
400
401
this . emitTriple ( activeTag . subject , this . dataFactory . namedNode ( RdfXmlParser . RDF + 'type' ) ,
401
- this . uriToNamedNode ( explicitType ) , null , activeTag . childrenTripleTerms ) ;
402
+ this . uriToNamedNode ( explicitType ) , null , activeTag . childrenTripleTerms , activeTag . reifier ) ;
402
403
}
403
404
}
404
405
}
@@ -509,7 +510,7 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
509
510
510
511
// Turn this property element into a node element
511
512
const nestedBNode : RDF . BlankNode = this . dataFactory . blankNode ( ) ;
512
- this . emitTriple ( activeTag . subject , activeTag . predicate , nestedBNode , activeTag . reifiedStatementId , activeTag . childrenTripleTerms ) ;
513
+ this . emitTriple ( activeTag . subject , activeTag . predicate , nestedBNode , activeTag . reifiedStatementId , activeTag . childrenTripleTerms , activeTag . reifier ) ;
513
514
activeTag . subject = nestedBNode ;
514
515
activeTag . predicate = null ;
515
516
} else if ( propertyAttribute . value === 'Collection' ) {
@@ -536,6 +537,12 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
536
537
activeTag . reifiedStatementId = this . valueToUri ( '#' + propertyAttribute . value , activeTag ) ;
537
538
this . claimNodeId ( activeTag . reifiedStatementId ) ;
538
539
continue ;
540
+ case 'annotation' :
541
+ activeTag . reifier = this . dataFactory . namedNode ( propertyAttribute . value ) ;
542
+ continue ;
543
+ case 'annotationNodeID' :
544
+ activeTag . reifier = this . dataFactory . blankNode ( propertyAttribute . value ) ;
545
+ continue ;
539
546
}
540
547
} else if ( propertyAttribute . uri === RdfXmlParser . XML && propertyAttribute . local === 'lang' ) {
541
548
activeTag . language = propertyAttribute . value === ''
@@ -567,11 +574,11 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
567
574
const subjectParent : RDF . Term = activeTag . subject ;
568
575
activeTag . subject = subSubjectValueBlank
569
576
? this . dataFactory . blankNode ( activeSubSubjectValue ) : this . valueToUri ( activeSubSubjectValue , activeTag ) ;
570
- this . emitTriple ( subjectParent , activeTag . predicate , activeTag . subject , activeTag . reifiedStatementId , activeTag . childrenTripleTerms ) ;
577
+ this . emitTriple ( subjectParent , activeTag . predicate , activeTag . subject , activeTag . reifiedStatementId , activeTag . childrenTripleTerms , activeTag . reifier ) ;
571
578
572
579
// Emit our buffered triples
573
580
for ( let i = 0 ; i < predicates . length ; i ++ ) {
574
- this . emitTriple ( activeTag . subject , predicates [ i ] , objects [ i ] , null , activeTag . childrenTripleTerms ) ;
581
+ this . emitTriple ( activeTag . subject , predicates [ i ] , objects [ i ] , null , activeTag . childrenTripleTerms , activeTag . reifier ) ;
575
582
}
576
583
activeTag . predicateEmitted = true ;
577
584
} else if ( subSubjectValueBlank ) {
@@ -592,15 +599,21 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
592
599
* @param {Term } statementId An optional resource that identifies the triple.
593
600
* If truthy, then the given triple will also be emitted reified.
594
601
* @param childrenTripleTerms An optional array to push quads into instead of emitting them.
602
+ * @param reifier The reifier to emit this triple under.
595
603
*/
596
604
protected emitTriple ( subject : RDF . Quad_Subject , predicate : RDF . Quad_Predicate , object : RDF . Quad_Object ,
597
- statementId ?: RDF . NamedNode , childrenTripleTerms ?: RDF . Quad [ ] ) {
605
+ statementId ?: RDF . NamedNode ,
606
+ childrenTripleTerms ?: RDF . Quad [ ] ,
607
+ reifier ?: RDF . NamedNode | RDF . BlankNode ) {
598
608
const quad = this . dataFactory . quad ( subject , predicate , object , this . defaultGraph ) ;
599
609
if ( childrenTripleTerms ) {
600
610
childrenTripleTerms . push ( quad ) ;
601
611
} else {
602
612
this . push ( quad ) ;
603
613
}
614
+ if ( reifier ) {
615
+ this . push ( this . dataFactory . quad ( reifier , this . dataFactory . namedNode ( RdfXmlParser . RDF + 'reifies' ) , quad ) ) ;
616
+ }
604
617
605
618
// Reify triple
606
619
if ( statementId ) {
@@ -676,7 +689,7 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
676
689
throw this . newParseError ( `Expected exactly one triple term in rdf:parseType="Triple" but got ${ poppedTag . childrenTripleTerms . length } ` ) ;
677
690
}
678
691
for ( const tripleTerm of poppedTag . childrenTripleTerms ) {
679
- this . emitTriple ( poppedTag . subject , poppedTag . predicate , tripleTerm , null , parentTag . childrenTripleTerms ) ;
692
+ this . emitTriple ( poppedTag . subject , poppedTag . predicate , tripleTerm , null , parentTag . childrenTripleTerms , parentTag . reifier ) ;
680
693
}
681
694
poppedTag . predicateEmitted = true ;
682
695
}
@@ -689,11 +702,11 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
689
702
if ( ! poppedTag . hadChildren && poppedTag . childrenParseType !== ParseType . PROPERTY ) {
690
703
// Property element contains text
691
704
this . emitTriple ( poppedTag . subject , poppedTag . predicate , this . createLiteral ( poppedTag . text || '' , poppedTag ) ,
692
- poppedTag . reifiedStatementId , poppedTag . childrenTripleTerms ) ;
705
+ poppedTag . reifiedStatementId , poppedTag . childrenTripleTerms , poppedTag . reifier ) ;
693
706
} else if ( ! poppedTag . predicateEmitted ) {
694
707
// Emit remaining properties on an anonymous property element
695
708
const subject : RDF . Term = this . dataFactory . blankNode ( ) ;
696
- this . emitTriple ( poppedTag . subject , poppedTag . predicate , subject , poppedTag . reifiedStatementId , poppedTag . childrenTripleTerms ) ;
709
+ this . emitTriple ( poppedTag . subject , poppedTag . predicate , subject , poppedTag . reifiedStatementId , poppedTag . childrenTripleTerms , poppedTag . reifier ) ;
697
710
for ( let i = 0 ; i < poppedTag . predicateSubPredicates . length ; i ++ ) {
698
711
this . emitTriple ( subject , poppedTag . predicateSubPredicates [ i ] , poppedTag . predicateSubObjects [ i ] , null , poppedTag . childrenTripleTerms ) ;
699
712
}
@@ -782,6 +795,7 @@ export interface IActiveTag {
782
795
childrenCollectionPredicate ?: RDF . NamedNode ;
783
796
childrenTagsToTripleTerms ?: boolean ;
784
797
childrenTripleTerms ?: RDF . Quad [ ] ;
798
+ reifier ?: RDF . NamedNode | RDF . BlankNode ;
785
799
}
786
800
787
801
export enum ParseType {
0 commit comments