pho 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGES +12 -1
  2. data/Rakefile +2 -2
  3. data/doc/index.html +15 -1
  4. data/doc/rdoc/classes/Pho.html +14 -0
  5. data/doc/rdoc/classes/Pho/DatatypeProperty.html +12 -12
  6. data/doc/rdoc/classes/Pho/Etags.html +36 -36
  7. data/doc/rdoc/classes/Pho/Facet/Results.html +19 -19
  8. data/doc/rdoc/classes/Pho/Facet/Term.html +6 -6
  9. data/doc/rdoc/classes/Pho/FieldPredicateMap.html +90 -90
  10. data/doc/rdoc/classes/Pho/FieldWeighting.html +12 -12
  11. data/doc/rdoc/classes/Pho/Job.html +64 -64
  12. data/doc/rdoc/classes/Pho/Jobs.html +61 -61
  13. data/doc/rdoc/classes/Pho/Namespaces.html +6 -1
  14. data/doc/rdoc/classes/Pho/QueryProfile.html +61 -61
  15. data/doc/rdoc/classes/Pho/RDFCollection.html +71 -71
  16. data/doc/rdoc/classes/Pho/RDF_JSON.html +118 -0
  17. data/doc/rdoc/classes/Pho/RDF_JSON/SetAlgebra.html +240 -0
  18. data/doc/rdoc/classes/Pho/Snapshot.html +35 -35
  19. data/doc/rdoc/classes/Pho/Status.html +26 -26
  20. data/doc/rdoc/classes/Pho/Store.html +342 -264
  21. data/doc/rdoc/classes/Pho/Update.html +127 -0
  22. data/doc/rdoc/classes/Pho/Update/Changeset.html +520 -0
  23. data/doc/rdoc/classes/Pho/Update/ChangesetBuilder.html +330 -0
  24. data/doc/rdoc/classes/Pho/Update/Changesets.html +204 -0
  25. data/doc/rdoc/classes/Pho/Update/LiteralStatement.html +248 -0
  26. data/doc/rdoc/classes/Pho/Update/ResourceStatement.html +213 -0
  27. data/doc/rdoc/classes/Pho/Update/Statement.html +302 -0
  28. data/doc/rdoc/classes/String.html +146 -0
  29. data/doc/rdoc/created.rid +1 -1
  30. data/doc/rdoc/files/CHANGES.html +33 -2
  31. data/doc/rdoc/files/lib/pho/changeset_builder_rb.html +108 -0
  32. data/doc/rdoc/files/lib/pho/changeset_rb.html +108 -0
  33. data/doc/rdoc/files/lib/pho/job_rb.html +1 -1
  34. data/doc/rdoc/files/lib/pho/query_profile_rb.html +1 -1
  35. data/doc/rdoc/files/lib/pho/rdf_json_rb.html +101 -0
  36. data/doc/rdoc/files/lib/pho/store_rb.html +1 -1
  37. data/doc/rdoc/files/lib/pho_rb.html +4 -1
  38. data/doc/rdoc/fr_class_index.html +10 -0
  39. data/doc/rdoc/fr_file_index.html +3 -0
  40. data/doc/rdoc/fr_method_index.html +140 -110
  41. data/lib/pho.rb +14 -1
  42. data/lib/pho/changeset.rb +312 -0
  43. data/lib/pho/changeset_builder.rb +118 -0
  44. data/lib/pho/job.rb +1 -1
  45. data/lib/pho/query_profile.rb +1 -1
  46. data/lib/pho/rdf_json.rb +81 -0
  47. data/lib/pho/store.rb +63 -25
  48. data/tests/tc_changeset.rb +273 -0
  49. data/tests/tc_changeset_builder.rb +151 -0
  50. data/tests/tc_changesets.rb +96 -0
  51. data/tests/tc_metabox.rb +20 -2
  52. data/tests/tc_query_profile.rb +4 -2
  53. data/tests/tc_rdf_json.rb +273 -0
  54. data/tests/tc_search.rb +5 -5
  55. data/tests/tc_sparql.rb +12 -0
  56. data/tests/ts_pho.rb +5 -1
  57. metadata +25 -3
