One SPARQL endpoint for Select, Describe and Construct using Jena ARQ - sparql

I have built a simple webpage as the frontend user interface for users to enter the sparql query. I am using Jena ARQ as the backend (I am using Grails) sparql query engine. Currently, users can only enter a "Select" query and I use:
ResultSet results = qexec.execSelect();
to execute the query and return the result. But now, I also want users to send Describe and Construct query from the same page to the backend. As has been discussed in this thread: Jena Sparql and construct, we need to use
Model results = qexec.execConstruct()
at the backend. So my question is, at the backend, how can I know if the query string is a Select query, a Describe Query or a Construct query, so that I can select from execSelect(), execDescribe() or execConstruct()? Is there anything I need to change for the frontend?

The Query class has methods for finding out the type of the query:
if (qexec.getQuery().isSelectType()) {
ResultSet results = qexec.execSelect();
// ...
} else {
Model results = qexec.execConstruct();
// ...
}
To be complete, you should probably handle DESCRIBE and ASK as well.

Related

Referencing results from a SPARQL query in a subsequent SPARQL query

We would like to use SPARQL in the following scenario:
Execute SPARQL query, e.g.
PREFIX brick: https://brickschema.org/schema/1.1/Brick#
SELECT ?ahu WHERE { ?ahu rdf:type brick:AHU }
Iterate over SPARQL query results and filter the results based on data from another source than RDF database, e.g. "filter out any ahu that do not have valid metadata a SQL database"
Execute another SPARQL query for each filtered result in the previous step, e.g.
PREFIX brick: https://brickschema.org/schema/1.1/Brick#
SELECT ?myZone WHERE {
?myZone rdf:type brick:HVAC_Zone .
"a particular ahu from previous steps" brick:feeds ?myZone}
Both SPARQL queries cannot be expressed as one SPARQL query since interaction with another data source is needed. How shall we design query in step 3 such that it "points" to the particular triplet (or SPARQL query result)?

laravel sql subquery

I have read the docs about raw queries but they say nothing about building subqueries. Can't I just enter raw sql inside a controller action or model at worst?)
i have two tables, rates and performance.
I cant get to write in Laravel parlance (either query builder or eloquent or raw query) in the controller (or model) the following sql subquery
SELECT ratedescription
FROM rates
WHERE rates.digit
IN (SELECT
performance.score
FROM performances
where performances.id = $i);
the $i is a parameter that goes into the method in the controller
This question is NOT for bouty. I have never said that, and it is SO who does it without even asking me.
I didn't use Laravel in a long time but can't you manage to do the same this with query builder?
laravel docs
Something like :
Rate::select("ratedescription")->whereIn("digit", function($query) {
$query->from("performances")->select("score")->where(...);
})->get();
My answermight be wrong since I'm didn't use either laravel or php for some time now but I hope it can help.
Have a nice day.

How to get elasticsearch to perform similar to SQL 'LIKE'

If using a SQL 'Like' statement to query data it will return data even if its only partially matched. For instance, if I'm searching for food and there's an item in my db called "raisins" when using SQL the query would return "raisins" even if my search only contained "rai". In elasticsearch, the query won't return a record unless the entire name (in this case "raisins") is specified. How can I get elasticsearch to behave similar to the SQL statement. I'm using Rails 3.1.1 and PostgreSQL. Thanks!
While creating index of model for elasticsearch use tokenizer on index which will fulfil your requirement. For. e.g.
tokenizer: {
:name_tokenizer => {type: "edgeNGram", max_gram: 100, min_gram: 3, side: "front"}
}
this will create tokens of size from 3 to 100 of your fields and as side is given as front it will check from the starting. You can get more details from here http://www.slideshare.net/clintongormley/terms-of-endearment-the-elasticsearch-query-dsl-explained

Query DBpedia for multiple keywords

I want to query DBpedia for multiple keywords, when I query freebase for example using this:
http://api.freebase.com/api/service/search?query=%2BEgypt%2BPyramids
I get reasonable results like: "Egyptian Pyramids", "Ancient Egypt", "Pyramids of Giza (Egypt)".
However whenever I try to query dbpedia with multiple keywords I get an empty ArrayofResult, although when I query for each keyword on its own I do get results..
I couldn't find any documentation for DBpedia's Keyword search service, only this: http://dbpedia.org/lookup
I write the query like this:
http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryClass=place&QueryString=Egypt+pyramid
Is this the right way of doing it?
Don't limit the results with place class, it seems doesn't work
http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryClass=&QueryString=Egyptian%20Pyramids

Return a model from a custom query without hitting the database

I have a custom query which eventually returns a list of objects. I need the function to return the actual objects but I don't want to hit the database twice for every query since it's already an expensive query. How can i return a model instance without hitting the db?
NB: I presume doing something like the following will actually create a new instance of a different model?
return [Object(pk=row[0]) for row in results]
NB: I also presume that this will hit the database, on function return
return [Object.objects.get(pk=row[0]) for row in results]
If you have Django 1.2+ you can use the raw() method to return list of Model instances using the results of a custom query. Something like this in your case:
query = "<your query goes here>"
Object.objects.raw(query)