@@ -43,10 +43,40 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
4343 }
4444 }
4545
46- return factory . translateStartpoint ( json , shownValues ) + "\nwhere {\n" + SPARQL + "\n}" ;
47- } ;
48-
49-
46+ return factory . translateStartpoint ( json , shownValues ) + "\nwhere {\n" + SPARQL + "\n} LIMIT 200" ;
47+ } ;
48+
49+
50+
51+
52+
53+
54+ /**
55+ * Function to translate the header of a SPARQL query, including the shown values
56+ * @param json
57+ * @param shownValues
58+ */
59+ factory . translateStartpoint = function ( json , shownValues ) {
60+
61+ var SPARQLStart = "" ;
62+
63+ if ( json . START . type === "LIST_ALL" ) {
64+ SPARQLStart = "SELECT DISTINCT " ;
65+ }
66+ else {
67+ SPARQLStart = "SELECT " ;
68+ }
69+
70+ for ( var i = 0 ; i < shownValues . length ; i ++ ) {
71+ SPARQLStart += "?" + shownValues [ i ] + " " ;
72+ }
73+
74+ return SPARQLStart ;
75+ } ;
76+
77+
78+
79+
5080 /**
5181 * Function to translate the header of a SPARQL query, including the shown values
5282 * @param json
@@ -68,7 +98,7 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
6898
6999 var spePro = false ;
70100 //Search for specialProperty in the JSON
71- for ( var i = 0 ; i < json . SUBJECTS . length ; i ++ ) {
101+ for ( i = 0 ; i < json . SUBJECTS . length ; i ++ ) {
72102
73103 for ( var j = 0 ; j < json . SUBJECTS [ i ] . properties . length ; j ++ ) {
74104 if ( json . SUBJECTS [ i ] . properties [ j ] . uri == 'test/specialObjectProperty' || json . SUBJECTS [ i ] . properties [ j ] . uri == 'test/specialDatatypeProperty' ) { spePro = true ; }
@@ -144,13 +174,13 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
144174 if ( typeof eigenschaft . link . linkPartner != "undefined" ) {
145175 SPARQL += eigenschaft . link . linkPartner + " .\n" ;
146176
147- for ( var i = 0 ; i < json . SUBJECTS . length ; i ++ ) {
177+ for ( i = 0 ; i < json . SUBJECTS . length ; i ++ ) {
148178 if ( json . SUBJECTS [ i ] . alias === eigenschaft . link . linkPartner ) {
149179 SPARQL += factory . translateSubject ( json . SUBJECTS [ i ] , shownValues , translated , json ) ;
150180 }
151181 }
152182 } else {
153- SPARQL += eigenschaft . alias + " .\n" ; ;
183+ SPARQL += eigenschaft . alias + " .\n" ;
154184 if ( eigenschaft . optional ) {
155185 SPARQL += "}\n" ;
156186 }
@@ -160,7 +190,7 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
160190
161191 if ( eigenschaft . operator === "MUST_NOT" ) {
162192 if ( typeof eigenschaft . link . linkPartner != "undefined" ) {
163- for ( var i = 0 ; i < json . SUBJECTS . length ; i ++ ) {
193+ for ( i = 0 ; i < json . SUBJECTS . length ; i ++ ) {
164194 if ( json . SUBJECTS [ i ] . alias === eigenschaft . link . linkPartner ) {
165195 SPARQL += factory . translateSubject ( json . SUBJECTS [ i ] , shownValues , translated , json ) ;
166196 }
@@ -174,7 +204,7 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
174204
175205 if ( eigenschaft . operator === "IS_OF" ) {
176206 SPARQL += "?" + itsSubject . alias + " ^<" + eigenschaft . uri + "> ?" + eigenschaft . link . linkPartner + " .\n" ;
177- for ( var i = 0 ; i < json . SUBJECTS . length ; i ++ ) {
207+ for ( i = 0 ; i < json . SUBJECTS . length ; i ++ ) {
178208 if ( json . SUBJECTS [ i ] . alias === eigenschaft . link . linkPartner ) {
179209 SPARQL += factory . translateSubject ( json . SUBJECTS [ i ] , shownValues , translated , json ) ;
180210 }
@@ -214,44 +244,51 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
214244 y = x ;
215245 if ( eigenschaft . operator === "MUST" ) {
216246
217- if ( eigenschaft . optional ) {
247+ if ( eigenschaft . optional ) {
218248 SPARQL += "OPTIONAL { \n" ;
219249 }
220250
221- if ( eigenschaft . arithmetic !== null && eigenschaft . arithmetic != "x" ) {
251+ if ( eigenschaft . arithmetic !== null && eigenschaft . arithmetic != "x" ) {
222252 x = y + "_temp" ;
223253 SPARQL += "?" + itsSubject . alias + " <" + eigenschaft . uri + "> " + x + ".\n" ;
224- SPARQL += "BIND ((" + eigenschaft . arithmetic . replace ( / x / g, x ) + ") as " + y + ") .\n" ;
254+ SPARQL += "BIND ((" + eigenschaft . arithmetic . replace ( / x / g, x ) + ") as " + y + ") .\n" ;
225255 }
226256 else {
227257
228258 //Tailors the uri if the subject is thing.
229259 // Necessary because Properties have URIs like: <http://dbpedia.org/ontology/Person/weight> but <http://dbpedia.org/ontology/weight> is needed
230260 var tailoredURI = eigenschaft . uri ;
231- if ( itsSubject . uri == 'test/Thing' && eigenschaft . uri !== 'test/specialDatatypeProperty' )
232- {
233- var prop = tailoredURI . substr ( tailoredURI . lastIndexOf ( '/' ) , tailoredURI . length - 1 )
261+ if ( itsSubject . uri == 'test/Thing' && eigenschaft . uri !== 'test/specialDatatypeProperty' ) {
262+ var prop = tailoredURI . substr ( tailoredURI . lastIndexOf ( '/' ) , tailoredURI . length - 1 ) ;
234263 tailoredURI = tailoredURI . substr ( 0 , tailoredURI . lastIndexOf ( '/' ) ) ;
235264 tailoredURI = tailoredURI . substr ( 0 , tailoredURI . lastIndexOf ( '/' ) ) + prop ;
236265
237266 }
238267
239268 //Special-property has to be translated with ?alias instead of it's URI
240269 tailoredURI = '<' + tailoredURI + '>' ;
241- if ( eigenschaft . uri == 'test/specialDatatypeProperty' ) { tailoredURI = '?' + eigenschaft . alias ; }
270+ if ( eigenschaft . uri == 'test/specialDatatypeProperty' ) {
271+ tailoredURI = '?' + eigenschaft . alias ;
272+ }
242273
243- SPARQL += "?" + itsSubject . alias + " " + tailoredURI + " " + y + " .\n" ;
274+ SPARQL += "?" + itsSubject . alias + " " + tailoredURI + " " + y + " .\n" ;
244275 }
245276
277+ if ( eigenschaft . compare !== null ) {
278+
279+ SPARQL += "FILTER ( "
280+ + eigenschaft . compare
281+ . replace ( / % b e f o r e _ a r i t h m e t i c % / g, x )
282+ . replace ( / % a f t e r _ a r i t h m e t i c % / g, y )
283+ + " ) .\n" ;
246284
247- if ( eigenschaft . compare !== null ) {
248285
249- SPARQL += "FILTER ( " + eigenschaft . compare . replace ( / x / g, x ) . replace ( / y / g, y ) + " ) .\n" ;
250286 }
251287
252- if ( eigenschaft . optional ) {
288+ if ( eigenschaft . optional ) {
253289 SPARQL += "}\n" ;
254290 }
291+
255292 }
256293
257294
0 commit comments