@@ -0,0 +1,151 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'rexml/document'
6
+ require 'uri'
7
+
8
+ class ChangesetBuilderTest < Test::Unit::TestCase
9
+
10
+ SINGLE_TRIPLE_RESOURCE = <<-EOL
11
+ {
12
+ "http://www.example.org" : {
13
+ "http://www.example.org/ns/predicate" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ]
14
+ }
15
+ }
16
+ EOL
17
+
18
+ SINGLE_TRIPLE_LITERAL = <<-EOL
19
+ {
20
+ "http://www.example.org" : {
21
+ "http://www.example.org/ns/predicate" : [ { "value" : "Title", "type" : "literal" } ]
22
+ }
23
+ }
24
+ EOL
25
+
26
+ TWO_TRIPLES = <<-EOL
27
+ {
28
+ "http://www.example.org" : {
29
+ "http://www.example.org/ns/resource" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ],
30
+ "http://www.example.org/ns/literal" : [ { "value" : "Title", "type" : "literal" } ]
31
+ }
32
+ }
33
+ EOL
34
+
35
+ SOME_TRIPLES = <<-EOL
36
+ {
37
+ "http://www.example.org" : {
38
+ "http://www.example.org/ns/resource" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ],
39
+ "http://www.example.org/ns/property" : [ { "value" : "Blah blah blah", "type" : "literal" } ]
40
+ },
41
+ "http://www.example.org/other" : {
42
+ "http://www.example.org/ns/property" : [ { "value" : "Something", "type" : "literal" } ]
43
+ }
44
+ }
45
+ EOL
46
+
47
+
48
+ def test_build_with_single_triple1
49
+
50
+ cs = Pho::Update::ChangesetBuilder.build("http://www.example.org", JSON.parse("{}"), JSON.parse( SINGLE_TRIPLE_RESOURCE ) )
51
+ assert_not_nil(cs)
52
+ assert_equal("http://www.example.org", cs.subject_of_change)
53
+ assert_equal(0, cs.removals.length)
54
+ assert_equal(1, cs.additions.length)
55
+ s = cs.additions[0]
56
+ assert_equal("http://www.example.org", s.subject)
57
+ assert_equal("http://www.example.org/ns/predicate", s.predicate)
58
+ assert_equal("http://www.example.org/page", s.object)
59
+ end
60
+
61
+ def test_build_with_single_triple2
62
+
63
+ cs = Pho::Update::ChangesetBuilder.build("http://www.example.org", JSON.parse("{}"), JSON.parse( SINGLE_TRIPLE_LITERAL ) )
64
+ assert_not_nil(cs)
65
+ assert_equal("http://www.example.org", cs.subject_of_change)
66
+ assert_equal(0, cs.removals.length)
67
+ assert_equal(1, cs.additions.length)
68
+ s = cs.additions[0]
69
+ assert_equal("http://www.example.org", s.subject)
70
+ assert_equal("http://www.example.org/ns/predicate", s.predicate)
71
+ assert_equal("Title", s.object)
72
+
73
+ end
74
+
75
+ def test_build_with_additions_and_removals
76
+
77
+ cs = Pho::Update::ChangesetBuilder.build("http://www.example.org", JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse( TWO_TRIPLES ) )
78
+ assert_not_nil(cs)
79
+ assert_equal("http://www.example.org", cs.subject_of_change)
80
+ assert_equal(1, cs.removals.length)
81
+ assert_equal(2, cs.additions.length)
82
+ s = cs.removals[0]
83
+ assert_equal("http://www.example.org", s.subject)
84
+ assert_equal("http://www.example.org/ns/predicate", s.predicate)
85
+ assert_equal("Title", s.object)
86
+ s = cs.additions[0]
87
+ assert_equal("http://www.example.org", s.subject)
88
+ assert_equal("http://www.example.org/ns/resource", s.predicate)
89
+ assert_equal("http://www.example.org/page", s.object)
90
+ s = cs.additions[1]
91
+ assert_equal("http://www.example.org", s.subject)
92
+ assert_equal("http://www.example.org/ns/literal", s.predicate)
93
+ assert_equal("Title", s.object)
94
+
95
+ end
96
+
97
+ def test_create_statements
98
+ statements = Pho::Update::ChangesetBuilder.create_statements( JSON.parse(SINGLE_TRIPLE_RESOURCE) )
99
+ assert_not_nil(statements)
100
+ assert(1, statements.length)
101
+
102
+ s = statements[0]
103
+
104
+ assert_equal("http://www.example.org", s.subject)
105
+ assert_equal("http://www.example.org/ns/predicate", s.predicate)
106
+ assert_equal("http://www.example.org/page", s.object)
107
+
108
+ end
109
+
110
+ def test_create_statements2
111
+ statements = Pho::Update::ChangesetBuilder.create_statements( JSON.parse(TWO_TRIPLES) )
112
+ assert_not_nil(statements)
113
+ assert(2, statements.length)
114
+ end
115
+
116
+ def test_batch_changeset
117
+ changesets = Pho::Update::ChangesetBuilder.build_batch(JSON.parse( TWO_TRIPLES ), JSON.parse( SOME_TRIPLES ) )
118
+ assert_equal(2, changesets.length)
119
+ first_uri_changes = changesets[0]
120
+ assert_equal("http://www.example.org", first_uri_changes.subject_of_change)
121
+ assert_equal(nil, first_uri_changes.creator_name)
122
+ assert_equal(nil, first_uri_changes.change_reason)
123
+ removals = first_uri_changes.removals
124
+ assert_equal(1, removals.length)
125
+ assert_equal("http://www.example.org/ns/literal", removals[0].predicate)
126
+ additions = first_uri_changes.additions
127
+ assert_equal(1, additions.length)
128
+ assert_equal("http://www.example.org/ns/property", additions[0].predicate)
129
+
130
+ second_uri_changes = changesets[1]
131
+ assert_equal("http://www.example.org/other", second_uri_changes.subject_of_change)
132
+ assert_equal(nil, second_uri_changes.creator_name)
133
+ assert_equal(nil, second_uri_changes.change_reason)
134
+ removals = second_uri_changes.removals
135
+ assert_equal(0, removals.length)
136
+ additions = second_uri_changes.additions
137
+ assert_equal(1, additions.length)
138
+ assert_equal("http://www.example.org/ns/property", additions[0].predicate)
139
+
140
+ end
141
+
142
+ def test_batch_changeset_with_change_description
143
+ changesets = Pho::Update::ChangesetBuilder.build_batch(JSON.parse( TWO_TRIPLES ), JSON.parse( SOME_TRIPLES ), "Bob Bobson", "Because I can" )
144
+ assert_equal(2, changesets.length)
145
+ first_uri_changes = changesets[0]
146
+ assert_equal("http://www.example.org", first_uri_changes.subject_of_change)
147
+ assert_equal("Bob Bobson", first_uri_changes.creator_name)
148
+ assert_equal("Because I can", first_uri_changes.change_reason)
149
+
150
+ end
151
+ end
@@ -0,0 +1,96 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'rexml/document'
6
+ require 'uri'
7
+
8
+ class ChangesetsTest < Test::Unit::TestCase
9
+ SINGLE_TRIPLE_RESOURCE = <<-EOL
10
+ {
11
+ "http://www.example.org" : {
12
+ "http://www.example.org/ns/predicate" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ]
13
+ }
14
+ }
15
+ EOL
16
+
17
+ SINGLE_TRIPLE_LITERAL = <<-EOL
18
+ {
19
+ "http://www.example.org" : {
20
+ "http://www.example.org/ns/predicate" : [ { "value" : "Title", "type" : "literal" } ]
21
+ }
22
+ }
23
+ EOL
24
+
25
+ def test_submit_all
26
+ mc = mock()
27
+ mc.expects(:set_auth)
28
+ mc.expects(:post).with("http://api.talis.com/stores/testing/meta", anything, {"Content-Type" => "application/vnd.talis.changeset+xml"} )
29
+
30
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
31
+
32
+ changesets = Array.new
33
+ changesets << Pho::Update::Changeset.new("http://www.example.org/my-resource") do |c|
34
+ c.add_removal( Pho::Update::Statement.create_resource("http://www.example.org/my-resource", "http://xmlns.com/foaf/0.1/homePage", "http://www.example.org/page") )
35
+ end
36
+
37
+ changesets << Pho::Update::Changeset.new("http://www.example.org/my-resource") do |c|
38
+ c.add_removal( Pho::Update::Statement.create_resource("http://www.example.org/my-resource", "http://xmlns.com/foaf/0.1/name", "Name") )
39
+ end
40
+
41
+ resp = Pho::Update::Changesets.submit_all(changesets, store)
42
+
43
+ end
44
+
45
+ def test_all_to_rdf
46
+
47
+ changesets = Array.new
48
+ changesets << Pho::Update::Changeset.new("http://www.example.org/my-resource") do |c|
49
+ c.add_removal( Pho::Update::Statement.create_resource("http://www.example.org/my-resource", "http://xmlns.com/foaf/0.1/homePage", "http://www.example.org/page") )
50
+ end
51
+
52
+ changesets << Pho::Update::Changeset.new("http://www.example.org/my-resource") do |c|
53
+ c.add_removal( Pho::Update::Statement.create_resource("http://www.example.org/my-resource", "http://xmlns.com/foaf/0.1/name", "Name") )
54
+ end
55
+
56
+ rdf = Pho::Update::Changesets.all_to_rdf(changesets)
57
+
58
+ doc = REXML::Document.new(rdf)
59
+ root = doc.root
60
+ assert_equal("RDF", root.name)
61
+ assert_equal("http://www.w3.org/1999/02/22-rdf-syntax-ns#", root.namespace)
62
+ count = 0
63
+ REXML::XPath.each(root, "cs:ChangeSet", Pho::Namespaces::MAPPING) do |cs|
64
+ count += 1
65
+ end
66
+ assert_equal(2, count)
67
+ end
68
+
69
+ # def test_build_with_single_triple1
70
+ #
71
+ # cs = Pho::Update::Changesets.build(nil, SINGLE_TRIPLE_RESOURCE)
72
+ # assert_not_nil(cs)
73
+ # assert_equal("http://www.example.org", cs.subject_of_change)
74
+ # assert_nil(cs.removal)
75
+ # assert_not_nil(cs.addition)
76
+ # s = cs.addition
77
+ # assert_equal("http://www.example.org", s.subject)
78
+ # assert_equal("http://www.example.org/predicate", s.predicate)
79
+ # assert_equal("http://www.example.org/page", s.object)
80
+ # end
81
+ #
82
+ # def test_build_with_single_triple2
83
+ #
84
+ # cs = Pho::Update::Changesets.build(nil, SINGLE_TRIPLE_LITERAL)
85
+ # assert_not_nil(cs)
86
+ # assert_equal("http://www.example.org", cs.subject_of_change)
87
+ # assert_nil(cs.removal)
88
+ # assert_not_nil(cs.addition)
89
+ # s = cs.addition
90
+ # assert_equal("http://www.example.org", s.subject)
91
+ # assert_equal("http://www.example.org/predicate", s.predicate)
92
+ # assert_equal("Title", s.object)
93
+ #
94
+ # end
95
+
96
+ end
@@ -21,7 +21,15 @@ class MetaboxTest < Test::Unit::TestCase
21
21
  store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
