diff --git a/a00101.html b/a00101.html index 083ac8fa..42663842 100644 --- a/a00101.html +++ b/a00101.html @@ -270,43 +270,43 @@

-
359  def constructBBOXQuerySegment(triplestoreconf,bboxpoints,widthm=None,curquery=None):
-
360  if "bboxquery" in triplestoreconf and \
-
361  triplestoreconf["bboxquery"]["type"] == "geosparql":
-
362  filterstatement=triplestoreconf["bboxquery"][
-
363  "query"].replace("%%x1%%", str(bboxpoints[0].asPoint().x())).replace("%%x2%%",str(bboxpoints[2].asPoint().x())).replace(
-
364  "%%y1%%", str(bboxpoints[0].asPoint().y())).replace("%%y2%%", str(bboxpoints[2].asPoint().y())) + "\n"
-
365  if curquery!=None:
-
366  return curquery[0:curquery.rfind('}')] + filterstatement + curquery[curquery.rfind('}') + 1:]
-
367  else:
-
368  return filterstatement
-
369  elif "bboxquery" in triplestoreconf and \
-
370  triplestoreconf["bboxquery"]["type"] == "minmax":
-
371  filterstatement=triplestoreconf["bboxquery"][
-
372  "query"].replace("%%minPoint%%", bboxpoints[1].asWkt()).replace("%%maxPoint%%", bboxpoints[3].asWkt())
-
373  if curquery!=None:
-
374  curquery = curquery[0:curquery.rfind('}')] + filterstatement + curquery[curquery.rfind('}') + 1:]
-
375  return curquery
-
376  else:
-
377  return filterstatement
-
378  elif "bboxquery" in triplestoreconf and \
-
379  triplestoreconf["bboxquery"]["type"] == "pointdistance":
-
380  filterstatement=triplestoreconf["bboxquery"][
-
381  "query"].replace("%%lat%%", str(bboxpoints[0].asPoint().y())).replace("%%lon%%",str(bboxpoints[0].asPoint().x())).replace("%%distance%%", str(widthm / 1000))
-
382  if curquery!=None:
-
383  return curquery[0:curquery.rfind('}')] + filterstatement + curquery[curquery.rfind('}') + 1:]
-
384  else:
-
385  return filterstatement
-
386  else:
-
387  geosparqltemplate="FILTER(<http://www.opengis.net/def/function/geosparql/sfIntersects>(?geo,\"POLYGON((%%x1%% %%y1%%, %%x1%% %%y2%%, %%x2%% %%y2%%, %%x2%% %%y1%%, %%x1%% %%y1%%))\"^^<http://www.opengis.net/ont/geosparql#wktLiteral>))"
-
388  filterstatement=geosparqltemplate.replace("%%x1%%", str(bboxpoints[0].asPoint().x())).replace("%%x2%%",
-
389  str(bboxpoints[2].asPoint().x())).replace(
-
390  "%%y1%%", str(bboxpoints[0].asPoint().y())).replace("%%y2%%",str(bboxpoints[2].asPoint().y())) + "\n"
-
391  if curquery!=None:
-
392  return curquery[0:curquery.rfind('}')] + filterstatement + curquery[curquery.rfind('}') + 1:]
-
393  else:
-
394  return filterstatement
-
395 
+
361  def constructBBOXQuerySegment(triplestoreconf,bboxpoints,widthm=None,curquery=None):
+
362  if "bboxquery" in triplestoreconf and \
+
363  triplestoreconf["bboxquery"]["type"] == "geosparql":
+
364  filterstatement=triplestoreconf["bboxquery"][
+
365  "query"].replace("%%x1%%", str(bboxpoints[0].asPoint().x())).replace("%%x2%%",str(bboxpoints[2].asPoint().x())).replace(
+
366  "%%y1%%", str(bboxpoints[0].asPoint().y())).replace("%%y2%%", str(bboxpoints[2].asPoint().y())) + "\n"
+
367  if curquery!=None:
+
368  return curquery[0:curquery.rfind('}')] + filterstatement + curquery[curquery.rfind('}') + 1:]
+
369  else:
+
370  return filterstatement
+
371  elif "bboxquery" in triplestoreconf and \
+
372  triplestoreconf["bboxquery"]["type"] == "minmax":
+
373  filterstatement=triplestoreconf["bboxquery"][
+
374  "query"].replace("%%minPoint%%", bboxpoints[1].asWkt()).replace("%%maxPoint%%", bboxpoints[3].asWkt())
+
375  if curquery!=None:
+
376  curquery = curquery[0:curquery.rfind('}')] + filterstatement + curquery[curquery.rfind('}') + 1:]
+
377  return curquery
+
378  else:
+
379  return filterstatement
+
380  elif "bboxquery" in triplestoreconf and \
+
381  triplestoreconf["bboxquery"]["type"] == "pointdistance":
+
382  filterstatement=triplestoreconf["bboxquery"][
+
383  "query"].replace("%%lat%%", str(bboxpoints[0].asPoint().y())).replace("%%lon%%",str(bboxpoints[0].asPoint().x())).replace("%%distance%%", str(widthm / 1000))
+
384  if curquery!=None:
+
385  return curquery[0:curquery.rfind('}')] + filterstatement + curquery[curquery.rfind('}') + 1:]
+
386  else:
+
387  return filterstatement
+
388  else:
+
389  geosparqltemplate="FILTER(<http://www.opengis.net/def/function/geosparql/sfIntersects>(?geo,\"POLYGON((%%x1%% %%y1%%, %%x1%% %%y2%%, %%x2%% %%y2%%, %%x2%% %%y1%%, %%x1%% %%y1%%))\"^^<http://www.opengis.net/ont/geosparql#wktLiteral>))"
+
390  filterstatement=geosparqltemplate.replace("%%x1%%", str(bboxpoints[0].asPoint().x())).replace("%%x2%%",
+
391  str(bboxpoints[2].asPoint().x())).replace(
+
392  "%%y1%%", str(bboxpoints[0].asPoint().y())).replace("%%y2%%",str(bboxpoints[2].asPoint().y())) + "\n"
+
393  if curquery!=None:
+
394  return curquery[0:curquery.rfind('}')] + filterstatement + curquery[curquery.rfind('}') + 1:]
+
395  else:
+
396  return filterstatement
+
397 
@@ -333,29 +333,29 @@

-
606  def detectGeoLiteralType(literal):
-
607  try:
-
608  geom = QgsGeometry.fromWkt(literal)
-
609  return "wkt"
-
610  except:
-
611  print("no wkt")
-
612  try:
-
613  geom = QgsGeometry.fromWkb(bytes.fromhex(literal))
-
614  return "wkb"
-
615  except:
-
616  print("no wkb")
-
617  try:
-
618  json.loads(literal)
-
619  return "geojson"
-
620  except:
-
621  print("no geojson")
-
622  try:
-
623  ogr.CreateGeometryFromGML(literal)
-
624  return "gml"
-
625  except:
-
626  print("no geojson")
-
627  return ""
-
628 
+
608  def detectGeoLiteralType(literal):
+
609  try:
+
610  geom = QgsGeometry.fromWkt(literal)
+
611  return "wkt"
+
612  except:
+
613  print("no wkt")
+
614  try:
+
615  geom = QgsGeometry.fromWkb(bytes.fromhex(literal))
+
616  return "wkb"
+
617  except:
+
618  print("no wkb")
+
619  try:
+
620  json.loads(literal)
+
621  return "geojson"
+
622  except:
+
623  print("no geojson")
+
624  try:
+
625  ogr.CreateGeometryFromGML(literal)
+
626  return "gml"
+
627  except:
+
628  print("no geojson")
+
629  return ""
+
630 
@@ -382,9 +382,9 @@

-
602  def detectLiteralTypeByURI(literal):
-
603  return ""
-
604 
+
604  def detectLiteralTypeByURI(literal):
+
605  return ""
+
606 
@@ -429,96 +429,96 @@

Executes a SPARQL query using RDFlib, with or without credentials and tries GET and POST query methods and uses proxy settings.

