rdf-n3 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -0
- data/History.txt +9 -0
- data/README.rdoc +4 -2
- data/Rakefile +37 -2
- data/VERSION +1 -1
- data/example.rb +1 -1
- data/lib/rdf/n3.rb +12 -5
- data/lib/rdf/n3/format.rb +0 -1
- data/lib/rdf/n3/patches/array_hacks.rb +46 -124
- data/lib/rdf/n3/patches/graph_properties.rb +34 -0
- data/lib/rdf/n3/patches/literal_hacks.rb +23 -0
- data/lib/rdf/n3/patches/literal_normalization.rb +120 -0
- data/lib/rdf/n3/patches/qname_hacks.rb +57 -0
- data/lib/rdf/n3/patches/rdf_escape.rb +3 -3
- data/lib/rdf/n3/patches/seq.rb +34 -0
- data/lib/rdf/n3/patches/uri_hacks.rb +19 -0
- data/lib/rdf/n3/reader.rb +110 -68
- data/lib/rdf/n3/reader/n3_grammar.rb +3876 -0
- data/lib/rdf/n3/{vocabulary.rb → vocab.rb} +0 -0
- data/lib/rdf/n3/writer.rb +444 -0
- data/rdf-n3.gemspec +38 -15
- data/script/console +8 -0
- data/script/parse +49 -0
- data/spec/cwm_spec.rb +13 -5
- data/spec/format_spec.rb +21 -0
- data/spec/literal_spec.rb +382 -0
- data/spec/matchers.rb +101 -0
- data/spec/n3reader_spec.rb +253 -185
- data/spec/rdf_helper.rb +115 -89
- data/spec/spec_helper.rb +39 -0
- data/spec/swap_spec.rb +24 -10
- data/spec/swap_test/n3parser.yml +193 -0
- data/spec/swap_test/regression.yml +226 -0
- data/spec/turtle_spec.rb +23 -8
- data/spec/writer_spec.rb +250 -0
- metadata +80 -22
- data/spec/swap_helper.rb +0 -136
- data/spec/triple_spec.rb +0 -236
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-n3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gregg Kellogg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-24 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -29,27 +29,29 @@ dependencies:
|
|
29
29
|
hash: 23
|
30
30
|
segments:
|
31
31
|
- 0
|
32
|
-
-
|
33
|
-
-
|
34
|
-
version: 0.
|
32
|
+
- 2
|
33
|
+
- 0
|
34
|
+
version: 0.2.0
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: treetop
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 7
|
46
46
|
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
47
49
|
- 0
|
48
|
-
version:
|
49
|
-
type: :
|
50
|
+
version: 1.4.0
|
51
|
+
type: :runtime
|
50
52
|
version_requirements: *id002
|
51
53
|
- !ruby/object:Gem::Dependency
|
52
|
-
name:
|
54
|
+
name: rspec
|
53
55
|
prerelease: false
|
54
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
57
|
none: false
|
@@ -63,21 +65,63 @@ dependencies:
|
|
63
65
|
type: :development
|
64
66
|
version_requirements: *id003
|
65
67
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
68
|
+
name: rdf-spec
|
67
69
|
prerelease: false
|
68
70
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
71
|
none: false
|
70
72
|
requirements:
|
71
73
|
- - ">="
|
72
74
|
- !ruby/object:Gem::Version
|
73
|
-
hash:
|
75
|
+
hash: 3
|
74
76
|
segments:
|
75
|
-
- 1
|
76
|
-
- 4
|
77
77
|
- 0
|
78
|
-
version:
|
78
|
+
version: "0"
|
79
79
|
type: :development
|
80
80
|
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rdf-rdfxml
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 23
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
- 2
|
93
|
+
- 0
|
94
|
+
version: 0.2.0
|
95
|
+
type: :development
|
96
|
+
version_requirements: *id005
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rdf-isomorphic
|
99
|
+
prerelease: false
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
type: :development
|
110
|
+
version_requirements: *id006
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yard
|
113
|
+
prerelease: false
|
114
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
type: :development
|
124
|
+
version_requirements: *id007
|
81
125
|
description: " RDF::N3 is an Notation-3 (n3-rdf) parser for Ruby using the RDF.rb library suite.\n"
|
82
126
|
email: gregg@kellogg-assoc.com
|
83
127
|
executables: []
|
@@ -100,15 +144,26 @@ files:
|
|
100
144
|
- lib/rdf/n3.rb
|
101
145
|
- lib/rdf/n3/format.rb
|
102
146
|
- lib/rdf/n3/patches/array_hacks.rb
|
147
|
+
- lib/rdf/n3/patches/graph_properties.rb
|
148
|
+
- lib/rdf/n3/patches/literal_hacks.rb
|
149
|
+
- lib/rdf/n3/patches/literal_normalization.rb
|
150
|
+
- lib/rdf/n3/patches/qname_hacks.rb
|
103
151
|
- lib/rdf/n3/patches/rdf_escape.rb
|
152
|
+
- lib/rdf/n3/patches/seq.rb
|
153
|
+
- lib/rdf/n3/patches/uri_hacks.rb
|
104
154
|
- lib/rdf/n3/reader.rb
|
105
155
|
- lib/rdf/n3/reader/n3_grammar.rb
|
106
156
|
- lib/rdf/n3/reader/n3_grammar.treetop
|
107
157
|
- lib/rdf/n3/version.rb
|
108
|
-
- lib/rdf/n3/
|
158
|
+
- lib/rdf/n3/vocab.rb
|
109
159
|
- lib/rdf/n3/writer.rb
|
110
160
|
- rdf-n3.gemspec
|
161
|
+
- script/console
|
162
|
+
- script/parse
|
111
163
|
- spec/cwm_spec.rb
|
164
|
+
- spec/format_spec.rb
|
165
|
+
- spec/literal_spec.rb
|
166
|
+
- spec/matchers.rb
|
112
167
|
- spec/n3reader_spec.rb
|
113
168
|
- spec/rdf_helper.rb
|
114
169
|
- spec/rdfcore/Manifest.rdf
|
@@ -465,7 +520,6 @@ files:
|
|
465
520
|
- spec/rdfcore/xmlsch-02/test003.rdf
|
466
521
|
- spec/spec.opts
|
467
522
|
- spec/spec_helper.rb
|
468
|
-
- spec/swap_helper.rb
|
469
523
|
- spec/swap_spec.rb
|
470
524
|
- spec/swap_test/.DS_Store
|
471
525
|
- spec/swap_test/animal.rdf
|
@@ -500,6 +554,7 @@ files:
|
|
500
554
|
- spec/swap_test/n3/n3parser.tests_n3_10019.nt
|
501
555
|
- spec/swap_test/n3/n3parser.tests_n3_10020.nt
|
502
556
|
- spec/swap_test/n3parser.tests
|
557
|
+
- spec/swap_test/n3parser.yml
|
503
558
|
- spec/swap_test/nodeID/classes.n3
|
504
559
|
- spec/swap_test/nodeID/classes.ref.rdf
|
505
560
|
- spec/swap_test/nodeID/ex1.rdf
|
@@ -539,6 +594,7 @@ files:
|
|
539
594
|
- spec/swap_test/ref/xml-syntax-basic-serialization.rdf
|
540
595
|
- spec/swap_test/ref/xmllit.nt
|
541
596
|
- spec/swap_test/regression.n3
|
597
|
+
- spec/swap_test/regression.yml
|
542
598
|
- spec/swap_test/reluri-1.n3
|
543
599
|
- spec/swap_test/strquot.n3
|
544
600
|
- spec/swap_test/syntax/colon-in-uri.rdf
|
@@ -575,7 +631,6 @@ files:
|
|
575
631
|
- spec/swap_test/xml-syntax/xml_prefix2.n3
|
576
632
|
- spec/swap_test/xml-syntax/xmlbase3.rdf
|
577
633
|
- spec/swap_test/xml-syntax/xmllit.rdf
|
578
|
-
- spec/triple_spec.rb
|
579
634
|
- spec/turtle/README.txt
|
580
635
|
- spec/turtle/bad-00.ttl
|
581
636
|
- spec/turtle/bad-01.ttl
|
@@ -665,6 +720,7 @@ files:
|
|
665
720
|
- spec/turtle/test-30.ttl
|
666
721
|
- spec/turtle_serializer_spec.rb
|
667
722
|
- spec/turtle_spec.rb
|
723
|
+
- spec/writer_spec.rb
|
668
724
|
has_rdoc: true
|
669
725
|
homepage: http://github.com/gkellogg/rdf-rdfa
|
670
726
|
licenses: []
|
@@ -701,11 +757,13 @@ specification_version: 3
|
|
701
757
|
summary: Notation-3 (n3-rdf) and Turtle reader/writer for RDF.rb.
|
702
758
|
test_files:
|
703
759
|
- spec/cwm_spec.rb
|
760
|
+
- spec/format_spec.rb
|
761
|
+
- spec/literal_spec.rb
|
762
|
+
- spec/matchers.rb
|
704
763
|
- spec/n3reader_spec.rb
|
705
764
|
- spec/rdf_helper.rb
|
706
765
|
- spec/spec_helper.rb
|
707
|
-
- spec/swap_helper.rb
|
708
766
|
- spec/swap_spec.rb
|
709
|
-
- spec/triple_spec.rb
|
710
767
|
- spec/turtle_serializer_spec.rb
|
711
768
|
- spec/turtle_spec.rb
|
769
|
+
- spec/writer_spec.rb
|
data/spec/swap_helper.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
require 'matchers'
|
2
|
-
|
3
|
-
module SWAPHelper
|
4
|
-
# Class representing test cases in format http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#
|
5
|
-
class TestCase
|
6
|
-
include Matchers
|
7
|
-
|
8
|
-
TEST_DIR = File.join(File.dirname(__FILE__), 'swap_test')
|
9
|
-
|
10
|
-
attr_accessor :about
|
11
|
-
attr_accessor :approval
|
12
|
-
attr_accessor :conclusionDocument
|
13
|
-
attr_accessor :data
|
14
|
-
attr_accessor :description
|
15
|
-
attr_accessor :discussion
|
16
|
-
attr_accessor :document
|
17
|
-
attr_accessor :entailmentRules
|
18
|
-
attr_accessor :inputDocument
|
19
|
-
attr_accessor :issue
|
20
|
-
attr_accessor :name
|
21
|
-
attr_accessor :outputDocument
|
22
|
-
attr_accessor :premiseDocument
|
23
|
-
attr_accessor :rdf_type
|
24
|
-
attr_accessor :status
|
25
|
-
attr_accessor :warning
|
26
|
-
attr_accessor :parser
|
27
|
-
|
28
|
-
@@test_cases = []
|
29
|
-
|
30
|
-
def initialize(triples)
|
31
|
-
triples.each do |statement|
|
32
|
-
next if statement.subject.is_a?(BNode)
|
33
|
-
# self.about ||= statement.subject
|
34
|
-
# self.name ||= statement.subject.short_name
|
35
|
-
|
36
|
-
if statement.is_type?
|
37
|
-
self.rdf_type = statement.object.short_name
|
38
|
-
elsif statement.predicate.short_name =~ /Document\Z/i
|
39
|
-
#puts "#{statement.predicate.short_name}: #{statement.object.inspect}"
|
40
|
-
self.send("#{statement.predicate.short_name}=", statement.object.to_s.sub(/^.*swap\/test/, TEST_DIR))
|
41
|
-
if statement.predicate.short_name == "inputDocument"
|
42
|
-
self.about ||= statement.object
|
43
|
-
self.name ||= statement.object.short_name
|
44
|
-
end
|
45
|
-
elsif self.respond_to?("#{statement.predicate.short_name}=")
|
46
|
-
self.send("#{statement.predicate.short_name}=", statement.object.to_s)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def inspect
|
52
|
-
"[Test Case " + %w(
|
53
|
-
about
|
54
|
-
name
|
55
|
-
inputDocument
|
56
|
-
outputDocument
|
57
|
-
issue
|
58
|
-
status
|
59
|
-
approval
|
60
|
-
description
|
61
|
-
discussion
|
62
|
-
issue
|
63
|
-
warning
|
64
|
-
).map {|a| v = self.send(a); "#{a}='#{v}'" if v}.compact.join(", ") +
|
65
|
-
"]"
|
66
|
-
end
|
67
|
-
|
68
|
-
def compare; :graph; end
|
69
|
-
|
70
|
-
# Read in file, and apply modifications reference either .html or .xhtml
|
71
|
-
def input
|
72
|
-
File.read(inputDocument)
|
73
|
-
end
|
74
|
-
|
75
|
-
def output
|
76
|
-
outputDocument && File.read(outputDocument)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Run test case, yields input for parser to create triples
|
80
|
-
def run_test
|
81
|
-
rdf_string = input
|
82
|
-
|
83
|
-
# Run
|
84
|
-
@parser = RdfXmlParser.new
|
85
|
-
yield(rdf_string, @parser)
|
86
|
-
|
87
|
-
@parser.graph.should be_equivalent_graph(output, self) if output
|
88
|
-
end
|
89
|
-
|
90
|
-
def trace
|
91
|
-
@parser.debug.to_a.join("\n")
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.parse_test_cases
|
95
|
-
return unless @@test_cases.empty?
|
96
|
-
|
97
|
-
@@positive_parser_tests = []
|
98
|
-
@@negative_parser_tests = []
|
99
|
-
@@positive_entailment_tests = []
|
100
|
-
@@negative_entailment_tests = []
|
101
|
-
|
102
|
-
manifest = File.read(File.join(TEST_DIR, "n3parser.tests"))
|
103
|
-
parser = Parser.new
|
104
|
-
begin
|
105
|
-
parser.parse(manifest, "http://www.w3.org/2000/10/swap/test/n3parser.tests")
|
106
|
-
rescue
|
107
|
-
raise "Parse error: #{$!}\n\t#{parser.debug.join("\t\n")}\n\n"
|
108
|
-
end
|
109
|
-
graph = parser.graph
|
110
|
-
|
111
|
-
# Group by subject
|
112
|
-
test_hash = graph.triples.inject({}) do |hash, st|
|
113
|
-
a = hash[st.subject] ||= []
|
114
|
-
a << st
|
115
|
-
hash
|
116
|
-
end
|
117
|
-
|
118
|
-
@@test_cases = test_hash.values.map {|statements| TestCase.new(statements)}.compact.sort_by{|t| t.about.is_a?(URIRef) ? t.about.uri.to_s : "zzz"}
|
119
|
-
|
120
|
-
@@test_cases.each do |tc|
|
121
|
-
next unless tc.status == "APPROVED"
|
122
|
-
case tc.rdf_type
|
123
|
-
when "PositiveParserTest" then @@positive_parser_tests << tc
|
124
|
-
when "NegativeParserTest" then @@negative_parser_tests << tc
|
125
|
-
when "PositiveEntailmentTest" then @@positive_entailment_tests << tc
|
126
|
-
when "NegativeEntailmentTest" then @@negative_entailment_tests << tc
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
def self.test_cases; parse_test_cases; @@test_cases; end
|
131
|
-
def self.positive_parser_tests; parse_test_cases; @@positive_parser_tests; end
|
132
|
-
def self.negative_parser_tests; parse_test_cases; @@negative_parser_tests; end
|
133
|
-
def self.positive_entailment_tests; parse_test_cases; @@positive_entailment_tests; end
|
134
|
-
def self.negative_entailment_tests; parse_test_cases; @@negative_entailment_tests; end
|
135
|
-
end
|
136
|
-
end
|
data/spec/triple_spec.rb
DELETED
@@ -1,236 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe "Triples" do
|
4
|
-
before(:all) { @graph = Graph.new(:store => ListStore.new) }
|
5
|
-
|
6
|
-
describe "with subjects" do
|
7
|
-
it "should allow URIRef" do
|
8
|
-
v = URIRef.new("http://foo")
|
9
|
-
Triple.new(v, RDF_TYPE, "obj").subject.should == v
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should allow BNode" do
|
13
|
-
v = BNode.new
|
14
|
-
Triple.new(v, RDF_TYPE, "obj").subject.should == v
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should allow Literal" do
|
18
|
-
v = Literal.untyped("foo")
|
19
|
-
Triple.new(v, RDF_TYPE, "obj").subject.should == v
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should allow Graph" do
|
23
|
-
v = Graph.new
|
24
|
-
Triple.new(v, RDF_TYPE, "obj").subject.should == v
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should allow QuotedGraph" do
|
28
|
-
v = QuotedGraph.new
|
29
|
-
Triple.new(v, RDF_TYPE, "obj").subject.should == v
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "with predicates" do
|
34
|
-
it "should allow URIRef" do
|
35
|
-
v = URIRef.new("http://foo")
|
36
|
-
Triple.new(RDF_NS.Seq, v, "obj").predicate.should == v
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should allow BNode" do
|
40
|
-
v = BNode.new
|
41
|
-
Triple.new(RDF_NS.Seq, v, "obj").predicate.should == v
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should not allow Literal" do
|
45
|
-
v = Literal.untyped("foo")
|
46
|
-
lambda {Triple.new(RDF_NS.Seq, v, "obj")}.should raise_error
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should not allow Graph" do
|
50
|
-
v = Graph.new
|
51
|
-
lambda {Triple.new(RDF_NS.Seq, v, "obj")}.should raise_error
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should not allow QuotedGraph" do
|
55
|
-
v = QuotedGraph.new
|
56
|
-
lambda {Triple.new(RDF_NS.Seq, v, "obj")}.should raise_error
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "with objects" do
|
61
|
-
it "should allow URIRef" do
|
62
|
-
v = URIRef.new("http://foo")
|
63
|
-
Triple.new(RDF_NS.Seq, RDF_TYPE, v).object.should == v
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should allow BNode" do
|
67
|
-
v = BNode.new
|
68
|
-
Triple.new(RDF_NS.Seq, RDF_TYPE, v).object.should == v
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should allow Literal" do
|
72
|
-
v = Literal.untyped("foo")
|
73
|
-
Triple.new(RDF_NS.Seq, RDF_TYPE, v).object.should == v
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should allow Graph" do
|
77
|
-
v = Graph.new
|
78
|
-
Triple.new(RDF_NS.Seq, RDF_TYPE, v).object.should == v
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should allow QuotedGraph" do
|
82
|
-
v = QuotedGraph.new
|
83
|
-
Triple.new(RDF_NS.Seq, RDF_TYPE, v).object.should == v
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should require that the object is a URIRef, BNode, Literal or Typed Literal" do
|
88
|
-
lambda do
|
89
|
-
Triple.new(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), [])
|
90
|
-
end.should raise_error
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "with BNodes" do
|
94
|
-
subject do
|
95
|
-
Triple.new(BNode.new, URIRef.new('http://xmlns.com/foaf/0.1/knows'), BNode.new)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should have a subject" do
|
99
|
-
subject.subject.class.should == BNode
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should emit an NTriple" do
|
103
|
-
subject.to_ntriples.should == "#{subject.subject.to_n3} <http://xmlns.com/foaf/0.1/knows> #{subject.object.to_n3} ."
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "with URIRefs" do
|
108
|
-
subject {
|
109
|
-
s = URIRef.new("http://tommorris.org/foaf#me")
|
110
|
-
p = URIRef.new("http://xmlns.com/foaf/0.1/name")
|
111
|
-
o = Literal.untyped("Tom Morris")
|
112
|
-
Triple.new(s,p,o)
|
113
|
-
}
|
114
|
-
|
115
|
-
it "should emit an NTriple" do
|
116
|
-
subject.to_ntriples.should == "<http://tommorris.org/foaf#me> <http://xmlns.com/foaf/0.1/name> \"Tom Morris\" ."
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "with coerced predicate" do
|
121
|
-
it "should make a string into a URI ref" do
|
122
|
-
Triple.coerce_predicate("http://localhost/").should == URIRef.new('http://localhost/')
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should leave a URIRef alone" do
|
126
|
-
ref = URIRef.new('http://localhost/')
|
127
|
-
Triple.coerce_predicate(ref).should == ref
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should barf on an illegal uri string" do
|
131
|
-
lambda do
|
132
|
-
Triple.coerce_predicate("I'm just a soul whose intention is good")
|
133
|
-
end.should raise_error(InvalidPredicate)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe "with coerced node" do
|
138
|
-
it 'should make a literal for Integer types' do
|
139
|
-
ref = 5
|
140
|
-
Triple.coerce_node(ref).should == Literal.build_from(ref)
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'should make a literal for Float types' do
|
144
|
-
ref = 15.4
|
145
|
-
Triple.coerce_node(ref).should == Literal.build_from(ref)
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'should make a literal for Date types' do
|
149
|
-
ref = Date::civil(2010, 1, 2)
|
150
|
-
Triple.coerce_node(ref).should == Literal.build_from(ref)
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'should make a literal for DateTime types' do
|
154
|
-
ref = DateTime.parse('2010-01-03T01:02:03')
|
155
|
-
Triple.coerce_node(ref).should == Literal.build_from(ref)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should leave URIRefs alone" do
|
159
|
-
ref = URIRef.new("http://localhost/")
|
160
|
-
Triple.coerce_node(ref).should == ref
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should accept an Addressable::URI object and make URIRef" do
|
164
|
-
Triple.coerce_node(Addressable::URI.parse("http://localhost/")).should == URIRef.new("http://localhost/")
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should leave BNodes alone" do
|
168
|
-
ref = BNode.new()
|
169
|
-
Triple.coerce_node(ref).should == ref
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should leave Literals alone" do
|
173
|
-
ref = Literal.untyped('foo')
|
174
|
-
Triple.coerce_node(ref).should == ref
|
175
|
-
|
176
|
-
typedref = Literal.build_from('foo')
|
177
|
-
Triple.coerce_node(ref).should == ref
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "with wildcards" do
|
183
|
-
it "should accept nil" do
|
184
|
-
t = Triple.new(nil, nil, nil)
|
185
|
-
t.is_pattern?.should be_true
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
describe "equivalence" do
|
190
|
-
before(:all) do
|
191
|
-
@test_cases = [
|
192
|
-
Triple.new(URIRef.new("http://foo"),URIRef.new("http://bar"),URIRef.new("http://baz")),
|
193
|
-
Triple.new(URIRef.new("http://foo"),URIRef.new("http://bar"),Literal.untyped("baz")),
|
194
|
-
Triple.new(URIRef.new("http://foo"),"http://bar",Literal.untyped("baz")),
|
195
|
-
Triple.new(BNode.new("foo"),URIRef.new("http://bar"),Literal.untyped("baz")),
|
196
|
-
Triple.new(BNode.new,URIRef.new("http://bar"),Literal.untyped("baz")),
|
197
|
-
]
|
198
|
-
end
|
199
|
-
it "should be equal to itself" do
|
200
|
-
@test_cases.each {|triple| triple.should == triple}
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should not be equal to something else" do
|
204
|
-
t = Triple.new(URIRef.new("http://fab"),URIRef.new("http://bar"),URIRef.new("http://baz")),
|
205
|
-
@test_cases.each {|triple| triple.should_not == t}
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should be equal to equivalent" do
|
209
|
-
@test_cases.each do |triple|
|
210
|
-
t = Triple.new(triple.subject, triple.predicate, triple.object)
|
211
|
-
triple.should == t
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should be equal to patterns" do
|
216
|
-
@test_cases.each do |triple|
|
217
|
-
[
|
218
|
-
Triple.new(triple.subject, triple.predicate, triple.object),
|
219
|
-
|
220
|
-
Triple.new(nil, triple.predicate, triple.object),
|
221
|
-
Triple.new(triple.subject, nil, triple.object),
|
222
|
-
Triple.new(triple.subject, triple.predicate, nil),
|
223
|
-
|
224
|
-
Triple.new(nil, nil, triple.object),
|
225
|
-
Triple.new(triple.subject, nil, nil),
|
226
|
-
Triple.new(nil, triple.predicate, nil),
|
227
|
-
|
228
|
-
Triple.new(nil, nil, nil),
|
229
|
-
].each do |t|
|
230
|
-
triple.should == t
|
231
|
-
t.should == triple
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|