URL encoding a SPARQL query for dbpedia.org - sparql

I am trying to write a code (in ABAP) for URL encoding a SPARQL query for dbpedia.org.
Is there any reference code or method?
Ex: Input:
select distinct ?Concept where {[] a ?Concept} LIMIT 100
Output:
http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=select+distinct+%3FConcept+where+%7B%5B%5D+a+%3FConcept%7D+LIMIT+100&format=text%2Fhtml&timeout=0&debug=on
Thanks
Krishna

Disclaimer: I know nothing about ABAP.
Having said that, I'd be surprised if there isn't a library function to do that. If not, you can try porting the one from the JDK:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/net/URLEncoder.java#URLEncoder

Related

Using unfiltered search in MarkLogic

Consider the following query:
xquery version "1.0-ml";
declare namespace ts = "http://marklogic.com/MLU/top-songs";
let $range_query := cts:element-range-query(xs:QName("ts:week"), ">=", xs:date("2009-05-01"))
let $query := cts:search(fn:doc(), $range_query)
return $query/ts:top-song/ts:title/text()
(Not: Range index for week has been enabled)
I believe that the above query can give results based only on the indexes and with this assumption I made the following change:
let $query := cts:search(fn:doc(), $range_query, "unfiltered")
I got the same results.
However,
fn:count($query/ts:top-song/ts:title/text()) gave a result of 8
and
xdmp:estimate($query/ts:top-song/ts:title/text())
gave an error:Expression is unsearchable
I believe this means that the query cannot be searched using indexes. If so, why does the unfiltered approach work just fine ?
The unfiltered search works and the xdmp:estimate expression doesn't because they're not using the same query and expression. The query you pass cts:search is fully searchable, so it will work when you call xdmp:estimate on it:
xdmp:estimate(cts:search(fn:doc(), $range_query, "unfiltered")
xdmp:estimate requires a "partially searchable" XPath expression, which has a specific definition according to MarkLogic. There are some subtle details about what makes an expression fully or partially or not searchable, and probably the most instructive way to go about it is using xdmp:query-trace to test the expression.

How Do I Query Against Data.gov

I am trying to teach myself this weekend how to run API queries against a data source in this case data.gov. At first I thought I'd use a simple SQL variant, but it seems in this case I have to use SPARQL.
I've read through the documentation, downloaded Twinkle, and can't seem to quite get it to run. Here is an example of a query I'm running. I'm basically trying to find all gas stations that are null around Denver, CO.
PREFIX station: https://api.data.gov/nrel/alt-fuel-stations/v1/nearest.json?api_key=???location=Denver+CO
SELECT *
WHERE
{ ?x station:network ?network like "null"
}
Any help would be very much appreciated.
SPARQL is a graph pattern language for RDF triples. A query consists of a set of "basic graph patterns" described by triple patterns of the form <subject>, <predicate>, <object>. RDF defines the subject and predicate with URI's and the object is either a URI (object property) or literal (datatype or language-tagged property). Each triple pattern in a query must therefore have three entities.
Since we don't have any examples of your data, I'll provide a way to explore the data a bit. Let's assume your prefix is correctly defined, which I doubt - it will not be the REST API URL, but the URI of the entity itself. Then you can try the following:
PREFIX station: <http://api.data.gov/nrel...>
SELECT *
WHERE
{ ?s station:network ?network .
}
...setting the PREFIX to correctly represent the namespace for network. Then look at the binding for ?network and find out how they represent null. Let's say it is a string as you show. Then the query would look like:
PREFIX station: <http://api.data.gov/nrel...>
SELECT ?s
WHERE
{ ?s station:network "null" .
}
There is no like in SPARQL, but you could use a FILTER clause using regex or other string matching features of SPARQL.
And please, please, please google "SPARQL" and "RDF". There is lots of information about SPARQL, and the W3C's SPARQL 1.1 Query Language Recommendation is a comprehensive source with many good examples.

SPARQL-DL query with owl-api

I'm writing an application using OWL-API and Hermit Reasoner. I would like to query data using SPARQL-DL by submitting query like:
PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>
SELECT ?i
WHERE { Type(?i, wine:PinotBlanc) }
OR WHERE { Type(?i, wine:DryRedWine) }
Can I Do this directy with owl-api or should I use an external library (http://www.derivo.de/en/resources/sparql-dl-api/ ) ? ( I need something like
queryEngine.query(my_query); )
As in July 2013, the OWL-API does not support natively SPARQL-DL. You need to plug a third party library in order to make it work.
I am aware of two implementations (there's maybe more): One by Derivo (your link) and another one by Pellet.
I used OWL-API with Hermit and Pellet; both worked fine. The advantage of Pellet over Hermit is that it supports built-ins.
i.e. In Pellet, for some class Teenager, you can get seventeen year old persons using the following query:
Person and (hasAge value "17.0"^^double)
If you (or somebody) are still interested in, I can provide the Java class for it.
A pure OWL-API-impl cannot provide non-workaround way to support SPARQL since it is not graph based solution.
Now, starting v5, there is ONT-API which is jena-based OWL-API impl.

Alfresco boost results from site

I'm trying to boost results from a particular Alfresco site compared to others.
I've written the following query but it's not working properly :
(((TAG:term or cm:name:term OR cm:title:term )^8 OR (cm:description:term )^6) AND PATH:'/app:company_home/st:sites/cm:Pub/cm:documentLibrary//*')^8
OR
(((TAG:term or cm:name:term OR cm:title:term )^4 OR (cm:description:term )^2) AND -PATH:'/app:company_home/st:sites/cm:Pub/cm:documentLibrary//*')
The result is overall correct but the results from Pub aren't the first ones in the list.
Is there a way to achieve that ?
^8 on the first part query part was just not enough. Putting a huge value like 100 makes it work perfectly !

How does FAST ESP's xrank operator work?

I have a bunch of documents in my index.
They all have "text" in field1. One has "boosttext" in field2.
I want FAST to put the document with "boosttext" to the front of the result set.
I tried this FQL query:
and(field1:string("text"), xrank(field2:string("boosttext", mode="AND"))
However, this will filter out all documents that do not have "boosttext" in field2 !!!
Has anyone successfully used xrank and can give me a hint? Thanks in advance.
-- Bob
... it seems that the following FQL expression works:
rank(field1:string("text"), xrank(field2:string("boosttext"))
-- Bob
xrank(field1:string("text"), field2:string("boosttext"), boost=100)
See: http://msdn.microsoft.com/en-us/library/ff394462.aspx
xrank(or(cat, dog), thoroughbred, boost=500, boostall=yes)