Skip to content
Browse files

small change to form, not yet implimented on the backend

  • Loading branch information...
1 parent 1745014 commit d52098998cbdbc6f192ab21a4830568e6695e6a7 Tim Richardson committed
Showing with 336 additions and 110 deletions.
  1. +17 −0 forms.py
  2. BIN forms.pyc
  3. +12 −7 templates/root.html
  4. +193 −0 testBed.py
  5. +2 −103 urls.py
  6. BIN urls.pyc
  7. +112 −0 views.py
  8. BIN views.pyc
View
17 forms.py
@@ -0,0 +1,17 @@
+'''
+Created on Oct 6, 2011
+
+@author: tim
+'''
+from django import forms
+
+query_choices = (
+ ('labels', 'Linked by labels'),
+ ('colabs', 'Collaborations'),
+ ('comps', 'On compilations together')
+)
+
+class requestForm(forms.Form):
+ url = forms.URLField(help_text="please enter a URI beginning http://data.kasabi.com/dataset/discogs/")
+ year = forms.IntegerField(min_value=1000, max_value=2012)
+ query = forms.ChoiceField(query_choices)
View
BIN forms.pyc
Binary file not shown.
View
19 templates/root.html
@@ -13,6 +13,14 @@
left:1em;
top:1em;
}
+form p label {
+ width:100px;
+ display:inline-block;
+ text-align:right;
+}
+form input[value="find"]{
+ margin-left:106px;
+}
circle {
stroke-width: 1.5px;
}
@@ -28,6 +36,7 @@
$('form').submit(function(e){
e.preventDefault();
var url = $('input[name="url"]').val();
+ var year = $('input[name="year"]').val();
var query = $('select[name="query"]').val();
var csrfmiddlewaretoken = $('input[name="csrfmiddlewaretoken"]').val();
$.ajax({
@@ -35,6 +44,7 @@
url : '/',
data: {
url : url,
+ year : year,
query : query,
csrfmiddlewaretoken : csrfmiddlewaretoken
},
@@ -112,13 +122,8 @@
<body>
<form method="">
{% csrf_token %}
- <input name="url" type="text" value="Use Discogs URL here"/>
- <select name="query">
- <option value="labels">Linked by label</option>
- <option value="colabs">Colaborations</option>
- <option value="comps">On compilations together</option>
- </select>
- <input type="submit" value="find" id="submit-button"/>
+ {{ form.as_p}}
+ <input type="submit" value="find">
</form>
<div id="result"></div>
<script type="text/javascript" src="{{ STATIC_URL }}d3/d3.js"></script>
View
193 testBed.py
@@ -0,0 +1,193 @@
+'''
+Created on Jul 4, 2011
+
+@author: tim
+'''
+import pytassium
+import time
+
+def SPARQLAndRespond(dataset, query):
+ response, data = dataset.select(query)
+ if response.status in range(200,300):
+ # data now contains a dictionary of results
+ import pprint
+ #pprint.pprint(data)
+ return data
+ else:
+ print "Oh no! %d %s " % (response.status, response.reason)
+
+### API KEY ###
+
+apiKey = '5dac588049e18e51fead5e788dc2449e38c2077a'
+
+##==---------------------==##
+##- Ordnance-Survey -##
+##==---------------------==##
+
+OSdataset = pytassium.Dataset('ordnance-survey-linked-data',apiKey)
+
+AllBouroughsWithGIS = """
+PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX admingeo: <http://data.ordnancesurvey.co.uk/ontology/admingeo/>
+PREFIX geometry: <http://data.ordnancesurvey.co.uk/ontology/geometry/>
+
+select * where {
+?s rdf:type admingeo:Borough.
+?s geometry:extent ?o
+}
+"""
+
+#SPARQLAndRespond(OSdataset, AllBouroughsWithGIS)
+
+##==---------------------==##
+##- Education -##
+##==---------------------==##
+
+EducationDataset = pytassium.Dataset('education',apiKey)
+
+LatymerSchoolQuery = '''
+SELECT * WHERE {
+<http://education.data.gov.uk/id/school/102055> ?p ?o.
+}
+'''
+
+#SPARQLAndRespond(EducationDataset, LatymerSchoolQuery)
+
+##==---------------------==##
+##- Species in the UK -##
+##==---------------------==##
+
+GeoSpecies = pytassium.Dataset('geospecies', apiKey)
+
+SpeciesInUKWithCommonName = """
+PREFIX geospecies: <http://rdf.geospecies.org/ont/geospecies#>
+PREFIX uk: <http://sws.geonames.org/2635167/>
+SELECT * WHERE{
+?species geospecies:hasCommonName ?name;
+geospecies:isExpectedIn uk:.
+}
+"""
+
+speciesTest = """
+PREFIX geospecies: <http://rdf.geospecies.org/ont/geospecies#>
+PREFIX uk: <http://sws.geonames.org/2635167/>
+PREFIX bats: <http://lod.geospecies.org/orders/TuTld>
+PREFIX dcterms: <http://purl.org/dc/terms/>
+
+SELECT DISTINCT ?family_name ?canonicalName ?speciesconcept ?geospeciespage
+
+WHERE {
+?x geospecies:hasFamilyName ?family_name;
+ geospecies:hasCanonicalName ?canonicalName;
+ dcterms:identifier ?speciesconcept;
+ geospecies:hasGeoSpeciesPage ?geospeciespage;
+ geospecies:inOrder bats:;
+ geospecies:isExpectedIn uk:.
+}
+ORDER BY ?family_name ?canonicalName
+"""
+
+#data = SPARQLAndRespond(GeoSpecies, SpeciesInUKWithCommonName)
+
+#for result in data[1]:
+# print result['name']
+
+##==---------------------==##
+##- DISCOGS -##
+##==---------------------==##
+
+Discogs = pytassium.Dataset('discogs', apiKey)
+
+artistsJoinedByLabels = """
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX mo: <http://purl.org/ontology/mo/>
+SELECT DISTINCT ?artist2 ?name WHERE{
+<http://data.kasabi.com/dataset/discogs/artist/cti> foaf:made ?release.
+?release mo:publisher ?label.
+?release2 mo:publisher ?label.
+?artist2 foaf:made ?release2.
+?artist2 foaf:name ?name.
+}
+"""
+
+Colabs = """
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX mo: <http://purl.org/ontology/mo/>
+PREFIX dc: <http://purl.org/dc/terms/>
+
+SELECT DISTINCT ?artist WHERE{
+<http://data.kasabi.com/dataset/discogs/artist/cti> foaf:made ?release.
+?artist foaf:made ?release.
+}
+"""
+
+Compalations = """
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX mo: <http://purl.org/ontology/mo/>
+PREFIX dc: <http://purl.org/dc/terms/>
+
+SELECT DISTINCT ?artist2 WHERE{
+<http://data.kasabi.com/dataset/discogs/artist/jan-hammer> foaf:made ?release.
+?release <http://xmlns.com/foaf/0.1/maker> ?artist2.
+}
+"""
+# <http://data.kasabi.com/dataset/discogs/artist/various>
+
+#data = SPARQLAndRespond(Discogs, artistsJoinedByLabels)
+
+##==-------------------------==##
+##== MUSICBRAINZ ==##
+##==-------------------------==##
+
+mb = pytassium.Dataset('musicbrainz', apiKey)
+bbcMu = pytassium.Dataset('bbc-music', apiKey)
+
+findMembers = """
+PREFIX mo: <http://purl.org/ontology/mo/>
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+SELECT ?mb WHERE{
+?group mo:discogs <http://www.discogs.com/artist/Radiohead>.
+?group foaf:member ?member.
+?member mo:musicbrainz ?mb.
+}
+"""
+discogs2lastfm = """
+PREFIX mo: <http://purl.org/ontology/mo/>
+SELECT * where{
+?artist mo:musicbrainz <%s>.
+?artist mo:wikipedia ?wiki
+}
+"""
+data = SPARQLAndRespond(mb, findMembers)
+
+wikiPages = []
+for result in data[1]:
+ query = discogs2lastfm % result['mb'].decode()
+ data2 = SPARQLAndRespond(bbcMu, query)
+ for result in data2[1]:
+ wikiPages.append(result['wiki'])
+
+##==-------------------------==##
+##== DBPEDIA ==##
+##==-------------------------==##
+
+dbpedia = pytassium.Dataset('dbpedia-36', apiKey)
+
+artistDetails = '''
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
+PREFIX dbpedia-prop: <http://dbpedia.org/property/>
+select * where{
+?s foaf:page <%s>.
+?s dbpedia-prop:origin ?origin.
+?s dbpedia-prop:dateOfBirth ?dob.
+?s dbpedia-owl:instrument ?instrument.
+?s dbpedia-owl:genre ?genre.
+}
+'''
+
+for page in wikiPages:
+ query = artistDetails % page
+ data3 = SPARQLAndRespond(dbpedia, query)
+ for result in data3[1]:
+ print result
View
105 urls.py
@@ -1,106 +1,5 @@
from django.conf.urls.defaults import patterns, include, url
-from django.shortcuts import render_to_response, HttpResponse
-from django.core.context_processors import csrf
-from django.core import serializers
-from django.utils import simplejson
-from django.template import RequestContext
-
-from json import JSONEncoder
-import pytassium
-
-def SPARQLAndRespond(dataset, query):
- response, data = dataset.select(query)
- if response.status in range(200,300):
- # data now contains a dictionary of results
- #import pprint
- #pprint.pprint(data)
- return data
- else:
- print "Oh no! %d %s " % (response.status, response.reason)
- return False
-
-def jsonTree(s, p, o):
- sent = dict()
- sent[s[0][0]] = s[1][0][s[0][0]].decode()
- objects = dict()
- for i, result in enumerate(o[1]):
- node = dict()
- for varName in result:
- node[varName] = result[varName].decode()
- objects['node'+str(i)] = node
- sent[p] = objects
- return simplejson.dumps(sent)
-
-def jsonNodeLink(s,p,o):
- nodes = []
- links = []
- nodes.append({s[0][0] : s[1][0][s[0][0]].decode()})
- for i, result in enumerate(o[1]):
- node = dict()
- for varName in result:
- node[varName] = result[varName].decode()
- nodes.append(node)
- links.append({'source':0,'target':i+1,'value':10})
- return simplejson.dumps({'nodes':nodes, 'links':links})
-
-def root(request):
- if not request.POST:
- c = RequestContext(request, {})
- c.update(csrf(request))
- return render_to_response('root.html',c)
- url = request.POST.get('url')
- query = request.POST.get('query')
-
- if query == 'labels':
- q = """
- PREFIX foaf: <http://xmlns.com/foaf/0.1/>
- PREFIX mo: <http://purl.org/ontology/mo/>
- SELECT DISTINCT ?artist ?name WHERE{
- <""" + url + """> foaf:made ?release.
- ?release mo:publisher ?label.
- ?release2 mo:publisher ?label.
- ?artist foaf:made ?release2.
- ?artist foaf:name ?name.
- }
- """
-
- elif query == 'colabs':
- q = """
- PREFIX foaf: <http://xmlns.com/foaf/0.1/>
- PREFIX mo: <http://purl.org/ontology/mo/>
- PREFIX dc: <http://purl.org/dc/terms/>
- SELECT DISTINCT ?artist ?name WHERE{
- <""" + url + """> foaf:made ?release.
- ?artist foaf:made ?release.
- ?artist foaf:name ?name.
- }
- """
-
- elif query == 'comps':
- q = """
- PREFIX foaf: <http://xmlns.com/foaf/0.1/>
- PREFIX mo: <http://purl.org/ontology/mo/>
- PREFIX dc: <http://purl.org/dc/terms/>
- SELECT DISTINCT ?artist ?name WHERE{
- <""" + url + """> foaf:made ?release.
- ?artist foaf:made ?release.
- ?artist foaf:name ?name.
- }
- """
-
- apiKey = '5dac588049e18e51fead5e788dc2449e38c2077a'
- Discogs = pytassium.Dataset('discogs', apiKey)
-
- rootQuery = """PREFIX foaf: <http://xmlns.com/foaf/0.1/>
- Select ?name where{<""" + url + """> foaf:name ?name.
- }"""
- subject = SPARQLAndRespond(Discogs, rootQuery)
- results = SPARQLAndRespond(Discogs, q)
-
- jsonny = jsonNodeLink(subject, query, results)
-
- return HttpResponse(jsonny, content_type="application/json; charset=utf8")
urlpatterns = patterns('',
- url(r'^$', root)
-)
+ url(r'^$', 'discorrelate.views.root')
+)
View
BIN urls.pyc
Binary file not shown.
View
112 views.py
@@ -0,0 +1,112 @@
+'''
+Created on Oct 6, 2011
+
+@author: tim
+'''
+from django.shortcuts import render_to_response, HttpResponse
+from django.core.context_processors import csrf
+from django.core import serializers
+from django.utils import simplejson
+from django.template import RequestContext
+
+from discorrelate.forms import requestForm
+
+from json import JSONEncoder
+import discogs_client as discogsAPI
+import pytassium
+
+def SPARQLAndRespond(dataset, query):
+ response, data = dataset.select(query)
+ if response.status in range(200,300):
+ # data now contains a dictionary of results
+ #import pprint
+ #pprint.pprint(data)
+ return data
+ else:
+ print "Oh no! %d %s " % (response.status, response.reason)
+ return False
+
+def jsonTree(s, p, o):
+ sent = dict()
+ sent[s[0][0]] = s[1][0][s[0][0]].decode()
+ objects = dict()
+ for i, result in enumerate(o[1]):
+ node = dict()
+ for varName in result:
+ node[varName] = result[varName].decode()
+ objects['node'+str(i)] = node
+ sent[p] = objects
+ return simplejson.dumps(sent)
+
+def jsonNodeLink(s,p,o):
+ nodes = []
+ links = []
+ nodes.append({s[0][0] : s[1][0][s[0][0]].decode()})
+ for i, result in enumerate(o[1]):
+ node = dict()
+ for varName in result:
+ node[varName] = result[varName].decode()
+ nodes.append(node)
+ links.append({'source':0,'target':i+1,'value':10})
+ return simplejson.dumps({'nodes':nodes, 'links':links})
+
+def root(request):
+ if not request.POST:
+ form = requestForm()
+ c = RequestContext(request, {'form':form})
+ c.update(csrf(request))
+ return render_to_response('root.html',c)
+ url = request.POST.get('url')
+ query = request.POST.get('query')
+
+ if query == 'labels':
+ q = """
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+ PREFIX mo: <http://purl.org/ontology/mo/>
+ SELECT DISTINCT ?artist ?name WHERE{
+ <""" + url + """> foaf:made ?release.
+ ?release mo:publisher ?label.
+ ?release2 mo:publisher ?label.
+ ?artist foaf:made ?release2.
+ ?artist foaf:name ?name.
+ }
+ """
+
+ elif query == 'colabs':
+ q = """
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+ PREFIX mo: <http://purl.org/ontology/mo/>
+ PREFIX dc: <http://purl.org/dc/terms/>
+ SELECT DISTINCT ?artist ?name WHERE{
+ <""" + url + """> foaf:made ?release.
+ ?artist foaf:made ?release.
+ ?artist foaf:name ?name.
+ }
+ """
+
+ elif query == 'comps':
+ q = """
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+ PREFIX mo: <http://purl.org/ontology/mo/>
+ PREFIX dc: <http://purl.org/dc/terms/>
+ SELECT DISTINCT ?artist ?name WHERE{
+ <""" + url + """> foaf:made ?release.
+ ?artist foaf:made ?release.
+ ?artist foaf:name ?name.
+ }
+ """
+
+ discogsAPI.user_agent = 'discorrelate/0.1 +http://www.rewire.it'
+
+ apiKey = '5dac588049e18e51fead5e788dc2449e38c2077a'
+ Discogs = pytassium.Dataset('discogs', apiKey)
+
+ rootQuery = """PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+ Select ?name where{<""" + url + """> foaf:name ?name.
+ }"""
+ subject = SPARQLAndRespond(Discogs, rootQuery)
+ results = SPARQLAndRespond(Discogs, q)
+
+ jsonny = jsonNodeLink(subject, query, results)
+
+ return HttpResponse(jsonny, content_type="application/json; charset=utf8")
View
BIN views.pyc
Binary file not shown.

0 comments on commit d520989

Please sign in to comment.
Something went wrong with that request. Please try again.