@@ -350,7 +350,7 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
350350 if ( typedNode ) {
351351 const type : RDF . NamedNode = this . uriToNamedNode ( tag . uri + tag . local ) ;
352352 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 ) ;
354354 }
355355
356356 if ( parentTag ) {
@@ -359,29 +359,30 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
359359 if ( parentTag . childrenCollectionSubject ) {
360360 // RDF:List-based properties
361361 const linkTerm : RDF . BlankNode = this . dataFactory . blankNode ( ) ;
362+ const restTerm = this . dataFactory . namedNode ( RdfXmlParser . RDF + 'rest' ) ;
362363
363364 // Emit <x> <p> <current-chain> OR <previous-chain> <rdf:rest> <current-chain>
364365 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 ) ;
366367
367368 // Emit <current-chain> <rdf:first> value
368369 this . emitTriple ( linkTerm , this . dataFactory . namedNode ( RdfXmlParser . RDF + 'first' ) ,
369370 activeTag . subject , activeTag . reifiedStatementId , activeTag . childrenTripleTerms ) ;
370371
371372 // Store <current-chain> in the parent node
372373 parentTag . childrenCollectionSubject = linkTerm ;
373- parentTag . childrenCollectionPredicate = this . dataFactory . namedNode ( RdfXmlParser . RDF + 'rest' ) ;
374+ parentTag . childrenCollectionPredicate = restTerm ;
374375 } else { // !parentTag.predicateEmitted
375376 // Set-based properties
376377 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 ) ;
378379 parentTag . predicateEmitted = true ;
379380 }
380381
381382 // Emit pending properties on the parent tag that had no defined subject yet.
382383 for ( let i = 0 ; i < parentTag . predicateSubPredicates . length ; i ++ ) {
383384 this . emitTriple ( activeTag . subject , parentTag . predicateSubPredicates [ i ] ,
384- parentTag . predicateSubObjects [ i ] , null , parentTag . childrenTripleTerms ) ;
385+ parentTag . predicateSubObjects [ i ] , null , parentTag . childrenTripleTerms , parentTag . reifier ) ;
385386 }
386387
387388 // 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.`);
393394 // Emit all collected triples
394395 for ( let i = 0 ; i < predicates . length ; i ++ ) {
395396 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 ) ;
397398 }
398399 // Emit the rdf:type as named node instead of literal
399400 if ( explicitType ) {
400401 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 ) ;
402403 }
403404 }
404405 }
@@ -509,7 +510,7 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
509510
510511 // Turn this property element into a node element
511512 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 ) ;
513514 activeTag . subject = nestedBNode ;
514515 activeTag . predicate = null ;
515516 } else if ( propertyAttribute . value === 'Collection' ) {
@@ -536,6 +537,12 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
536537 activeTag . reifiedStatementId = this . valueToUri ( '#' + propertyAttribute . value , activeTag ) ;
537538 this . claimNodeId ( activeTag . reifiedStatementId ) ;
538539 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 ;
539546 }
540547 } else if ( propertyAttribute . uri === RdfXmlParser . XML && propertyAttribute . local === 'lang' ) {
541548 activeTag . language = propertyAttribute . value === ''
@@ -567,11 +574,11 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
567574 const subjectParent : RDF . Term = activeTag . subject ;
568575 activeTag . subject = subSubjectValueBlank
569576 ? 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 ) ;
571578
572579 // Emit our buffered triples
573580 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 ) ;
575582 }
576583 activeTag . predicateEmitted = true ;
577584 } else if ( subSubjectValueBlank ) {
@@ -592,15 +599,21 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
592599 * @param {Term } statementId An optional resource that identifies the triple.
593600 * If truthy, then the given triple will also be emitted reified.
594601 * @param childrenTripleTerms An optional array to push quads into instead of emitting them.
602+ * @param reifier The reifier to emit this triple under.
595603 */
596604 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 ) {
598608 const quad = this . dataFactory . quad ( subject , predicate , object , this . defaultGraph ) ;
599609 if ( childrenTripleTerms ) {
600610 childrenTripleTerms . push ( quad ) ;
601611 } else {
602612 this . push ( quad ) ;
603613 }
614+ if ( reifier ) {
615+ this . push ( this . dataFactory . quad ( reifier , this . dataFactory . namedNode ( RdfXmlParser . RDF + 'reifies' ) , quad ) ) ;
616+ }
604617
605618 // Reify triple
606619 if ( statementId ) {
@@ -676,7 +689,7 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
676689 throw this . newParseError ( `Expected exactly one triple term in rdf:parseType="Triple" but got ${ poppedTag . childrenTripleTerms . length } ` ) ;
677690 }
678691 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 ) ;
680693 }
681694 poppedTag . predicateEmitted = true ;
682695 }
@@ -689,11 +702,11 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
689702 if ( ! poppedTag . hadChildren && poppedTag . childrenParseType !== ParseType . PROPERTY ) {
690703 // Property element contains text
691704 this . emitTriple ( poppedTag . subject , poppedTag . predicate , this . createLiteral ( poppedTag . text || '' , poppedTag ) ,
692- poppedTag . reifiedStatementId , poppedTag . childrenTripleTerms ) ;
705+ poppedTag . reifiedStatementId , poppedTag . childrenTripleTerms , poppedTag . reifier ) ;
693706 } else if ( ! poppedTag . predicateEmitted ) {
694707 // Emit remaining properties on an anonymous property element
695708 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 ) ;
697710 for ( let i = 0 ; i < poppedTag . predicateSubPredicates . length ; i ++ ) {
698711 this . emitTriple ( subject , poppedTag . predicateSubPredicates [ i ] , poppedTag . predicateSubObjects [ i ] , null , poppedTag . childrenTripleTerms ) ;
699712 }
@@ -782,6 +795,7 @@ export interface IActiveTag {
782795 childrenCollectionPredicate ?: RDF . NamedNode ;
783796 childrenTagsToTripleTerms ?: boolean ;
784797 childrenTripleTerms ?: RDF . Quad [ ] ;
798+ reifier ?: RDF . NamedNode | RDF . BlankNode ;
785799}
786800
787801export enum ParseType {
0 commit comments