Skip to content

Commit f55a17a

Browse files
committed
A nodeElement can also use the rdf:resource attribute, if none of the other standard attributes are defined.
1 parent 865b5f9 commit f55a17a

4 files changed

Lines changed: 103 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![Gem Version](https://badge.fury.io/rb/rdf-rdfxml.png)](https://badge.fury.io/rb/rdf-rdfxml)
66
[![Build Status](https://github.com/ruby-rdf/rdf-rdfxml/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf-rdfxml/actions?query=workflow%3ACI)
7-
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-rdfxml/badge.svg)](https://coveralls.io/github/ruby-rdf/rdf-rdfxml)
7+
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-rdfxml/badge.svg?branch=develop)](https://coveralls.io/github/ruby-rdf/rdf-rdfxml?branch=develop)
88
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
99

1010
## DESCRIPTION

etc/doap.ttl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
88

99
<> a doap:Project;
10+
doap:name "RDF::RDFXML";
11+
doap:shortdesc "RDF/XML reader/writer for Ruby RDF.rb."@en;
12+
doap:description """
13+
RDF::RDFXML is an RDF/XML reader/writer for Ruby using the RDF.rb library suite.
14+
"""@en;
1015
dc:creator <https://greggkellogg.net/foaf#me>;
1116
doap:blog <https://greggkellogg.net/>;
1217
doap:bug-database <https://github.com/ruby-rdf/rdf-rdfxml/issues>;
1318
doap:category <http://dbpedia.org/resource/Resource_Description_Framework>,
1419
<http://dbpedia.org/resource/Ruby_(programming_language)>;
1520
doap:created "2010-06-03"^^xsd:date;
16-
doap:description """
17-
RDF::RDFXML is an RDF/XML reader/writer for Ruby using the RDF.rb library suite.
18-
"""@en;
1921
doap:developer <https://greggkellogg.net/foaf#me>;
2022
doap:documenter <https://greggkellogg.net/foaf#me>;
2123
doap:download-page <>;
@@ -25,7 +27,5 @@
2527
doap:programming-language "Ruby";
2628
doap:mailing-list <https://lists.w3.org/Archives/Public/public-rdf-ruby/>;
2729
doap:maintainer <https://greggkellogg.net/foaf#me>;
28-
doap:name "RDF::RDFXML";
29-
doap:shortdesc "RDF/XML reader/writer for Ruby."@en;
3030
xhv:license <https://unlicense.org/1.0/>;
3131
foaf:maker <https://greggkellogg.net/foaf#me> .

lib/rdf/rdfxml/reader.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module RDF::RDFXML
1111
#
1212
# Based on RDF/XML Syntax Specification: http://www.w3.org/TR/REC-rdf-syntax/
1313
#
14+
# Extension: A nodeElement can also use the rdf:resource attribute, if none of the other standard attributes are defined.
15+
#
1416
# @author [Gregg Kellogg](http://greggkellogg.net/)
1517
class Reader < RDF::Reader
1618
format Format
@@ -586,6 +588,7 @@ def parse_subject(el, ec)
586588
about = el.attribute_with_ns("about", RDF.to_uri.to_s)
587589
id = el.attribute_with_ns("ID", RDF.to_uri.to_s)
588590
nodeID = el.attribute_with_ns("nodeID", RDF.to_uri.to_s)
591+
resource = el.attribute_with_ns("resource", RDF.to_uri.to_s)
589592

590593
if nodeID && about
591594
add_error(el, "Cannot have rdf:nodeID and rdf:about.")
@@ -606,6 +609,10 @@ def parse_subject(el, ec)
606609
about = RDF::NTriples.unescape(about.value)
607610
add_debug(el) {"parse_subject, about: #{about.inspect}"}
608611
uri(ec.base, about)
612+
when resource
613+
resource = RDF::NTriples.unescape(resource.value)
614+
add_debug(el) {"parse_subject, resource: #{resource.inspect}"}
615+
uri(ec.base, resource)
609616
else
610617
add_debug(el, "parse_subject, BNode")
611618
RDF::Node.new

spec/reader_spec.rb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,96 @@
393393
expect(graph).to be_equivalent_graph(expected, about: "http://example.com/", logger: logger)
394394
end
395395
end
396+
397+
context :parseType do
398+
{
399+
"Literal (xml-canon/test001)": {
400+
input: %(
401+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
402+
xmlns:eg="http://example.org/">
403+
<rdf:Description rdf:about="http://www.example.org/a">
404+
<eg:prop rdf:parseType="Literal">Foo</eg:prop>
405+
</rdf:Description>
406+
</rdf:RDF>
407+
),
408+
expected: %(
409+
<http://www.example.org/a> <http://example.org/prop> "Foo"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
410+
)
411+
},
412+
"Resource": {
413+
input: %(
414+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
415+
xmlns:random="http://random.ioctl.org/#">
416+
417+
<rdf:Description rdf:about="http://random.ioctl.org/#bar">
418+
<random:someProperty rdf:parseType="Resource" />
419+
</rdf:Description>
420+
421+
</rdf:RDF>
422+
),
423+
expected: %(
424+
<http://random.ioctl.org/#bar> <http://random.ioctl.org/#someProperty> _:a1 .
425+
)
426+
},
427+
"Collection": {
428+
input: %(
429+
<rdf:RDF
430+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
431+
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
432+
xmlns:eg="http://example.org/eg#">
433+
434+
<rdf:Description rdf:about="http://example.org/eg#eric">
435+
<rdf:type rdf:parseType="Resource">
436+
<eg:intersectionOf rdf:parseType="Collection">
437+
<rdf:Description rdf:about="http://example.org/eg#Person"/>
438+
<rdf:Description rdf:about="http://example.org/eg#Male"/>
439+
</eg:intersectionOf>
440+
</rdf:type>
441+
</rdf:Description>
442+
</rdf:RDF>
443+
),
444+
expected: %(
445+
<http://example.org/eg#eric> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> _:a0 .
446+
_:a0 <http://example.org/eg#intersectionOf> _:a1 .
447+
_:a1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.org/eg#Person> .
448+
_:a1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:a2 .
449+
_:a2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.org/eg#Male> .
450+
_:a2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
451+
)
452+
},
453+
"Collection (with rdf:resource)": {
454+
input: %(
455+
<rdf:RDF
456+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
457+
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
458+
xmlns:eg="http://example.org/eg#">
459+
460+
<rdf:Description rdf:about="http://example.org/eg#eric">
461+
<rdf:type rdf:parseType="Resource">
462+
<eg:intersectionOf rdf:parseType="Collection">
463+
<rdf:Description rdf:resource="http://example.org/eg#Person"/>
464+
<rdf:Description rdf:resource="http://example.org/eg#Male"/>
465+
</eg:intersectionOf>
466+
</rdf:type>
467+
</rdf:Description>
468+
</rdf:RDF>
469+
),
470+
expected: %(
471+
<http://example.org/eg#eric> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> _:a0 .
472+
_:a0 <http://example.org/eg#intersectionOf> _:a1 .
473+
_:a1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.org/eg#Person> .
474+
_:a1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:a2 .
475+
_:a2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.org/eg#Male> .
476+
_:a2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
477+
)
478+
},
479+
}.each do |name, params|
480+
it name do
481+
graph = parse(params[:input], base_uri: "http://example.com", validate: true)
482+
expect(graph).to be_equivalent_graph(params[:expected], about: "http://example.com/", logger: logger)
483+
end
484+
end
485+
end
396486
end
397487
end
398488

0 commit comments

Comments
 (0)