rdfa_parser 0.1.0
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/.gitignore +7 -0
- data/History.txt +47 -0
- data/README.rdoc +61 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/bin/rdfa_parser +55 -0
- data/lib/rdfa_parser.rb +35 -0
- data/lib/rdfa_parser/bnode.rb +92 -0
- data/lib/rdfa_parser/exceptions.rb +11 -0
- data/lib/rdfa_parser/graph.rb +222 -0
- data/lib/rdfa_parser/literal.rb +375 -0
- data/lib/rdfa_parser/namespace.rb +91 -0
- data/lib/rdfa_parser/rdfa_parser.rb +415 -0
- data/lib/rdfa_parser/triple.rb +100 -0
- data/lib/rdfa_parser/uriref.rb +94 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/bnode_spec.rb +51 -0
- data/spec/graph_spec.rb +230 -0
- data/spec/literal_spec.rb +282 -0
- data/spec/matchers.rb +134 -0
- data/spec/namespace_spec.rb +61 -0
- data/spec/rdfa_helper.rb +127 -0
- data/spec/rdfa_parser_spec.rb +119 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/triple_spec.rb +145 -0
- data/spec/uriref_spec.rb +117 -0
- data/spec/xhtml1-testcases/.sparql +13 -0
- data/spec/xhtml1-testcases/0001.nt +1 -0
- data/spec/xhtml1-testcases/0001.sparql +3 -0
- data/spec/xhtml1-testcases/0001.xhtml +11 -0
- data/spec/xhtml1-testcases/0002.sparql +3 -0
- data/spec/xhtml1-testcases/0003.sparql +3 -0
- data/spec/xhtml1-testcases/0006.nt +2 -0
- data/spec/xhtml1-testcases/0006.sparql +8 -0
- data/spec/xhtml1-testcases/0006.xhtml +16 -0
- data/spec/xhtml1-testcases/0007.nt +3 -0
- data/spec/xhtml1-testcases/0007.sparql +5 -0
- data/spec/xhtml1-testcases/0007.xhtml +16 -0
- data/spec/xhtml1-testcases/0008.nt +1 -0
- data/spec/xhtml1-testcases/0008.sparql +3 -0
- data/spec/xhtml1-testcases/0008.xhtml +16 -0
- data/spec/xhtml1-testcases/0009.nt +1 -0
- data/spec/xhtml1-testcases/0009.sparql +3 -0
- data/spec/xhtml1-testcases/0009.xhtml +14 -0
- data/spec/xhtml1-testcases/0010.nt +2 -0
- data/spec/xhtml1-testcases/0010.sparql +4 -0
- data/spec/xhtml1-testcases/0010.xhtml +13 -0
- data/spec/xhtml1-testcases/0011.nt +3 -0
- data/spec/xhtml1-testcases/0011.sparql +17 -0
- data/spec/xhtml1-testcases/0011.xhtml +14 -0
- data/spec/xhtml1-testcases/0012.nt +1 -0
- data/spec/xhtml1-testcases/0012.sparql +3 -0
- data/spec/xhtml1-testcases/0012.xhtml +12 -0
- data/spec/xhtml1-testcases/0013.nt +1 -0
- data/spec/xhtml1-testcases/0013.sparql +3 -0
- data/spec/xhtml1-testcases/0013.xhtml +12 -0
- data/spec/xhtml1-testcases/0014.nt +1 -0
- data/spec/xhtml1-testcases/0014.sparql +3 -0
- data/spec/xhtml1-testcases/0014.xhtml +15 -0
- data/spec/xhtml1-testcases/0015.nt +2 -0
- data/spec/xhtml1-testcases/0015.sparql +4 -0
- data/spec/xhtml1-testcases/0015.xhtml +13 -0
- data/spec/xhtml1-testcases/0017.nt +3 -0
- data/spec/xhtml1-testcases/0017.sparql +6 -0
- data/spec/xhtml1-testcases/0017.xhtml +16 -0
- data/spec/xhtml1-testcases/0018.nt +1 -0
- data/spec/xhtml1-testcases/0018.sparql +3 -0
- data/spec/xhtml1-testcases/0018.xhtml +17 -0
- data/spec/xhtml1-testcases/0019.nt +1 -0
- data/spec/xhtml1-testcases/0019.sparql +3 -0
- data/spec/xhtml1-testcases/0019.xhtml +14 -0
- data/spec/xhtml1-testcases/0020.nt +1 -0
- data/spec/xhtml1-testcases/0020.sparql +3 -0
- data/spec/xhtml1-testcases/0020.xhtml +17 -0
- data/spec/xhtml1-testcases/0021.nt +1 -0
- data/spec/xhtml1-testcases/0021.sparql +3 -0
- data/spec/xhtml1-testcases/0021.xhtml +17 -0
- data/spec/xhtml1-testcases/0023.nt +1 -0
- data/spec/xhtml1-testcases/0023.sparql +3 -0
- data/spec/xhtml1-testcases/0023.xhtml +16 -0
- data/spec/xhtml1-testcases/0025.nt +2 -0
- data/spec/xhtml1-testcases/0025.sparql +4 -0
- data/spec/xhtml1-testcases/0025.xhtml +19 -0
- data/spec/xhtml1-testcases/0026.nt +1 -0
- data/spec/xhtml1-testcases/0026.sparql +3 -0
- data/spec/xhtml1-testcases/0026.xhtml +16 -0
- data/spec/xhtml1-testcases/0027.nt +1 -0
- data/spec/xhtml1-testcases/0027.sparql +3 -0
- data/spec/xhtml1-testcases/0027.xhtml +17 -0
- data/spec/xhtml1-testcases/0029.nt +1 -0
- data/spec/xhtml1-testcases/0029.sparql +3 -0
- data/spec/xhtml1-testcases/0029.xhtml +17 -0
- data/spec/xhtml1-testcases/0030.nt +1 -0
- data/spec/xhtml1-testcases/0030.sparql +3 -0
- data/spec/xhtml1-testcases/0030.xhtml +16 -0
- data/spec/xhtml1-testcases/0031.nt +1 -0
- data/spec/xhtml1-testcases/0031.sparql +3 -0
- data/spec/xhtml1-testcases/0031.xhtml +14 -0
- data/spec/xhtml1-testcases/0032.nt +1 -0
- data/spec/xhtml1-testcases/0032.sparql +3 -0
- data/spec/xhtml1-testcases/0032.xhtml +15 -0
- data/spec/xhtml1-testcases/0033.nt +2 -0
- data/spec/xhtml1-testcases/0033.sparql +5 -0
- data/spec/xhtml1-testcases/0033.xhtml +19 -0
- data/spec/xhtml1-testcases/0034.nt +1 -0
- data/spec/xhtml1-testcases/0034.sparql +3 -0
- data/spec/xhtml1-testcases/0034.xhtml +14 -0
- data/spec/xhtml1-testcases/0035.nt +1 -0
- data/spec/xhtml1-testcases/0035.sparql +3 -0
- data/spec/xhtml1-testcases/0035.xhtml +17 -0
- data/spec/xhtml1-testcases/0036.nt +1 -0
- data/spec/xhtml1-testcases/0036.sparql +3 -0
- data/spec/xhtml1-testcases/0036.xhtml +17 -0
- data/spec/xhtml1-testcases/0037.nt +1 -0
- data/spec/xhtml1-testcases/0037.sparql +3 -0
- data/spec/xhtml1-testcases/0037.xhtml +18 -0
- data/spec/xhtml1-testcases/0038.nt +1 -0
- data/spec/xhtml1-testcases/0038.sparql +3 -0
- data/spec/xhtml1-testcases/0038.xhtml +14 -0
- data/spec/xhtml1-testcases/0039.nt +1 -0
- data/spec/xhtml1-testcases/0039.sparql +3 -0
- data/spec/xhtml1-testcases/0039.xhtml +17 -0
- data/spec/xhtml1-testcases/0040.nt +1 -0
- data/spec/xhtml1-testcases/0040.sparql +3 -0
- data/spec/xhtml1-testcases/0040.xhtml +16 -0
- data/spec/xhtml1-testcases/0041.nt +1 -0
- data/spec/xhtml1-testcases/0041.sparql +3 -0
- data/spec/xhtml1-testcases/0041.xhtml +18 -0
- data/spec/xhtml1-testcases/0042.nt +0 -0
- data/spec/xhtml1-testcases/0042.sparql +4 -0
- data/spec/xhtml1-testcases/0042.xhtml +15 -0
- data/spec/xhtml1-testcases/0046.nt +3 -0
- data/spec/xhtml1-testcases/0046.sparql +6 -0
- data/spec/xhtml1-testcases/0046.xhtml +13 -0
- data/spec/xhtml1-testcases/0047.nt +3 -0
- data/spec/xhtml1-testcases/0047.sparql +6 -0
- data/spec/xhtml1-testcases/0047.xhtml +13 -0
- data/spec/xhtml1-testcases/0048.nt +3 -0
- data/spec/xhtml1-testcases/0048.sparql +6 -0
- data/spec/xhtml1-testcases/0048.xhtml +14 -0
- data/spec/xhtml1-testcases/0049.nt +2 -0
- data/spec/xhtml1-testcases/0049.sparql +4 -0
- data/spec/xhtml1-testcases/0049.xhtml +14 -0
- data/spec/xhtml1-testcases/0050.nt +2 -0
- data/spec/xhtml1-testcases/0050.sparql +5 -0
- data/spec/xhtml1-testcases/0050.xhtml +14 -0
- data/spec/xhtml1-testcases/0051.nt +2 -0
- data/spec/xhtml1-testcases/0051.sparql +4 -0
- data/spec/xhtml1-testcases/0051.xhtml +12 -0
- data/spec/xhtml1-testcases/0052.nt +1 -0
- data/spec/xhtml1-testcases/0052.sparql +3 -0
- data/spec/xhtml1-testcases/0052.xhtml +13 -0
- data/spec/xhtml1-testcases/0053.nt +2 -0
- data/spec/xhtml1-testcases/0053.sparql +4 -0
- data/spec/xhtml1-testcases/0053.xhtml +13 -0
- data/spec/xhtml1-testcases/0054.nt +2 -0
- data/spec/xhtml1-testcases/0054.sparql +4 -0
- data/spec/xhtml1-testcases/0054.xhtml +14 -0
- data/spec/xhtml1-testcases/0055.nt +2 -0
- data/spec/xhtml1-testcases/0055.sparql +4 -0
- data/spec/xhtml1-testcases/0055.xhtml +16 -0
- data/spec/xhtml1-testcases/0056.nt +3 -0
- data/spec/xhtml1-testcases/0056.sparql +5 -0
- data/spec/xhtml1-testcases/0056.xhtml +13 -0
- data/spec/xhtml1-testcases/0057.nt +4 -0
- data/spec/xhtml1-testcases/0057.sparql +6 -0
- data/spec/xhtml1-testcases/0057.xhtml +14 -0
- data/spec/xhtml1-testcases/0058.nt +6 -0
- data/spec/xhtml1-testcases/0058.sparql +9 -0
- data/spec/xhtml1-testcases/0058.xhtml +14 -0
- data/spec/xhtml1-testcases/0059.nt +6 -0
- data/spec/xhtml1-testcases/0059.sparql +8 -0
- data/spec/xhtml1-testcases/0059.xhtml +16 -0
- data/spec/xhtml1-testcases/0060.nt +2 -0
- data/spec/xhtml1-testcases/0060.sparql +4 -0
- data/spec/xhtml1-testcases/0060.xhtml +14 -0
- data/spec/xhtml1-testcases/0061.nt +1 -0
- data/spec/xhtml1-testcases/0061.sparql +3 -0
- data/spec/xhtml1-testcases/0061.xhtml +11 -0
- data/spec/xhtml1-testcases/0062.nt +1 -0
- data/spec/xhtml1-testcases/0062.sparql +3 -0
- data/spec/xhtml1-testcases/0062.xhtml +12 -0
- data/spec/xhtml1-testcases/0063.nt +1 -0
- data/spec/xhtml1-testcases/0063.sparql +3 -0
- data/spec/xhtml1-testcases/0063.xhtml +11 -0
- data/spec/xhtml1-testcases/0064.nt +1 -0
- data/spec/xhtml1-testcases/0064.sparql +4 -0
- data/spec/xhtml1-testcases/0064.xhtml +13 -0
- data/spec/xhtml1-testcases/0065.nt +3 -0
- data/spec/xhtml1-testcases/0065.sparql +6 -0
- data/spec/xhtml1-testcases/0065.xhtml +22 -0
- data/spec/xhtml1-testcases/0066.nt +1 -0
- data/spec/xhtml1-testcases/0066.sparql +3 -0
- data/spec/xhtml1-testcases/0066.xhtml +11 -0
- data/spec/xhtml1-testcases/0067.nt +1 -0
- data/spec/xhtml1-testcases/0067.sparql +3 -0
- data/spec/xhtml1-testcases/0067.xhtml +11 -0
- data/spec/xhtml1-testcases/0068.nt +1 -0
- data/spec/xhtml1-testcases/0068.sparql +3 -0
- data/spec/xhtml1-testcases/0068.xhtml +14 -0
- data/spec/xhtml1-testcases/0069.nt +1 -0
- data/spec/xhtml1-testcases/0069.sparql +3 -0
- data/spec/xhtml1-testcases/0069.xhtml +14 -0
- data/spec/xhtml1-testcases/0070.nt +1 -0
- data/spec/xhtml1-testcases/0070.sparql +3 -0
- data/spec/xhtml1-testcases/0070.xhtml +13 -0
- data/spec/xhtml1-testcases/0071.nt +1 -0
- data/spec/xhtml1-testcases/0071.sparql +3 -0
- data/spec/xhtml1-testcases/0071.xhtml +16 -0
- data/spec/xhtml1-testcases/0072.nt +1 -0
- data/spec/xhtml1-testcases/0072.sparql +3 -0
- data/spec/xhtml1-testcases/0072.xhtml +16 -0
- data/spec/xhtml1-testcases/0073.nt +1 -0
- data/spec/xhtml1-testcases/0073.sparql +3 -0
- data/spec/xhtml1-testcases/0073.xhtml +16 -0
- data/spec/xhtml1-testcases/0074.nt +1 -0
- data/spec/xhtml1-testcases/0074.sparql +3 -0
- data/spec/xhtml1-testcases/0074.xhtml +16 -0
- data/spec/xhtml1-testcases/0075.nt +1 -0
- data/spec/xhtml1-testcases/0075.sparql +3 -0
- data/spec/xhtml1-testcases/0075.xhtml +16 -0
- data/spec/xhtml1-testcases/0076.nt +23 -0
- data/spec/xhtml1-testcases/0076.sparql +70 -0
- data/spec/xhtml1-testcases/0076.xhtml +35 -0
- data/spec/xhtml1-testcases/0077.nt +23 -0
- data/spec/xhtml1-testcases/0077.sparql +70 -0
- data/spec/xhtml1-testcases/0077.xhtml +58 -0
- data/spec/xhtml1-testcases/0078.nt +6 -0
- data/spec/xhtml1-testcases/0078.sparql +7 -0
- data/spec/xhtml1-testcases/0078.xhtml +15 -0
- data/spec/xhtml1-testcases/0079.nt +3 -0
- data/spec/xhtml1-testcases/0079.sparql +6 -0
- data/spec/xhtml1-testcases/0079.xhtml +15 -0
- data/spec/xhtml1-testcases/0080.nt +1 -0
- data/spec/xhtml1-testcases/0080.sparql +3 -0
- data/spec/xhtml1-testcases/0080.xhtml +13 -0
- data/spec/xhtml1-testcases/0081.nt +6 -0
- data/spec/xhtml1-testcases/0081.sparql +9 -0
- data/spec/xhtml1-testcases/0081.xhtml +15 -0
- data/spec/xhtml1-testcases/0082.nt +8 -0
- data/spec/xhtml1-testcases/0082.sparql +11 -0
- data/spec/xhtml1-testcases/0082.xhtml +15 -0
- data/spec/xhtml1-testcases/0083.nt +6 -0
- data/spec/xhtml1-testcases/0083.sparql +9 -0
- data/spec/xhtml1-testcases/0083.xhtml +15 -0
- data/spec/xhtml1-testcases/0084.nt +8 -0
- data/spec/xhtml1-testcases/0084.sparql +11 -0
- data/spec/xhtml1-testcases/0084.xhtml +18 -0
- data/spec/xhtml1-testcases/0085.nt +4 -0
- data/spec/xhtml1-testcases/0085.sparql +6 -0
- data/spec/xhtml1-testcases/0085.xhtml +17 -0
- data/spec/xhtml1-testcases/0086.nt +0 -0
- data/spec/xhtml1-testcases/0086.sparql +4 -0
- data/spec/xhtml1-testcases/0086.xhtml +13 -0
- data/spec/xhtml1-testcases/0087.nt +23 -0
- data/spec/xhtml1-testcases/0087.sparql +70 -0
- data/spec/xhtml1-testcases/0087.xhtml +35 -0
- data/spec/xhtml1-testcases/0088.nt +3 -0
- data/spec/xhtml1-testcases/0088.sparql +6 -0
- data/spec/xhtml1-testcases/0088.xhtml +14 -0
- data/spec/xhtml1-testcases/0089.nt +1 -0
- data/spec/xhtml1-testcases/0089.sparql +3 -0
- data/spec/xhtml1-testcases/0089.xhtml +13 -0
- data/spec/xhtml1-testcases/0090.nt +1 -0
- data/spec/xhtml1-testcases/0090.sparql +3 -0
- data/spec/xhtml1-testcases/0090.xhtml +16 -0
- data/spec/xhtml1-testcases/0091.nt +3 -0
- data/spec/xhtml1-testcases/0091.sparql +6 -0
- data/spec/xhtml1-testcases/0091.xhtml +16 -0
- data/spec/xhtml1-testcases/0092.nt +3 -0
- data/spec/xhtml1-testcases/0092.sparql +16 -0
- data/spec/xhtml1-testcases/0092.xhtml +15 -0
- data/spec/xhtml1-testcases/0093.nt +2 -0
- data/spec/xhtml1-testcases/0093.sparql +4 -0
- data/spec/xhtml1-testcases/0093.xhtml +15 -0
- data/spec/xhtml1-testcases/0094.nt +3 -0
- data/spec/xhtml1-testcases/0094.sparql +16 -0
- data/spec/xhtml1-testcases/0094.xhtml +15 -0
- data/spec/xhtml1-testcases/0099.nt +1 -0
- data/spec/xhtml1-testcases/0099.sparql +3 -0
- data/spec/xhtml1-testcases/0099.xhtml +20 -0
- data/spec/xhtml1-testcases/0100.nt +3 -0
- data/spec/xhtml1-testcases/0100.sparql +15 -0
- data/spec/xhtml1-testcases/0100.xhtml +16 -0
- data/spec/xhtml1-testcases/0101.nt +3 -0
- data/spec/xhtml1-testcases/0101.sparql +15 -0
- data/spec/xhtml1-testcases/0101.xhtml +16 -0
- data/spec/xhtml1-testcases/0102.nt +1 -0
- data/spec/xhtml1-testcases/0102.sparql +15 -0
- data/spec/xhtml1-testcases/0102.xhtml +16 -0
- data/spec/xhtml1-testcases/0103.nt +1 -0
- data/spec/xhtml1-testcases/0103.sparql +15 -0
- data/spec/xhtml1-testcases/0103.xhtml +15 -0
- data/spec/xhtml1-testcases/0104.nt +3 -0
- data/spec/xhtml1-testcases/0104.sparql +5 -0
- data/spec/xhtml1-testcases/0104.xhtml +18 -0
- data/spec/xhtml1-testcases/0105.nt +1 -0
- data/spec/xhtml1-testcases/0105.sparql +7 -0
- data/spec/xhtml1-testcases/0105.xhtml +13 -0
- data/spec/xhtml1-testcases/0106.nt +1 -0
- data/spec/xhtml1-testcases/0106.sparql +7 -0
- data/spec/xhtml1-testcases/0106.xhtml +13 -0
- data/spec/xhtml1-testcases/0107.nt +0 -0
- data/spec/xhtml1-testcases/0107.sparql +4 -0
- data/spec/xhtml1-testcases/0107.xhtml +11 -0
- data/spec/xhtml1-testcases/0108.nt +1 -0
- data/spec/xhtml1-testcases/0108.sparql +3 -0
- data/spec/xhtml1-testcases/0108.xhtml +14 -0
- data/spec/xhtml1-testcases/0109.nt +1 -0
- data/spec/xhtml1-testcases/0109.sparql +3 -0
- data/spec/xhtml1-testcases/0109.xhtml +15 -0
- data/spec/xhtml1-testcases/0110.nt +1 -0
- data/spec/xhtml1-testcases/0110.sparql +4 -0
- data/spec/xhtml1-testcases/0110.xhtml +12 -0
- data/spec/xhtml1-testcases/0111.nt +2 -0
- data/spec/xhtml1-testcases/0111.sparql +5 -0
- data/spec/xhtml1-testcases/0111.xhtml +14 -0
- data/spec/xhtml1-testcases/0112.nt +1 -0
- data/spec/xhtml1-testcases/0112.sparql +3 -0
- data/spec/xhtml1-testcases/0112.xhtml +16 -0
- data/spec/xhtml1-testcases/0113.nt +2 -0
- data/spec/xhtml1-testcases/0113.sparql +4 -0
- data/spec/xhtml1-testcases/0113.xhtml +12 -0
- data/spec/xhtml1-testcases/0114.nt +3 -0
- data/spec/xhtml1-testcases/0114.sparql +5 -0
- data/spec/xhtml1-testcases/0114.xhtml +15 -0
- data/spec/xhtml1-testcases/0115.nt +4 -0
- data/spec/xhtml1-testcases/0115.sparql +14 -0
- data/spec/xhtml1-testcases/0115.xhtml +17 -0
- data/spec/xhtml1-testcases/0116.nt +2 -0
- data/spec/xhtml1-testcases/0116.sparql +6 -0
- data/spec/xhtml1-testcases/0116.xhtml +10 -0
- data/spec/xhtml1-testcases/0117.nt +2 -0
- data/spec/xhtml1-testcases/0117.sparql +4 -0
- data/spec/xhtml1-testcases/0117.xhtml +15 -0
- data/spec/xhtml1-testcases/0118.nt +1 -0
- data/spec/xhtml1-testcases/0118.sparql +5 -0
- data/spec/xhtml1-testcases/0118.xhtml +16 -0
- data/spec/xhtml1-testcases/0119.nt +1 -0
- data/spec/xhtml1-testcases/0119.sparql +5 -0
- data/spec/xhtml1-testcases/0119.xhtml +19 -0
- data/spec/xhtml1-testcases/0120.nt +1 -0
- data/spec/xhtml1-testcases/0120.sparql +5 -0
- data/spec/xhtml1-testcases/0120.xhtml +17 -0
- data/spec/xhtml1-testcases/0121.nt +2 -0
- data/spec/xhtml1-testcases/0121.sparql +4 -0
- data/spec/xhtml1-testcases/0121.xhtml +24 -0
- data/spec/xhtml1-testcases/0122.nt +1 -0
- data/spec/xhtml1-testcases/0122.sparql +4 -0
- data/spec/xhtml1-testcases/0122.xhtml +16 -0
- data/spec/xhtml1-testcases/0123.nt +3 -0
- data/spec/xhtml1-testcases/0123.sparql +5 -0
- data/spec/xhtml1-testcases/0123.xhtml +18 -0
- data/spec/xhtml1-testcases/0124.nt +4 -0
- data/spec/xhtml1-testcases/0124.sparql +6 -0
- data/spec/xhtml1-testcases/0124.xhtml +14 -0
- data/spec/xhtml1-testcases/0125.nt +1 -0
- data/spec/xhtml1-testcases/0125.sparql +5 -0
- data/spec/xhtml1-testcases/0125.xhtml +16 -0
- data/spec/xhtml1-testcases/0126.nt +3 -0
- data/spec/xhtml1-testcases/0126.sparql +5 -0
- data/spec/xhtml1-testcases/0126.xhtml +15 -0
- data/spec/xhtml1-testcases/1001.nt +6 -0
- data/spec/xhtml1-testcases/1001.sparql +8 -0
- data/spec/xhtml1-testcases/1001.xhtml +20 -0
- data/spec/xhtml1-testcases/9999.nt +3 -0
- data/spec/xhtml1-testcases/9999.xhtml +14 -0
- data/spec/xhtml1-testcases/rdfa-xhtml1-test-manifest.rdf +1303 -0
- data/tasks/rspec.rake +21 -0
- metadata +485 -0
data/.gitignore
ADDED
data/History.txt
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
=== 0.1.0 2009-10-17
|
|
2
|
+
* First gem release, all XHTML1 approved test cases pass at http://rdfa.digitalbazaar.com/test-suite/
|
|
3
|
+
|
|
4
|
+
=== 0.0.5 2009-10-17
|
|
5
|
+
* Fixed generation of RDF/XML for XML Literals.
|
|
6
|
+
* Update Specs for style
|
|
7
|
+
* Add eql? and hash methods to BNode and URIRef to allow for uniq
|
|
8
|
+
* Added test based on 0017 to find BNode XML output problems.
|
|
9
|
+
* Allow empty BNodes to be considered to be named
|
|
10
|
+
* Add xml:lang to XMLLiterals as necessary
|
|
11
|
+
* Don't add existing namespace definition to XML Literal
|
|
12
|
+
* Special output for XML Literal to treat xml:lang within string. Add on create.
|
|
13
|
+
* Added Namespace#xmlns_hash
|
|
14
|
+
* Use XML Parser, not HTML (this should probably vary on doc type). HTML parser was removing namespace declarations from XMLLiterals.
|
|
15
|
+
* Added _profile_ option to RdfaParser#parse to set parsetype to xhtml1, html4, or html5. Right now only xhtml1 is used.
|
|
16
|
+
* Use to_html when re-serializing XMLLiterals, whitespace was being destroid otherwise.
|
|
17
|
+
* All specs pass!
|
|
18
|
+
|
|
19
|
+
=== 0.0.4 2009-10-16
|
|
20
|
+
* Fixed namespace bug in RDF/XML generation from Graph
|
|
21
|
+
* Fixed URI generation from namespace, which failed when suffix was a defined method of Namespace (use ns + suffix)
|
|
22
|
+
|
|
23
|
+
=== 0.0.3 2009-10-12
|
|
24
|
+
* Added --quiet option to executable
|
|
25
|
+
* BNode RDF/XML output
|
|
26
|
+
* Output all default namespaces in RDF/XML
|
|
27
|
+
=== 0.0.2 2009-10-10
|
|
28
|
+
* Switch to jeweler from newgem/hoe
|
|
29
|
+
* RdfaParser.new just creates parser, allowing a different graph to be substituted.
|
|
30
|
+
* parser.parse() performs parse.
|
|
31
|
+
* Added Graph.to_rdfxml to output graph in XML serialization
|
|
32
|
+
|
|
33
|
+
=== 0.0.1 2009-09-26
|
|
34
|
+
|
|
35
|
+
* Previous versions based on original work by Ben Adida.
|
|
36
|
+
* Spec tests use Redland/Rasqal to check results.
|
|
37
|
+
* Version 0.9.16 of Rasqal does not support UNION, so those tests are compared against NTriples
|
|
38
|
+
* Passes most XHTML+RDFa tests. Of those that don't pass:
|
|
39
|
+
* NTriple BNode production differences.
|
|
40
|
+
* XMLLiteral attribute/namespace ordering differences (requires deep XML compare, not in Nokogiri).
|
|
41
|
+
* Unexplained failures:
|
|
42
|
+
* Test0102: XMLLiteral with explicit namespace and xml:lang; not overwriting existing langs
|
|
43
|
+
* Test0103: XMLLiteral with explicit namespace; not overwriting local namespaces
|
|
44
|
+
* Test0105: inner @rel neither CURIE nor LinkType
|
|
45
|
+
* Test0106: chaining with empty value in inner @rel
|
|
46
|
+
* Test0121: "[]" is a valid safe CURIE
|
|
47
|
+
* RDFa parser seems to be working correctly, but Nokogiri parses embedded <p> incorrectly
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
= rdfa_parser
|
|
2
|
+
|
|
3
|
+
* http://github.com/gkellogg/rdfa_parser
|
|
4
|
+
|
|
5
|
+
== DESCRIPTION:
|
|
6
|
+
|
|
7
|
+
RDFa parser written in pure Ruby. Yields each triple, or generate in-memory graph
|
|
8
|
+
|
|
9
|
+
== FEATURES/PROBLEMS:
|
|
10
|
+
|
|
11
|
+
* Most, but not all tests pass.
|
|
12
|
+
* Tests performed by comparison to expected NTriples, not based on SPARQL query
|
|
13
|
+
* Ultimately, this should be merged in with the Reddy gem to become part of a comprehensive Ruby RDF implementation
|
|
14
|
+
* Support libraries (Graph, Triple, and URIRef are used substantially intact, to facilitate a future merger)
|
|
15
|
+
|
|
16
|
+
== SYNOPSIS:
|
|
17
|
+
|
|
18
|
+
Based on original work of Ben Adida.
|
|
19
|
+
|
|
20
|
+
Basic usage:
|
|
21
|
+
|
|
22
|
+
require 'rdfa_parser'
|
|
23
|
+
parser = RdfaParser::RdfaParser.new(stream, base_uri) do |triple|
|
|
24
|
+
puts triple.to_ntriple
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
== REQUIREMENTS:
|
|
28
|
+
|
|
29
|
+
* addressable
|
|
30
|
+
* nokogiri
|
|
31
|
+
* redland (for testing only)
|
|
32
|
+
|
|
33
|
+
== INSTALL:
|
|
34
|
+
|
|
35
|
+
* sudo gem install rdfa_parser
|
|
36
|
+
|
|
37
|
+
== LICENSE:
|
|
38
|
+
|
|
39
|
+
(The MIT License)
|
|
40
|
+
|
|
41
|
+
Copyright (c) 2009 Gregg Kellogg
|
|
42
|
+
Copyright (c) 2008 Tom Morris and contributors (Portions of Reddy utilities)
|
|
43
|
+
|
|
44
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
45
|
+
a copy of this software and associated documentation files (the
|
|
46
|
+
'Software'), to deal in the Software without restriction, including
|
|
47
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
48
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
49
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
50
|
+
the following conditions:
|
|
51
|
+
|
|
52
|
+
The above copyright notice and this permission notice shall be
|
|
53
|
+
included in all copies or substantial portions of the Software.
|
|
54
|
+
|
|
55
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
56
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
57
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
58
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
59
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
60
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
61
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
begin
|
|
3
|
+
gem 'jeweler'
|
|
4
|
+
require 'jeweler'
|
|
5
|
+
Jeweler::Tasks.new do |gemspec|
|
|
6
|
+
gemspec.name = "rdfa_parser"
|
|
7
|
+
gemspec.summary = "RDFa parser written in pure Ruby."
|
|
8
|
+
gemspec.description = " Yields each triple, or generate in-memory graph"
|
|
9
|
+
gemspec.email = "gregg@kellogg-assoc.com"
|
|
10
|
+
gemspec.homepage = "http://github.com/gkellogg/rdfa_parser"
|
|
11
|
+
gemspec.authors = ["Gregg Kellogg"]
|
|
12
|
+
gemspec.add_dependency('addressable', '>= 2.0.0')
|
|
13
|
+
gemspec.add_dependency('nokogiri', '>= 1.3.3')
|
|
14
|
+
gemspec.add_dependency('builder', '>= 2.1.2')
|
|
15
|
+
gemspec.add_development_dependency('rspec')
|
|
16
|
+
gemspec.add_development_dependency('activesupport', '>= 2.3.0')
|
|
17
|
+
gemspec.extra_rdoc_files = %w(README.rdoc History.txt)
|
|
18
|
+
end
|
|
19
|
+
Jeweler::GemcutterTasks.new
|
|
20
|
+
rescue LoadError
|
|
21
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
require 'spec/rake/spectask'
|
|
25
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
|
27
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
33
|
+
spec.rcov = true
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
task :spec => :check_dependencies
|
|
37
|
+
|
|
38
|
+
task :default => :spec
|
|
39
|
+
|
|
40
|
+
require 'rake/rdoctask'
|
|
41
|
+
Rake::RDocTask.new do |rdoc|
|
|
42
|
+
if File.exist?('VERSION')
|
|
43
|
+
version = File.read('VERSION')
|
|
44
|
+
else
|
|
45
|
+
version = ""
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
49
|
+
rdoc.title = "rdfa_parser #{version}"
|
|
50
|
+
rdoc.rdoc_files.include('README*', "History.txt")
|
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
52
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
data/bin/rdfa_parser
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env ruby -s
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/rdfa_parser")
|
|
4
|
+
require 'getoptlong'
|
|
5
|
+
|
|
6
|
+
class Parse
|
|
7
|
+
def parse(file, base_uri)
|
|
8
|
+
puts "Parse: #{file}" if $quiet
|
|
9
|
+
parser = RdfaParser::RdfaParser.new
|
|
10
|
+
parser.parse(File.read(file), base_uri)
|
|
11
|
+
output = case $format
|
|
12
|
+
when "xml"
|
|
13
|
+
parser.graph.to_rdfxml
|
|
14
|
+
else
|
|
15
|
+
parser.graph.to_ntriples
|
|
16
|
+
end
|
|
17
|
+
puts output unless $quiet
|
|
18
|
+
|
|
19
|
+
puts parser.debug.join("\n\t") if $verbose
|
|
20
|
+
rescue RdfaParser::ParserException => e
|
|
21
|
+
puts "Parse failure: #{e.message}"
|
|
22
|
+
puts parser.debug if $verbose && parser
|
|
23
|
+
#raise
|
|
24
|
+
rescue Exception => e
|
|
25
|
+
puts "Parser fault: #{e.message}"
|
|
26
|
+
puts parser.debug if parser && !$quiet
|
|
27
|
+
raise
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
$verbose = false
|
|
32
|
+
base_uri = "http://example.com"
|
|
33
|
+
|
|
34
|
+
opts = GetoptLong.new(
|
|
35
|
+
["--verbose", GetoptLong::NO_ARGUMENT],
|
|
36
|
+
["--quiet", GetoptLong::NO_ARGUMENT],
|
|
37
|
+
["--debug", GetoptLong::NO_ARGUMENT],
|
|
38
|
+
["--format", GetoptLong::REQUIRED_ARGUMENT],
|
|
39
|
+
["--uri", GetoptLong::REQUIRED_ARGUMENT]
|
|
40
|
+
)
|
|
41
|
+
opts.each do |opt, arg|
|
|
42
|
+
case opt
|
|
43
|
+
when '--verbose' then $verbose = true
|
|
44
|
+
when '--quiet' then $quiet = true
|
|
45
|
+
when '--debug' then $DEBUG = true
|
|
46
|
+
when '--format' then $format = arg
|
|
47
|
+
when '--uri' then base_uri = arg
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
x = Parse.new
|
|
52
|
+
ARGV.each do |test_file|
|
|
53
|
+
x.parse(test_file, base_uri)
|
|
54
|
+
end
|
|
55
|
+
|
data/lib/rdfa_parser.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
3
|
+
|
|
4
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'rdfa_parser/**.rb')).each { |f| require f }
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
require 'nokogiri'
|
|
8
|
+
require 'addressable/uri'
|
|
9
|
+
require 'builder'
|
|
10
|
+
rescue LoadError
|
|
11
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
|
12
|
+
gem 'nokogiri'
|
|
13
|
+
gem 'addressable'
|
|
14
|
+
require 'nokogiri'
|
|
15
|
+
require 'addressable/uri'
|
|
16
|
+
require 'builder'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module RdfaParser
|
|
20
|
+
LINK_TYPES = %w(
|
|
21
|
+
alternate appendix bookmark cite chapter contents copyright first glossary
|
|
22
|
+
help icon index last license meta next p3pv1 prev role section stylesheet subsection
|
|
23
|
+
start top up
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
RDF_TYPE = URIRef.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
|
|
27
|
+
XML_LITERAL = Literal::Encoding.xmlliteral
|
|
28
|
+
|
|
29
|
+
RDF_NS = Namespace.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf")
|
|
30
|
+
RDFS_NS = Namespace.new("http://www.w3.org/2000/01/rdf-schema#", "rdfs")
|
|
31
|
+
XHV_NS = Namespace.new("http://www.w3.org/1999/xhtml/vocab#", "xhv")
|
|
32
|
+
XML_NS = Namespace.new("http://www.w3.org/XML/1998/namespace", "xml")
|
|
33
|
+
|
|
34
|
+
XH_MAPPING = {"" => Namespace.new("http://www.w3.org/1999/xhtml/vocab\#", nil)}
|
|
35
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module RdfaParser
|
|
2
|
+
# The BNode class creates RDF blank nodes.
|
|
3
|
+
class BNode
|
|
4
|
+
@@next_generated = "a"
|
|
5
|
+
@@named_nodes = {}
|
|
6
|
+
|
|
7
|
+
# Create a new BNode, optionally accept a identifier for the BNode. Otherwise, generated sequentially
|
|
8
|
+
def initialize(identifier = nil)
|
|
9
|
+
if identifier != nil && self.valid_id?(identifier)
|
|
10
|
+
# Generate a name if it's blank
|
|
11
|
+
@identifier = (@@named_nodes[identifier] ||= identifier.to_s.length > 0 ? identifier : self )
|
|
12
|
+
else
|
|
13
|
+
# Don't actually allocate the name until it's used, to save generation space
|
|
14
|
+
# (and make checking test cases easier)
|
|
15
|
+
@identifier = self
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
return self.identifier.to_s
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# Exports the BNode in N-Triples form.
|
|
25
|
+
#
|
|
26
|
+
# ==== Example
|
|
27
|
+
# b = BNode.new; b.to_n3 # => returns a string of the BNode in n3 form
|
|
28
|
+
#
|
|
29
|
+
# ==== Returns
|
|
30
|
+
# @return [String] The BNode in n3.
|
|
31
|
+
#
|
|
32
|
+
# @author Tom Morris
|
|
33
|
+
|
|
34
|
+
def to_n3
|
|
35
|
+
"_:#{self.identifier}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
# Exports the BNode in N-Triples form.
|
|
40
|
+
#
|
|
41
|
+
# ==== Example
|
|
42
|
+
# b = BNode.new; b.to_ntriples # => returns a string of the BNode in N-Triples form
|
|
43
|
+
#
|
|
44
|
+
# ==== Returns
|
|
45
|
+
# @return [String] The BNode in N-Triples.
|
|
46
|
+
#
|
|
47
|
+
# @author Tom Morris
|
|
48
|
+
|
|
49
|
+
def to_ntriples
|
|
50
|
+
self.to_n3
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Output URI as resource reference for RDF/XML
|
|
54
|
+
def xml_args
|
|
55
|
+
[{"rdf:nodeID" => self.identifier}]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# The identifier used used for this BNode. Not evaluated until this is called, which means
|
|
59
|
+
# that BNodes that are never used in a triple won't polute the sequence.
|
|
60
|
+
def identifier
|
|
61
|
+
return @identifier unless @identifier.is_a?(BNode)
|
|
62
|
+
if @identifier.equal?(self)
|
|
63
|
+
# Generate from the sequence a..zzz, unless already taken
|
|
64
|
+
@@next_generated = @@next_generated.succ while @@named_nodes.has_key?(@@next_generated)
|
|
65
|
+
@identifier, @@next_generated = @@next_generated, @@next_generated.succ
|
|
66
|
+
else
|
|
67
|
+
# Previously allocated node
|
|
68
|
+
@identifier = @identifier.identifier
|
|
69
|
+
end
|
|
70
|
+
@identifier
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def eql?(other)
|
|
74
|
+
other.is_a?(self.class) && self.identifier == other.identifier
|
|
75
|
+
end
|
|
76
|
+
alias_method :==, :eql?
|
|
77
|
+
|
|
78
|
+
# Needed for uniq
|
|
79
|
+
def hash; to_s.hash; end
|
|
80
|
+
|
|
81
|
+
# Start _identifier_ sequence from scratch
|
|
82
|
+
def self.reset(init = "a")
|
|
83
|
+
@@next_generated = init
|
|
84
|
+
@@named_nodes = {}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
protected
|
|
88
|
+
def valid_id?(name)
|
|
89
|
+
name =~ /^[a-zA-Z_][a-zA-Z0-9]*$/ || name.empty?
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module RdfaParser
|
|
2
|
+
class RdfException < RuntimeError; end
|
|
3
|
+
class ParserException < RdfException; end
|
|
4
|
+
class GraphException < RdfException; end
|
|
5
|
+
class TypeError < RdfException; end
|
|
6
|
+
class AboutEachException < ParserException; end
|
|
7
|
+
class UriRelativeException < RdfException; end
|
|
8
|
+
class InvalidPredicate < RdfException; end
|
|
9
|
+
class InvalidSubject < RdfException; end
|
|
10
|
+
class InvalidObject < RdfException; end
|
|
11
|
+
end
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
module RdfaParser
|
|
2
|
+
# A simple graph to hold triples (from Reddy)
|
|
3
|
+
class Graph
|
|
4
|
+
attr_accessor :triples, :nsbinding
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@triples = []
|
|
8
|
+
@nsbinding = {}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.load (uri)
|
|
12
|
+
RdfXmlParser.new(open(uri)).graph
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def size
|
|
16
|
+
@triples.size
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def each
|
|
20
|
+
@triples.each { |value| yield value }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def subjects
|
|
24
|
+
@triples.map {|t| t.subject}.uniq
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def [] (item)
|
|
28
|
+
@triples[item]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def each_with_subject(subject)
|
|
32
|
+
@triples.each do |value|
|
|
33
|
+
yield value if value.subject == subject
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def get_resource(subject)
|
|
38
|
+
@triples.find_all { |i| true if i.subject == subject}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
##
|
|
42
|
+
# Adds a triple to a graph directly from the intended subject, predicate, and object.
|
|
43
|
+
#
|
|
44
|
+
# ==== Example
|
|
45
|
+
# g = Graph.new; g.add_triple(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new) # => results in the triple being added to g; returns an array of g's triples
|
|
46
|
+
#
|
|
47
|
+
# @param [URIRef, BNode] s the subject of the triple
|
|
48
|
+
# @param [URIRef] p the predicate of the triple
|
|
49
|
+
# @param [URIRef, BNode, Literal, TypedLiteral] o the object of the triple
|
|
50
|
+
#
|
|
51
|
+
# ==== Returns
|
|
52
|
+
# @return [Array] An array of the triples (leaky abstraction? consider returning the graph instead)
|
|
53
|
+
#
|
|
54
|
+
# @raise [Error] Checks parameter types and raises if they are incorrect.
|
|
55
|
+
# @author Tom Morris
|
|
56
|
+
def add_triple(s, p, o)
|
|
57
|
+
@triples += [ Triple.new(s, p, o) ]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
##
|
|
62
|
+
# Adds an extant triple to a graph
|
|
63
|
+
#
|
|
64
|
+
# ==== Example
|
|
65
|
+
# g = Graph.new; t = Triple.new(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new); g << t) # => results in the triple being added to g; returns an array of g's triples
|
|
66
|
+
#
|
|
67
|
+
# @param [Triple] t the triple to be added to the graph
|
|
68
|
+
#
|
|
69
|
+
# ==== Returns
|
|
70
|
+
# @return [Array] An array of the triples (leaky abstraction? consider returning the graph instead)
|
|
71
|
+
#
|
|
72
|
+
# @author Tom Morris
|
|
73
|
+
def << (triple)
|
|
74
|
+
# self.add_triple(s, p, o)
|
|
75
|
+
@triples += [ triple ]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
##
|
|
79
|
+
# Exports the graph to RDF in N-Triples form.
|
|
80
|
+
#
|
|
81
|
+
# ==== Example
|
|
82
|
+
# g = Graph.new; g.add_triple(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new); g.to_ntriples # => returns a string of the graph in N-Triples form
|
|
83
|
+
#
|
|
84
|
+
# ==== Returns
|
|
85
|
+
# @return [String] The graph in N-Triples.
|
|
86
|
+
#
|
|
87
|
+
# @author Tom Morris
|
|
88
|
+
|
|
89
|
+
def to_ntriples
|
|
90
|
+
@triples.collect do |t|
|
|
91
|
+
t.to_ntriples
|
|
92
|
+
end * "\n" + "\n"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Output graph using to_ntriples
|
|
96
|
+
def to_s; self.to_ntriples; end
|
|
97
|
+
|
|
98
|
+
# Dump model to RDF/XML
|
|
99
|
+
def to_rdfxml
|
|
100
|
+
replace_text = {}
|
|
101
|
+
rdfxml = ""
|
|
102
|
+
xml = builder = Builder::XmlMarkup.new(:target => rdfxml, :indent => 2)
|
|
103
|
+
|
|
104
|
+
extended_bindings = nsbinding.merge(
|
|
105
|
+
"rdf" => RDF_NS,
|
|
106
|
+
"rdfs" => RDFS_NS,
|
|
107
|
+
"xhv" => XHV_NS,
|
|
108
|
+
"xml" => XML_NS
|
|
109
|
+
)
|
|
110
|
+
rdf_attrs = extended_bindings.values.inject({}) { |hash, ns| hash.merge(ns.xmlns_attr => ns.uri.to_s)}
|
|
111
|
+
uri_bindings = extended_bindings.values.inject({}) { |hash, ns| hash.merge(ns.uri.to_s => ns.short)}
|
|
112
|
+
xml.instruct!
|
|
113
|
+
xml.rdf(:RDF, rdf_attrs) do
|
|
114
|
+
# Add statements for each subject
|
|
115
|
+
subjects.each do |s|
|
|
116
|
+
xml.rdf(:Description, (s.is_a?(BNode) ? "rdf:nodeID" : "rdf:about") => s) do
|
|
117
|
+
each_with_subject(s) do |triple|
|
|
118
|
+
xml_args = triple.object.xml_args
|
|
119
|
+
if triple.object.is_a?(Literal) && triple.object.xmlliteral?
|
|
120
|
+
replace_text["__replace_with_#{triple.object.object_id}__"] = xml_args[0]
|
|
121
|
+
xml_args[0] = "__replace_with_#{triple.object.object_id}__"
|
|
122
|
+
end
|
|
123
|
+
xml.tag!(triple.predicate.to_qname(uri_bindings), *xml_args)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Perform literal substitutions
|
|
130
|
+
replace_text.each_pair do |match, value|
|
|
131
|
+
rdfxml.sub!(match, value)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
rdfxml
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
##
|
|
138
|
+
# Creates a new namespace given a URI and the short name and binds it to the graph.
|
|
139
|
+
#
|
|
140
|
+
# ==== Example
|
|
141
|
+
# g = Graph.new; g.namespace("http://xmlns.com/foaf/0.1/", "foaf") # => binds the Foaf namespace to g
|
|
142
|
+
#
|
|
143
|
+
# @param [String] uri the URI of the namespace
|
|
144
|
+
# @param [String] short the short name of the namespace
|
|
145
|
+
#
|
|
146
|
+
# ==== Returns
|
|
147
|
+
# @return [Namespace] The newly created namespace.
|
|
148
|
+
#
|
|
149
|
+
# @raise [Error] Checks validity of the desired shortname and raises if it is incorrect.
|
|
150
|
+
# @raise [Error] Checks that the newly created Namespace is of type Namespace and raises if it is incorrect.
|
|
151
|
+
# @author Tom Morris
|
|
152
|
+
|
|
153
|
+
def namespace(uri, short)
|
|
154
|
+
self.bind Namespace.new(uri, short)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def bind(namespace)
|
|
158
|
+
if namespace.class == Namespace
|
|
159
|
+
@nsbinding["#{namespace.short}"] = namespace
|
|
160
|
+
else
|
|
161
|
+
raise GraphException, "Can't bind #{namespace.inspect} as namespace"
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def has_bnode_identifier?(bnodeid)
|
|
166
|
+
temp_bnode = BNode.new(bnodeid)
|
|
167
|
+
returnval = false
|
|
168
|
+
@triples.each { |triple|
|
|
169
|
+
if triple.subject.eql?(temp_bnode)
|
|
170
|
+
returnval = true
|
|
171
|
+
break
|
|
172
|
+
end
|
|
173
|
+
if triple.object.eql?(temp_bnode)
|
|
174
|
+
returnval = true
|
|
175
|
+
break
|
|
176
|
+
end
|
|
177
|
+
}
|
|
178
|
+
return returnval
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def get_bnode_by_identifier(bnodeid)
|
|
182
|
+
temp_bnode = BNode.new(bnodeid)
|
|
183
|
+
each do |triple|
|
|
184
|
+
if triple.subject == temp_bnode
|
|
185
|
+
return triple.subject
|
|
186
|
+
end
|
|
187
|
+
if triple.object == temp_bnode
|
|
188
|
+
return triple.object
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
return false
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def get_by_type(object)
|
|
195
|
+
out = []
|
|
196
|
+
each do |t|
|
|
197
|
+
next unless t.is_type?
|
|
198
|
+
next unless case object
|
|
199
|
+
when String
|
|
200
|
+
object == t.object.to_s
|
|
201
|
+
when Regexp
|
|
202
|
+
object.match(t.object.to_s)
|
|
203
|
+
else
|
|
204
|
+
object == t.object
|
|
205
|
+
end
|
|
206
|
+
out << t.subject
|
|
207
|
+
end
|
|
208
|
+
return out
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def join(graph)
|
|
212
|
+
if graph.class == Graph
|
|
213
|
+
graph.each { |t|
|
|
214
|
+
self << t
|
|
215
|
+
}
|
|
216
|
+
else
|
|
217
|
+
raise GraphException, "join requires you provide a graph object"
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
end
|
|
222
|
+
end
|