22
22
  store.store_data("data")
23
23
  end
24
-
24
+
25
+ def test_store_data_in_graph
26
+ mc = mock()
27
+ mc.expects(:set_auth)
28
+ mc.expects(:post).with("http://api.talis.com/stores/testing/meta/graphs/1", "data", {"Content-Type" => "application/rdf+xml"} )
29
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
30
+ store.store_data("data", "1")
31
+ end
32
+
25
33
  def test_store_file
26
34
  mc = mock()
27
35
  mc.expects(:set_auth)
@@ -42,7 +50,17 @@ class MetaboxTest < Test::Unit::TestCase
42
50
  store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
43
51
  store.store_url( "http://www.example.org" )
44
52
  end
45
-
53
+
54
+ def test_store_url_in_graph
55
+ mc = mock()
56
+ mc.expects(:set_auth)
57
+ mc.expects(:get).with("http://www.example.org", nil, {"Accept" => "application/rdf+xml"}).returns( HTTP::Message.new_response("data") )
58
+ mc.expects(:post).with("http://api.talis.com/stores/testing/meta/graphs/1", "data", {"Content-Type" => "application/rdf+xml"} )
59
+
60
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
61
+ store.store_url( "http://www.example.org", nil, "1" )
62
+ end
63
+
46
64
  def test_describe_with_default_mimetype
