ldpath 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,67 +5,145 @@ describe Ldpath::Transform do
5
5
  it "should transform literals" do
6
6
  subject.apply(literal: "xyz")
7
7
  end
8
-
8
+
9
9
  it "should transform uris" do
10
- subject.apply(uri:"http://www.w3.org/2003/01/geo/wgs84_pos#")
11
- end
12
-
13
- it "should transform nested uris" do
14
- subject.apply(uri: { uri: "info:a"})
10
+ actual = subject.apply(iri: "info:a")
11
+ expect(actual).to eq RDF::URI.new("info:a")
15
12
  end
16
-
13
+
17
14
  it "should transform prefix + localNames" do
18
- subject.apply(prefix: "info", localName:"a")
15
+ actual = subject.apply(prefix: "rdf", localName: "type")
16
+ expect(actual).to eq RDF.type
19
17
  end
20
-
18
+
21
19
  it "should transform mappings" do
22
- subject.apply parser.parse("x = . ;")
20
+ actual = subject.apply parser.parse("x = . ;")
21
+ expect(actual.length).to eq 1
22
+ mapping = actual.first
23
+ expect(mapping).to be_a_kind_of Ldpath::FieldMapping
24
+ expect(mapping.name).to eq "x"
25
+ expect(mapping.selector).to be_a_kind_of Ldpath::SelfSelector
23
26
  end
24
-
27
+
25
28
  it "should transform wildcards" do
26
- subject.apply parser.parse("xyz = * ;\n")
29
+ actual = subject.apply parser.parse("xyz = * ;\n")
30
+
31
+ mapping = actual.first
32
+ expect(mapping).to be_a_kind_of Ldpath::FieldMapping
33
+ expect(mapping.name).to eq "xyz"
34
+ expect(mapping.selector).to be_a_kind_of Ldpath::WildcardSelector
27
35
  end
28
-
36
+
29
37
  it "should transform reverse properties" do
30
- subject.apply parser.parse("xyz = ^info:a ;\n")
38
+ actual = subject.apply parser.parse("xyz = ^info:a ;\n")
39
+
40
+ mapping = actual.first
41
+ expect(mapping).to be_a_kind_of Ldpath::FieldMapping
42
+ expect(mapping.name).to eq "xyz"
43
+ expect(mapping.selector).to be_a_kind_of Ldpath::ReversePropertySelector
44
+ expect(mapping.selector.property).to eq RDF::URI.new("info:a")
31
45
  end
32
-
33
- it "should transform recursive properties" do
34
- subject.apply parser.parse("xyz = (info:a)* ;\n")
35
- subject.apply parser.parse("xyz = (info:a)+ ;\n")
36
- subject.apply parser.parse("xyz = (info:a){,5} ;\n")
37
- subject.apply parser.parse("xyz = (info:a){2,5} ;\n")
38
- subject.apply parser.parse("xyz = (info:a){2,} ;\n")
46
+
47
+ describe "recursive properties" do
48
+ it "is a zero-or-one matcher" do
49
+ actual = subject.apply parser.parse("xyz = (info:a)? ;\n")
50
+ selector = actual.first.selector
51
+ expect(selector).to be_a_kind_of Ldpath::RecursivePathSelector
52
+ expect(selector.property.property).to eq RDF::URI.new("info:a")
53
+ expect(selector.repeat).to eq 0..1
54
+ end
55
+
56
+ it "is a 0-to-infinity matcher" do
57
+ actual = subject.apply parser.parse("xyz = (info:a)* ;\n")
58
+
59
+ selector = actual.first.selector
60
+ expect(selector).to be_a_kind_of Ldpath::RecursivePathSelector
61
+ expect(selector.property.property).to eq RDF::URI.new("info:a")
62
+ expect(selector.repeat).to eq 0..Ldpath::Transform::Infinity
63
+ end
64
+
65
+ it "is a 1-to-infinity matcher" do
66
+ actual = subject.apply parser.parse("xyz = (info:a)+ ;\n")
67
+
68
+ selector = actual.first.selector
69
+ expect(selector).to be_a_kind_of Ldpath::RecursivePathSelector
70
+ expect(selector.property.property).to eq RDF::URI.new("info:a")
71
+ expect(selector.repeat).to eq 1..Ldpath::Transform::Infinity
72
+ end
73
+
74
+ it "is a 0 to 5 matcher" do
75
+ actual = subject.apply parser.parse("xyz = (info:a){,5} ;\n")
76
+
77
+ selector = actual.first.selector
78
+ expect(selector).to be_a_kind_of Ldpath::RecursivePathSelector
79
+ expect(selector.property.property).to eq RDF::URI.new("info:a")
80
+ expect(selector.repeat).to eq 0..5
81
+ end
82
+
83
+ it "is a 2 to 5 matcher" do
84
+ actual = subject.apply parser.parse("xyz = (info:a){2,5} ;\n")
85
+
86
+ selector = actual.first.selector
87
+ expect(selector).to be_a_kind_of Ldpath::RecursivePathSelector
88
+ expect(selector.property.property).to eq RDF::URI.new("info:a")
89
+ expect(selector.repeat).to eq 2..5
90
+ end
91
+
92
+ it "is a 2 to infinity matcher" do
93
+ actual = subject.apply parser.parse("xyz = (info:a){2,} ;\n")
94
+
95
+ selector = actual.first.selector
96
+ expect(selector).to be_a_kind_of Ldpath::RecursivePathSelector
97
+ expect(selector.property.property).to eq RDF::URI.new("info:a")
98
+ expect(selector.repeat).to eq 2..Ldpath::Transform::Infinity
99
+ end
39
100
  end
