@@ -18,7 +18,7 @@ class Reader < RDF::Reader
1818 format Format
1919 include RDF ::Util ::Logger
2020
21- CORE_SYNTAX_TERMS = %w( RDF ID about parseType resource nodeID datatype ) . map { |n | "http://www.w3.org/1999/02/22-rdf-syntax-ns##{ n } " }
21+ CORE_SYNTAX_TERMS = %w( RDF ID annotation annotationNodeID about parseType resource nodeID datatype ) . map { |n | "http://www.w3.org/1999/02/22-rdf-syntax-ns##{ n } " }
2222 OLD_TERMS = %w( aboutEach aboutEachPrefix bagID ) . map { |n | "http://www.w3.org/1999/02/22-rdf-syntax-ns##{ n } " }
2323
2424 # The Recursive Baggage
@@ -393,6 +393,7 @@ def nodeElement(el, ec)
393393 # is deleted.
394394 attrs = { }
395395 id = datatype = parseType = resourceAttr = nodeID = nil
396+ annotation = annotationNodeID = nil
396397
397398 child . attribute_nodes . each do |attr |
398399 if attr . namespace . to_s . empty?
@@ -406,35 +407,43 @@ def nodeElement(el, ec)
406407 # No production. Lang and base elements already extracted
407408 elsif attr . namespace . href == RDF . to_uri . to_s
408409 case attr . name
409- when "ID" then id = attr . value
410- when "datatype" then datatype = attr . value
411- when "parseType" then parseType = attr . value
412- when "resource" then resourceAttr = attr . value
413- when "nodeID" then nodeID = attr . value
414- when "version" then nil # version already extracted
415- else attrs [ attr ] = attr . value
410+ when "annotation"
411+ annotation = ec . base . join ( RDF ::NTriples . unescape ( attr . value ) )
412+ when "annotationNodeID"
413+ nodeID_check ( child , RDF ::NTriples . unescape ( attr . value ) )
414+ annotationNodeID = bnode ( attr . value )
415+ when "datatype" then datatype = attr . value
416+ when "ID" then id = attr . value
417+ when "nodeID" then nodeID = attr . value
418+ when "parseType" then parseType = attr . value
419+ when "resource" then resourceAttr = attr . value
420+ when "version" then nil # version already extracted
421+ else attrs [ attr ] = attr . value
416422 end
417423 elsif attr . namespace . href == RDF ::ITS . to_s
418424 # No production. Direction already extracted
419425 else
420426 attrs [ attr ] = attr . value
421427 end
422428 end
423-
424- add_error ( el , "Cannot have rdf:nodeID and rdf:resource." ) if nodeID && resourceAttr
429+
430+ add_error ( child , "Cannot have rdf:nodeID and rdf:resource." ) if nodeID && resourceAttr
431+ add_error ( child , "Cannot have rdf:annotationNodeID and rdf:annotation." ) if annotationNodeID && annotation
425432
426433 # Apply character transformations
427434 id = id_check ( el , RDF ::NTriples . unescape ( id ) , nil ) if id
428435 resourceAttr = RDF ::NTriples . unescape ( resourceAttr ) if resourceAttr
429436 nodeID = nodeID_check ( el , RDF ::NTriples . unescape ( nodeID ) ) if nodeID
430437
431- add_debug ( child ) { "attrs: #{ attrs . inspect } " }
438+ # add_debug(child) {"attrs: #{attrs.inspect}"}
432439 add_debug ( child ) { "datatype: #{ datatype } " } if datatype
433440 add_debug ( child ) { "parseType: #{ parseType } " } if parseType
434441 add_debug ( child ) { "resource: #{ resourceAttr } " } if resourceAttr
435442 add_debug ( child ) { "nodeID: #{ nodeID } " } if nodeID
443+ add_debug ( child ) { "annotation: #{ nodeID } " } if annotation
444+ add_debug ( child ) { "annotationNodeID: #{ nodeID } " } if annotationNodeID
436445 add_debug ( child ) { "id: #{ id } " } if id
437-
446+
438447 if attrs . empty? && datatype . nil? && parseType . nil? && element_nodes . size == 1
439448 # Production resourcePropertyElt
440449
@@ -446,6 +455,9 @@ def nodeElement(el, ec)
446455 add_debug ( child ) { "resourcePropertyElt: #{ node_path ( new_node_element ) } " }
447456 new_subject = nodeElement ( new_node_element , new_ec )
448457 add_triple ( child , subject , predicate , new_subject )
458+ reify ( id , child , subject , predicate , new_subject , ec ) if id
459+ annotate ( annotation , child , subject , predicate , new_subject , ec ) if annotation
460+ annotate ( annotationNodeID , child , subject , predicate , new_subject , ec ) if annotationNodeID
449461 elsif attrs . empty? && parseType . nil? && element_nodes . size == 0 && text_nodes . size > 0
450462 # Production literalPropertyElt
451463 add_debug ( child , "literalPropertyElt" )
@@ -460,6 +472,8 @@ def nodeElement(el, ec)
460472 literal = RDF ::Literal . new ( child . inner_text , **literal_opts )
461473 add_triple ( child , subject , predicate , literal )
462474 reify ( id , child , subject , predicate , literal , ec ) if id
475+ annotate ( annotation , child , subject , predicate , literal , ec ) if annotation
476+ annotate ( annotationNodeID , child , subject , predicate , literal , ec ) if annotationNodeID
463477 elsif parseType == 'Resource'
464478 # Production parseTypeResourcePropertyElt
465479 add_debug ( child , "parseTypeResourcePropertyElt" )
@@ -474,7 +488,9 @@ def nodeElement(el, ec)
474488
475489 # Reification
476490 reify ( id , child , subject , predicate , n , child_ec ) if id
477-
491+ annotate ( annotation , child , subject , predicate , n , child_ec ) if annotation
492+ annotate ( annotationNodeID , child , subject , predicate , n , child_ec ) if annotationNodeID
493+
478494 # If the element content c is not empty, then use event n to create a new sequence of events as follows:
479495 #
480496 # start-element(URI := rdf:Description,
@@ -506,7 +522,9 @@ def nodeElement(el, ec)
506522 n = s . first || RDF [ "nil" ]
507523 add_triple ( child , subject , predicate , n )
508524 reify ( id , child , subject , predicate , n , child_ec ) if id
509-
525+ annotate ( annotation , child , subject , predicate , n , child_ec ) if annotation
526+ annotate ( annotationNodeID , child , subject , predicate , n , child_ec ) if annotationNodeID
527+
510528 # Add first/rest entries for all list elements
511529 s . each_index do |i |
512530 n = s [ i ]
@@ -591,6 +609,8 @@ def nodeElement(el, ec)
591609
592610 # Reification
593611 reify ( id , child , subject , predicate , literal , child_ec ) if id
612+ annotate ( annotation , child , subject , predicate , literal , child_ec ) if annotation
613+ annotate ( annotationNodeID , child , subject , predicate , literal , child_ec ) if annotationNodeID
594614 else
595615 resource = if resourceAttr
596616 uri ( ec . base , resourceAttr )
@@ -619,6 +639,8 @@ def nodeElement(el, ec)
619639
620640 # Reification
621641 reify ( id , child , subject , predicate , resource , child_ec ) if id
642+ annotate ( annotation , child , subject , predicate , resource , child_ec ) if annotation
643+ annotate ( annotationNodeID , child , subject , predicate , resource , child_ec ) if annotationNodeID
622644 end
623645 end
624646 end
@@ -638,6 +660,12 @@ def reify(id, el, subject, predicate, object, ec)
638660 add_triple ( el , rsubject , RDF . type , RDF [ "Statement" ] )
639661 end
640662
663+ # Annotate the triple term formed by subjec, predicate, and object referenced by id given the EvaluationContext (ec) and current XMl element (el).
664+ def annotate ( id , el , subject , predicate , object , ec )
665+ add_debug ( el , "annotate, id: #{ id } " )
666+ add_triple ( el , id , RDF . reifies , RDF ::Statement . new ( subject , predicate , object , tripleTerm : true ) )
667+ end
668+
641669 # Figure out the subject from the element.
642670 def parse_subject ( el , ec )
643671 old_property_check ( el )
0 commit comments