agraph 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,7 +33,7 @@ module AllegroGraph
33
33
  type
34
34
  end
35
35
 
36
- def create_polygon(points, parameters = { })
36
+ def create_cartesian_polygon(points, parameters = { })
37
37
  type = parameters.delete :type
38
38
  parameters = Utility::ParameterMapper.map parameters, :create_polygon
39
39
 
@@ -44,6 +44,22 @@ module AllegroGraph
44
44
  true
45
45
  end
46
46
 
47
+ def create_spherical_polygon(points, parameters = { })
48
+ type = parameters.delete :type
49
+ parameters = Utility::ParameterMapper.map parameters, :create_polygon
50
+
51
+ raise ArgumentError, "at least three points has to defined" unless points.is_a?(Array) && points.size >= 3
52
+ parameters[:point] = points.map do |point|
53
+ "\"" +
54
+ Utility::ParameterMapper.latitude_to_iso(point[0]) +
55
+ Utility::ParameterMapper.longitude_to_iso(point[1]) +
56
+ "\"^^#{type}"
57
+ end
58
+
59
+ @resource.request_json :put, self.path + "/polygon", :parameters => parameters, :expected_status_code => 204
60
+ true
61
+ end
62
+
47
63
  end
48
64
 
49
65
  end
@@ -1,4 +1,3 @@
1
- require 'logger'
2
1
 
3
2
  module AllegroGraph
4
3
 
@@ -29,7 +28,7 @@ module AllegroGraph
29
28
  end
30
29
 
31
30
  def request_json(http_method, path, options = { })
32
- ::Transport::JSON.request http_method, self.url + path, credentials.merge(options).merge(:logger => Logger.new(STDOUT))
31
+ ::Transport::JSON.request http_method, self.url + path, credentials.merge(options)
33
32
  end
34
33
 
35
34
  def version
@@ -189,6 +189,19 @@
189
189
  :response:
190
190
  :code: "204"
191
191
  :body: ""
192
+ -
193
+ :http_method: "put"
194
+ :url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/polygon"
195
+ :parameters:
196
+ :resource: "\"test_polygon\""
197
+ :point:
198
+ - "\"+02.0000000+002.0000000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
199
+ - "\"+10.0000000+002.0000000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
200
+ - "\"+10.0000000+010.0000000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
201
+ - "\"+02.0000000+010.0000000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
202
+ :response:
203
+ :code: "204"
204
+ :body: ""
192
205
  -
193
206
  :http_method: "get"
194
207
  :url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/box"
@@ -47,7 +47,7 @@ describe "geo-spatial data" do
47
47
  end
48
48
 
49
49
  it "should return true" do
50
- result = @geometric.create_polygon @polygon, :name => "test_polygon", :type => @type
50
+ result = @geometric.create_cartesian_polygon @polygon, :name => "test_polygon", :type => @type
51
51
  result.should be_true
52
52
  end
53
53
 
@@ -90,9 +90,9 @@ describe "geo-spatial data" do
90
90
  end
91
91
 
92
92
  it "should find objects inside that polygon" do
93
- @geometric.create_polygon [ [ 5.0, 5.0 ], [ 5.0, 12.0 ], [ 12.0, 12.0 ], [ 12.0, 5.0 ] ],
94
- :name => "test_polygon",
95
- :type => @type
93
+ @geometric.create_cartesian_polygon [ [ 5.0, 5.0 ], [ 5.0, 12.0 ], [ 12.0, 12.0 ], [ 12.0, 5.0 ] ],
94
+ :name => "test_polygon",
95
+ :type => @type
96
96
 
97
97
  result = @statements.find_inside_polygon :type => @type,
98
98
  :predicate => "\"at\"",
@@ -112,6 +112,10 @@ describe "geo-spatial data" do
112
112
  :latitude_max => 20.0,
113
113
  :longitude_max => 20.0
114
114
  @statements.create "\"test_subject\"", "\"at\"", "\"+10.00+010.00\"^^#{@type}"