47
65
  mc = mock()
48
66
  mc.expects(:set_auth)
@@ -55,7 +55,7 @@ EOL
55
55
 
56
56
  assert_has_single_property_with_literal(root, "frm:name", "title")
57
57
  assert_has_single_property_with_literal(root, "bf:weight", "10")
58
-
58
+
59
59
  end
60
60
 
61
61
 
@@ -86,10 +86,12 @@ EOL
86
86
 
87
87
  fpmap = children[0]
88
88
  assert_has_single_property_with_literal(fpmap, "rdfs:label", "test query profile")
89
+
90
+ assert_equal(3, fpmap.get_elements("bf:fieldWeight").length )
89
91
 
90
92
  end
91
93
 
92
- def test_get_query_profile_from_store
94
+ def test_get_queryprofile_from_store
93
95
  mc = mock()
94
96
  mc.expects(:set_auth)
95
97
  mc.expects(:get).with("http://api.talis.com/stores/testing/config/queryprofiles/1", anything, {"Accept" => "application/json"})
@@ -0,0 +1,273 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'rexml/document'
6
+ require 'uri'
7
+
8
+ class RDFJSONTest < Test::Unit::TestCase
9
+ SINGLE_TRIPLE_RESOURCE = <<-EOL
10
+ {
11
+ "http://www.example.org" : {
12
+ "http://www.example.org/ns/resource" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ]
13
+ }
14
+ }
15
+ EOL
16
+
17
+ SINGLE_TRIPLE_RESOURCE2 = <<-EOL
18
+ {
19
+ "http://www.example.org" : {
20
+ "http://www.example.org/ns/resource" : [ { "value" : "http://www.example.org/other-page", "type" : "uri" } ]
21
+ }
22
+ }
23
+ EOL
24
+
25
+ SINGLE_TRIPLE_LITERAL = <<-EOL
26
+ {
27
+ "http://www.example.org" : {
28
+ "http://www.example.org/ns/literal" : [ { "value" : "Title", "type" : "literal" } ]
29
+ }
30
+ }
31
+ EOL
32
+
33
+ SINGLE_TRIPLE_LITERAL2 = <<-EOL
34
+ {
35
+ "http://www.example.org" : {
36
+ "http://www.example.org/ns/literal" : [ { "value" : "Other Title", "type" : "literal" } ]
37
+ }
38
+ }
39
+ EOL
40
+
41
+
42
+ SINGLE_TRIPLE_DIFF_TYPE = <<-EOL
43
+ {
44
+ "http://www.example.org" : {
45
+ "http://www.example.org/ns/literal" : [ { "value" : "http://www.example.com", "type" : "uri" } ]
46
+ }
47
+ }
48
+ EOL
49
+
50
+ TWO_TRIPLES = <<-EOL
51
+ {
52
+ "http://www.example.org" : {
53
+ "http://www.example.org/ns/resource" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ],
54
+ "http://www.example.org/ns/literal" : [ { "value" : "Title", "type" : "literal" } ]
55
+ }
56
+ }
57
+ EOL
58
+
59
+ REPEATED_TRIPLES = <<-EOL
60
+ {
61
+ "http://www.example.org" : {
62
+ "http://www.example.org/ns/literal" : [ { "value" : "Title", "type" : "literal" }, { "value" : "Other Title", "type" : "literal" } ]
63
+ }
64
+ }
65
+ EOL
66
+
67
+ SINGLE_TRIPLE_LITERAL_ENGLISH = <<-EOL
68
+ {
69
+ "http://www.example.org" : {
70
+ "http://www.example.org/ns/literal" : [ { "value" : "English", "type" : "literal", "lang" : "en" } ]
71
+ }
72
+ }
73
+ EOL
74
+
75
+ SINGLE_TRIPLE_LITERAL_FRENCH = <<-EOL
76
+ {
77
+ "http://www.example.org" : {
78
+ "http://www.example.org/ns/literal" : [ { "value" : "French", "type" : "literal", "lang" : "fr" } ]
79
+ }
80
+ }
81
+ EOL
82
+
83
+ SINGLE_TYPED_TRIPLE_INT = <<-EOL
84
+ {
85
+ "http://www.example.org" : {
86
+ "http://www.example.org/ns/literal" : [ { "value" : "1", "type" : "literal", "datatype" : "http://www.w3.org/2001/XMLSchema#int" } ]
87
+ }
88
+ }
89
+ EOL
90
+
91
+ SINGLE_TYPED_TRIPLE_FLOAT = <<-EOL
92
+ {
93
+ "http://www.example.org" : {
94
+ "http://www.example.org/ns/literal" : [ { "value" : "2.5", "type" : "literal", "datatype" : "http://www.w3.org/2001/XMLSchema#float" } ]
95
+ }
96
+ }
97
+ EOL
98
+
99
+
100
+ def test_minus_with_iso_graphs()
101
+
102
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_RESOURCE), JSON.parse(SINGLE_TRIPLE_RESOURCE) )
103
+ assert_not_nil(difference)
104
+ assert_equal(0, difference.keys.length)
105
+
106
+ end
107
+
108
+ def test_minus_with_single_resource_value_change()
109
+
110
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_RESOURCE), JSON.parse(SINGLE_TRIPLE_RESOURCE2) )
111
+ assert_not_nil(difference)
112
+ assert_equal(1, difference.keys.length)
113
+ assert_equal( "http://www.example.org/page",
114
+ difference["http://www.example.org"]["http://www.example.org/ns/resource"][0]["value"] )
115
+
116
+ #reverse
117
+
118
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_RESOURCE2), JSON.parse(SINGLE_TRIPLE_RESOURCE) )
119
+ assert_not_nil(difference)
120
+ assert_equal(1, difference.keys.length)
121
+ assert_equal( "http://www.example.org/other-page",
122
+ difference["http://www.example.org"]["http://www.example.org/ns/resource"][0]["value"] )
123
+
124
+ end
125
+
126
+ def test_minus_with_single_literal_value_change()
127
+
128
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TRIPLE_LITERAL2) )
129
+ assert_not_nil(difference)
130
+ assert_equal(1, difference.keys.length)
131
+ assert_equal( "Title",
132
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
133
+
134
+ #reverse
135
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL2), JSON.parse(SINGLE_TRIPLE_LITERAL) )
136
+ assert_not_nil(difference)
137
+ assert_equal(1, difference.keys.length)
138
+ assert_equal( "Other Title",
139
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
140
+
141
+ end
142
+
143
+ def test_minus_with_different_typed_predicate_values()
144
+
145
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TRIPLE_DIFF_TYPE) )
146
+ assert_not_nil(difference)
147
+ assert_equal(1, difference.keys.length)
148
+ assert_equal( "Title",
149
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
150
+
151
+ #reverse
152
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_DIFF_TYPE), JSON.parse(SINGLE_TRIPLE_LITERAL) )
153
+ assert_not_nil(difference)
154
+ assert_equal(1, difference.keys.length)
155
+ assert_equal( "http://www.example.com",
156
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
157
+
158
+ end
159
+
160
+ def test_minus_with_different_size_graphs()
161
+
162
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_RESOURCE), JSON.parse(TWO_TRIPLES) )
163
+ assert_not_nil(difference)
164
+ assert_equal(0, difference.keys.length)
165
+
166
+ #reverse
167
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(TWO_TRIPLES), JSON.parse(SINGLE_TRIPLE_RESOURCE) )
168
+ assert_not_nil(difference)
169
+ assert_equal(1, difference.keys.length)
170
+ assert_equal( "Title",
171
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
172
+
173
+ end
174
+
175
+ def test_minus_with_repeated_properties()
176
+
177
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(REPEATED_TRIPLES) )
178
+ assert_not_nil(difference)
179
+ assert_equal(0, difference.keys.length)
180
+
181
+ #reverse
182
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(REPEATED_TRIPLES), JSON.parse(SINGLE_TRIPLE_LITERAL) )
183
+ assert_not_nil(difference)
184
+ assert_equal(1, difference.keys.length)
185
+ assert_equal( "Other Title",
186
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
187
+
188
+ end
189
+
190
+ def test_minus_with_language_qualified_literals()
191
+
192
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TRIPLE_LITERAL) )
193
+ assert_not_nil(difference)
194
+ assert_equal(0, difference.keys.length)
195
+
196
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH), JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH) )
197
+ assert_not_nil(difference)
198
+ assert_equal(0, difference.keys.length)
199
+
200
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH) )
201
+ assert_not_nil(difference)
202
+ assert_equal(1, difference.keys.length)
203
+ assert_equal( "Title",
204
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
205
+
206
+ #reverse no lang and english
207
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH), JSON.parse(SINGLE_TRIPLE_LITERAL) )
208
+ assert_not_nil(difference)
209
+ assert_equal(1, difference.keys.length)
210
+ assert_equal( "English",
211
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
212
+ assert_equal( "en",
213
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["lang"] )
214
+
215
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH), JSON.parse(SINGLE_TRIPLE_LITERAL_FRENCH) )
216
+ assert_not_nil(difference)
217
+ assert_equal(1, difference.keys.length)
218
+ assert_equal( "English",
219
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
220
+ assert_equal( "en",
221
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["lang"] )
222
+
223
+ #reverse no lang and english
224
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL_FRENCH), JSON.parse(SINGLE_TRIPLE_LITERAL_ENGLISH) )
225
+ assert_not_nil(difference)
226
+ assert_equal(1, difference.keys.length)
227
+ assert_equal( "French",
228
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
229
+ assert_equal( "fr",
230
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["lang"] )
231
+
232
+ end
233
+
234
+ def test_minus_with_typed_literals()
235
+
236
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TYPED_TRIPLE_INT), JSON.parse(SINGLE_TYPED_TRIPLE_INT) )
237
+ assert_not_nil(difference)
238
+ assert_equal(0, difference.keys.length)
239
+
240
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TRIPLE_LITERAL), JSON.parse(SINGLE_TYPED_TRIPLE_INT) )
241
+ assert_not_nil(difference)
242
+ assert_equal(1, difference.keys.length)
243
+ assert_equal( "Title",
244
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
245
+
246
+ #reverse no type and int
247
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TYPED_TRIPLE_INT), JSON.parse(SINGLE_TRIPLE_LITERAL) )
248
+ assert_not_nil(difference)
249
+ assert_equal(1, difference.keys.length)
250
+ assert_equal( "1",
251
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
252
+ assert_equal( "http://www.w3.org/2001/XMLSchema#int",
253
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["datatype"] )
254
+
255
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TYPED_TRIPLE_INT), JSON.parse(SINGLE_TYPED_TRIPLE_FLOAT) )
256
+ assert_not_nil(difference)
257
+ assert_equal(1, difference.keys.length)
258
+ assert_equal( "1",
259
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
260
+ assert_equal( "http://www.w3.org/2001/XMLSchema#int",
261
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["datatype"] )
262
+
263
+ #reverse float and int
264
+ difference = Pho::RDF_JSON::SetAlgebra.minus( JSON.parse(SINGLE_TYPED_TRIPLE_FLOAT), JSON.parse(SINGLE_TYPED_TRIPLE_INT) )
265
+ assert_not_nil(difference)
266
+ assert_equal(1, difference.keys.length)
267
+ assert_equal( "2.5",
268
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["value"] )
269
+ assert_equal( "http://www.w3.org/2001/XMLSchema#float",
270
+ difference["http://www.example.org"]["http://www.example.org/ns/literal"][0]["datatype"] )
271
+
272
+ end
273
+ end