On 09/04/14 16:50, Chris Dollin wrote:
On Wednesday, April 09, 2014 12:35:42 PM Walter Travassos wrote:


Recentelly I discoverd the functions on ARQ but I ´m having a little
dificult to use these functions. I´m trying to query the DBpedia using de
function afn:namespaces to find the namespaces of some resources. Here is my
code:

             String query =

                         "PREFIX afn:
<http://jena.hpl.hp.com/ARQ/function#>"+

                         "select  distinct ?s ?p ?namespace " +

                         "where {?s ?p ?o ." +

                         "filter (isURI(?s)) " +

                         "filter (isURI(?o))" +

                         "filter (afn:namespace(?s) = (afn:namespace(?o))  )}
limit 10";

Handy tip: put newlines (\n) on each line of your query so that
if there's a syntax error the line numbers help.

Note that this query crawls over the entire content of dbpedia.

But I always recieve the error 500.

Server internal error. I expect it ran out of space or time trying to
fetch every triple in the data. Note that the DISTINCT will force it
to scan the data even though there's a LIMIT -- the LIMIT applies
to the distinct results, not the pre-distinct results. If I understand
correctly.

(You should be able tow rite a LIMITed sub-query to get a few results
and then apply the DISTINCT in an outer query.)

Chris



I'm surprised that anything is working.  500 is not good.

The query is not executed by ARQ - it's executed by whatever is at "http://dbpedia.org/sparql/"; (it's a version of Virtuoso)

afn:namespace is specific to ARQ and not understood by Virtuoso. It should return 400 if it can't execute it.

A standards compliance way to do it is to use:

replace(str(?x), "(/|#[^/#]*)$", "")

which chops the tail off the string of the URI.

either as
FILTER (replace(str(?s), "(/|#[^/#]*)$", "") =
        replace(str(?o), "(/|#[^/#]*)$", "")

or

# BIND to split the line up for readability
BIND(?X AS replace(str(?s), "(/|#[^/#]*)$", ""))
FILTER ( STRSTARTS(str(?o), ?X) )

But as Chris says, your query is very expensive and DBpedia will in all likelihood timeout during execution giving truncated results.

        Andy

Reply via email to