115
+ @statement_one = [ "\"test_subject\"", "\"at\"", "\"+100000+0100000\"^^#{@type}"]
116
+
117
+ @statements.create "\"another_subject\"", "\"at\"", "\"+15.00+015.00\"^^#{@type}"
118
+ @statement_two = [ "\"another_subject\"", "\"at\"", "\"+150000+0150000\"^^#{@type}"]
115
119
  end
116
120
 
117
121
  it "should find objects inside a haversine" do
@@ -121,7 +125,20 @@ describe "geo-spatial data" do
121
125
  :longitude => 9.0,
122
126
  :radius => 200.0,
123
127
  :unit => :km
124
- result.should include([ "\"test_subject\"", "\"at\"", "\"+100000+0100000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>"])
128
+ result.should include(@statement_one)
129
+ result.should_not include(@statement_two)
130
+ end
131
+
132
+ it "should find objects inside that polygon" do
133
+ @geometric.create_spherical_polygon [ [ 5.0, 5.0 ], [ 5.0, 12.0 ], [ 12.0, 12.0 ], [ 12.0, 5.0 ] ],
134
+ :name => "test_polygon",
135
+ :type => @type
136
+
137
+ result = @statements.find_inside_polygon :type => @type,
138
+ :predicate => "\"at\"",
139
+ :polygon_name => "test_polygon"
140
+ result.should include(@statement_one)
141
+ result.should_not include(@statement_two)
125
142
  end
126
143
 
127
144
  end
@@ -50,14 +50,27 @@ describe AllegroGraph::Proxy::Geometric do
50
50
 
51
51
  end
52
52
 
53
- describe "create_polygon" do
53
+ describe "create_cartesian_polygon" do
54
54
 
55
55
  before :each do
56
56
  @polygon = [ [ 2.0, 2.0 ], [ 10.0, 2.0 ], [ 10.0, 10.0 ], [ 2.0, 10.0 ] ]
57
57
  end
58
58
 
59
59
  it "should create a polygon" do
60
- result = @geometric.create_polygon @polygon, :name => "test_polygon", :type => @type
60
+ result = @geometric.create_cartesian_polygon @polygon, :name => "test_polygon", :type => @type
61
+ result.should be_true
62
+ end
63
+
64
+ end
65
+
66
+ describe "create_spherical_polygon" do
67
+
68
+ before :each do
69
+ @polygon = [ [ 2.0, 2.0 ], [ 10.0, 2.0 ], [ 10.0, 10.0 ], [ 2.0, 10.0 ] ]
70
+ end
71
+
72
+ it "should create a polygon" do
73
+ result = @geometric.create_spherical_polygon @polygon, :name => "test_polygon", :type => @type
61
74
  result.should be_true
62
75
  end
63
76
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agraph
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 3
9
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
10
11
  platform: ruby
11
12
  authors:
12
13
  - "Philipp Br\xC3\xBCll"
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-11-29 00:00:00 +01:00
18
+ date: 2010-12-15 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 23
28
30
  segments:
29
31
  - 1
30
32
  - 0
@@ -40,6 +42,7 @@ dependencies:
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
45
+ hash: 7
43
46
  segments:
44
47
  - 2
45
48
  version: "2"
@@ -53,6 +56,7 @@ dependencies:
53
56
  requirements:
54
57
  - - ">="
55
58
  - !ruby/object:Gem::Version
59
+ hash: 11
56
60
  segments:
57
61
  - 1
58
62
  - 2
@@ -119,6 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
123
  requirements:
120
124
  - - ">="
121
125
  - !ruby/object:Gem::Version
126
+ hash: 57
122
127
  segments:
123
128
  - 1
124
129
  - 8
@@ -129,6 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
134
  requirements:
130
135
  - - ">="
131
136
  - !ruby/object:Gem::Version
137
+ hash: 3
132
138
  segments:
133
139
  - 0
134
140
  version: "0"