rdf_context 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +2 -0
- data/.gitignore +10 -0
- data/.gitmodules +3 -0
- data/History.txt +73 -0
- data/README.rdoc +145 -0
- data/Rakefile +77 -0
- data/VERSION +1 -0
- data/bin/reddy +59 -0
- data/lib/rdf_context.rb +60 -0
- data/lib/rdf_context/bnode.rb +99 -0
- data/lib/rdf_context/conjunctive_graph.rb +47 -0
- data/lib/rdf_context/exceptions.rb +11 -0
- data/lib/rdf_context/graph.rb +333 -0
- data/lib/rdf_context/literal.rb +340 -0
- data/lib/rdf_context/n3_grammar.rb +2171 -0
- data/lib/rdf_context/n3_grammar.treetop +143 -0
- data/lib/rdf_context/n3parser.rb +152 -0
- data/lib/rdf_context/namespace.rb +82 -0
- data/lib/rdf_context/nokogiri_hacks.rb +8 -0
- data/lib/rdf_context/parser.rb +119 -0
- data/lib/rdf_context/rdfaparser.rb +398 -0
- data/lib/rdf_context/rdfxmlparser.rb +525 -0
- data/lib/rdf_context/store/abstract_sql_store.rb +843 -0
- data/lib/rdf_context/store/abstract_store.rb +64 -0
- data/lib/rdf_context/store/list_store.rb +63 -0
- data/lib/rdf_context/store/memory_store.rb +323 -0
- data/lib/rdf_context/store/sqlite3_store.rb +223 -0
- data/lib/rdf_context/string_hacks.rb +108 -0
- data/lib/rdf_context/term_utils.rb +196 -0
- data/lib/rdf_context/triple.rb +144 -0
- data/lib/rdf_context/uriref.rb +95 -0
- data/script/console +10 -0
- data/spec/bnode_spec.rb +58 -0
- data/spec/conjunctive_graph_spec.rb +60 -0
- data/spec/graph_spec.rb +390 -0
- data/spec/list_store_spec.rb +12 -0
- data/spec/literal_spec.rb +314 -0
- data/spec/matchers.rb +150 -0
- data/spec/memory_store_spec.rb +23 -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 +148 -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/rdfxml_helper.rb +137 -0
- data/spec/rdfxml_spec.rb +362 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/sqlite3_store_spec.rb +41 -0
- data/spec/store_helper.rb +231 -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 +696 -0
@@ -0,0 +1,843 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'abstract_store')
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
module RdfContext
|
5
|
+
# SQL-92 formula-aware implementation of an RDF Store.
|
6
|
+
# It stores it's triples in the following partitions:
|
7
|
+
# - Asserted non rdf:type statements
|
8
|
+
# - Asserted literal statements
|
9
|
+
# - Asserted rdf:type statements (in a table which models Class membership). The motivation for this partition is primarily query speed and scalability as most graphs will always have more rdf:type statements than others
|
10
|
+
# - All Quoted statements
|
11
|
+
#
|
12
|
+
# In addition it persists namespace mappings in a seperate table
|
13
|
+
#
|
14
|
+
# Based on Python RdfLib AbstractSQLStore
|
15
|
+
class AbstractSQLStore < AbstractStore
|
16
|
+
include TermUtils
|
17
|
+
|
18
|
+
COUNT_SELECT = 0
|
19
|
+
CONTEXT_SELECT = 1
|
20
|
+
TRIPLE_SELECT = 2
|
21
|
+
TRIPLE_SELECT_NO_ORDER = 3
|
22
|
+
|
23
|
+
ASSERTED_NON_TYPE_PARTITION = 3
|
24
|
+
ASSERTED_TYPE_PARTITION = 4
|
25
|
+
QUOTED_PARTITION = 5
|
26
|
+
ASSERTED_LITERAL_PARTITION = 6
|
27
|
+
|
28
|
+
FULL_TRIPLE_PARTITIONS = [QUOTED_PARTITION,ASSERTED_LITERAL_PARTITION]
|
29
|
+
|
30
|
+
INTERNED_PREFIX = 'kb_'
|
31
|
+
|
32
|
+
STRONGLY_TYPED_TERMS = false
|
33
|
+
|
34
|
+
# @param[URIRef] identifier:: URIRef of the Store. Defaults to CWD
|
35
|
+
# @param[Hash] configuration:: Hash containing infomation open can use to connect to datastore.
|
36
|
+
def initialize(identifier = nil, configuration = {})
|
37
|
+
@literalCache = {}
|
38
|
+
@otherCache = {}
|
39
|
+
@bnodeCache = {}
|
40
|
+
@uriCache = {}
|
41
|
+
|
42
|
+
@context_aware = true
|
43
|
+
@formula_aware = true
|
44
|
+
@transaction_aware = true
|
45
|
+
@autocommit_default = true
|
46
|
+
|
47
|
+
raise StoreException.new("Identifier must be nil or a URIRef") if identifier && !identifier.is_a?(URIRef)
|
48
|
+
@identifier = identifier || URIRef.new("file:/#{Dir.getwd}")
|
49
|
+
|
50
|
+
@internedId = INTERNED_PREFIX + Digest::SHA1.hexdigest(@identifier.to_s)[0..9] # Only first 10 bytes of digeset
|
51
|
+
|
52
|
+
@db = configuration.empty? ? nil : open(configuration)
|
53
|
+
end
|
54
|
+
|
55
|
+
def close(commit_pending_transactions = false)
|
56
|
+
@db.commit if commit_pending_transactions && @db.transaction_active?
|
57
|
+
@db.close
|
58
|
+
end
|
59
|
+
|
60
|
+
# Add a triple to the store
|
61
|
+
# Add to default context, if context is nil
|
62
|
+
def add(triple, context = nil, quoted = false)
|
63
|
+
context ||= @identifier
|
64
|
+
executeSQL("SET AUTOCOMMIT=0") if @autocommit_default
|
65
|
+
|
66
|
+
if quoted || triple.predicate != RDF_TYPE
|
67
|
+
# Quoted statement or non rdf:type predicate
|
68
|
+
# Check if object is a literal
|
69
|
+
if triple.object.is_a?(Literal)
|
70
|
+
addCmd, *params = self.buildLiteralTripleSQLCommand(triple, context)
|
71
|
+
else
|
72
|
+
addCmd, *params = self.buildTripleSQLCommand(triple, context, quoted)
|
73
|
+
end
|
74
|
+
elsif triple.predicate == RDF_TYPE
|
75
|
+
addCmd, *params = self.buildTypeSQLCommand(triple.subject, triple.object, context)
|
76
|
+
end
|
77
|
+
|
78
|
+
executeSQL(addCmd, params)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Remove a triple from the context and store
|
82
|
+
#
|
83
|
+
# if subject, predicate and object are nil and context is not nil, the context is removed
|
84
|
+
def remove(triple, context = nil)
|
85
|
+
if context
|
86
|
+
if triple.subject == nil && triple.predicate.nil? && triple.object.nil?
|
87
|
+
return remove_context(context)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if triple.predicate.nil? || triple.predicate != RDF_TYPE
|
92
|
+
# Remove predicates other than rdf:type
|
93
|
+
if !STRONGLY_TYPED_TERMS || triple.object.is_a?(Literal)
|
94
|
+
clauseString, *params = self.buildClause(literal_table,triple,context)
|
95
|
+
if !clauseString.empty?
|
96
|
+
cmd = "DELETE FROM #{literal_table} #{clauseString}"
|
97
|
+
else
|
98
|
+
cmd = "DELETE FROM #{literal_table}"
|
99
|
+
end
|
100
|
+
executeSQL(_normalizeSQLCmd(cmd), params)
|
101
|
+
end
|
102
|
+
|
103
|
+
[quoted_table, asserted_table].each do |table|
|
104
|
+
# If asserted non rdf:type table and obj is Literal, don't do anything (already taken care of)
|
105
|
+
next if table == asserted_table && triple.object.is_a?(Literal)
|
106
|
+
|
107
|
+
clauseString, *params = self.buildClause(table, triple, context)
|
108
|
+
if !clauseString.empty?
|
109
|
+
cmd = "DELETE FROM #{table} #{clauseString}"
|
110
|
+
else
|
111
|
+
cmd = "DELETE FROM #{table}"
|
112
|
+
end
|
113
|
+
executeSQL(_normalizeSQLCmd(cmd), params)
|
114
|
+
end
|
115
|
+
elsif triple.predicate == RDF_TYPE || triple.predicate.nil?
|
116
|
+
# Need to check rdf:type and quoted partitions (in addition perhaps)
|
117
|
+
clauseString, *params = self.buildClause(asserted_type_table,triple,context, true)
|
118
|
+
if !clauseString.empty?
|
119
|
+
cmd = "DELETE FROM #{asserted_type_table} #{clauseString}"
|
120
|
+
else
|
121
|
+
cmd = "DELETE FROM #{asserted_type_table}"
|
122
|
+
end
|
123
|
+
executeSQL(_normalizeSQLCmd(cmd), params)
|
124
|
+
|
125
|
+
clauseString, *params = self.buildClause(quoted_table,triple,context)
|
126
|
+
if !clauseString.empty?
|
127
|
+
cmd = "DELETE FROM #{quoted_table} #{clauseString}"
|
128
|
+
else
|
129
|
+
cmd = "DELETE FROM #{quoted_table}"
|
130
|
+
end
|
131
|
+
executeSQL(_normalizeSQLCmd(cmd), params)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# A generator over all the triples matching pattern.
|
136
|
+
#
|
137
|
+
# quoted table:: <id>_quoted_statements
|
138
|
+
# asserted rdf:type table:: <id>_type_statements
|
139
|
+
# asserted non rdf:type table:: <id>_asserted_statements
|
140
|
+
#
|
141
|
+
# triple columns: subject,predicate,object,context,termComb,objLanguage,objDatatype
|
142
|
+
# class membership columns: member,klass,context termComb
|
143
|
+
#
|
144
|
+
# FIXME: These union all selects *may* be further optimized by joins
|
145
|
+
def triples(triple, context = nil) # :yields: triple, context
|
146
|
+
parameters = []
|
147
|
+
|
148
|
+
if triple.predicate == RDF_TYPE
|
149
|
+
# select from asserted rdf:type partition and quoted table (if a context is specified)
|
150
|
+
clauseString, *params = self.buildClause('typeTable',triple,context, true)
|
151
|
+
parameters += params
|
152
|
+
selects = [
|
153
|
+
[
|
154
|
+
asserted_type_table,
|
155
|
+
'typeTable',
|
156
|
+
clauseString,
|
157
|
+
ASSERTED_TYPE_PARTITION
|
158
|
+
],
|
159
|
+
]
|
160
|
+
# elsif triple.predicate.is_a?(REGEXTerm) && triple.predicate.compiledExpr.match(RDF_TYPE) || triple.predicate.nil?
|
161
|
+
elsif triple.predicate.nil?
|
162
|
+
# Select from quoted partition (if context is specified), literal partition if (obj is Literal or None) and asserted non rdf:type partition (if obj is URIRef or None)
|
163
|
+
selects = []
|
164
|
+
if !STRONGLY_TYPED_TERMS || triple.object.is_a?(Literal) || triple.object.nil?
|
165
|
+
clauseString, *params = self.buildClause('literal',triple,context)
|
166
|
+
parameters += params
|
167
|
+
selects += [
|
168
|
+
[
|
169
|
+
literal_table,
|
170
|
+
'literal',
|
171
|
+
clauseString,
|
172
|
+
ASSERTED_LITERAL_PARTITION
|
173
|
+
]
|
174
|
+
]
|
175
|
+
end
|
176
|
+
|
177
|
+
if !triple.object.is_a?(Literal) || triple.object.nil?
|
178
|
+
clauseString, *params = self.buildClause('asserted',triple,context)
|
179
|
+
parameters += params
|
180
|
+
selects += [
|
181
|
+
[
|
182
|
+
asserted_table,
|
183
|
+
'asserted',
|
184
|
+
clauseString,
|
185
|
+
ASSERTED_NON_TYPE_PARTITION
|
186
|
+
]
|
187
|
+
]
|
188
|
+
end
|
189
|
+
|
190
|
+
clauseString, *params = self.buildClause('typeTable',Triple.new(triple.subject, RDF_TYPE, triple.object),context, true)
|
191
|
+
parameters += params
|
192
|
+
selects += [
|
193
|
+
[
|
194
|
+
asserted_type_table,
|
195
|
+
'typeTable',
|
196
|
+
clauseString,
|
197
|
+
ASSERTED_TYPE_PARTITION
|
198
|
+
]
|
199
|
+
]
|
200
|
+
elsif triple.predicate
|
201
|
+
# select from asserted non rdf:type partition (optionally), quoted partition (if context is speciied), and literal partition (optionally)
|
202
|
+
selects = []
|
203
|
+
if !STRONGLY_TYPED_TERMS || triple.object.is_a?(Literal) || triple.object.nil?
|
204
|
+
clauseString, *params = self.buildClause('literal',triple,context)
|
205
|
+
parameters += params
|
206
|
+
selects += [
|
207
|
+
[
|
208
|
+
literal_table,
|
209
|
+
'literal',
|
210
|
+
clauseString,
|
211
|
+
ASSERTED_LITERAL_PARTITION
|
212
|
+
]
|
213
|
+
]
|
214
|
+
end
|
215
|
+
|
216
|
+
if !triple.object.is_a?(Literal) || triple.object.nil?
|
217
|
+
clauseString, *params = self.buildClause('asserted',triple,context)
|
218
|
+
parameters += params
|
219
|
+
selects += [
|
220
|
+
[
|
221
|
+
asserted_table,
|
222
|
+
'asserted',
|
223
|
+
clauseString,
|
224
|
+
ASSERTED_NON_TYPE_PARTITION
|
225
|
+
]
|
226
|
+
]
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
if context
|
231
|
+
clauseString, *params = self.buildClause('quoted',triple,context)
|
232
|
+
parameters += params
|
233
|
+
selects += [
|
234
|
+
[
|
235
|
+
quoted_table,
|
236
|
+
'quoted',
|
237
|
+
clauseString,
|
238
|
+
QUOTED_PARTITION
|
239
|
+
]
|
240
|
+
]
|
241
|
+
end
|
242
|
+
|
243
|
+
q = _normalizeSQLCmd(unionSELECT(selects))
|
244
|
+
results = []
|
245
|
+
executeSQL(q, parameters) do |row|
|
246
|
+
triple, graphKlass, idKlass, graphId = extractTriple(row, context)
|
247
|
+
currentContext = graphKlass.new(:store => self, :identifier => idKlass.new(graphId))
|
248
|
+
if block_given?
|
249
|
+
yield(triple, currentContext)
|
250
|
+
else
|
251
|
+
results << triple
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
results.uniq
|
256
|
+
end
|
257
|
+
|
258
|
+
def contains?(triple, context = nil)
|
259
|
+
#puts "contains? #{triple}"
|
260
|
+
object = triple.object
|
261
|
+
if object.is_a?(Literal)
|
262
|
+
triple = Triple.new(triple.subject, triple.predicate, nil)
|
263
|
+
triples(triple, context) do |t, cg|
|
264
|
+
return true if t.object == object
|
265
|
+
end
|
266
|
+
false
|
267
|
+
else
|
268
|
+
!triples(triple, context).empty?
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
# Number of statements in the store.
|
273
|
+
def size(context = nil)
|
274
|
+
parameters = []
|
275
|
+
quotedContext = assertedContext = typeContext = literalContext = nil
|
276
|
+
|
277
|
+
clauseParts = self.buildContextClause(context,quoted_table)
|
278
|
+
if clauseParts
|
279
|
+
quotedContext = clauseParts.shift
|
280
|
+
parameters += clauseParts
|
281
|
+
end
|
282
|
+
|
283
|
+
clauseParts = self.buildContextClause(context,asserted_table)
|
284
|
+
if clauseParts
|
285
|
+
assertedContext = clauseParts.shift
|
286
|
+
parameters += clauseParts
|
287
|
+
end
|
288
|
+
|
289
|
+
clauseParts = self.buildContextClause(context,asserted_type_table)
|
290
|
+
if clauseParts
|
291
|
+
typeContext = clauseParts.shift
|
292
|
+
parameters += clauseParts
|
293
|
+
end
|
294
|
+
|
295
|
+
clauseParts = self.buildContextClause(context,literal_table)
|
296
|
+
if clauseParts
|
297
|
+
literalContext = clauseParts.shift
|
298
|
+
parameters += clauseParts
|
299
|
+
end
|
300
|
+
|
301
|
+
if context
|
302
|
+
selects = [
|
303
|
+
[
|
304
|
+
asserted_type_table,
|
305
|
+
'typeTable',
|
306
|
+
typeContext ? 'where ' + typeContext : '',
|
307
|
+
ASSERTED_TYPE_PARTITION
|
308
|
+
],
|
309
|
+
[
|
310
|
+
quoted_table,
|
311
|
+
'quoted',
|
312
|
+
quotedContext ? 'where ' + quotedContext : '',
|
313
|
+
QUOTED_PARTITION
|
314
|
+
],
|
315
|
+
[
|
316
|
+
asserted_table,
|
317
|
+
'asserted',
|
318
|
+
assertedContext ? 'where ' + assertedContext : '',
|
319
|
+
ASSERTED_NON_TYPE_PARTITION
|
320
|
+
],
|
321
|
+
[
|
322
|
+
literal_table,
|
323
|
+
'literal',
|
324
|
+
literalContext ? 'where ' + literalContext : '',
|
325
|
+
ASSERTED_LITERAL_PARTITION
|
326
|
+
],
|
327
|
+
]
|
328
|
+
q=unionSELECT(selects, :distinct => true, :select_type => COUNT_SELECT)
|
329
|
+
else
|
330
|
+
selects = [
|
331
|
+
[
|
332
|
+
asserted_type_table,
|
333
|
+
'typeTable',
|
334
|
+
typeContext ? 'where ' + typeContext : '',
|
335
|
+
ASSERTED_TYPE_PARTITION
|
336
|
+
],
|
337
|
+
[
|
338
|
+
asserted_table,
|
339
|
+
'asserted',
|
340
|
+
assertedContext ? 'where ' + assertedContext : '',
|
341
|
+
ASSERTED_NON_TYPE_PARTITION
|
342
|
+
],
|
343
|
+
[
|
344
|
+
literal_table,
|
345
|
+
'literal',
|
346
|
+
literalContext ? 'where ' + literalContext : '',
|
347
|
+
ASSERTED_LITERAL_PARTITION
|
348
|
+
],
|
349
|
+
]
|
350
|
+
q=unionSELECT(selects, :select_type => COUNT_SELECT)
|
351
|
+
end
|
352
|
+
|
353
|
+
count = 0
|
354
|
+
executeSQL(self._normalizeSQLCmd(q), parameters) do |row|
|
355
|
+
count += row[0].to_i
|
356
|
+
end
|
357
|
+
count
|
358
|
+
end
|
359
|
+
|
360
|
+
# Contexts containing the triple (no matching), or total number of contexts in store
|
361
|
+
def contexts(triple = nil)
|
362
|
+
parameters = []
|
363
|
+
|
364
|
+
if triple
|
365
|
+
subject, predicate, object = triple.subject, triple.predicate, triple.object
|
366
|
+
if predicate == RDF_TYPE
|
367
|
+
# select from asserted rdf:type partition and quoted table (if a context is specified)
|
368
|
+
clauseString, *params = self.buildClause('typeTable',triple,nil, true)
|
369
|
+
parameters += params
|
370
|
+
selects = [
|
371
|
+
[
|
372
|
+
asserted_type_table,
|
373
|
+
'typeTable',
|
374
|
+
clauseString,
|
375
|
+
ASSERTED_TYPE_PARTITION
|
376
|
+
],
|
377
|
+
]
|
378
|
+
#elsif predicate.is_a?(REGEXTerm) && predicate.compiledExpr.match(RDF_TYPE) || predicate.nil?
|
379
|
+
elsif predicate.nil?
|
380
|
+
# Select from quoted partition (if context is specified), literal partition if (obj is Literal or None) and asserted non rdf:type partition (if obj is URIRef or None)
|
381
|
+
clauseString, *params = self.buildClause('typeTable',Triple.new(subject, RDF_TYPE, object),nil, true)
|
382
|
+
parameters += params
|
383
|
+
selects = [
|
384
|
+
[
|
385
|
+
asserted_type_table,
|
386
|
+
'typeTable',
|
387
|
+
clauseString,
|
388
|
+
ASSERTED_TYPE_PARTITION
|
389
|
+
],
|
390
|
+
]
|
391
|
+
|
392
|
+
if !STRONGLY_TYPED_TERMS || triple.object.is_a?(Literal) || triple.object.nil?
|
393
|
+
clauseString, *params = self.buildClause('literal',triple)
|
394
|
+
parameters += params
|
395
|
+
selects += [
|
396
|
+
[
|
397
|
+
literal_table,
|
398
|
+
'literal',
|
399
|
+
clauseString,
|
400
|
+
ASSERTED_LITERAL_PARTITION
|
401
|
+
]
|
402
|
+
]
|
403
|
+
end
|
404
|
+
if !object.is_a?(Literal) || object.nil?
|
405
|
+
clauseString, *params = self.buildClause('asserted',triple)
|
406
|
+
parameters += params
|
407
|
+
selects += [
|
408
|
+
[
|
409
|
+
asserted_table,
|
410
|
+
'asserted',
|
411
|
+
clauseString,
|
412
|
+
ASSERTED_NON_TYPE_PARTITION
|
413
|
+
]
|
414
|
+
]
|
415
|
+
end
|
416
|
+
elsif predicate
|
417
|
+
# select from asserted non rdf:type partition (optionally), quoted partition (if context is speciied), and literal partition (optionally)
|
418
|
+
selects = []
|
419
|
+
if !STRONGLY_TYPED_TERMS || object.is_a?(Literal) || object.nil?
|
420
|
+
clauseString, *params = self.buildClause('literal',triple)
|
421
|
+
parameters += params
|
422
|
+
selects += [
|
423
|
+
[
|
424
|
+
literal_table,
|
425
|
+
'literal',
|
426
|
+
clauseString,
|
427
|
+
ASSERTED_LITERAL_PARTITION
|
428
|
+
]
|
429
|
+
]
|
430
|
+
end
|
431
|
+
if !object.is_a?(Literal) || object.nil?
|
432
|
+
clauseString, *params = self.buildClause('asserted',triple)
|
433
|
+
parameters += params
|
434
|
+
selects += [
|
435
|
+
[
|
436
|
+
asserted_table,
|
437
|
+
'asserted',
|
438
|
+
clauseString,
|
439
|
+
ASSERTED_NON_TYPE_PARTITION
|
440
|
+
]
|
441
|
+
]
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
clauseString, *params = self.buildClause('quoted',triple)
|
446
|
+
parameters += params
|
447
|
+
selects += [
|
448
|
+
[
|
449
|
+
quoted_table,
|
450
|
+
'quoted',
|
451
|
+
clauseString,
|
452
|
+
QUOTED_PARTITION
|
453
|
+
]
|
454
|
+
]
|
455
|
+
q=unionSELECT(selects, :distinct => true, :select_type => CONTEXT_SELECT)
|
456
|
+
else
|
457
|
+
selects = [
|
458
|
+
[
|
459
|
+
asserted_type_table,
|
460
|
+
'typeTable',
|
461
|
+
'',
|
462
|
+
ASSERTED_TYPE_PARTITION
|
463
|
+
],
|
464
|
+
[
|
465
|
+
quoted_table,
|
466
|
+
'quoted',
|
467
|
+
'',
|
468
|
+
QUOTED_PARTITION
|
469
|
+
],
|
470
|
+
[
|
471
|
+
asserted_table,
|
472
|
+
'asserted',
|
473
|
+
'',
|
474
|
+
ASSERTED_NON_TYPE_PARTITION
|
475
|
+
],
|
476
|
+
[
|
477
|
+
literal_table,
|
478
|
+
'literal',
|
479
|
+
'',
|
480
|
+
ASSERTED_LITERAL_PARTITION
|
481
|
+
],
|
482
|
+
]
|
483
|
+
end
|
484
|
+
|
485
|
+
results = []
|
486
|
+
q=unionSELECT(selects, :distinct => true, :select_type => CONTEXT_SELECT)
|
487
|
+
executeSQL(_normalizeSQLCmd(q), parameters) do |row|
|
488
|
+
id, termComb = row
|
489
|
+
|
490
|
+
termCombString = REVERSE_TERM_COMBINATIONS[termComb.to_i]
|
491
|
+
subjTerm, predTerm, objTerm, ctxTerm = termCombString.chars.to_a
|
492
|
+
|
493
|
+
graphKlass, idKlass = constructGraph(ctxTerm)
|
494
|
+
results << graphKlass.new(:store => self, :identifier => idKlass.new(id))
|
495
|
+
end
|
496
|
+
results
|
497
|
+
end
|
498
|
+
|
499
|
+
# Namespace persistence interface implementation
|
500
|
+
#
|
501
|
+
# Bind namespace to store, returns bound namespace
|
502
|
+
def bind(namespace)
|
503
|
+
executeSQL("INSERT INTO #{namespace_binds} VALUES (?, ?)", namespace.prefix, namespace.uri)
|
504
|
+
# May throw exception, should be handled in driver-specific class
|
505
|
+
|
506
|
+
namespace
|
507
|
+
end
|
508
|
+
|
509
|
+
# Namespace for prefix
|
510
|
+
def namespace(prefix)
|
511
|
+
executeSQL("SELECT uri FROM #{namespace_binds} WHERE prefix=?", prefix) do |row|
|
512
|
+
return Namespace.new(row[0], prefix)
|
513
|
+
end
|
514
|
+
nil
|
515
|
+
end
|
516
|
+
|
517
|
+
# Prefix for namespace
|
518
|
+
def prefix(namespace)
|
519
|
+
uri = namespace.is_a?(Namespace) ? namespace.uri.to_s : namespace
|
520
|
+
executeSQL("SELECT prefix FROM #{namespace_binds} WHERE uri=?", uri) do |row|
|
521
|
+
return row[0]
|
522
|
+
end
|
523
|
+
nil
|
524
|
+
end
|
525
|
+
|
526
|
+
# List of namespace bindings, as a hash
|
527
|
+
def nsbinding
|
528
|
+
namespaces = []
|
529
|
+
executeSQL("SELECT prefix, uri FROM #{namespace_binds}") do |row|
|
530
|
+
namespaces << Namespace.new(row[1], row[0])
|
531
|
+
end
|
532
|
+
namespaces
|
533
|
+
end
|
534
|
+
|
535
|
+
# Transactional interfaces
|
536
|
+
def commit; @db.commit; end
|
537
|
+
|
538
|
+
def rollback; @db.rollback; end
|
539
|
+
|
540
|
+
protected
|
541
|
+
def quoted_table; "#{@internedId}_quoted_statements"; end
|
542
|
+
def asserted_table; "#{@internedId}_asserted_statements"; end
|
543
|
+
def asserted_type_table; "#{@internedId}_type_statements"; end
|
544
|
+
def literal_table; "#{@internedId}_literal_statements"; end
|
545
|
+
def namespace_binds; "#{@internedId}_namespace_binds"; end
|
546
|
+
|
547
|
+
def remove_context(identifier)
|
548
|
+
executeSQL("SET AUTOCOMMIT=0") if @autocommit_default
|
549
|
+
|
550
|
+
%w(quoted asserted type literal)
|
551
|
+
[quoted_table,asserted_table,asserted_type_table,literal_table].each do |table|
|
552
|
+
clauseString, *params = self.buildContextClause(identifier,table)
|
553
|
+
executeSQL(
|
554
|
+
_normalizeSQLCmd("DELETE from #{table} where #{clauseString}"),
|
555
|
+
params
|
556
|
+
)
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
# This takes the query string and parameters and (depending on the SQL implementation) either fill in
|
561
|
+
# the parameter in-place or pass it on to the DB impl (if it supports this).
|
562
|
+
# The default (here) is to fill the parameters in-place surrounding each param with quote characters
|
563
|
+
#
|
564
|
+
# Yields each row
|
565
|
+
def executeSQL(qStr, *params, &block)
|
566
|
+
@db.execute(qStr, *params, &block)
|
567
|
+
end
|
568
|
+
|
569
|
+
# Escape backslashes and single quotes
|
570
|
+
def escapeQuotes(qstr)
|
571
|
+
qstr.nil? ? "" : qstr.gsub("\\","\\\\").gsub("'", "\\'")
|
572
|
+
end
|
573
|
+
|
574
|
+
# Normalize a SQL command before executing it. Commence unicode black magic
|
575
|
+
def _normalizeSQLCmd(cmd)
|
576
|
+
cmd # XXX
|
577
|
+
end
|
578
|
+
|
579
|
+
#T akes a term and 'normalizes' it.
|
580
|
+
# Literals are escaped, Graphs are replaced with just their identifiers
|
581
|
+
def normalizeTerm(term)
|
582
|
+
case term
|
583
|
+
when Graph then normalizeTerm(term.identifier)
|
584
|
+
when Literal then escapeQuotes(term.to_n3)
|
585
|
+
when URIRef then term.to_s.rdf_escape
|
586
|
+
when BNode then term.to_s
|
587
|
+
else term
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
# Builds an insert command for a type table
|
592
|
+
# Returns string and list of parameters
|
593
|
+
def buildTypeSQLCommand(member,klass,context)
|
594
|
+
[
|
595
|
+
"INSERT INTO #{asserted_type_table} VALUES (?, ?, ?, ?)",
|
596
|
+
normalizeTerm(member),
|
597
|
+
normalizeTerm(klass),
|
598
|
+
normalizeTerm(context),
|
599
|
+
type2TermCombination(member, klass, context)
|
600
|
+
]
|
601
|
+
end
|
602
|
+
|
603
|
+
# Builds an insert command for literal triples (statements where the object is a Literal)
|
604
|
+
# Returns string and list of parameters
|
605
|
+
def buildLiteralTripleSQLCommand(triple,context)
|
606
|
+
triplePattern = statement2TermCombination(triple,context)
|
607
|
+
[
|
608
|
+
"INSERT INTO #{literal_table} VALUES (?, ?, ?, ?, ?,?,?)",
|
609
|
+
normalizeTerm(triple.subject),
|
610
|
+
normalizeTerm(triple.predicate),
|
611
|
+
normalizeTerm(triple.object),
|
612
|
+
normalizeTerm(context),
|
613
|
+
triplePattern,
|
614
|
+
(triple.object.is_a?(Literal) ? triple.object.lang : NULL),
|
615
|
+
(triple.object.is_a?(Literal) ? triple.object.encoding.value.to_s : NULL),
|
616
|
+
]
|
617
|
+
end
|
618
|
+
|
619
|
+
# Builds an insert command for regular triple table
|
620
|
+
def buildTripleSQLCommand(triple,context,quoted)
|
621
|
+
stmt_table = quoted ? quoted_table : asserted_table
|
622
|
+
triplePattern = statement2TermCombination(triple,context)
|
623
|
+
|
624
|
+
if quoted
|
625
|
+
[
|
626
|
+
"INSERT INTO #{stmt_table} VALUES (?, ?, ?, ?, ?,?,?)",
|
627
|
+
normalizeTerm(triple.subject),
|
628
|
+
normalizeTerm(triple.predicate),
|
629
|
+
normalizeTerm(triple.object),
|
630
|
+
normalizeTerm(context),
|
631
|
+
triplePattern,
|
632
|
+
(triple.object.is_a?(Literal) ? triple.object.lang : NULL),
|
633
|
+
(triple.object.is_a?(Literal) ? triple.object.encoding.value.to_s : NULL),
|
634
|
+
]
|
635
|
+
else
|
636
|
+
[
|
637
|
+
"INSERT INTO #{stmt_table} VALUES (?, ?, ?, ?, ?)",
|
638
|
+
normalizeTerm(triple.subject),
|
639
|
+
normalizeTerm(triple.predicate),
|
640
|
+
normalizeTerm(triple.object),
|
641
|
+
normalizeTerm(context),
|
642
|
+
triplePattern
|
643
|
+
]
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
# Builds WHERE clauses for the supplied terms and, context
|
648
|
+
def buildClause(tableName,triple,context=nil,typeTable=false)
|
649
|
+
parameters=[]
|
650
|
+
if typeTable
|
651
|
+
rdf_type_memberClause = rdf_type_klassClause = rdf_type_contextClause = nil
|
652
|
+
|
653
|
+
# Subject clause
|
654
|
+
clauseParts = self.buildTypeMemberClause(self.normalizeTerm(triple.subject),tableName)
|
655
|
+
if clauseParts
|
656
|
+
rdf_type_memberClause = clauseParts.shift
|
657
|
+
parameters += clauseParts
|
658
|
+
end
|
659
|
+
|
660
|
+
# Object clause
|
661
|
+
clauseParts = self.buildTypeClassClause(self.normalizeTerm(triple.object),tableName)
|
662
|
+
if clauseParts
|
663
|
+
rdf_type_klassClause = clauseParts.shift
|
664
|
+
parameters += clauseParts
|
665
|
+
end
|
666
|
+
|
667
|
+
# Context clause
|
668
|
+
clauseParts = self.buildContextClause(context,tableName)
|
669
|
+
if clauseParts
|
670
|
+
rdf_type_contextClause = clauseParts.shift
|
671
|
+
parameters += clauseParts
|
672
|
+
end
|
673
|
+
|
674
|
+
clauses = [rdf_type_memberClause,rdf_type_klassClause,rdf_type_contextClause].compact
|
675
|
+
else
|
676
|
+
subjClause = predClause = objClause = contextClause = litDTypeClause = litLanguageClause = nil
|
677
|
+
|
678
|
+
# Subject clause
|
679
|
+
clauseParts = self.buildSubjClause(self.normalizeTerm(triple.subject),tableName)
|
680
|
+
if clauseParts
|
681
|
+
subjClause = clauseParts.shift
|
682
|
+
parameters += clauseParts
|
683
|
+
end
|
684
|
+
|
685
|
+
# Predicate clause
|
686
|
+
clauseParts = self.buildPredClause(self.normalizeTerm(triple.predicate),tableName)
|
687
|
+
if clauseParts
|
688
|
+
predClause = clauseParts.shift
|
689
|
+
parameters += clauseParts
|
690
|
+
end
|
691
|
+
|
692
|
+
# Object clause
|
693
|
+
clauseParts = self.buildObjClause(self.normalizeTerm(triple.object),tableName)
|
694
|
+
if clauseParts
|
695
|
+
objClause = clauseParts.shift
|
696
|
+
parameters += clauseParts
|
697
|
+
end
|
698
|
+
|
699
|
+
# Context clause
|
700
|
+
clauseParts = self.buildContextClause(context,tableName)
|
701
|
+
if clauseParts
|
702
|
+
contextClause = clauseParts.shift
|
703
|
+
parameters += clauseParts
|
704
|
+
end
|
705
|
+
|
706
|
+
# Datatype clause
|
707
|
+
clauseParts = self.buildLitDTypeClause(triple.object,tableName)
|
708
|
+
if clauseParts
|
709
|
+
litDTypeClause = clauseParts.shift
|
710
|
+
parameters += clauseParts
|
711
|
+
end
|
712
|
+
|
713
|
+
# Language clause
|
714
|
+
clauseParts = self.buildLitLanguageClause(triple.object,tableName)
|
715
|
+
if clauseParts
|
716
|
+
litLanguageClause = clauseParts.shift
|
717
|
+
parameters += clauseParts
|
718
|
+
end
|
719
|
+
|
720
|
+
clauses = [subjClause,predClause,objClause,contextClause,litDTypeClause,litLanguageClause].compact
|
721
|
+
end
|
722
|
+
|
723
|
+
clauseString = clauses.join(' and ')
|
724
|
+
clauseString = "WHERE #{clauseString}" unless clauseString.empty?
|
725
|
+
|
726
|
+
[clauseString] + parameters
|
727
|
+
end
|
728
|
+
|
729
|
+
def buildLitDTypeClause(obj,tableName)
|
730
|
+
"#{tableName}.objDatatype='#{obj.encoding.value}'" if obj.is_a?(Literal) && obj.encoding
|
731
|
+
end
|
732
|
+
|
733
|
+
def buildLitLanguageClause(obj,tableName)
|
734
|
+
"#{tableName}.objDatatype='#{obj.lang}'" if obj.is_a?(Literal) && obj.lang
|
735
|
+
end
|
736
|
+
|
737
|
+
# Stubs for Clause Functions that are overridden by specific implementations (MySQL vs SQLite for instance)
|
738
|
+
def buildSubjClause(subject,tableName); end
|
739
|
+
def buildPredClause(predicate,tableName); end
|
740
|
+
def buildObjClause(obj,tableName); end
|
741
|
+
def buildContextClause(context,tableName); end
|
742
|
+
def buildTypeMemberClause(subject,tableName); end
|
743
|
+
def buildTypeClassClause(obj,tableName); end
|
744
|
+
|
745
|
+
# Helper function for executing EXPLAIN on all dispatched SQL statements - for the pupose of analyzing
|
746
|
+
# index usage
|
747
|
+
def queryAnalysis(query)
|
748
|
+
end
|
749
|
+
|
750
|
+
# Helper function for building union all select statement
|
751
|
+
# @param [Array] select_components:: list of [table_name, table_alias, table_type, where_clause]
|
752
|
+
# @param [Hash] options:: Options
|
753
|
+
# <em>options[:distinct]</em>:: true or false
|
754
|
+
# <em>options[:select_type]</em>:: Defaults to TRIPLE_SELECT
|
755
|
+
def unionSELECT(selectComponents, options = {})
|
756
|
+
selectType = options[:select_type] || TRIPLE_SELECT
|
757
|
+
selects = []
|
758
|
+
|
759
|
+
selectComponents.each do |sc|
|
760
|
+
tableName, tableAlias, whereClause, tableType = sc
|
761
|
+
|
762
|
+
case
|
763
|
+
when selectType == COUNT_SELECT
|
764
|
+
selectString = "select count(*)"
|
765
|
+
tableSource = " from #{tableName} "
|
766
|
+
when selectType == CONTEXT_SELECT
|
767
|
+
selectString = "select #{tableAlias}.context, " +
|
768
|
+
"#{tableAlias}.termComb as termComb "
|
769
|
+
tableSource = " from #{tableName} as #{tableAlias} "
|
770
|
+
when FULL_TRIPLE_PARTITIONS.include?(tableType)
|
771
|
+
selectString = "select *"
|
772
|
+
tableSource = " from #{tableName} as #{tableAlias} "
|
773
|
+
when tableType == ASSERTED_TYPE_PARTITION
|
774
|
+
selectString = "select #{tableAlias}.member as subject, " +
|
775
|
+
"\"#{RDF_TYPE}\" as predicate, " +
|
776
|
+
"#{tableAlias}.klass as object, " +
|
777
|
+
"#{tableAlias}.context as context, " +
|
778
|
+
"#{tableAlias}.termComb as termComb, " +
|
779
|
+
"NULL as objLanguage, " +
|
780
|
+
"NULL as objDatatype"
|
781
|
+
tableSource = " from #{tableName} as #{tableAlias} "
|
782
|
+
when tableType == ASSERTED_NON_TYPE_PARTITION
|
783
|
+
selectString = "select *, NULL as objLanguage, NULL as objDatatype"
|
784
|
+
tableSource = " from #{tableName} as #{tableAlias} "
|
785
|
+
else
|
786
|
+
raise StoreException, "unionSELECT failed to find template: selectType = #{selectType}, tableType = #{tableType}"
|
787
|
+
end
|
788
|
+
|
789
|
+
selects << "#{selectString}#{tableSource}#{whereClause}"
|
790
|
+
end
|
791
|
+
|
792
|
+
orderStmt = selectType == TRIPLE_SELECT ? " order by subject, predicate, object" : ""
|
793
|
+
|
794
|
+
selects.join(options[:distinct] ? " union all ": " union ") + orderStmt
|
795
|
+
end
|
796
|
+
|
797
|
+
# Takes a tuple which represents an entry in a result set and
|
798
|
+
# converts it to a tuple of terms using the termComb integer
|
799
|
+
# to interpret how to instanciate each term
|
800
|
+
# tupleRt is an array containing one or more of:
|
801
|
+
# - subject
|
802
|
+
# - predicate
|
803
|
+
# - obj
|
804
|
+
# - rtContext
|
805
|
+
# - termComb
|
806
|
+
# - objLanguage
|
807
|
+
# - objDatatype
|
808
|
+
def extractTriple(tupleRt, hardCodedContext = nil)
|
809
|
+
subject, predicate, obj, rtContext, termComb, objLanguage, objDatatype = tupleRt
|
810
|
+
|
811
|
+
raise StoreException, "extractTriple: unknow termComb: '#{termComb}'" unless REVERSE_TERM_COMBINATIONS.has_key?(termComb.to_i)
|
812
|
+
|
813
|
+
context = rtContext || hardCodedContext
|
814
|
+
termCombString = REVERSE_TERM_COMBINATIONS[termComb.to_i]
|
815
|
+
subjTerm, predTerm, objTerm, ctxTerm = termCombString.chars.to_a
|
816
|
+
|
817
|
+
s = createTerm(subject, subjTerm)
|
818
|
+
p = createTerm(predicate, predTerm)
|
819
|
+
o = createTerm(obj, objTerm, objLanguage, objDatatype)
|
820
|
+
|
821
|
+
graphKlass, idKlass = constructGraph(ctxTerm)
|
822
|
+
return [Triple.new(s, p, o), graphKlass, idKlass, context]
|
823
|
+
end
|
824
|
+
|
825
|
+
# Takes a term value, and term type
|
826
|
+
# and Creates a term object. QuotedGraphs are instantiated differently
|
827
|
+
def createTerm(termString,termType,objLanguage=nil,objDatatype=nil)
|
828
|
+
case termType
|
829
|
+
when "L"
|
830
|
+
@literalCache[[termString, objLanguage, objDatatype]] ||= Literal.n3_encoded(termString, objLanguage, objDatatype)
|
831
|
+
# when "F"
|
832
|
+
# @otherCache[[termType, termString]] ||= QuotedGraph(:identifier => URIRef(termString), :store => self)
|
833
|
+
when "B"
|
834
|
+
@bnodeCache[termString] ||= BNode.new(termString)
|
835
|
+
when "U"
|
836
|
+
@uriCache[termString] || URIRef.new(termString)
|
837
|
+
# when "V"
|
838
|
+
else
|
839
|
+
raise StoreException.new("Unknown termType: #{termType}")
|
840
|
+
end
|
841
|
+
end
|
842
|
+
end
|
843
|
+
end
|