Skip to content

Commit 836546b

Browse files
Merge pull request #152 from CLARIAH/dev
fix #150
2 parents a3718b4 + 7e21e09 commit 836546b

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/gquery.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,16 @@ def get_parameters(rq, variables, endpoint, query_metadata, auth=None):
126126
vtype = 'string'
127127
vlang = None
128128
vdatatype = None
129+
vformat = None
129130

130131
mtype = match.group('type')
131132
muserdefined = match.group('userdefined')
132133

133-
if mtype in ['iri','number','literal','string']:
134+
if mtype in ['number','literal','string']:
134135
vtype = mtype
136+
if mtype in ['iri']: #TODO: proper form validation of input parameter uris
137+
vtype = 'string'
138+
vformat = 'iri'
135139
elif mtype:
136140
vtype = 'string'
137141

@@ -149,7 +153,8 @@ def get_parameters(rq, variables, endpoint, query_metadata, auth=None):
149153
'enum': sorted(vcodes),
150154
'type': vtype,
151155
'datatype': vdatatype,
152-
'lang': vlang
156+
'lang': vlang,
157+
'format': vformat
153158
}
154159

155160
glogger.info('Finished parsing the following parameters: {}'.format(parameters))
@@ -327,13 +332,16 @@ def rewrite_query(query, parameters, get_args):
327332
# If the parameter has a value
328333
if v:
329334
# IRI
330-
if p['type'] == 'iri':
335+
if p['type'] == 'iri': # TODO: never reached anymore, since iris are now type=string with format=iri
331336
query = query.replace(p['original'], "{}{}{}".format('<',v,'>'))
332337
# A number (without a datatype)
333338
elif p['type'] == 'number':
334339
query = query.replace(p['original'], v)
335340
# Literals
336341
elif p['type'] == 'literal' or p['type'] == 'string':
342+
# If it's a iri
343+
if p['format'] == 'iri':
344+
query = query.replace(p['original'], "{}{}{}".format('<',v,'>'))
337345
# If there is a language tag
338346
if p['lang']:
339347
query = query.replace(p['original'], "\"{}\"@{}".format(v, p['lang']))

src/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ def process_sparql_query_text(query_text, loader, call_name, extraMetadata):
188188
param['required'] = p['required']
189189
param['in'] = "query"
190190
param['description'] = "A value of type {} that will substitute {} in the original query".format(p['type'], p['original'])
191+
if p['lang']:
192+
param['description'] = "A value of type {}@{} that will substitute {} in the original query".format(p['type'], p['lang'], p['original'])
193+
if p['format']:
194+
param['format'] = p['format']
195+
param['description'] = "A value of type {} ({}) that will substitute {} in the original query".format(p['type'], p['format'], p['original'])
191196
if p['enum']:
192197
param['enum'] = p['enum']
193198

tests/test_gquery.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def test_get_parameters(self):
4242

4343
orig = param['original']
4444
if '_iri' in orig:
45-
self.assertEqual(param['type'], 'iri', 'Should be type iri')
45+
self.assertEqual(param['type'], 'string', 'Should be type string')
46+
self.assertEqual(param['format'], 'iri', 'Should be format iri')
4647
if '_number' in orig:
4748
self.assertEqual(param['type'], 'number',
4849
'Should be type number')
@@ -145,7 +146,8 @@ def build_get_parameter(self, origName, rwName):
145146
'enum': [],
146147
'type': 'literal',
147148
'datatype': 'xsd:string',
148-
'lang': 'en'
149+
'lang': 'en',
150+
'format': None
149151
}
150152

151153
def test_rewrite_query(self):

0 commit comments

Comments
 (0)