gkellogg-reddy 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +2 -0
- data/.gitignore +9 -0
- data/.gitmodules +3 -0
- data/History.txt +66 -0
- data/README.rdoc +107 -0
- data/Rakefile +96 -0
- data/VERSION +1 -0
- data/bin/reddy +59 -0
- data/lib/reddy.rb +62 -0
- data/lib/reddy/bnode.rb +101 -0
- data/lib/reddy/conjunctive_graph.rb +47 -0
- data/lib/reddy/exceptions.rb +11 -0
- data/lib/reddy/graph.rb +327 -0
- data/lib/reddy/literal.rb +340 -0
- data/lib/reddy/n3_grammar.rb +2171 -0
- data/lib/reddy/n3_grammar.treetop +143 -0
- data/lib/reddy/n3parser.rb +151 -0
- data/lib/reddy/namespace.rb +82 -0
- data/lib/reddy/nokogiri_hacks.rb +8 -0
- data/lib/reddy/parser.rb +127 -0
- data/lib/reddy/rdfaparser.rb +398 -0
- data/lib/reddy/rdfxmlparser.rb +529 -0
- data/lib/reddy/store/abstract_store.rb +64 -0
- data/lib/reddy/store/list_store.rb +61 -0
- data/lib/reddy/store/memory_store.rb +349 -0
- data/lib/reddy/string_hacks.rb +108 -0
- data/lib/reddy/triple.rb +144 -0
- data/lib/reddy/uriref.rb +95 -0
- data/script/console +10 -0
- data/spec/bnode_spec.rb +58 -0
- data/spec/conjunctive_graph_spec.rb +59 -0
- data/spec/graph_spec.rb +390 -0
- data/spec/literal_spec.rb +314 -0
- data/spec/matchers.rb +148 -0
- data/spec/n3parser_spec.rb +229 -0
- data/spec/namespaces_spec.rb +66 -0
- data/spec/ntriples/test.nt +78 -0
- data/spec/parser_spec.rb +29 -0
- data/spec/rdfa-triples/0001.nt +1 -0
- data/spec/rdfa-triples/0006.nt +2 -0
- data/spec/rdfa-triples/0007.nt +3 -0
- data/spec/rdfa-triples/0008.nt +1 -0
- data/spec/rdfa-triples/0009.nt +1 -0
- data/spec/rdfa-triples/0010.nt +2 -0
- data/spec/rdfa-triples/0011.nt +3 -0
- data/spec/rdfa-triples/0012.nt +1 -0
- data/spec/rdfa-triples/0013.nt +1 -0
- data/spec/rdfa-triples/0014.nt +1 -0
- data/spec/rdfa-triples/0015.nt +2 -0
- data/spec/rdfa-triples/0017.nt +3 -0
- data/spec/rdfa-triples/0018.nt +1 -0
- data/spec/rdfa-triples/0019.nt +1 -0
- data/spec/rdfa-triples/0020.nt +1 -0
- data/spec/rdfa-triples/0021.nt +1 -0
- data/spec/rdfa-triples/0023.nt +1 -0
- data/spec/rdfa-triples/0025.nt +2 -0
- data/spec/rdfa-triples/0026.nt +1 -0
- data/spec/rdfa-triples/0027.nt +1 -0
- data/spec/rdfa-triples/0029.nt +1 -0
- data/spec/rdfa-triples/0030.nt +1 -0
- data/spec/rdfa-triples/0031.nt +1 -0
- data/spec/rdfa-triples/0032.nt +1 -0
- data/spec/rdfa-triples/0033.nt +2 -0
- data/spec/rdfa-triples/0034.nt +1 -0
- data/spec/rdfa-triples/0035.nt +1 -0
- data/spec/rdfa-triples/0036.nt +1 -0
- data/spec/rdfa-triples/0037.nt +1 -0
- data/spec/rdfa-triples/0038.nt +1 -0
- data/spec/rdfa-triples/0039.nt +1 -0
- data/spec/rdfa-triples/0040.nt +1 -0
- data/spec/rdfa-triples/0041.nt +1 -0
- data/spec/rdfa-triples/0042.nt +0 -0
- data/spec/rdfa-triples/0046.nt +3 -0
- data/spec/rdfa-triples/0047.nt +3 -0
- data/spec/rdfa-triples/0048.nt +3 -0
- data/spec/rdfa-triples/0049.nt +2 -0
- data/spec/rdfa-triples/0050.nt +2 -0
- data/spec/rdfa-triples/0051.nt +2 -0
- data/spec/rdfa-triples/0052.nt +1 -0
- data/spec/rdfa-triples/0053.nt +2 -0
- data/spec/rdfa-triples/0054.nt +2 -0
- data/spec/rdfa-triples/0055.nt +2 -0
- data/spec/rdfa-triples/0056.nt +3 -0
- data/spec/rdfa-triples/0057.nt +4 -0
- data/spec/rdfa-triples/0058.nt +6 -0
- data/spec/rdfa-triples/0059.nt +6 -0
- data/spec/rdfa-triples/0060.nt +2 -0
- data/spec/rdfa-triples/0061.nt +1 -0
- data/spec/rdfa-triples/0062.nt +1 -0
- data/spec/rdfa-triples/0063.nt +1 -0
- data/spec/rdfa-triples/0064.nt +1 -0
- data/spec/rdfa-triples/0065.nt +3 -0
- data/spec/rdfa-triples/0066.nt +1 -0
- data/spec/rdfa-triples/0067.nt +1 -0
- data/spec/rdfa-triples/0068.nt +1 -0
- data/spec/rdfa-triples/0069.nt +1 -0
- data/spec/rdfa-triples/0070.nt +1 -0
- data/spec/rdfa-triples/0071.nt +1 -0
- data/spec/rdfa-triples/0072.nt +1 -0
- data/spec/rdfa-triples/0073.nt +1 -0
- data/spec/rdfa-triples/0074.nt +1 -0
- data/spec/rdfa-triples/0075.nt +1 -0
- data/spec/rdfa-triples/0076.nt +23 -0
- data/spec/rdfa-triples/0077.nt +23 -0
- data/spec/rdfa-triples/0078.nt +6 -0
- data/spec/rdfa-triples/0079.nt +3 -0
- data/spec/rdfa-triples/0080.nt +1 -0
- data/spec/rdfa-triples/0081.nt +6 -0
- data/spec/rdfa-triples/0082.nt +8 -0
- data/spec/rdfa-triples/0083.nt +6 -0
- data/spec/rdfa-triples/0084.nt +8 -0
- data/spec/rdfa-triples/0085.nt +4 -0
- data/spec/rdfa-triples/0086.nt +0 -0
- data/spec/rdfa-triples/0087.nt +23 -0
- data/spec/rdfa-triples/0088.nt +3 -0
- data/spec/rdfa-triples/0089.nt +1 -0
- data/spec/rdfa-triples/0090.nt +1 -0
- data/spec/rdfa-triples/0091.nt +3 -0
- data/spec/rdfa-triples/0092.nt +3 -0
- data/spec/rdfa-triples/0093.nt +2 -0
- data/spec/rdfa-triples/0094.nt +3 -0
- data/spec/rdfa-triples/0099.nt +1 -0
- data/spec/rdfa-triples/0100.nt +3 -0
- data/spec/rdfa-triples/0101.nt +3 -0
- data/spec/rdfa-triples/0102.nt +1 -0
- data/spec/rdfa-triples/0103.nt +1 -0
- data/spec/rdfa-triples/0104.nt +3 -0
- data/spec/rdfa-triples/0105.nt +1 -0
- data/spec/rdfa-triples/0106.nt +1 -0
- data/spec/rdfa-triples/0107.nt +0 -0
- data/spec/rdfa-triples/0108.nt +1 -0
- data/spec/rdfa-triples/0109.nt +1 -0
- data/spec/rdfa-triples/0110.nt +1 -0
- data/spec/rdfa-triples/0111.nt +2 -0
- data/spec/rdfa-triples/0112.nt +1 -0
- data/spec/rdfa-triples/0113.nt +2 -0
- data/spec/rdfa-triples/0114.nt +3 -0
- data/spec/rdfa-triples/0115.nt +4 -0
- data/spec/rdfa-triples/0116.nt +2 -0
- data/spec/rdfa-triples/0117.nt +2 -0
- data/spec/rdfa-triples/0118.nt +1 -0
- data/spec/rdfa-triples/0119.nt +1 -0
- data/spec/rdfa-triples/0120.nt +1 -0
- data/spec/rdfa-triples/0121.nt +2 -0
- data/spec/rdfa-triples/0122.nt +1 -0
- data/spec/rdfa-triples/0123.nt +3 -0
- data/spec/rdfa-triples/0124.nt +4 -0
- data/spec/rdfa-triples/0125.nt +1 -0
- data/spec/rdfa-triples/0126.nt +3 -0
- data/spec/rdfa-triples/1001.nt +6 -0
- data/spec/rdfa_helper.rb +189 -0
- data/spec/rdfa_parser_spec.rb +130 -0
- data/spec/rdfcore/Manifest.rdf +5395 -0
- data/spec/rdfcore/amp-in-url/test001.nt +16 -0
- data/spec/rdfcore/amp-in-url/test001.rdf +40 -0
- data/spec/rdfcore/datatypes-intensional/test001.nt +18 -0
- data/spec/rdfcore/datatypes-intensional/test002.nt +18 -0
- data/spec/rdfcore/datatypes/test001.nt +15 -0
- data/spec/rdfcore/datatypes/test001.rdf +29 -0
- data/spec/rdfcore/datatypes/test002.nt +14 -0
- data/spec/rdfcore/datatypes/test002.rdf +27 -0
- data/spec/rdfcore/datatypes/test002b.nt +17 -0
- data/spec/rdfcore/datatypes/test003a.nt +16 -0
- data/spec/rdfcore/datatypes/test003b.nt +16 -0
- data/spec/rdfcore/datatypes/test005a.nt +16 -0
- data/spec/rdfcore/datatypes/test005b.nt +16 -0
- data/spec/rdfcore/datatypes/test006.nt +17 -0
- data/spec/rdfcore/datatypes/test008a.nt +15 -0
- data/spec/rdfcore/datatypes/test008b.nt +15 -0
- data/spec/rdfcore/datatypes/test009a.nt +15 -0
- data/spec/rdfcore/datatypes/test009b.nt +15 -0
- data/spec/rdfcore/datatypes/test010.nt +17 -0
- data/spec/rdfcore/datatypes/test011a.nt +17 -0
- data/spec/rdfcore/datatypes/test011b.nt +17 -0
- data/spec/rdfcore/horst-01/test001.rdf +38 -0
- data/spec/rdfcore/horst-01/test002.rdf +39 -0
- data/spec/rdfcore/horst-01/test003.rdf +40 -0
- data/spec/rdfcore/horst-01/test004.rdf +42 -0
- data/spec/rdfcore/pfps-10/test001a.nt +14 -0
- data/spec/rdfcore/pfps-10/test001b.nt +15 -0
- data/spec/rdfcore/rdf-charmod-literals/test001.nt +15 -0
- data/spec/rdfcore/rdf-charmod-literals/test001.rdf +34 -0
- data/spec/rdfcore/rdf-charmod-uris/test001.nt +14 -0
- data/spec/rdfcore/rdf-charmod-uris/test001.rdf +34 -0
- data/spec/rdfcore/rdf-charmod-uris/test002.nt +15 -0
- data/spec/rdfcore/rdf-charmod-uris/test002.rdf +33 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/error001.rdf +27 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/error002.rdf +34 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test001.nt +17 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test001.rdf +27 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test002.nt +19 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test002.rdf +37 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test003.nt +18 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test003.rdf +29 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test004.nt +29 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test004.rdf +33 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test006.nt +40 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test006.rdf +28 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test007.nt +20 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test007.rdf +32 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test008.nt +15 -0
- data/spec/rdfcore/rdf-containers-syntax-vs-schema/test008.rdf +28 -0
- data/spec/rdfcore/rdf-element-not-mandatory/test001.nt +10 -0
- data/spec/rdfcore/rdf-element-not-mandatory/test001.rdf +14 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0001.nt +14 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0001.rdf +35 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0003.nt +14 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0003.rdf +35 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0004.nt +14 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0004.rdf +34 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0005.nt +15 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0005.rdf +40 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0006.nt +14 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0006.rdf +32 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0009.nt +14 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0009.rdf +32 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0010.nt +14 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0010.rdf +38 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0011.nt +15 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0011.rdf +40 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0012.nt +15 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0012.rdf +40 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0013.nt +15 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0013.rdf +40 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0014.nt +15 -0
- data/spec/rdfcore/rdf-ns-prefix-confusion/test0014.rdf +42 -0
- data/spec/rdfcore/rdfms-abouteach/error001.rdf +35 -0
- data/spec/rdfcore/rdfms-abouteach/error002.rdf +35 -0
- data/spec/rdfcore/rdfms-difference-between-ID-and-about/error1.rdf +25 -0
- data/spec/rdfcore/rdfms-difference-between-ID-and-about/test1.nt +14 -0
- data/spec/rdfcore/rdfms-difference-between-ID-and-about/test1.rdf +22 -0
- data/spec/rdfcore/rdfms-difference-between-ID-and-about/test2.nt +14 -0
- data/spec/rdfcore/rdfms-difference-between-ID-and-about/test2.rdf +22 -0
- data/spec/rdfcore/rdfms-difference-between-ID-and-about/test3.nt +14 -0
- data/spec/rdfcore/rdfms-difference-between-ID-and-about/test3.rdf +22 -0
- data/spec/rdfcore/rdfms-duplicate-member-props/test001.nt +17 -0
- data/spec/rdfcore/rdfms-duplicate-member-props/test001.rdf +30 -0
- data/spec/rdfcore/rdfms-empty-property-elements/error001.rdf +33 -0
- data/spec/rdfcore/rdfms-empty-property-elements/error002.rdf +33 -0
- data/spec/rdfcore/rdfms-empty-property-elements/error003.rdf +39 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test001.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test001.rdf +33 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test002.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test002.rdf +31 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test003.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test003.rdf +32 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test004.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test004.rdf +32 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test005.nt +18 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test005.rdf +32 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test006.nt +18 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test006.rdf +32 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test007.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test007.rdf +32 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test008.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test008.rdf +31 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test009.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test009.rdf +32 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test010.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test010.rdf +31 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test011.nt +18 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test011.rdf +30 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test012.nt +18 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test012.rdf +30 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test013.nt +15 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test013.rdf +35 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test014.nt +15 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test014.rdf +34 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test015.nt +15 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test015.rdf +38 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test016.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test016.rdf +31 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test017.nt +14 -0
- data/spec/rdfcore/rdfms-empty-property-elements/test017.rdf +38 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test001.nt +14 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test001.rdf +33 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test002.nt +15 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test002.rdf +33 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test003.nt +14 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test003.rdf +31 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test004.nt +15 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test004.rdf +33 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test005.nt +14 -0
- data/spec/rdfcore/rdfms-identity-anon-resources/test005.rdf +31 -0
- data/spec/rdfcore/rdfms-not-id-and-resource-attr/test001.nt +19 -0
- data/spec/rdfcore/rdfms-not-id-and-resource-attr/test001.rdf +29 -0
- data/spec/rdfcore/rdfms-not-id-and-resource-attr/test002.nt +15 -0
- data/spec/rdfcore/rdfms-not-id-and-resource-attr/test002.rdf +29 -0
- data/spec/rdfcore/rdfms-not-id-and-resource-attr/test004.nt +18 -0
- data/spec/rdfcore/rdfms-not-id-and-resource-attr/test004.rdf +29 -0
- data/spec/rdfcore/rdfms-not-id-and-resource-attr/test005.nt +19 -0
- data/spec/rdfcore/rdfms-not-id-and-resource-attr/test005.rdf +29 -0
- data/spec/rdfcore/rdfms-para196/test001.nt +17 -0
- data/spec/rdfcore/rdfms-para196/test001.rdf +35 -0
- data/spec/rdfcore/rdfms-rdf-id/error001.rdf +26 -0
- data/spec/rdfcore/rdfms-rdf-id/error002.rdf +26 -0
- data/spec/rdfcore/rdfms-rdf-id/error003.rdf +29 -0
- data/spec/rdfcore/rdfms-rdf-id/error004.rdf +27 -0
- data/spec/rdfcore/rdfms-rdf-id/error005.rdf +31 -0
- data/spec/rdfcore/rdfms-rdf-id/error006.rdf +26 -0
- data/spec/rdfcore/rdfms-rdf-id/error007.rdf +29 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-001.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-002.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-003.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-004.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-005.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-006.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-007.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-008.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-009.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-010.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-011.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-012.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-013.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-014.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-015.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-016.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-017.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-018.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-019.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/error-020.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-001.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-001.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-002.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-002.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-003.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-003.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-004.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-004.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-005.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-005.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-006.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-006.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-007.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-007.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-008.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-008.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-009.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-009.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-010.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-010.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-011.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-011.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-012.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-012.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-013.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-013.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-014.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-014.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-015.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-015.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-016.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-016.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-017.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-017.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-018.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-018.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-019.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-019.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-020.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-020.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-021.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-021.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-022.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-022.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-023.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-023.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-024.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-024.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-025.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-025.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-026.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-026.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-027.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-027.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-028.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-028.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-029.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-029.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-030.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-030.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-031.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-031.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-032.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-032.rdf +24 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-033.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-033.rdf +24 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-034.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-034.rdf +24 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-035.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-035.rdf +24 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-036.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-036.rdf +24 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-037.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/test-037.rdf +24 -0
- data/spec/rdfcore/rdfms-rdf-names-use/warn-001.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/warn-001.rdf +23 -0
- data/spec/rdfcore/rdfms-rdf-names-use/warn-002.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/warn-002.rdf +25 -0
- data/spec/rdfcore/rdfms-rdf-names-use/warn-003.nt +1 -0
- data/spec/rdfcore/rdfms-rdf-names-use/warn-003.rdf +24 -0
- data/spec/rdfcore/rdfms-reification-required/test001.nt +15 -0
- data/spec/rdfcore/rdfms-reification-required/test001.rdf +29 -0
- data/spec/rdfcore/rdfms-seq-representation/empty.nt +13 -0
- data/spec/rdfcore/rdfms-seq-representation/test001.nt +19 -0
- data/spec/rdfcore/rdfms-seq-representation/test001.rdf +33 -0
- data/spec/rdfcore/rdfms-seq-representation/test002.nt +14 -0
- data/spec/rdfcore/rdfms-seq-representation/test003a.nt +14 -0
- data/spec/rdfcore/rdfms-seq-representation/test003b.nt +14 -0
- data/spec/rdfcore/rdfms-seq-representation/test004.nt +14 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/error001.rdf +26 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/error002.rdf +26 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/error003.rdf +29 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/error004.rdf +25 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/error005.rdf +25 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/error006.rdf +28 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/test001.nt +14 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/test001.rdf +28 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/test002.nt +19 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/test002.rdf +38 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/test003.nt +17 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/test003.rdf +28 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/test004.nt +21 -0
- data/spec/rdfcore/rdfms-syntax-incomplete/test004.rdf +36 -0
- data/spec/rdfcore/rdfms-uri-substructure/error001.nt +18 -0
- data/spec/rdfcore/rdfms-uri-substructure/test001.nt +17 -0
- data/spec/rdfcore/rdfms-uri-substructure/test001.rdf +29 -0
- data/spec/rdfcore/rdfms-xml-literal-namespaces/test001.nt +13 -0
- data/spec/rdfcore/rdfms-xml-literal-namespaces/test001.rdf +33 -0
- data/spec/rdfcore/rdfms-xml-literal-namespaces/test002.nt +14 -0
- data/spec/rdfcore/rdfms-xml-literal-namespaces/test002.rdf +47 -0
- data/spec/rdfcore/rdfms-xmllang/test001.nt +14 -0
- data/spec/rdfcore/rdfms-xmllang/test001.rdf +30 -0
- data/spec/rdfcore/rdfms-xmllang/test002.nt +14 -0
- data/spec/rdfcore/rdfms-xmllang/test002.rdf +29 -0
- data/spec/rdfcore/rdfms-xmllang/test003.nt +14 -0
- data/spec/rdfcore/rdfms-xmllang/test003.rdf +28 -0
- data/spec/rdfcore/rdfms-xmllang/test004.nt +14 -0
- data/spec/rdfcore/rdfms-xmllang/test004.rdf +28 -0
- data/spec/rdfcore/rdfms-xmllang/test005.nt +14 -0
- data/spec/rdfcore/rdfms-xmllang/test005.rdf +28 -0
- data/spec/rdfcore/rdfms-xmllang/test006.nt +14 -0
- data/spec/rdfcore/rdfms-xmllang/test006.rdf +29 -0
- data/spec/rdfcore/rdfms-xmllang/test007a.nt +14 -0
- data/spec/rdfcore/rdfms-xmllang/test007b.nt +14 -0
- data/spec/rdfcore/rdfms-xmllang/test007c.nt +14 -0
- data/spec/rdfcore/rdfs-container-membership-superProperty/not1C.rdf +13 -0
- data/spec/rdfcore/rdfs-container-membership-superProperty/not1P.rdf +14 -0
- data/spec/rdfcore/rdfs-domain-and-range/nonconclusions005.rdf +28 -0
- data/spec/rdfcore/rdfs-domain-and-range/nonconclusions006.rdf +28 -0
- data/spec/rdfcore/rdfs-domain-and-range/premises005.rdf +32 -0
- data/spec/rdfcore/rdfs-domain-and-range/premises006.rdf +32 -0
- data/spec/rdfcore/rdfs-domain-and-range/test001.nt +16 -0
- data/spec/rdfcore/rdfs-domain-and-range/test001.rdf +29 -0
- data/spec/rdfcore/rdfs-domain-and-range/test002.nt +16 -0
- data/spec/rdfcore/rdfs-domain-and-range/test002.rdf +29 -0
- data/spec/rdfcore/rdfs-entailment/test001.nt +16 -0
- data/spec/rdfcore/rdfs-entailment/test002.nt +15 -0
- data/spec/rdfcore/rdfs-no-cycles-in-subClassOf/test001.nt +18 -0
- data/spec/rdfcore/rdfs-no-cycles-in-subClassOf/test001.rdf +37 -0
- data/spec/rdfcore/rdfs-no-cycles-in-subPropertyOf/test001.nt +18 -0
- data/spec/rdfcore/rdfs-no-cycles-in-subPropertyOf/test001.rdf +40 -0
- data/spec/rdfcore/rdfs-subClassOf-a-Property/test001.nt +15 -0
- data/spec/rdfcore/rdfs-subPropertyOf-semantics/test001.nt +24 -0
- data/spec/rdfcore/rdfs-subPropertyOf-semantics/test002.nt +21 -0
- data/spec/rdfcore/statement-entailment/test001a.nt +12 -0
- data/spec/rdfcore/statement-entailment/test001b.nt +2 -0
- data/spec/rdfcore/statement-entailment/test002a.nt +2 -0
- data/spec/rdfcore/statement-entailment/test002b.nt +5 -0
- data/spec/rdfcore/tex-01/test001.rdf +34 -0
- data/spec/rdfcore/tex-01/test002.rdf +33 -0
- data/spec/rdfcore/unrecognised-xml-attributes/test001.nt +15 -0
- data/spec/rdfcore/unrecognised-xml-attributes/test001.rdf +31 -0
- data/spec/rdfcore/unrecognised-xml-attributes/test002.nt +14 -0
- data/spec/rdfcore/unrecognised-xml-attributes/test002.rdf +32 -0
- data/spec/rdfcore/xml-canon/test001.nt +16 -0
- data/spec/rdfcore/xml-canon/test001.rdf +28 -0
- data/spec/rdfcore/xmlbase/test001.nt +14 -0
- data/spec/rdfcore/xmlbase/test001.rdf +27 -0
- data/spec/rdfcore/xmlbase/test002.nt +14 -0
- data/spec/rdfcore/xmlbase/test002.rdf +28 -0
- data/spec/rdfcore/xmlbase/test003.nt +14 -0
- data/spec/rdfcore/xmlbase/test003.rdf +25 -0
- data/spec/rdfcore/xmlbase/test004.nt +18 -0
- data/spec/rdfcore/xmlbase/test004.rdf +27 -0
- data/spec/rdfcore/xmlbase/test006.nt +15 -0
- data/spec/rdfcore/xmlbase/test006.rdf +26 -0
- data/spec/rdfcore/xmlbase/test007.nt +14 -0
- data/spec/rdfcore/xmlbase/test007.rdf +25 -0
- data/spec/rdfcore/xmlbase/test008.nt +14 -0
- data/spec/rdfcore/xmlbase/test008.rdf +25 -0
- data/spec/rdfcore/xmlbase/test009.nt +14 -0
- data/spec/rdfcore/xmlbase/test009.rdf +26 -0
- data/spec/rdfcore/xmlbase/test010.nt +14 -0
- data/spec/rdfcore/xmlbase/test010.rdf +26 -0
- data/spec/rdfcore/xmlbase/test011.nt +14 -0
- data/spec/rdfcore/xmlbase/test011.rdf +27 -0
- data/spec/rdfcore/xmlbase/test013.nt +15 -0
- data/spec/rdfcore/xmlbase/test013.rdf +28 -0
- data/spec/rdfcore/xmlbase/test014.nt +15 -0
- data/spec/rdfcore/xmlbase/test014.rdf +28 -0
- data/spec/rdfcore/xmlsch-02/test001.rdf +34 -0
- data/spec/rdfcore/xmlsch-02/test002.rdf +34 -0
- data/spec/rdfcore/xmlsch-02/test003.rdf +37 -0
- data/spec/rdfcore_helper.rb +137 -0
- data/spec/rdfxml_spec.rb +349 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/store_spec.rb +205 -0
- data/spec/string_hacks_spec.rb +21 -0
- data/spec/triple_spec.rb +172 -0
- data/spec/uriref_spec.rb +117 -0
- data/test/longtests_spec.rb +25 -0
- data/test/n3_tests/lcsh/sh85062913.n3 +41 -0
- data/test/n3_tests/lcsh/sh85062913.nt +21 -0
- data/test/n3_tests/lcsh/sh85082139.n3 +157 -0
- data/test/n3_tests/lcsh/sh85082139.nt +79 -0
- data/test/n3_tests/lcsh/sh85118553.n3 +123 -0
- data/test/n3_tests/lcsh/sh85118553.nt +63 -0
- data/test/n3_tests/misc/on_now-01.n3 +30 -0
- data/test/n3_tests/misc/on_now-01.nt +15 -0
- data/test/n3_tests/n3p/simple-01.n3 +1 -0
- data/test/n3_tests/n3p/simple-01.nt +0 -0
- data/test/n3_tests/n3p/simple-02.n3 +4 -0
- data/test/n3_tests/n3p/simple-02.nt +0 -0
- data/test/n3_tests/n3p/simple-03.n3 +5 -0
- data/test/n3_tests/n3p/simple-03.nt +1 -0
- data/test/n3_tests/n3p/simple-04.n3 +6 -0
- data/test/n3_tests/n3p/simple-04.nt +3 -0
- data/test/n3_tests/n3p/simple-05.n3 +7 -0
- data/test/n3_tests/n3p/simple-05.nt +2 -0
- data/test/n3_tests/n3p/simple-06.n3 +6 -0
- data/test/n3_tests/n3p/simple-06.nt +4 -0
- data/test/n3_tests/n3p/simple-07.n3 +7 -0
- data/test/n3_tests/n3p/simple-07.nt +6 -0
- data/test/perf_test/test.rb +11 -0
- data/test/perf_test/tommorris.rdf +2267 -0
- data/test/rdf_tests/cc197bad-dc9c-440d-a5b5-d52ba2e14234.nt +24 -0
- data/test/rdf_tests/cc197bad-dc9c-440d-a5b5-d52ba2e14234.rdf +46 -0
- data/test/rdf_tests/tm_001.nt +1 -0
- data/test/rdf_tests/tm_001.rdf +7 -0
- data/test/rdf_tests/xml-literal-mixed.nt +7 -0
- data/test/rdf_tests/xml-literal-mixed.rdf +15 -0
- data/test/xml.rdf +6 -0
- metadata +698 -0
@@ -0,0 +1,143 @@
|
|
1
|
+
grammar N3Grammer
|
2
|
+
rule document
|
3
|
+
statements
|
4
|
+
end
|
5
|
+
|
6
|
+
rule statements
|
7
|
+
(space / (statement / directive) space* ('.' space*)? )*
|
8
|
+
end
|
9
|
+
|
10
|
+
rule statement
|
11
|
+
subject space+ property_list
|
12
|
+
end
|
13
|
+
|
14
|
+
rule subject
|
15
|
+
node
|
16
|
+
end
|
17
|
+
|
18
|
+
rule verb
|
19
|
+
">-" prop "->" # has xxx of
|
20
|
+
/ "<-" prop "<-" # is xxx of
|
21
|
+
# / # / operator # has operator:xxx of??? NOT IMPLMENTED
|
22
|
+
/ prop # has xxx of -- shorthand
|
23
|
+
# / "has" prop # has xxx of
|
24
|
+
# / "is" prop "of" # is xxx of
|
25
|
+
/ "a" # has rdf:type of
|
26
|
+
# / "=" # has daml:equivaent of
|
27
|
+
end
|
28
|
+
|
29
|
+
rule prop
|
30
|
+
node
|
31
|
+
end
|
32
|
+
|
33
|
+
rule node
|
34
|
+
uri_ref / anonnode / 'this'
|
35
|
+
end
|
36
|
+
|
37
|
+
rule anonnode
|
38
|
+
"[" space* property_list space* "]" # something which ...
|
39
|
+
/ "{" statementlist "}" # the statementlist itself as a resource
|
40
|
+
/ "(" nodelist ")" {
|
41
|
+
def anonnode; true; end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
rule property_list
|
46
|
+
verb space+ object_list space* ";" space+ property_list
|
47
|
+
/ verb space+ object_list
|
48
|
+
/ ":-" anonnode #to allow two anonymous forms to be given eg [ a :Truth; :- { :sky :color :blue } ] )
|
49
|
+
/ ":-" anonnode ";" property_list
|
50
|
+
/ '.'
|
51
|
+
end
|
52
|
+
|
53
|
+
rule object_list
|
54
|
+
object "," space* object_list / object
|
55
|
+
end
|
56
|
+
|
57
|
+
rule directive
|
58
|
+
'@prefix' space+ nprefix:nprefix? ':' space+ uri_ref:uri_ref {
|
59
|
+
def directive; true; end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
rule uri_ref
|
64
|
+
qname / "<" uri:URI_Reference ">"
|
65
|
+
end
|
66
|
+
|
67
|
+
rule qname
|
68
|
+
nprefix ":" localname / ':' localname
|
69
|
+
end
|
70
|
+
|
71
|
+
rule object
|
72
|
+
subject / literal
|
73
|
+
end
|
74
|
+
|
75
|
+
rule literal
|
76
|
+
(string_single / string_multi) ("^^<" uri:URI_Reference ">" / "@" language )?
|
77
|
+
end
|
78
|
+
|
79
|
+
rule language
|
80
|
+
[a-z]+ ( "-" [a-z0-9]+ )*
|
81
|
+
end
|
82
|
+
|
83
|
+
rule localname
|
84
|
+
fragid
|
85
|
+
end
|
86
|
+
|
87
|
+
rule URI_Reference
|
88
|
+
[^{}<>]*
|
89
|
+
end
|
90
|
+
|
91
|
+
rule nprefix
|
92
|
+
((alpha / "_") alphanumeric*)
|
93
|
+
end
|
94
|
+
|
95
|
+
rule fragid
|
96
|
+
alpha alphanumeric*
|
97
|
+
end
|
98
|
+
|
99
|
+
rule alpha
|
100
|
+
[a-zA-Z]
|
101
|
+
end
|
102
|
+
|
103
|
+
rule alphanumeric
|
104
|
+
alpha / [0-9] / "_"
|
105
|
+
end
|
106
|
+
|
107
|
+
rule space
|
108
|
+
[ \t\n\r]+ / comment
|
109
|
+
end
|
110
|
+
|
111
|
+
rule comment
|
112
|
+
'#' (![\n\r] .)*
|
113
|
+
end
|
114
|
+
|
115
|
+
# " constant-value-with-escaping "
|
116
|
+
rule string_single
|
117
|
+
'""' !["] / '"' string_single_char+ '"'
|
118
|
+
end
|
119
|
+
|
120
|
+
rule string_single_char
|
121
|
+
!["\n\r] (
|
122
|
+
("\\"
|
123
|
+
[\\\"nrt]
|
124
|
+
/ ( "u" hexdigit hexdigit hexdigit hexdigit )
|
125
|
+
/ ( "U" "00" hexdigit hexdigit hexdigit hexdigit hexdigit hexdigit)
|
126
|
+
)
|
127
|
+
/ .)
|
128
|
+
end
|
129
|
+
|
130
|
+
rule hexdigit
|
131
|
+
[0-9a-fA-F]
|
132
|
+
end
|
133
|
+
|
134
|
+
# """ constant value with escaping including single or double occurrences of quotes and/or newlines """
|
135
|
+
rule string_multi
|
136
|
+
'"""' string_multi_char* '"""'
|
137
|
+
end
|
138
|
+
|
139
|
+
rule string_multi_char
|
140
|
+
!'"""' . # something like this; need to think about it some more
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'treetop'
|
2
|
+
|
3
|
+
Treetop.load(File.join(File.dirname(__FILE__), "n3_grammar"))
|
4
|
+
|
5
|
+
module Reddy
|
6
|
+
class Parser; end
|
7
|
+
class N3Parser < Parser
|
8
|
+
|
9
|
+
# Parse N3 document from a string or input stream to closure or graph.
|
10
|
+
#
|
11
|
+
# Optionally, the stream may be a Nokogiri::HTML::Document or Nokogiri::XML::Document
|
12
|
+
# With a block, yeilds each statement with URIRef, BNode or Literal elements
|
13
|
+
#
|
14
|
+
# @param [String] n3_str:: the Notation3/Turtle string
|
15
|
+
# @param [String] uri:: the URI of the document
|
16
|
+
# @param [Hash] options:: Options include the following
|
17
|
+
# <em>options[:debug]</em>:: Array to place debug messages
|
18
|
+
# <em>options[:strict]</em>:: Abort or proceed on error
|
19
|
+
# @return [Graph]
|
20
|
+
# @raise Reddy::RdfException or subclass
|
21
|
+
#
|
22
|
+
# @author Patrick Sinclair (metade)
|
23
|
+
def parse(stream, uri = nil, options = {}, &block) # :yields: triple
|
24
|
+
super
|
25
|
+
|
26
|
+
@callback = block
|
27
|
+
parser = N3GrammerParser.new
|
28
|
+
|
29
|
+
@doc = stream.respond_to?(:read) ? stream.read : stream
|
30
|
+
|
31
|
+
document = parser.parse(@doc)
|
32
|
+
unless document
|
33
|
+
reason = parser.failure_reason
|
34
|
+
raise ParserException.new(reason)
|
35
|
+
end
|
36
|
+
|
37
|
+
process_directives(document)
|
38
|
+
process_statements(document)
|
39
|
+
@graph
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def process_directives(document)
|
45
|
+
directives = document.elements.find_all { |e| e.elements.first.respond_to? :directive }
|
46
|
+
directives.map! { |d| d.elements.first }
|
47
|
+
directives.each { |d| namespace(d.uri_ref.uri.text_value, d.nprefix.text_value) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def namespace(uri, prefix)
|
51
|
+
uri = @uri if uri == '#'
|
52
|
+
prefix = '__local__' if prefix == ''
|
53
|
+
@graph.bind(Namespace.new(uri, prefix))
|
54
|
+
end
|
55
|
+
|
56
|
+
def process_statements(document)
|
57
|
+
subjects = document.elements.find_all { |e| e.elements.first.respond_to? :subject }
|
58
|
+
subjects.map! { |s| s.elements.first }
|
59
|
+
subjects.each do |s|
|
60
|
+
subject = process_node(s.subject)
|
61
|
+
properties = process_properties(s.property_list)
|
62
|
+
properties.each do |p|
|
63
|
+
predicate = process_verb(p.verb)
|
64
|
+
objects = process_objects(p.object_list)
|
65
|
+
objects.each { |object| add_triple("statement", subject, predicate, object) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def process_anonnode(anonnode)
|
71
|
+
bnode = BNode.new
|
72
|
+
properties = process_properties(anonnode.property_list)
|
73
|
+
properties.each do |p|
|
74
|
+
predicate = process_node(p.verb)
|
75
|
+
objects = process_objects(p.object_list)
|
76
|
+
objects.each { |object| add_triple("anonnode", bnode, predicate, object) }
|
77
|
+
end
|
78
|
+
bnode
|
79
|
+
end
|
80
|
+
|
81
|
+
def process_verb(verb)
|
82
|
+
return URIRef.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type') if (verb.text_value=='a')
|
83
|
+
return process_node(verb)
|
84
|
+
end
|
85
|
+
|
86
|
+
def process_node(node)
|
87
|
+
if (node.respond_to? :uri)
|
88
|
+
URIRef.new(node.uri.text_value)
|
89
|
+
else
|
90
|
+
prefix = (node.respond_to? :nprefix) ? node.nprefix.text_value : nil
|
91
|
+
localname = node.localname.text_value
|
92
|
+
build_uri(prefix, localname)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def process_properties(properties)
|
97
|
+
result = []
|
98
|
+
result << properties if (properties.respond_to? :verb)
|
99
|
+
result << process_properties(properties.property_list) if (properties.respond_to? :property_list)
|
100
|
+
result.flatten
|
101
|
+
end
|
102
|
+
|
103
|
+
def process_objects(objects)
|
104
|
+
result = []
|
105
|
+
if (objects.respond_to? :object)
|
106
|
+
result << process_object(objects.object)
|
107
|
+
else
|
108
|
+
result << process_object(objects)
|
109
|
+
end
|
110
|
+
result << process_objects(objects.object_list) if (objects.respond_to? :object_list)
|
111
|
+
result.flatten
|
112
|
+
end
|
113
|
+
|
114
|
+
def process_object(object)
|
115
|
+
if (object.respond_to? :localname or object.respond_to? :uri)
|
116
|
+
process_node(object)
|
117
|
+
elsif (object.respond_to? :property_list)
|
118
|
+
process_anonnode(object)
|
119
|
+
else
|
120
|
+
process_literal(object)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def process_literal(object)
|
125
|
+
encoding, language = nil, nil
|
126
|
+
string, type = object.elements
|
127
|
+
|
128
|
+
unless type.elements.nil?
|
129
|
+
#puts type.elements.inspect
|
130
|
+
if (type.elements[0].text_value=='@')
|
131
|
+
language = type.elements[1].text_value
|
132
|
+
else
|
133
|
+
encoding = type.elements[1].text_value
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Evaluate text_value to remove redundant escapes
|
138
|
+
#puts string.elements[1].text_value.dump
|
139
|
+
Literal.n3_encoded(string.elements[1].text_value, language, encoding)
|
140
|
+
end
|
141
|
+
|
142
|
+
def build_uri(prefix, localname)
|
143
|
+
prefix = '__local__' if prefix.nil?
|
144
|
+
if (prefix=='_')
|
145
|
+
BNode.new(localname, @named_bnodes)
|
146
|
+
else
|
147
|
+
@graph.nsbinding[prefix].send(localname)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Reddy
|
2
|
+
# From Reddy
|
3
|
+
class Namespace
|
4
|
+
attr_accessor :prefix, :uri, :fragment
|
5
|
+
|
6
|
+
##
|
7
|
+
# Creates a new namespace given a URI and the prefix.
|
8
|
+
#
|
9
|
+
# nil is a valid prefix to specify the default namespace
|
10
|
+
# ==== Example
|
11
|
+
# Namespace.new("http://xmlns.com/foaf/0.1/", "foaf") # => returns a new Foaf namespace
|
12
|
+
#
|
13
|
+
# @param [String] uri:: the URI of the namespace
|
14
|
+
# @param [String] prefix:: the prefix of the namespace
|
15
|
+
# @param [Boolean] fragment:: are the identifiers on this resource fragment identifiers? (e.g. '#') Defaults to false.
|
16
|
+
# @return [Namespace]:: The newly created namespace.
|
17
|
+
# @raise [Error]:: Checks validity of the desired prefix and raises if it is incorrect.
|
18
|
+
#
|
19
|
+
# @author Tom Morris, Pius Uzamere
|
20
|
+
def initialize(uri, prefix, fragment = nil)
|
21
|
+
@uri = URIRef.new(uri) unless uri.is_a?(URIRef)
|
22
|
+
@fragment = fragment
|
23
|
+
@fragment = uri.to_s.match(/\#$/) ? true : false if fragment.nil?
|
24
|
+
prefix = nil if prefix.to_s.empty?
|
25
|
+
if prefix_valid?(prefix)
|
26
|
+
@prefix = prefix
|
27
|
+
else
|
28
|
+
raise ParserException, "Invalid prefix '#{prefix}'"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Allows the construction of arbitrary URIs on the namespace.
|
34
|
+
#
|
35
|
+
# ==== Example
|
36
|
+
# foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf"); foaf.knows # => returns a new URIRef with URI "http://xmlns.com/foaf/0.1/knows"
|
37
|
+
# foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf", true); foaf.knows # => returns a new URIRef with URI "http://xmlns.com/foaf/0.1/#knows"
|
38
|
+
#
|
39
|
+
# @return [URIRef]:: The newly created URIRegerence.
|
40
|
+
# @raise [Error]:: Checks validity of the desired prefix and raises if it is incorrect.
|
41
|
+
# @author Tom Morris, Pius Uzamere
|
42
|
+
def method_missing(methodname, *args)
|
43
|
+
self + methodname
|
44
|
+
end
|
45
|
+
|
46
|
+
# Construct a URIRef from a namespace as in method_missing, but without method collision issues
|
47
|
+
def +(suffix)
|
48
|
+
URIRef.new((fragment ? "##{suffix}" : suffix.to_s), @uri)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Bind this namespace to a Graph
|
52
|
+
def bind(graph)
|
53
|
+
graph.bind(self)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Compare namespaces
|
57
|
+
def eql?(other)
|
58
|
+
@prefix == other.prefix && @uri == other.uri && @fragment == other.fragment
|
59
|
+
end
|
60
|
+
alias_method :==, :eql?
|
61
|
+
|
62
|
+
# Output xmlns attribute name
|
63
|
+
def xmlns_attr
|
64
|
+
prefix.nil? ? "xmlns" : "xmlns:#{prefix}"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Output namespace definition as a hash
|
68
|
+
def xmlns_hash
|
69
|
+
{xmlns_attr => @uri.to_s}
|
70
|
+
end
|
71
|
+
|
72
|
+
def inspect
|
73
|
+
"Namespace[abbr='#{prefix}',uri='#{uri}']"
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
# The Namespace prefix must be an NCName
|
78
|
+
def prefix_valid?(prefix)
|
79
|
+
NC_REGEXP.match(prefix) || prefix.to_s.empty?
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/reddy/parser.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
module Reddy
|
2
|
+
# Generic Reddy Parser class
|
3
|
+
class Parser
|
4
|
+
attr_reader :debug
|
5
|
+
attr_accessor :doc, :graph
|
6
|
+
|
7
|
+
##
|
8
|
+
# Creates a new parser for N3 (or Turtle).
|
9
|
+
#
|
10
|
+
# @param [Hash] options:: Options from
|
11
|
+
# <em>options[:graph]</em>:: Graph to parse into, otherwise a new Reddy::Graph instance is created
|
12
|
+
# <em>options[:debug]</em>:: Array to place debug messages
|
13
|
+
# <em>options[:type]</em>:: One of _rdfxml_, _html_, or _n3_
|
14
|
+
# <em>options[:strict]</em>:: Raise Error if true, continue with lax parsing, otherwise
|
15
|
+
#
|
16
|
+
# @author Gregg Kellogg
|
17
|
+
def initialize(options = {})
|
18
|
+
# initialize the triplestore
|
19
|
+
@graph = options[:graph]
|
20
|
+
@debug = options[:debug]
|
21
|
+
@strict = options[:strict]
|
22
|
+
@named_bnodes = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Instantiate Parser and parse document
|
26
|
+
#
|
27
|
+
# @param [IO, String] stream:: the RDF IO stream, string, Nokogiri::HTML::Document or Nokogiri::XML::Document
|
28
|
+
# @param [String] uri:: the URI of the document
|
29
|
+
# @param [Hash] options:: Options from
|
30
|
+
# <em>options[:debug]</em>:: Array to place debug messages
|
31
|
+
# <em>options[:type]</em>:: One of _rdfxml_, _html_, or _n3_
|
32
|
+
# <em>options[:strict]</em>:: Raise Error if true, continue with lax parsing, otherwise
|
33
|
+
# @return [Graph]:: Returns the graph containing parsed triples
|
34
|
+
# @raise [Error]:: Raises RdfError if _strict_
|
35
|
+
#
|
36
|
+
# @author Gregg Kellogg
|
37
|
+
def self.parse(stream, uri = nil, options = {}, &block) # :yields: triple
|
38
|
+
parser = self.new(options)
|
39
|
+
parser.parse(stream, uri, options, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Parse RDF document from a string or input stream to closure or graph.
|
43
|
+
#
|
44
|
+
# Virtual Class, prototype for Parser subclass.
|
45
|
+
#
|
46
|
+
# @param [IO, String] stream:: the RDF IO stream, string, Nokogiri::HTML::Document or Nokogiri::XML::Document
|
47
|
+
# @param [String] uri:: the URI of the document
|
48
|
+
# @param [Hash] options:: Options from
|
49
|
+
# <em>options[:debug]</em>:: Array to place debug messages
|
50
|
+
# <em>options[:strict]</em>:: Raise Error if true, continue with lax parsing, otherwise
|
51
|
+
# @return [Graph]:: Returns the graph containing parsed triples
|
52
|
+
# @raise [Error]:: Raises RdfError if _strict_
|
53
|
+
#
|
54
|
+
# @author Gregg Kellogg
|
55
|
+
def parse(stream, uri = nil, options = {}, &block) # :yields: triple
|
56
|
+
if self.class == Parser
|
57
|
+
# Create a delegate of a specific parser class
|
58
|
+
@delegate ||= case options[:type].to_s
|
59
|
+
when "n3", "ntriples", "turtle" then N3Parser.new(options)
|
60
|
+
when "rdfa", "html", "xhtml" then RdfaParser.new(options)
|
61
|
+
when "xml", "rdf", "rdfxml" then RdfXmlParser.new(options)
|
62
|
+
else
|
63
|
+
RdfXmlParser.new(options)
|
64
|
+
# raise ParserException.new("type option must be one of :rdfxml, :html, or :n3")
|
65
|
+
end
|
66
|
+
@delegate.parse(stream, uri, options, &block)
|
67
|
+
else
|
68
|
+
# Common parser operations
|
69
|
+
@uri = Addressable::URI.parse(uri.to_s).to_s unless uri.nil?
|
70
|
+
@strict = options[:strict] if options.has_key?(:strict)
|
71
|
+
@debug = options[:debug] if options.has_key?(:debug)
|
72
|
+
|
73
|
+
@graph ||= Graph.new(:identifier => @uri)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Return N3 Parser instance
|
78
|
+
def self.n3_parser(options = {}); N3Parser.new(options); end
|
79
|
+
# Return RDF/XML Parser instance
|
80
|
+
def self.rdfxml_parser(options = {}); RdfXmlParser.new(options); end
|
81
|
+
# Return Rdfa Parser instance
|
82
|
+
def self.rdfa_parser(options = {}); RdfaParser.new(options); end
|
83
|
+
|
84
|
+
protected
|
85
|
+
# Figure out the document path, if it is a Nokogiri::XML::Element or Attribute
|
86
|
+
def node_path(node)
|
87
|
+
case node
|
88
|
+
when Nokogiri::XML::Element, Nokogiri::XML::Attr then "#{node_path(node.parent)}/#{node.name}"
|
89
|
+
when String then node
|
90
|
+
else ""
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Add debug event to debug array, if specified
|
95
|
+
#
|
96
|
+
# @param [XML Node, any] node:: XML Node or string for showing context
|
97
|
+
# @param [String] message::
|
98
|
+
def add_debug(node, message)
|
99
|
+
puts "#{node_path(node)}: #{message}" if $DEBUG
|
100
|
+
@debug << "#{node_path(node)}: #{message}" if @debug
|
101
|
+
end
|
102
|
+
|
103
|
+
# add a triple, object can be literal or URI or bnode
|
104
|
+
#
|
105
|
+
# @param [Nokogiri::XML::Node, any] node:: XML Node or string for showing context
|
106
|
+
# @param [URIRef, BNode] subject:: the subject of the triple
|
107
|
+
# @param [URIRef] predicate:: the predicate of the triple
|
108
|
+
# @param [URIRef, BNode, Literal] object:: the object of the triple
|
109
|
+
# @return [Array]:: An array of the triples (leaky abstraction? consider returning the graph instead)
|
110
|
+
# @raise [Error]:: Checks parameter types and raises if they are incorrect if parsing mode is _strict_.
|
111
|
+
#
|
112
|
+
# @author Gregg Kellogg
|
113
|
+
def add_triple(node, subject, predicate, object)
|
114
|
+
triple = Triple.new(subject, predicate, object)
|
115
|
+
add_debug(node, "triple: #{triple}")
|
116
|
+
if @callback
|
117
|
+
@callback.call(triple) # Perform yield to saved block
|
118
|
+
else
|
119
|
+
@graph << triple
|
120
|
+
end
|
121
|
+
triple
|
122
|
+
rescue RdfException => e
|
123
|
+
add_debug(node, "add_triple raised #{e.class}: #{e.message}")
|
124
|
+
raise if @strict
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|