40
-
101
+
41
102
  it "should transform tap selectors" do
42
- subject.apply parser.parse("xyz = ?<x>info:a ;\n")
103
+ actual = subject.apply parser.parse("xyz = ?<x>info:a ;\n")
104
+
105
+ selector = actual.first.selector
106
+ expect(selector).to be_a_kind_of Ldpath::TapSelector
107
+ expect(selector.identifier).to eq "x"
108
+ expect(selector.tap).to be_a_kind_of Ldpath::PropertySelector
43
109
  end
44
-
110
+
45
111
  it "should transform loose property selectors" do
46
- subject.apply parser.parse("xyz = ~info:a ;\n")
47
- end
112
+ actual = subject.apply parser.parse("xyz = ~info:a ;\n")
48
113
 
114
+ selector = actual.first.selector
115
+ expect(selector).to be_a_kind_of Ldpath::LoosePropertySelector
116
+ expect(selector.property).to eq RDF::URI.new("info:a")
117
+ end
49
118
 
50
119
  it "should transform namespaces" do
51
- subject.apply parser.parse("@prefix foaf: <http://xmlns.com/foaf/0.1/>")
120
+ subject.apply parser.parse("@prefix xyz: <info:xyz>")
121
+ expect(subject.prefixes).to include "xyz"
122
+ expect(subject.prefixes["xyz"].to_s).to eq "info:xyz"
52
123
  end
53
-
124
+
54
125
  it "should transform path selectors" do
55
- subject.apply parser.parse("x = . / . ;")
126
+ actual = subject.apply parser.parse("x = info:a / . ;")
127
+
128
+ selector = actual.first.selector
129
+ expect(selector).to be_a_kind_of Ldpath::PathSelector
130
+ expect(selector.left).to be_a_kind_of Ldpath::PropertySelector
131
+ expect(selector.right).to be_a_kind_of Ldpath::SelfSelector
56
132
  end
57
-
133
+
58
134
  it "should transform functions" do
59
- subject.apply parser.function_selector.parse("fn:concat(foaf:givename,\" \",foaf:surname)")
135
+ selector = subject.apply parser.function_selector.parse("fn:concat(foaf:givename,\" \",foaf:surname)")
136
+
137
+ expect(selector).to be_a_kind_of Ldpath::FunctionSelector
138
+ expect(selector.fname).to eq "concat"
139
+ expect(selector.arguments.length).to eq 3
60
140
  end
61
-
141
+
62
142
  it "should transform the foaf example" do
63
- subject.apply parser.parse(File.read(File.expand_path(File.join(__FILE__, "..", "fixtures", "foaf_example.program")))
64
- )
143
+ subject.apply parser.parse(File.read(File.expand_path(File.join(__FILE__, "..", "fixtures", "foaf_example.program"))))
65
144
  end
