I'm working on developing a front end for a service where, currently, users come up with their own SPARQL query and set their parameters within that, for example:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX framenet: <http://www.newsreader-project.eu/framenet/>
PREFIX gaf: <http://groundedannotationframework.org/files/2014/01/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX sem: <http://semanticweb.cs.vu.nl/2009/11/sem/>
# All allowed parameters:
# output: html, offset: 0, limit: 100,
# uri.0: {uri_0}, uri.1: {uri_1}
# filter_block: ?filterfield bif:contains "{string}" ., date_filter_block: ?d owltime:year "{datefilter}"^^xsd:int .
# uri_filter_block: ?filterfield rdfs:label ?_label . ?_label bif:contains "{string}" .
SELECT ?event (COUNT(*) AS ?event_size) ?datetime ?event_label
WHERE {
{
SELECT DISTINCT ?event ?datetime ?event_label
WHERE {
{ ?event sem:hasActor {uri_0} } UNION { ?event sem:hasPlace {uri_0} }
?event sem:hasTime ?t ; rdfs:label ?event_label .
?t owltime:inDateTime ?d .
?d owltime:year "{datefilter}"^^xsd:int .
?t rdfs:label ?datetimetmp .
FILTER (regex(?datetimetmp,"\\d{4}-\\d{2}"))
BIND (SUBSTR(?datetimetmp,1,10) AS ?datetime)
}
ORDER BY ?datetime
OFFSET 0
LIMIT 100
}
?event ?p ?o .
}
GROUP BY ?event ?datetime ?event_label
ORDER BY ?datetime
and a page like this is generated which displays the results of the query as a table.
What I'm trying to do is create a page which the user can use to enter their desired parameters in an 'easier' way. So, instead of typing limit:100
in the SPARQL query, I've provided them with a text box entitled 'Limit' which they then enter a value into. I also have a drop down list which lists all of the different query types (such as 'Get events mentioning a named actor' which I have shown you here, or others such as 'Get the properties of a type' or 'Get events with a specific frame net value').
I have an index.html file and a code.js file and, up until now, I've simply had a page with text boxes and a submit button which, when clicked upon/enter is pressed, a function is ran which uses an ajax request to 'pull' the table from a url that I've generated, such as the page of results I linked to up above. This url is generated in the following way:
var runQuery = function move(actor, pageNum) {
var initUrl = "https://newsreader.scraperwiki.com/{0}/page/{1}?uris.0={2}"
var queryUrl = initUrl.replace("{1}", pageNum);
var queryUrl = queryUrl.replace("{2}", "dbpedia:" + actor);
limit = $(textInput[1]).val();
offset = $(textInput[2]).val();
stringFilter = $(textInput[3]).val();
dateFilter = $(textInput[4]).val();
framenet = $(textInput[5]).val();
if (limit != "") {queryUrl += ("&limit=" + limit)};
if (offset != "") {queryUrl += ("&offset=" + offset)};
if (stringFilter != "") {queryUrl += ("&filter=" + stringFilter)};
if (dateFilter != "") {queryUrl += ("&datefilter=" + dateFilter)};
//...more code follows...
The full code can be found here.
This all works fine for what I've done so far, but I'm having trouble trying to think of ways to concisely alter the var queryUrl = queryUrl.replace("{2}", "dbpedia:" + actor;
line in particular and the rest of the code to account for the different prefixes used for different query types (in the SPARQL query up above it is PREFIX dbpedia: <http...
, but it is sometimes PREFIX dbo: <http...
, etc).
After that long winded explanation, what I want to know is if there is an alternative to manually manipulating queryUrl
and using a load of conditional statements to account for all of the different query types and, if so, how can I do it? I'm very new to any kind of web stuff and I'm a bit lost! Any advice on how to approach accounting for the different query types as concisely as possible would be great. The only way I can think of how to do it at the minute is to have some sort of code that says...
if (actor != "") {
queryUrl = queryUrl.replace("{2}", "dbpedia:" + actor);
} else if (....) {
queryUrl = queryUrl.replace("{2}", "dbo:" + ....);
} else... etc
.. (where actor is referring to the name of a thing) but I think doing it this way would be clunky and would get confusing with all of the different formats that would need to be accounted for.
Thanks in advance, and if any more information is needed about my problem then please don't hesitate to tell me!
edit: I've since came to the conclusion that dbpedia-spotlight isn't very useful for my problem that I've highlighted in this question.
I've decided to access the API page output as JSON so that I can access the queries from there instead of accounting for every type of queryUrl. Any additional thoughts and answers would be greatly appreciated, but are now unnecessary.
Thanks!