<commit_before>__author__ = 'jpi'

from django.views.generic import View
from django.http import HttpResponse


class GetNearbyPlacesDBPedia(View):

    def get(self, request, *args, **kwargs):
        lat, lon = float(kwargs["lat"]), float(kwargs["lon"])
        min_lat, max_lat = lat - 0.1, lat + 0.1
        min_lon, max_lon = lon - 0.1, lon + 0.1

        result = ""
        return HttpResponse(result,
                            content_type="application/json")<commit_msg>GetNearbyPlacesDBPedia web service<commit_after>__author__ = 'jpi'

from django.views.generic import View
from django.http import HttpResponse
from SPARQLWrapper import SPARQLWrapper, JSON

import json


class GetNearbyPlacesDBPedia(View):

    def get(self, request, *args, **kwargs):
        lat, lon = float(kwargs["lat"]), float(kwargs["lon"])
        min_lat, max_lat = lat - 0.01, lat + 0.01
        min_lon, max_lon = lon - 0.01, lon + 0.01

        sparql = SPARQLWrapper("http://dbpedia.org/sparql")
        sparql.setQuery("select distinct ?link, ?name where "
        	"{?link geo:lat ?latitude . ?link geo:long ?longitude . ?link foaf:name ?name "
        	"filter (xsd:decimal(?latitude) >= " + str(min_lat)  + ") "
        	"filter (xsd:decimal(?latitude) <= " + str(max_lat) + ") "
        	"filter (xsd:decimal(?longitude) >= " + str(min_lon) + ") "
        	"filter (xsd:decimal(?longitude) <= " + str(max_lon) + ")}")
        sparql.setReturnFormat(JSON)
        places = sparql.query().convert()

        result = {"entries":[]}

        for place in places["results"]["bindings"]:
    		result["entries"].append({"name": place["name"]["value"], "url": place["link"]["value"]})

        return HttpResponse(json.dumps(result),
                            content_type="application/json")
{'fraction_non_alphanumeric': 0.15500839395635144, 'fraction_numerical': 0.01119194180190263, 'mean_word_length': 2.9557522123893807, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5697050', 'n_tokens_mistral': 611, 'n_tokens_neox': 582, 'n_words': 122}