label replaced by text, which is existing attribute

pull/59/head
Roman Graf 2016-10-11 14:48:59 +02:00
parent d7137221db
commit 03b6fd7b74
1 changed files with 6 additions and 6 deletions

View File

@ -3,10 +3,10 @@ import requests
from SPARQLWrapper import SPARQLWrapper, JSON from SPARQLWrapper import SPARQLWrapper, JSON
misperrors = {'error': 'Error'} misperrors = {'error': 'Error'}
mispattributes = {'input': ['label'], 'output': ['text']} mispattributes = {'input': ['text'], 'output': ['text']}
moduleinfo = {'version': '0.1', 'author': 'Roman Graf', 'description': 'An expansion hover module to extract information from Wikidata to have additional information about particular term for analysis.', 'module-type': ['hover']} moduleinfo = {'version': '0.2', 'author': 'Roman Graf', 'description': 'An expansion hover module to extract information from Wikidata to have additional information about particular term for analysis.', 'module-type': ['hover']}
moduleconfig = [] moduleconfig = []
# sample query label 'Microsoft' should provide Wikidata link https://www.wikidata.org/wiki/Q2283 in response # sample query text 'Microsoft' should provide Wikidata link https://www.wikidata.org/wiki/Q2283 in response
wiki_api_url = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql' wiki_api_url = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql'
@ -14,15 +14,15 @@ def handler(q=False):
if q is False: if q is False:
return False return False
request = json.loads(q) request = json.loads(q)
if not request.get('label'): if not request.get('text'):
misperrors['error'] = 'Query label missing' misperrors['error'] = 'Query text missing'
return misperrors return misperrors
sparql = SPARQLWrapper(wiki_api_url) sparql = SPARQLWrapper(wiki_api_url)
query_string = \ query_string = \
"SELECT ?item \n" \ "SELECT ?item \n" \
"WHERE { \n" \ "WHERE { \n" \
"?item rdfs:label\"" + request.get('label') + "\" @en \n" \ "?item rdfs:label\"" + request.get('text') + "\" @en \n" \
"}\n"; "}\n";
sparql.setQuery(query_string) sparql.setQuery(query_string)
sparql.setReturnFormat(JSON) sparql.setReturnFormat(JSON)