-
398  def executeQuery(triplestoreurl, query,triplestoreconf=None):
-
399  results=False
-
400  SPARQLUtils.exception = None
-
401  QgsMessageLog.logMessage(str(triplestoreurl), MESSAGE_CATEGORY, Qgis.Info)
-
402  if triplestoreurl["type"]=="endpoint":
-
403  s = QSettings() # getting proxy from qgis options settings
-
404  proxyEnabled = s.value("proxy/proxyEnabled")
-
405  proxyType = s.value("proxy/proxyType")
-
406  proxyHost = s.value("proxy/proxyHost")
-
407  proxyPort = s.value("proxy/proxyPort")
-
408  proxyUser = s.value("proxy/proxyUser")
-
409  proxyPassword = s.value("proxy/proxyPassword")
-
410  if proxyHost != None and proxyHost != "" and proxyPort != None and proxyPort != "":
-
411  QgsMessageLog.logMessage('Proxy? ' + str(proxyHost), MESSAGE_CATEGORY, Qgis.Info)
-
412  proxy = urllib.request.ProxyHandler({'http': proxyHost})
-
413  opener = urllib.request.build_opener(proxy)
-
414  urllib.request.install_opener(opener)
-
415  QgsMessageLog.logMessage('Started task "{}"'.format(query.replace("<","").replace(">","")), MESSAGE_CATEGORY, Qgis.Info)
-
416  sparql = SPARQLWrapper(triplestoreurl["url"])
-
417  if triplestoreconf!=None and "auth" in triplestoreconf and "userCredential" in triplestoreconf["auth"] \
-
418  and triplestoreconf["auth"]["userCredential"]!="" \
-
419  and "userPassword" in triplestoreconf["auth"] \
-
420  and triplestoreconf["auth"]["userPassword"] != None:
-
421  #QgsMessageLog.logMessage('Credentials? ' + str(triplestoreconf["auth"]["userCredential"])+" "+str(triplestoreconf["auth"]["userPassword"]), MESSAGE_CATEGORY, Qgis.Info)
-
422  if "method" in triplestoreconf["auth"] and triplestoreconf["auth"]["method"] in SPARQLUtils.authmethods:
-
423  sparql.setHTTPAuth(SPARQLUtils.authmethods[triplestoreconf["auth"]["method"]])
-
424  else:
-
425  sparql.setHTTPAuth(BASIC)
-
426  sparql.setCredentials(triplestoreconf["auth"]["userCredential"], triplestoreconf["auth"]["userPassword"])
-
427  sparql.setQuery(query)
-
428  sparql.setMethod(GET)
-
429  sparql.setReturnFormat(JSON)
-
430  try:
-
431  if len(query)>2000:
-
432  raise Exception
-
433  results = sparql.queryAndConvert()
-
434  QgsMessageLog.logMessage("Result: QUERY FINISHED WITH RESULTS", MESSAGE_CATEGORY, Qgis.Info)
-
435  #QgsMessageLog.logMessage("Result: " + str(results), MESSAGE_CATEGORY, Qgis.Info)
-
436  if isinstance(results,dict) and "status_code" in results:
-
437  #QgsMessageLog.logMessage("Result: " + str(results), MESSAGE_CATEGORY, Qgis.Info)
-
438  raise Exception
-
439  except Exception as e:
-
440  try:
-
441  sparql = SPARQLWrapper(triplestoreurl["url"],agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11")
-
442  sparql.setQuery(query)
-
443  if triplestoreconf != None and "auth" in triplestoreconf and "userCredential" in triplestoreconf["auth"] \
-
444  and triplestoreconf["auth"]["userCredential"] != "" \
-
445  and "userPassword" in triplestoreconf["auth"] \
-
446  and triplestoreconf["auth"]["userPassword"] != None:
-
447  #QgsMessageLog.logMessage(
-
448  # 'Credentials? ' + str(triplestoreconf["auth"]["userCredential"]) + " " + str(
-
449  # triplestoreconf["auth"]["userPassword"]), MESSAGE_CATEGORY, Qgis.Info)
-
450  if "method" in triplestoreconf["auth"] and triplestoreconf["auth"][
-
451  "method"] in SPARQLUtils.authmethods:
-
452  sparql.setHTTPAuth(SPARQLUtils.authmethods[triplestoreconf["auth"]["method"]])
-
453  else:
-
454  sparql.setHTTPAuth(BASIC)
-
455  sparql.setCredentials(triplestoreconf["auth"]["userCredential"],
-
456  triplestoreconf["auth"]["userPassword"])
-
457  sparql.setMethod(POST)
-
458  sparql.setReturnFormat(JSON)
-
459  results = sparql.queryAndConvert()
-
460  QgsMessageLog.logMessage("Result: QUERY FINISHED WITH RESULTS", MESSAGE_CATEGORY, Qgis.Info)
-
461  #QgsMessageLog.logMessage("Result: " + str(results), MESSAGE_CATEGORY, Qgis.Info)
-
462  if isinstance(results,dict) and "status_code" in results:
-
463  SPARQLUtils.exception = str(results)
-
464  raise Exception
-
465  except:
-
466  QgsMessageLog.logMessage("Exception: " + str(e), MESSAGE_CATEGORY, Qgis.Info)
-
467  SPARQLUtils.exception=str(e)
-
468  if "OntopUnsupportedInputQueryException: The expression Exists" in str(e):
-
469  return "Exists error"
-
470  return False
-
471  else:
-
472  graph=triplestoreurl["instance"]
-
473  QgsMessageLog.logMessage("Graph: " + str(triplestoreurl), MESSAGE_CATEGORY, Qgis.Info)
-
474  QgsMessageLog.logMessage("Query: " + str(query).replace("<", "").replace(">", ""), MESSAGE_CATEGORY, Qgis.Info)
-
475  if graph!=None:
-
476  if "CONSTRUCT" in str(query):
-
477  results = graph.query(query)
-
478  resg = Graph()
-
479  for res in results:
-
480  resg.add(res)
-
481  results=resg
-
482  else:
-
483  results=json.loads(graph.query(query).serialize(format="json"))
-
484  QgsMessageLog.logMessage("Result: " + str(results)+" triples", MESSAGE_CATEGORY, Qgis.Info)
-
485  #QgsMessageLog.logMessage("Result: " + str(len(results))+" triples", MESSAGE_CATEGORY, Qgis.Info)
-
486  return results
-
487 
+
400  def executeQuery(triplestoreurl, query,triplestoreconf=None):
+
401  results=False
+
402  SPARQLUtils.exception = None
+
403  QgsMessageLog.logMessage(str(triplestoreurl), MESSAGE_CATEGORY, Qgis.Info)
+
404  if triplestoreurl["type"]=="endpoint":
+
405  s = QSettings() # getting proxy from qgis options settings
+
406  proxyEnabled = s.value("proxy/proxyEnabled")
+
407  proxyType = s.value("proxy/proxyType")
+
408  proxyHost = s.value("proxy/proxyHost")
+
409  proxyPort = s.value("proxy/proxyPort")
+
410  proxyUser = s.value("proxy/proxyUser")
+
411  proxyPassword = s.value("proxy/proxyPassword")
+
412  if proxyHost != None and proxyHost != "" and proxyPort != None and proxyPort != "":
+
413  QgsMessageLog.logMessage('Proxy? ' + str(proxyHost), MESSAGE_CATEGORY, Qgis.Info)
+
414  proxy = urllib.request.ProxyHandler({'http': proxyHost})
+
415  opener = urllib.request.build_opener(proxy)
+
416  urllib.request.install_opener(opener)
+
417  QgsMessageLog.logMessage('Started task "{}"'.format(query.replace("<","").replace(">","")), MESSAGE_CATEGORY, Qgis.Info)
+
418  sparql = SPARQLWrapper(triplestoreurl["url"])
+
419  if triplestoreconf!=None and "auth" in triplestoreconf and "userCredential" in triplestoreconf["auth"] \
+
420  and triplestoreconf["auth"]["userCredential"]!="" \
+
421  and "userPassword" in triplestoreconf["auth"] \
+
422  and triplestoreconf["auth"]["userPassword"] != None:
+
423  #QgsMessageLog.logMessage('Credentials? ' + str(triplestoreconf["auth"]["userCredential"])+" "+str(triplestoreconf["auth"]["userPassword"]), MESSAGE_CATEGORY, Qgis.Info)
+
424  if "method" in triplestoreconf["auth"] and triplestoreconf["auth"]["method"] in SPARQLUtils.authmethods:
+
425  sparql.setHTTPAuth(SPARQLUtils.authmethods[triplestoreconf["auth"]["method"]])
+
426  else:
+
427  sparql.setHTTPAuth(BASIC)
+
428  sparql.setCredentials(triplestoreconf["auth"]["userCredential"], triplestoreconf["auth"]["userPassword"])
+
429  sparql.setQuery(query)
+
430  sparql.setMethod(GET)
+
431  sparql.setReturnFormat(JSON)
+
432  try:
+
433  if len(query)>2000:
+
434  raise Exception
+
435  results = sparql.queryAndConvert()
+
436  QgsMessageLog.logMessage("Result: QUERY FINISHED WITH RESULTS", MESSAGE_CATEGORY, Qgis.Info)
+
437  #QgsMessageLog.logMessage("Result: " + str(results), MESSAGE_CATEGORY, Qgis.Info)
+
438  if isinstance(results,dict) and "status_code" in results:
+
439  #QgsMessageLog.logMessage("Result: " + str(results), MESSAGE_CATEGORY, Qgis.Info)
+
440  raise Exception
+
441  except Exception as e:
+
442  try:
+
443  sparql = SPARQLWrapper(triplestoreurl["url"],agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11")
+
444  sparql.setQuery(query)
+
445  if triplestoreconf != None and "auth" in triplestoreconf and "userCredential" in triplestoreconf["auth"] \
+
446  and triplestoreconf["auth"]["userCredential"] != "" \
+
447  and "userPassword" in triplestoreconf["auth"] \
+
448  and triplestoreconf["auth"]["userPassword"] != None:
+
449  #QgsMessageLog.logMessage(
+
450  # 'Credentials? ' + str(triplestoreconf["auth"]["userCredential"]) + " " + str(
+
451  # triplestoreconf["auth"]["userPassword"]), MESSAGE_CATEGORY, Qgis.Info)
+
452  if "method" in triplestoreconf["auth"] and triplestoreconf["auth"][
+
453  "method"] in SPARQLUtils.authmethods:
+
454  sparql.setHTTPAuth(SPARQLUtils.authmethods[triplestoreconf["auth"]["method"]])
+
455  else:
+
456  sparql.setHTTPAuth(BASIC)
+
457  sparql.setCredentials(triplestoreconf["auth"]["userCredential"],
+
458  triplestoreconf["auth"]["userPassword"])
+
459  sparql.setMethod(POST)
+
460  sparql.setReturnFormat(JSON)
+
461  results = sparql.queryAndConvert()
+
462  QgsMessageLog.logMessage("Result: QUERY FINISHED WITH RESULTS", MESSAGE_CATEGORY, Qgis.Info)
+
463  #QgsMessageLog.logMessage("Result: " + str(results), MESSAGE_CATEGORY, Qgis.Info)
+
464  if isinstance(results,dict) and "status_code" in results:
+
465  SPARQLUtils.exception = str(results)
+
466  raise Exception
+
467  except:
+
468  QgsMessageLog.logMessage("Exception: " + str(e), MESSAGE_CATEGORY, Qgis.Info)
+
469  SPARQLUtils.exception=str(e)
+
470  if "OntopUnsupportedInputQueryException: The expression Exists" in str(e):
+
471  return "Exists error"
+
472  return False
+
473  else:
+
474  graph=triplestoreurl["instance"]
+
475  QgsMessageLog.logMessage("Graph: " + str(triplestoreurl), MESSAGE_CATEGORY, Qgis.Info)
+
476  QgsMessageLog.logMessage("Query: " + str(query).replace("<", "").replace(">", ""), MESSAGE_CATEGORY, Qgis.Info)
+
477  if graph!=None:
+
478  if "CONSTRUCT" in str(query):
+
479  results = graph.query(query)
+
480  resg = Graph()
+
481  for res in results:
+
482  resg.add(res)
+
483  results=resg
+
484  else:
+
485  results=json.loads(graph.query(query).serialize(format="json"))
+
486  #QgsMessageLog.logMessage("Result: " + str(len(results))+" triples", MESSAGE_CATEGORY, Qgis.Info)
+
487  #QgsMessageLog.logMessage("Result: " + str(len(results))+" triples", MESSAGE_CATEGORY, Qgis.Info)
+
488  return results
+
489 
@@ -555,25 +555,25 @@

-
541  def expandRelValToAmount(query,amount):
-
542  QgsMessageLog.logMessage('ExpandQuery '+str(amount)+"_" + str(query), MESSAGE_CATEGORY, Qgis.Info)
-
543  if "?rel" not in query and "?val" not in query:
-
544  return query
-
545  selectpart=query[0:query.find("WHERE")]
-
546  optionals="?item ?rel ?val . "
-
547  if amount>1:
-
548  for i in range(1,amount+1):
-
549  selectpart+=" ?rel"+str(i)+" ?val"+str(i)+" "
-
550  if i==1:
-
551  optionals += "OPTIONAL { ?val ?rel" + str(i) + " ?val" + str(i) + " . "
-
552  else:
-
553  optionals+="OPTIONAL { ?val"+str(i-1)+" ?rel"+str(i)+" ?val"+str(i)+" . "
-
554  for i in range(1,amount+1):
-
555  optionals+="}"
-
556  query=query.replace(query[0:query.find("WHERE")],selectpart).replace("?item ?rel ?val . ",optionals)
-
557  QgsMessageLog.logMessage('ExpandQuery '+str(query), MESSAGE_CATEGORY, Qgis.Info)
-
558  return query
-
559 
+
543  def expandRelValToAmount(query,amount):
+
544  QgsMessageLog.logMessage('ExpandQuery '+str(amount)+"_" + str(query), MESSAGE_CATEGORY, Qgis.Info)
+
545  if "?rel" not in query and "?val" not in query:
+
546  return query
+
547  selectpart=query[0:query.find("WHERE")]
+
548  optionals="?item ?rel ?val . "
+
549  if amount>1:
+
550  for i in range(1,amount+1):
+
551  selectpart+=" ?rel"+str(i)+" ?val"+str(i)+" "
+
552  if i==1:
+
553  optionals += "OPTIONAL { ?val ?rel" + str(i) + " ?val" + str(i) + " . "
+
554  else:
+
555  optionals+="OPTIONAL { ?val"+str(i-1)+" ?rel"+str(i)+" ?val"+str(i)+" . "
+
556  for i in range(1,amount+1):
+
557  optionals+="}"
+
558  query=query.replace(query[0:query.find("WHERE")],selectpart).replace("?item ?rel ?val . ",optionals)
+
559  QgsMessageLog.logMessage('ExpandQuery '+str(query), MESSAGE_CATEGORY, Qgis.Info)
+
560  return query
+
561 
@@ -644,98 +644,98 @@

706  def getLabelsForClasses(classes, query, triplestoreconf, triplestoreurl,preferredlang="en",typeindicator="class"):
-
707  # url="https://www.wikidata.org/w/api.php?action=wbgetentities&props=labels&ids="
-
708  result = classes
-
709  if query==None:
-
710  if typeindicator=="class":
-
711  query="SELECT ?class ?label\n WHERE { %%concepts%% \n "+SPARQLUtils.resolvePropertyToTriplePattern("%%labelproperty%%","?label","?class",triplestoreconf,"OPTIONAL","FILTER(LANG(?label) = \""+str(preferredlang)+"\") ")+" \n} "
-
712  if "SELECT" in query and "resource" in triplestoreconf \
-
713  and "type" in triplestoreconf["resource"] \
-
714  and ((triplestoreconf["resource"]["type"]=="endpoint"
-
715  and "sparql11" in triplestoreconf["resource"]
-
716  and triplestoreconf["resource"]["sparql11"]==True)
-
717  or triplestoreconf["resource"]["type"]!="endpoint"):
-
718  vals = "VALUES ?class {\n "
-
719  for qid in classes.keys():
-
720  vals += "<"+qid + "> \n"
-
721  vals += "}\n"
-
722  query = query.replace("%%concepts%%", vals)
-
723  #QgsMessageLog.logMessage("Querying for "+str(len(vals))+" concepts", MESSAGE_CATEGORY, Qgis.Info)
-
724  results = SPARQLUtils.executeQuery(triplestoreurl, query)
-
725  if results == False:
-
726  return result
-
727  #QgsMessageLog.logMessage("Got " + str(len(results)) + " labels", MESSAGE_CATEGORY, Qgis.Info)
-
728  for res in results["results"]["bindings"]:
-
729  if res["class"]["value"] in classes and "label" in res:
-
730  classes[res["class"]["value"]]["label"]=res["label"]["value"]
-
731  else:
-
732  classes[res["class"]["value"]]["label"] = ""
-
733  elif query.startswith("http"):
-
734  url = query
-
735  i = 0
-
736  qidquery = ""
-
737  wdprefix = ""
-
738  firstkey=next(iter(classes))
-
739  #QgsMessageLog.logMessage(str(firstkey), MESSAGE_CATEGORY, Qgis.Info)
-
740  if "Q" in firstkey:
-
741  wdprefix = "http://www.wikidata.org/entity/"
-
742  elif "P" in firstkey:
-
743  wdprefix = "http://www.wikidata.org/prop/direct/"
-
744  for qid in classes.keys():
-
745  #QgsMessageLog.logMessage(str(qid), MESSAGE_CATEGORY, Qgis.Info)
-
746  if "wikidata" in triplestoreurl["url"] and "Q" in qid:
-
747  qidquery += "Q" + qid.split("Q")[1]
-
748  elif "wikidata" in triplestoreurl["url"] and "P" in qid:
-
749  qidquery += "P" + qid.split("P")[1]
-
750  elif "wikidata" in triplestoreurl["url"]:
-
751  result[qid]["label"] = qid
-
752  continue
-
753  if (i % 50) == 0:
-
754  while qidquery.endswith("|"):
-
755  qidquery=qidquery[:-1]
-
756  #QgsMessageLog.logMessage(str(url.replace("%%concepts%%", qidquery)), MESSAGE_CATEGORY, Qgis.Info)
-
757  myResponse = json.loads(requests.get(url.replace("%%concepts%%", qidquery).replace("%%language%%",preferredlang)).text)
-
758  #QgsMessageLog.logMessage(str(myResponse), MESSAGE_CATEGORY, Qgis.Info)
-
759  #QgsMessageLog.logMessage("Entities: "+str(len(myResponse["entities"])), MESSAGE_CATEGORY, Qgis.Info)
-
760  if "entities" in myResponse:
-
761  for ent in myResponse["entities"]:
-
762  QgsMessageLog.logMessage(str(ent), MESSAGE_CATEGORY, Qgis.Info)
-
763  if ent.startswith("P"):
-
764  wdprefix="http://www.wikidata.org/prop/direct/"
-
765  elif ent.startswith("Q"):
-
766  wdprefix="http://www.wikidata.org/entity/"
-
767  else:
-
768  wdprefix=""
-
769  QgsMessageLog.logMessage(str(result), MESSAGE_CATEGORY, Qgis.Info)
-
770  if preferredlang in myResponse["entities"][ent]["labels"]:
-
771  result[wdprefix+ent]["label"] = myResponse["entities"][ent]["labels"][preferredlang]["value"]
-
772  elif "en" in myResponse["entities"][ent]["labels"]:
-
773  result[wdprefix+ent]["label"] = myResponse["entities"][ent]["labels"]["en"]["value"]
-
774  else:
-
775  result[wdprefix+ent]["label"]=qid
-
776  qidquery = ""
-
777  else:
-
778  qidquery += "|"
-
779  i = i + 1
-
780  if qidquery!="":
-
781  while qidquery.endswith("|"):
-
782  qidquery = qidquery[:-1]
-
783  #QgsMessageLog.logMessage(str(url.replace("%%concepts%%", qidquery)), MESSAGE_CATEGORY, Qgis.Info)
-
784  myResponse = json.loads(requests.get(url.replace("%%concepts%%", qidquery)).text)
-
785  #QgsMessageLog.logMessage(str(myResponse), MESSAGE_CATEGORY, Qgis.Info)
-
786  #QgsMessageLog.logMessage("Entities: "+str(len(myResponse["entities"])), MESSAGE_CATEGORY, Qgis.Info)
-
787  if "entities" in myResponse:
-
788  for ent in myResponse["entities"]:
-
789  print(ent)
-
790  if preferredlang in myResponse["entities"][ent]["labels"]:
-
791  result[wdprefix+ent]["label"] = myResponse["entities"][ent]["labels"][preferredlang]["value"]
-
792  elif "en" in myResponse["entities"][ent]["labels"]:
-
793  result[wdprefix+ent]["label"] = myResponse["entities"][ent]["labels"]["en"]["value"]
-
794  else:
-
795  result[wdprefix+ent]["label"] = ""
-
796  return result
-
797 
+
708  def getLabelsForClasses(classes, query, triplestoreconf, triplestoreurl,preferredlang="en",typeindicator="class"):
+
709  # url="https://www.wikidata.org/w/api.php?action=wbgetentities&props=labels&ids="
+
710  result = classes
+
711  if query==None:
+
712  if typeindicator=="class":
+
713  query="SELECT ?class ?label\n WHERE { %%concepts%% \n "+SPARQLUtils.resolvePropertyToTriplePattern("%%labelproperty%%","?label","?class",triplestoreconf,"OPTIONAL","FILTER(LANG(?label) = \""+str(preferredlang)+"\") ")+" \n} "
+
714  if "SELECT" in query and "resource" in triplestoreconf \
+
715  and "type" in triplestoreconf["resource"] \
+
716  and ((triplestoreconf["resource"]["type"]=="endpoint"
+
717  and "sparql11" in triplestoreconf["resource"]
+
718  and triplestoreconf["resource"]["sparql11"]==True)
+
719  or triplestoreconf["resource"]["type"]!="endpoint"):
+
720  vals = "VALUES ?class {\n "
+
721  for qid in classes.keys():
+
722  vals += "<"+qid + "> \n"
+
723  vals += "}\n"
+
724  query = query.replace("%%concepts%%", vals)
+
725  #QgsMessageLog.logMessage("Querying for "+str(len(vals))+" concepts", MESSAGE_CATEGORY, Qgis.Info)
+
726  results = SPARQLUtils.executeQuery(triplestoreurl, query)
+
727  if results == False:
+
728  return result
+
729  #QgsMessageLog.logMessage("Got " + str(len(results)) + " labels", MESSAGE_CATEGORY, Qgis.Info)
+
730  for res in results["results"]["bindings"]:
+
731  if res["class"]["value"] in classes and "label" in res:
+
732  classes[res["class"]["value"]]["label"]=res["label"]["value"]
+
733  else:
+
734  classes[res["class"]["value"]]["label"] = ""
+
735  elif query.startswith("http"):
+
736  url = query
+
737  i = 0
+
738  qidquery = ""
+
739  wdprefix = ""
+
740  firstkey=next(iter(classes))
+
741  #QgsMessageLog.logMessage(str(firstkey), MESSAGE_CATEGORY, Qgis.Info)
+
742  if "Q" in firstkey:
+
743  wdprefix = "http://www.wikidata.org/entity/"
+
744  elif "P" in firstkey:
+
745  wdprefix = "http://www.wikidata.org/prop/direct/"
+
746  for qid in classes.keys():
+
747  #QgsMessageLog.logMessage(str(qid), MESSAGE_CATEGORY, Qgis.Info)
+
748  if "wikidata" in triplestoreurl["url"] and "Q" in qid:
+
749  qidquery += "Q" + qid.split("Q")[1]
+
750  elif "wikidata" in triplestoreurl["url"] and "P" in qid:
+
751  qidquery += "P" + qid.split("P")[1]
+
752  elif "wikidata" in triplestoreurl["url"]:
+
753  result[qid]["label"] = qid
+
754  continue
+
755  if (i % 50) == 0:
+
756  while qidquery.endswith("|"):
+
757  qidquery=qidquery[:-1]
+
758  #QgsMessageLog.logMessage(str(url.replace("%%concepts%%", qidquery)), MESSAGE_CATEGORY, Qgis.Info)
+
759  myResponse = json.loads(requests.get(url.replace("%%concepts%%", qidquery).replace("%%language%%",preferredlang)).text)
+
760  #QgsMessageLog.logMessage(str(myResponse), MESSAGE_CATEGORY, Qgis.Info)
+
761  #QgsMessageLog.logMessage("Entities: "+str(len(myResponse["entities"])), MESSAGE_CATEGORY, Qgis.Info)
+
762  if "entities" in myResponse:
+
763  for ent in myResponse["entities"]:
+
764  #QgsMessageLog.logMessage(str(ent), MESSAGE_CATEGORY, Qgis.Info)
+
765  if ent.startswith("P"):
+
766  wdprefix="http://www.wikidata.org/prop/direct/"
+
767  elif ent.startswith("Q"):
+
768  wdprefix="http://www.wikidata.org/entity/"
+
769  else:
+
770  wdprefix=""
+
771  #QgsMessageLog.logMessage(str(result), MESSAGE_CATEGORY, Qgis.Info)
+
772  if preferredlang in myResponse["entities"][ent]["labels"]:
+
773  result[wdprefix+ent]["label"] = myResponse["entities"][ent]["labels"][preferredlang]["value"]
+
774  elif "en" in myResponse["entities"][ent]["labels"]:
+
775  result[wdprefix+ent]["label"] = myResponse["entities"][ent]["labels"]["en"]["value"]
+
776  else:
+
777  result[wdprefix+ent]["label"]=qid
+
778  qidquery = ""
+
779  else:
+
780  qidquery += "|"
+
781  i = i + 1
+
782  if qidquery!="":
+
783  while qidquery.endswith("|"):
+
784  qidquery = qidquery[:-1]
+
785  #QgsMessageLog.logMessage(str(url.replace("%%concepts%%", qidquery)), MESSAGE_CATEGORY, Qgis.Info)
+
786  myResponse = json.loads(requests.get(url.replace("%%concepts%%", qidquery)).text)
+
787  #QgsMessageLog.logMessage(str(myResponse), MESSAGE_CATEGORY, Qgis.Info)
+
788  #QgsMessageLog.logMessage("Entities: "+str(len(myResponse["entities"])), MESSAGE_CATEGORY, Qgis.Info)
+
789  if "entities" in myResponse:
+
790  for ent in myResponse["entities"]:
+
791  print(ent)
+
792  if preferredlang in myResponse["entities"][ent]["labels"]:
+
793  result[wdprefix+ent]["label"] = myResponse["entities"][ent]["labels"][preferredlang]["value"]
+
794  elif "en" in myResponse["entities"][ent]["labels"]:
+
795  result[wdprefix+ent]["label"] = myResponse["entities"][ent]["labels"]["en"]["value"]
+
796  else:
+
797  result[wdprefix+ent]["label"] = ""
+
798  return result
+
799 
@@ -778,15 +778,15 @@

-
495  def handleException(callingtask="",title=None,text=None):
-
496  if SPARQLUtils.exception!=None:
-
497  ErrorMessageBox(callingtask+" An error occurred!","<html>"+str(SPARQLUtils.exception).replace("\n","<br/>")+"</html>").exec_()
-
498  return True
-
499  if title!=None and text!=None:
-
500  ErrorMessageBox(callingtask+" "+title,"<html>"+text.replace("\n","<br/>")+"</html>").exec_()
-
501  return True
-
502  return False
-
503 
+
497  def handleException(callingtask="",title=None,text=None):
+
498  if SPARQLUtils.exception!=None:
+
499  ErrorMessageBox(callingtask+" An error occurred!","<html>"+str(SPARQLUtils.exception).replace("\n","<br/>")+"</html>").exec_()
+
500  return True
+
501  if title!=None and text!=None:
+
502  ErrorMessageBox(callingtask+" "+title,"<html>"+text.replace("\n","<br/>")+"</html>").exec_()
+
503  return True
+
504  return False
+
505 
@@ -829,27 +829,27 @@

-
646  def handleGeoJSONFile(myjson,currentlayergeojson,onlygeo):
-
647  result=[]
-
648  if "data" in myjson and "type" in myjson["data"] and myjson["data"]["type"] == "FeatureCollection":
-
649  features = myjson["data"]["features"]
-
650  curcounter = 0
-
651  for feat in features:
-
652  if currentlayergeojson==None:
-
653  result.append(feat["geometry"])
-
654  else:
-
655  if onlygeo and "properties" in feat:
-
656  del feat["properties"]
-
657  if "id" in feat and curcounter > 0:
-
658  feat["id"] = feat["id"] + "_" + str(curcounter)
-
659  if "properties" in currentlayergeojson:
-
660  if "properties" not in feat:
-
661  feat["properties"] = {}
-
662  for prop in currentlayergeojson["properties"]:
-
663  feat["properties"][prop] = currentlayergeojson["properties"][prop]
-
664  result.append(feat)
-
665  curcounter = 1
-
666 
+
648  def handleGeoJSONFile(myjson,currentlayergeojson,onlygeo):
+
649  result=[]
+
650  if "data" in myjson and "type" in myjson["data"] and myjson["data"]["type"] == "FeatureCollection":
+
651  features = myjson["data"]["features"]
+
652  curcounter = 0
+
653  for feat in features:
+
654  if currentlayergeojson==None:
+
655  result.append(feat["geometry"])
+
656  else:
+
657  if onlygeo and "properties" in feat:
+
658  del feat["properties"]
+
659  if "id" in feat and curcounter > 0:
+
660  feat["id"] = feat["id"] + "_" + str(curcounter)
+
661  if "properties" in currentlayergeojson:
+
662  if "properties" not in feat:
+
663  feat["properties"] = {}
+
664  for prop in currentlayergeojson["properties"]:
+
665  feat["properties"][prop] = currentlayergeojson["properties"][prop]
+
666  result.append(feat)
+
667  curcounter = 1
+
668 
@@ -892,39 +892,39 @@

-
668  def handleURILiteral(uri,currentlayergeojson,onlygeo=True):
-
669  if uri.startswith("http"):
-
670  if uri.endswith(".map") or uri.endswith("geojson"):
-
671  try:
-
672  f = urlopen(uri)
-
673  myjson = json.loads(f.read())
-
674  return SPARQLUtils.handleGeoJSONFile(myjson,currentlayergeojson,onlygeo)
-
675  except Exception as e:
-
676  QgsMessageLog.logMessage("Error getting geoshape " + str(uri) + " - " + str(e))
-
677  elif uri.startswith("http") and uri.endswith(".kml"):
-
678  try:
-
679  f = urlopen(uri)
-
680  kmlfile=f.read()
-
681  f=open("temp.kml","w")
-
682  f.write(kmlfile)
-
683  f.close()
-
684  vlayer = QgsVectorLayer("temp.kml", "layer", "ogr")
-
685  return SPARQLUtils.mergeLayers(vlayer,currentlayergeojson)
-
686  except Exception as e:
-
687  QgsMessageLog.logMessage("Error getting kml " + str(uri) + " - " + str(e))
-
688  elif uri.startswith("http") and uri.endswith(".gml"):
-
689  try:
-
690  f = urlopen(uri)
-
691  gmlfile=f.read()
-
692  f=open("temp.gml","w")
-
693  f.write(gmlfile)
-
694  f.close()
-
695  vlayer = QgsVectorLayer("temp.gml", "layer", "ogr")
-
696  return SPARQLUtils.mergeLayers(vlayer,currentlayergeojson)
-
697  except Exception as e:
-
698  QgsMessageLog.logMessage("Error getting gml " + str(uri) + " - " + str(e))
-
699  return None
-
700 
+
670  def handleURILiteral(uri,currentlayergeojson,onlygeo=True):
+
671  if uri.startswith("http"):
+
672  if uri.endswith(".map") or uri.endswith("geojson"):
+
673  try:
+
674  f = urlopen(uri)
+
675  myjson = json.loads(f.read())
+
676  return SPARQLUtils.handleGeoJSONFile(myjson,currentlayergeojson,onlygeo)
+
677  except Exception as e:
+
678  QgsMessageLog.logMessage("Error getting geoshape " + str(uri) + " - " + str(e))
+
679  elif uri.startswith("http") and uri.endswith(".kml"):
+
680  try:
+
681  f = urlopen(uri)
+
682  kmlfile=f.read()
+
683  f=open("temp.kml","w")
+
684  f.write(kmlfile)
+
685  f.close()
+
686  vlayer = QgsVectorLayer("temp.kml", "layer", "ogr")
+
687  return SPARQLUtils.mergeLayers(vlayer,currentlayergeojson)
+
688  except Exception as e:
+
689  QgsMessageLog.logMessage("Error getting kml " + str(uri) + " - " + str(e))
+
690  elif uri.startswith("http") and uri.endswith(".gml"):
+
691  try:
+
692  f = urlopen(uri)
+
693  gmlfile=f.read()
+
694  f=open("temp.gml","w")
+
695  f.write(gmlfile)
+
696  f.close()
+
697  vlayer = QgsVectorLayer("temp.gml", "layer", "ogr")
+
698  return SPARQLUtils.mergeLayers(vlayer,currentlayergeojson)
+
699  except Exception as e:
+
700  QgsMessageLog.logMessage("Error getting gml " + str(uri) + " - " + str(e))
+
701  return None
+
702 
@@ -951,15 +951,15 @@

-
505  def instanceToNS(uri):
-
506  if not uri.startswith("http"):
-
507  return uri
-
508  if "#" in uri:
-
509  return uri[:uri.rfind("#") + 1]
-
510  if "/" in uri:
-
511  return uri[:uri.rfind("/") + 1]
-
512  return uri
-
513 
+
507  def instanceToNS(uri):
+
508  if not uri.startswith("http"):
+
509  return uri
+
510  if "#" in uri:
+
511  return uri[:uri.rfind("#") + 1]
+
512  if "/" in uri:
+
513  return uri[:uri.rfind("/") + 1]
+
514  return uri
+
515 
@@ -986,11 +986,11 @@

-
489  def invertPrefixes(prefixes):
-
490  #QgsMessageLog.logMessage("Invert Prefixes: " + str(prefixes), MESSAGE_CATEGORY, Qgis.Info)
-
491  inv_map = {v: k for k, v in prefixes.items()}
-
492  return inv_map
-
493 
+
491  def invertPrefixes(prefixes):
+
492  #QgsMessageLog.logMessage("Invert Prefixes: " + str(prefixes), MESSAGE_CATEGORY, Qgis.Info)
+
493  inv_map = {v: k for k, v in prefixes.items()}
+
494  return inv_map
+
495 
@@ -1027,25 +1027,25 @@

-
515  def labelFromURI(uri,prefixlist=None):
-
516  if not uri.startswith("http"):
-
517  return uri
-
518  if uri.endswith("#"):
-
519  uri=uri[0:-1]
-
520  if "#" in uri:
-
521  prefix=uri[:uri.rfind("#")+1]
-
522  if prefixlist!=None and prefix in prefixlist:
-
523  return str(prefixlist[prefix])+":"+str(uri[uri.rfind("#") + 1:])
-
524  return uri[uri.rfind("#") + 1:]
-
525  if uri.endswith("/"):
-
526  uri=uri[0:-1]
-
527  if "/" in uri:
-
528  prefix=uri[:uri.rfind("/")+1]
-
529  if prefixlist!=None and prefix in prefixlist:
-
530  return str(prefixlist[prefix])+":"+str(uri[uri.rfind("/") + 1:])
-
531  return uri[uri.rfind("/") + 1:]
-
532  return uri
-
533 
+
517  def labelFromURI(uri,prefixlist=None):
+
518  if not uri.startswith("http"):
+
519  return uri
+
520  if uri.endswith("#"):
+
521  uri=uri[0:-1]
+
522  if "#" in uri:
+
523  prefix=uri[:uri.rfind("#")+1]
+
524  if prefixlist!=None and prefix in prefixlist:
+
525  return str(prefixlist[prefix])+":"+str(uri[uri.rfind("#") + 1:])
+
526  return uri[uri.rfind("#") + 1:]
+
527  if uri.endswith("/"):
+
528  uri=uri[0:-1]
+
529  if "/" in uri:
+
530  prefix=uri[:uri.rfind("/")+1]
+
531  if prefixlist!=None and prefix in prefixlist:
+
532  return str(prefixlist[prefix])+":"+str(uri[uri.rfind("/") + 1:])
+
533  return uri[uri.rfind("/") + 1:]
+
534  return uri
+
535 
@@ -1082,10 +1082,10 @@

-
561  def loadAdditionalGraphResources(existinggraph,graphuri):
-
562  if graphuri==None or graphuri=="":
-
563  return None
-
564 
+
563  def loadAdditionalGraphResources(existinggraph,graphuri):
+
564  if graphuri==None or graphuri=="":
+
565  return None
+
566 
@@ -1122,41 +1122,41 @@

-
566  def loadGraph(graphuri,graph=None):
-
567  if graphuri==None or graphuri=="":
-
568  return None
-
569  s = QSettings() # getting proxy from qgis options settings
-
570  proxyEnabled = s.value("proxy/proxyEnabled")
-
571  proxyType = s.value("proxy/proxyType")
-
572  proxyHost = s.value("proxy/proxyHost")
-
573  proxyPort = s.value("proxy/proxyPort")
-
574  proxyUser = s.value("proxy/proxyUser")
-
575  proxyPassword = s.value("proxy/proxyPassword")
-
576  if proxyHost != None and proxyHost != "" and proxyPort != None and proxyPort != "":
-
577  #QgsMessageLog.logMessage('Proxy? ' + str(proxyHost), MESSAGE_CATEGORY, Qgis.Info)
-
578  proxy = urllib.request.ProxyHandler({'http': proxyHost})
-
579  opener = urllib.request.build_opener(proxy)
-
580  urllib.request.install_opener(opener)
-
581  #QgsMessageLog.logMessage('Started task "{}"'.format("Load Graph"), MESSAGE_CATEGORY, Qgis.Info)
-
582  if graph==None:
-
583  graph = Graph()
-
584  try:
-
585  if graphuri.startswith("http"):
-
586  QgsMessageLog.logMessage(" Data: " + str(graphuri) + "", MESSAGE_CATEGORY, Qgis.Info)
-
587  with urllib.request.urlopen(graphuri) as data:
-
588  readit=data.read().decode()
-
589  QgsMessageLog.logMessage(" Data: "+str(readit)+"", MESSAGE_CATEGORY, Qgis.Info)
-
590  filepath = graphuri.split(".")
-
591  graph.parse(data=readit,format=filepath[len(filepath) - 1])
-
592  else:
-
593  filepath = graphuri.split(".")
-
594  result = graph.parse(graphuri, format=filepath[len(filepath) - 1])
-
595  except Exception as e:
-
596  QgsMessageLog.logMessage('Failed "{}"'.format(str(e)), MESSAGE_CATEGORY, Qgis.Info)
-
597  #self.exception = str(e)
-
598  return None
-
599  return graph
-
600 
+
568  def loadGraph(graphuri,graph=None):
+
569  if graphuri==None or graphuri=="":
+
570  return None
+
571  s = QSettings() # getting proxy from qgis options settings
+
572  proxyEnabled = s.value("proxy/proxyEnabled")
+
573  proxyType = s.value("proxy/proxyType")
+
574  proxyHost = s.value("proxy/proxyHost")
+
575  proxyPort = s.value("proxy/proxyPort")
+
576  proxyUser = s.value("proxy/proxyUser")
+
577  proxyPassword = s.value("proxy/proxyPassword")
+
578  if proxyHost != None and proxyHost != "" and proxyPort != None and proxyPort != "":
+
579  #QgsMessageLog.logMessage('Proxy? ' + str(proxyHost), MESSAGE_CATEGORY, Qgis.Info)
+
580  proxy = urllib.request.ProxyHandler({'http': proxyHost})
+
581  opener = urllib.request.build_opener(proxy)
+
582  urllib.request.install_opener(opener)
+
583  #QgsMessageLog.logMessage('Started task "{}"'.format("Load Graph"), MESSAGE_CATEGORY, Qgis.Info)
+
584  if graph==None:
+
585  graph = Graph()
+
586  try:
+
587  if graphuri.startswith("http"):
+
588  QgsMessageLog.logMessage(" Data: " + str(graphuri) + "", MESSAGE_CATEGORY, Qgis.Info)
+
589  with urllib.request.urlopen(graphuri) as data:
+
590  readit=data.read().decode()
+
591  QgsMessageLog.logMessage(" Data: "+str(readit)+"", MESSAGE_CATEGORY, Qgis.Info)
+
592  filepath = graphuri.split(".")
+
593  graph.parse(data=readit,format=filepath[len(filepath) - 1])
+
594  else:
+
595  filepath = graphuri.split(".")
+
596  result = graph.parse(graphuri, format=filepath[len(filepath) - 1])
+
597  except Exception as e:
+
598  QgsMessageLog.logMessage('Failed "{}"'.format(str(e)), MESSAGE_CATEGORY, Qgis.Info)
+
599  #self.exception = str(e)
+
600  return None
+
601  return graph
+
602 
@@ -1193,21 +1193,21 @@

-
630  def mergeLayers(layer1,geojson):
-
631  result=[]
-
632  if "properties" not in geojson:
-
633  geojson["properties"]={}
-
634  feats1 = layer1.getFeatures()
-
635  for feature in feats1:
-
636  curfeature={"type":"Feature","id":feature.id,"properties":{},"geometry":feature.geometry().asJson()}
-
637  if "properties" in geojson:
-
638  for prop in geojson["properties"]:
-
639  curfeature["properties"][prop]=geojson["properties"][prop]
-
640  for attr in feature:
-
641  curfeature["properties"][attr] = feature[attr]
-
642  result.append(curfeature)
-
643  return result
-
644 
+
632  def mergeLayers(layer1,geojson):
+
633  result=[]
+
634  if "properties" not in geojson:
+
635  geojson["properties"]={}
+
636  feats1 = layer1.getFeatures()
+
637  for feature in feats1:
+
638  curfeature={"type":"Feature","id":feature.id,"properties":{},"geometry":feature.geometry().asJson()}
+
639  if "properties" in geojson:
+
640  for prop in geojson["properties"]:
+
641  curfeature["properties"][prop]=geojson["properties"][prop]
+
642  for attr in feature:
+
643  curfeature["properties"][attr] = feature[attr]
+
644  result.append(curfeature)
+
645  return result
+
646 
@@ -1250,21 +1250,21 @@

-
799  def patternsToUnion(patternarray,propvar,itemvar):
-
800  res=""
-
801  if len(patternarray)==1:
-
802  return patternarray[0]
-
803  if patternarray>1:
-
804  first=True
-
805  for pat in patternarray:
-
806  if first:
-
807  first=False
-
808  res+="{ "+str(itemvar)+" <"+str(pat)+"> "+str(propvar)+" . } "
-
809  else:
-
810  res+="UNION { "+str(itemvar)+" <"+str(pat)+"> "+str(propvar)+" . } "
-
811  return res
-
812  return res
-
813 
+
801  def patternsToUnion(patternarray,propvar,itemvar):
+
802  res=""
+
803  if len(patternarray)==1:
+
804  return patternarray[0]
+
805  if patternarray>1:
+
806  first=True
+
807  for pat in patternarray:
+
808  if first:
+
809  first=False
+
810  res+="{ "+str(itemvar)+" <"+str(pat)+"> "+str(propvar)+" . } "
+
811  else:
+
812  res+="UNION { "+str(itemvar)+" <"+str(pat)+"> "+str(propvar)+" . } "
+
813  return res
+
814  return res
+
815 
@@ -1313,12 +1313,12 @@

-
815  def propertyVarPatternToUnion(propertyid,triplestoreconf,propvar,itemvar):
-
816  propidcleaned = propertyid.replace("%", "")
-
817  if propidcleaned in triplestoreconf:
-
818  return SPARQLUtils.patternsToUnion(triplestoreconf[propidcleaned],propvar,itemvar)
-
819  return ""
-
820 
+
817  def propertyVarPatternToUnion(propertyid,triplestoreconf,propvar,itemvar):
+
818  propidcleaned = propertyid.replace("%", "")
+
819  if propidcleaned in triplestoreconf:
+
820  return SPARQLUtils.patternsToUnion(triplestoreconf[propidcleaned],propvar,itemvar)
+
821  return ""
+
822 
@@ -1367,36 +1367,36 @@

-
328  def queryPreProcessing(query,triplestoreconf,concept=None,convertToCollectionForm=False):
-
329  QgsMessageLog.logMessage('Preprocessing"{}"'.format(query.replace("<", "").replace(">", "")), MESSAGE_CATEGORY,
-
330  Qgis.Info)
-
331  if convertToCollectionForm:
-
332  query=query.replace("?con %%typeproperty%% %%concept%% .","%%concept%% %%collectionmemberproperty%% ?con .")
-
333  if concept!=None:
-
334  if "resource" in triplestoreconf and "url" in triplestoreconf["resource"] and "wikidata" in triplestoreconf["resource"]["url"] and concept[concept.find('(')+1:-1].startswith("Q"):
-
335  query=query.replace("%%concept%%",str("wd:" + concept[concept.find('(')+1:-1]))
-
336  else:
-
337  query = query.replace("%%concept%%", "<" + str(concept) + ">")
-
338  typeproperty = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
-
339  if "typeproperty" in triplestoreconf:
-
340  typeproperty=triplestoreconf["typeproperty"]
-
341  subclassproperty = "http://www.w3.org/2000/01/rdf-schema#subClassOf"
-
342  if "subclassproperty" in triplestoreconf:
-
343  subclassproperty=triplestoreconf["subclassproperty"]
-
344  labelproperty = "http://www.w3.org/2000/01/rdf-schema#label"
-
345  if "labelproperty" in triplestoreconf:
-
346  labelproperty =triplestoreconf["labelproperty"]
-
347  collectionmemberproperty="http://www.w3.org/2000/01/rdf-schema#member"
-
348  if "collectionmemberproperty" in triplestoreconf:
-
349  collectionmemberproperty=triplestoreconf["collectionmemberproperty"]
-
350  query=query.replace("%%subclassproperty%%","<"+subclassproperty+">")\
-
351  .replace("%%typeproperty%%","<"+typeproperty+">")\
-
352  .replace("%%labelproperty%%","<"+labelproperty[0]+">")\
-
353  .replace("%%collectionmemberproperty%%","<"+collectionmemberproperty+">").replace("<<","<").replace(">>",">")
-
354  QgsMessageLog.logMessage('Preprocessing finished"{}"'.format(query.replace("<", "").replace(">", "")), MESSAGE_CATEGORY,
-
355  Qgis.Info)
-
356  return query
-
357 
+
330  def queryPreProcessing(query,triplestoreconf,concept=None,convertToCollectionForm=False):
+
331  QgsMessageLog.logMessage('Preprocessing"{}"'.format(query.replace("<", "").replace(">", "")), MESSAGE_CATEGORY,
+
332  Qgis.Info)
+
333  if convertToCollectionForm:
+
334  query=query.replace("?con %%typeproperty%% %%concept%% .","%%concept%% %%collectionmemberproperty%% ?con .")
+
335  if concept!=None:
+
336  if "resource" in triplestoreconf and "url" in triplestoreconf["resource"] and "wikidata" in triplestoreconf["resource"]["url"] and concept[concept.find('(')+1:-1].startswith("Q"):
+
337  query=query.replace("%%concept%%",str("wd:" + concept[concept.find('(')+1:-1]))
+
338  else:
+
339  query = query.replace("%%concept%%", "<" + str(concept) + ">")
+
340  typeproperty = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
+
341  if "typeproperty" in triplestoreconf:
+
342  typeproperty=triplestoreconf["typeproperty"]
+
343  subclassproperty = "http://www.w3.org/2000/01/rdf-schema#subClassOf"
+
344  if "subclassproperty" in triplestoreconf:
+
345  subclassproperty=triplestoreconf["subclassproperty"]
+
346  labelproperty = "http://www.w3.org/2000/01/rdf-schema#label"
+
347  if "labelproperty" in triplestoreconf:
+
348  labelproperty =triplestoreconf["labelproperty"]
+
349  collectionmemberproperty="http://www.w3.org/2000/01/rdf-schema#member"
+
350  if "collectionmemberproperty" in triplestoreconf:
+
351  collectionmemberproperty=triplestoreconf["collectionmemberproperty"]
+
352  query=query.replace("%%subclassproperty%%","<"+subclassproperty+">")\
+
353  .replace("%%typeproperty%%","<"+typeproperty+">")\
+
354  .replace("%%labelproperty%%","<"+labelproperty[0]+">")\
+
355  .replace("%%collectionmemberproperty%%","<"+collectionmemberproperty+">").replace("<<","<").replace(">>",">")
+
356  QgsMessageLog.logMessage('Preprocessing finished"{}"'.format(query.replace("<", "").replace(">", "")), MESSAGE_CATEGORY,
+
357  Qgis.Info)
+
358  return query
+
359 
@@ -1469,39 +1469,39 @@

-
838  def resolvePropertyToTriplePattern(propertyid,propvar,itemvar,triplestoreconf,patterntype,filterstatement,proplabel=False,asUnion=True):
-
839  if filterstatement==None:
-
840  filterstatement=""
-
841  propidcleaned=propertyid.replace("%","")
-
842  if propidcleaned in triplestoreconf:
-
843  res=""
-
844  first=True
-
845  if asUnion and patterntype=="OPTIONAL":
-
846  res+="OPTIONAL { "
-
847  for propid in triplestoreconf[propidcleaned]:
-
848  thepattern=str(itemvar)+" <"+str(propid)+"> "+str(propvar)+" .\n "+filterstatement
-
849  if proplabel and "url" in triplestoreconf["resource"] and (
-
850  "wikidata" in triplestoreconf["resource"]["url"] or "factgrid" in triplestoreconf["resource"][
-
851  "url"]):
-
852  thepattern="?prop <http://wikiba.se/ontology#directClaim> "+str(itemvar)+" . ?prop <"+str(propid)+"> "+str(propvar)+" .\n"+filterstatement
-
853  if patterntype=="OPTIONAL" and not asUnion:
-
854  res+="OPTIONAL { "+thepattern+"}\n"
-
855  elif patterntype == "OPTIONAL" and asUnion:
-
856  if first:
-
857  first=False
-
858  res+=" { "+thepattern+" } "
-
859  else:
-
860  res += " UNION { " + thepattern + "}\n"
-
861  else:
-
862  res+=thepattern
-
863  if asUnion and patterntype=="OPTIONAL":
-
864  res+="} "
-
865  return res
-
866  if proplabel and "url" in triplestoreconf["resource"] and (
-
867  "wikidata" in triplestoreconf["resource"]["url"] or "factgrid" in triplestoreconf["resource"]["url"]):
-
868  return "?prop <http://wikiba.se/ontology#directClaim> "+str(itemvar)+" . ?prop "+str(propertyid)+" "+str(propvar)+" .\n"
-
869  else:
-
870  return str(itemvar)+" "+str(propertyid)+" "+str(propvar)+" .\n"
+
840  def resolvePropertyToTriplePattern(propertyid,propvar,itemvar,triplestoreconf,patterntype,filterstatement,proplabel=False,asUnion=True):
+
841  if filterstatement==None:
+
842  filterstatement=""
+
843  propidcleaned=propertyid.replace("%","")
+
844  if propidcleaned in triplestoreconf:
+
845  res=""
+
846  first=True
+
847  if asUnion and patterntype=="OPTIONAL":
+
848  res+="OPTIONAL { "
+
849  for propid in triplestoreconf[propidcleaned]:
+
850  thepattern=str(itemvar)+" <"+str(propid)+"> "+str(propvar)+" .\n "+filterstatement
+
851  if proplabel and "url" in triplestoreconf["resource"] and (
+
852  "wikidata" in triplestoreconf["resource"]["url"] or "factgrid" in triplestoreconf["resource"][
+
853  "url"]):
+
854  thepattern="?prop <http://wikiba.se/ontology#directClaim> "+str(itemvar)+" . ?prop <"+str(propid)+"> "+str(propvar)+" .\n"+filterstatement
+
855  if patterntype=="OPTIONAL" and not asUnion:
+
856  res+="OPTIONAL { "+thepattern+"}\n"
+
857  elif patterntype == "OPTIONAL" and asUnion:
+
858  if first:
+
859  first=False
+
860  res+=" { "+thepattern+" } "
+
861  else:
+
862  res += " UNION { " + thepattern + "}\n"
+
863  else:
+
864  res+=thepattern
+
865  if asUnion and patterntype=="OPTIONAL":
+
866  res+="} "
+
867  return res
+
868  if proplabel and "url" in triplestoreconf["resource"] and (
+
869  "wikidata" in triplestoreconf["resource"]["url"] or "factgrid" in triplestoreconf["resource"]["url"]):
+
870  return "?prop <http://wikiba.se/ontology#directClaim> "+str(itemvar)+" . ?prop "+str(propertyid)+" "+str(propvar)+" .\n"
+
871  else:
+
872  return str(itemvar)+" "+str(propertyid)+" "+str(propvar)+" .\n"
@@ -1528,21 +1528,21 @@

-
822  def selectQueryToConstructQuery(query):
-
823  mquery=query[query.find("WHERE"):query.rfind("}")+1]
-
824  query=query[query.find("WHERE"):]
-
825  constructpart=""
-
826  for line in mquery.split("\n"):
-
827  if "BIND" in line or "FILTER" in line or "EXISTS" in line:
-
828  continue
-
829  elif "OPTIONAL" in line:
-
830  constructpart += line[0:line.rfind("}")].replace("OPTIONAL {","") + "\n"
-
831  else:
-
832  constructpart+=line+"\n"
-
833  result="CONSTRUCT \n"+constructpart.replace("WHERE","")+"\n"+query
-
834  QgsMessageLog.logMessage('SELECT TO CONSTRUCT '+str(result), MESSAGE_CATEGORY,Qgis.Info)
-
835  return result
-
836 
+
824  def selectQueryToConstructQuery(query):
+
825  mquery=query[query.find("WHERE"):query.rfind("}")+1]
+
826  query=query[query.find("WHERE"):]
+
827  constructpart=""
+
828  for line in mquery.split("\n"):
+
829  if "BIND" in line or "FILTER" in line or "EXISTS" in line:
+
830  continue
+
831  elif "OPTIONAL" in line:
+
832  constructpart += line[0:line.rfind("}")].replace("OPTIONAL {","") + "\n"
+
833  else:
+
834  constructpart+=line+"\n"
+
835  result="CONSTRUCT \n"+constructpart.replace("WHERE","")+"\n"+query
+
836  QgsMessageLog.logMessage('SELECT TO CONSTRUCT '+str(result), MESSAGE_CATEGORY,Qgis.Info)
+
837  return result
+
838 
@@ -1579,11 +1579,11 @@

-
535  def shortenLiteral(literal,numchars):
-
536  return literal[numchars:]
-
537 
-
538 
+
537  def shortenLiteral(literal,numchars):
+
538  return literal[numchars:]
539 
+
540 
+
541 
@@ -2468,7 +2468,8 @@

-Initial value:
"http://www.opengis.net/ont/crs/usesValue":"ObjectProperty",
"http://rdfs.org/ns/void#triples": "DatatypeProperty",
+
"http://purl.org/vocommons/voaf#occurrences":"DatatypeProperty",
"http://rdfs.org/ns/void#entities": "DatatypeProperty",
"http://rdfs.org/ns/void#propertyPartition": "ObjectProperty",
"http://rdfs.org/ns/void#classPartition": "ObjectProperty",