34
35:- module(georss,
36 [ georss_candidate/2,
37 georss_candidate/3,
38 georss_simple_candidate/2,
39 georss_gml_candidate/2,
40 georss_uri_shape_triple/5
41 ]). 42
43:- use_module(library(semweb/rdf_db)). 44:- use_module(library(dcg/basics)). 45:- use_module(gml). 46
47:- rdf_meta(georss_simple_candidate(r,?,?)). 48
49:- rdf_register_ns(georss,'http://www.georss.org/georss/'). 50:- rdf_register_ns(foaf,'http://xmlns.com/foaf/0.1/').
59georss_candidate(URI, Shape) :-
60 georss_simple_candidate(URI, Shape).
61georss_candidate(URI, Shape) :-
62 georss_gml_candidate(URI, Shape).
69georss_candidate(URI, Shape, Source) :-
70 var(Source),
71 georss_simple_candidate(URI, Shape, Source).
72georss_candidate(URI, Shape, Source) :-
73 var(Source),
74 georss_gml_candidate(URI, Shape, Source).
75
76georss_candidate(URI, Shape, Source) :-
77 nonvar(Source),
78 georss_simple_candidate(URI, Shape, Source).
79georss_candidate(URI, Shape, Source) :-
80 nonvar(Source),
81 georss_gml_candidate(URI, Shape, Source).
82
92georss_simple_candidate(URI, Shape) :-
93 georss_simple_candidate(URI, Shape, _).
94
95georss_simple_candidate(URI, Point, Source) :-
96 rdf(URI, georss:point, PointStringLit, Source),
97 parse_poslist_literal(PointStringLit,[Point]).
98georss_simple_candidate(URI, linestring(Line), Source) :-
99 rdf(URI, georss:line, LineStringLit, Source),
100 parse_poslist_literal(LineStringLit,Line).
101georss_simple_candidate(URI, polygon([Line]), Source) :-
102 rdf(URI, georss:polygon, LineStringLit, Source),
103 parse_poslist_literal(LineStringLit,Line).
104georss_simple_candidate(URI, box(Line), Source) :-
105 rdf(URI, georss:box, LineStringLit, Source),
106 parse_poslist_literal(LineStringLit,Line).
107georss_simple_candidate(URI, Circle, Source) :-
108 rdf(URI, georss:circle, CenterRadiusLit, Source),
109 parse_circle_literal(CenterRadiusLit,Circle).
110
111parse_poslist_literal(literal(Lit), Shape) :-
112 atom_codes(Lit,LSC),
113 phrase(poslist(Shape),LSC).
114
115parse_circle_literal(literal(Lit), Shape) :-
116 atom_codes(Lit,CRC),
117 phrase(circle(Shape),CRC).
118
119circle(circle(Center,Radius)) -->
120 blanks, pos(Center), blank, blanks, float(Radius), blanks.
127georss_uri_shape_triple(URI, Shape, URI, P, O) :-
128 ( ( var(URI)
129 ; var(Shape)
130 )
131 -> georss_simple_candidate(URI,Shape)
132 ; true
133 ),
134 functor(Shape,GeomType,_),
135 georss_simple_predicate(GeomType, P),
136 georss_simple_literal(Shape, O).
137
(point,P) :- rdf_equal(georss:point,P).
139georss_simple_predicate(linestring,P) :- rdf_equal(georss:line,P).
140georss_simple_predicate(linearring,P) :- rdf_equal(georss:line,P).
141georss_simple_predicate(polygon,P) :- rdf_equal(georss:polygon,P).
142
(X, literal(L)) :-
144 phrase(coordinates(X), Atomics),
145 atomic_list_concat(Atomics, ' ', L).
146
147coordinates(polygon([Coords|_])) --> !, point_list(Coords).
148coordinates(linestring(Coords)) --> !, point_list(Coords).
149coordinates(linearing(Coords)) --> !, point_list(Coords).
150coordinates(Point) --> point(Point).
151
152point_list([]) --> [].
153point_list([H|T]) -->
154 point(H), point_list(T).
155
156point(Point) -->
157 { Point =.. [ point | List ] },
158 List.
159
170georss_gml_candidate(URI, Shape) :-
171 georss_gml_candidate(URI, Shape, _).
172
173georss_gml_candidate(URI, Shape, Source) :-
174 ( rdf_equal(georss:where, P)
175 ; rdf_equal(foaf:based_near, P)
176 ),
177 georss_gml_triple(URI, P, GML, Source),
178 gml_shape(GML, Shape).
179
(URI, Property, GML, Source) :-
181 rdf(URI, Property, Lit, Source),
182 gml_literal(Lit, GML).
183
184gml_literal(literal(type(_,GML)),GML) :- !.
185gml_literal(literal(GML),GML).
186
187poslist(T) --> blank_star, poslist_plus(T), blank_star, !.
188poslist_plus([H|T]) --> pos(H), poslist_star(T).
189poslist_star(T) --> blank_plus, poslist(T).
190poslist_star([]) --> [], !.
191
192pos(point(X,Y)) --> c(X), blank_plus, c(Y).
193pos(point(X,Y,Z)) --> c(X), blank_plus, c(Y), blank_plus, c(Z).
194pos(point(X,Y,Z,M)) --> c(X), blank_plus, c(Y), blank_plus, c(Z), blank_plus, c(M).
195c(X) --> float(X).
196
197blank_plus --> blank, blank_star, !.
198blank_plus --> " ", !.
199blank_star --> blanks, !.
200blank_star --> [], !