66
-
145
+
67
146
  it "should parse the program.ldpath" do
68
147
  subject.apply parser.parse File.read(File.expand_path(File.join(__FILE__, "..", "fixtures", "program.ldpath")))
69
148
  end
70
-
71
149
  end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe "LDPath list functions" do
4
+ let(:object) { RDF::URI.new("info:a") }
5
+
6
+ let(:graph) do
7
+ graph = RDF::Graph.new
8
+ l = RDF::List[1, 2, 3]
9
+ graph << [object, RDF::URI.new("http://example.com/list"), l]
10
+ graph << l
11
+ graph
12
+ end
13
+
14
+ subject do
15
+ program.evaluate object, graph
16
+ end
17
+
18
+ describe "fn:flatten" do
19
+ let(:program) do
20
+ Ldpath::Program.parse <<-EOF
21
+ @prefix ex : <http://example.com/> ;
22
+ list_items = fn:flatten(ex:list) :: xsd:string ;
23
+ EOF
24
+ end
25
+
26
+ it "collapses the RDF list into individual values" do
27
+ expect(subject["list_items"]).to match_array ["1", "2", "3"]
28
+ end
29
+ end
30
+
31
+ describe "fn:flatten" do
32
+ let(:program) do
33
+ Ldpath::Program.parse <<-EOF
34
+ @prefix ex : <http://example.com/> ;
35
+ list_item = fn:get(ex:list, "1") :: xsd:string ;
36
+ EOF
37
+ end
38
+
39
+ it "extracts a single term by position from the RDF list" do
40
+ expect(subject["list_item"]).to eq ["2"]
41
+ end
42
+ end
43
+
44
+ describe "fn:subList" do
45
+ let(:program) do
46
+ Ldpath::Program.parse <<-EOF
47
+ @prefix ex : <http://example.com/> ;
48
+ list_items = fn:subList(ex:list, "1") :: xsd:string ;
49
+ list_items_by_range = fn:subList(ex:list, "0", "1") :: xsd:string ;
50
+ EOF
51
+ end
52
+
53
+ it "extracts a list of terms by index" do
54
+ expect(subject["list_items"]).to eq ["2", "3"]
55
+ end
56
+
57
+ it "selects the range, inclusively" do
58
+ expect(subject["list_items_by_range"]).to eq ["1", "2"]
59
+ end
60
+ end
61
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,4 +4,4 @@ require 'ldpath'
4
4
  require 'rdf/reasoner'
5
5
 
6
6
  RDF::Reasoner.apply(:rdfs)
7
- RDF::Reasoner.apply(:owl)
7
+ RDF::Reasoner.apply(:owl)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldpath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-05 00:00:00.000000000 Z
11
+ date: 2015-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -104,6 +104,9 @@ extra_rdoc_files: []
104
104
  files:
105
105
  - ".gitignore"
106
106
  - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".rubocop_hound.yml"
109
+ - ".rubocop_todo.yml"
107
110
  - ".travis.yml"
108
111
  - Gemfile
109
112
  - LICENSE.txt
@@ -127,6 +130,7 @@ files:
127
130
  - spec/ldpath_program_spec.rb
128
131
  - spec/ldpath_spec.rb
129
132
  - spec/ldpath_transform_spec.rb
133
+ - spec/lib/functions/list_spec.rb
130
134
  - spec/spec_helper.rb
131
135
  homepage: https://github.com/cbeer/ldpath.rb
132
136
  licenses:
@@ -148,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
152
  version: '0'
149
153
  requirements: []
150
154
  rubyforge_project:
151
- rubygems_version: 2.4.6
155
+ rubygems_version: 2.4.5
152
156
  signing_key:
153
157
  specification_version: 4
154
158
  summary: Ruby implementation of LDPath
@@ -160,4 +164,5 @@ test_files:
160
164
  - spec/ldpath_program_spec.rb
161
165
  - spec/ldpath_spec.rb
162
166
  - spec/ldpath_transform_spec.rb
167
+ - spec/lib/functions/list_spec.rb
163
168
  - spec/spec_helper.rb