I am attempting to get information from UK Data Communities on planning decisions from here. I have tried to run the query considering the SPARQL endpoint that they provide. It's the first time I am running a query with SPARQL so I have followed general indications in here and considered a previous thread with other data from this site.
My code looks like:
library(SPARQL)
# create the query
endpoint <- "http://opendatacommunities.org/sparql"
query <-
"PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT *
WHERE {
?s ?p ?o
}"
# submit query
qd <- SPARQL(endpoint,query)
However I get the following error:
Error: XML content does not seem to be XML: 'Request Timeout'
I have tried to edit my query by stating explicitly the format argument in SPARQL() as xml (qd <- SPARQL(endpoint,query, format = "xml")) but I have obtained similar result. I would be grateful if someone could give some hints about what is going wrong.
Try using an endpoint of "http://opendatacommunities.org/sparql.xml".
Your endpoint is does not appear to be an endpoint but an HTML page only.
Related
I have a list of approximately 6k wikidata instance IDs (beginning Q#####) I want to look up the human-readable labels for. I am not too familiar with SPARQL, but following some guidelines have managed to find a query that works for a single ID.
from SPARQLWrapper import SPARQLWrapper, JSON
query = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT *
WHERE {
wd: Q##### rdfs:label ?label .
FILTER (langMatches( lang(?label), "EN" ) )
}
LIMIT 1
"""
sparql = SPARQLWrapper("http://query.wikidata.org/sparql")
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
output = sparql.query().convert()
I had hoped that iterating over a list of IDs would be as simple as putting the IDs in a dataframe and using the apply function...
ids_DF['label'] = ids_DF['instance_id'].apply(my_query_function)
... However, when I do that it errors out with a "HTTPError: Too Many Requests" warning. Looking into the documentation, specifically the query limits section, it says the following:
Query limits
There is a hard query deadline configured which is set to 60 seconds. There are also following limits:
One client (user agent + IP) is allowed 60 seconds of processing time each 60 seconds
One client is allowed 30 error queries per minute
I'm unsure how to go about resolving this. Am I looking to run 6k error queries (i'm unsure what an error query even is)? In which case I presumably need to run them in batches to avoid going over the 30 second window.
My first attempt to resolve this was been to put a delay of 2 seconds after each query (see third from last line below). I noticed that each instance ID was taking approximately 1 second to return a value so my thinking was that a delay would boost the amount of time taken to 3 seconds (which should comfortably keep me within the limit). However, that still returns the same error. I've tried extending this sleep period as well, with the same results.
from SPARQLWrapper import SPARQLWrapper, JSON
query = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT *
WHERE {
wd: Q##### rdfs:label ?label .
FILTER (langMatches( lang(?label), "EN" ) )
}
LIMIT 1
"""
sparql = SPARQLWrapper("http://query.wikidata.org/sparql")
sparql.setQuery(query)
time.sleep(2) # imported from time
sparql.setReturnFormat(JSON)
output = sparql.query().convert()
A similar question on this topic was asked here but I've not been able to follow the advice given.
Note: Before anyone marks this as duplicate to How to query Wikidata for "also known as", no actual working answer was given there.
The question I have is similar to that thread: How do I get matching entities from "also known as" using a query (without getting time-out errors)? I have a working solution to match the "also known as" column for properties, but I cannot get it to work for all entities. This is that query:
SELECT DISTINCT ?property
WHERE {
?property a wikibase:Property .
?property skos:altLabel ?altLabel .
FILTER (CONTAINS(?altLabel, "<ALSOKNOWNAS>"#en))
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .}
}
The < ALSOKNOWNAS > indicates where a label is inserted from my script. As an example, when placing the word "invented" in the query, the query returns the page P61 for "discoverer or inventor".
Removing the first line of the WHERE statement does not work. I'm not very proficient in WIkidata query, but I hope someone can help me.
Present records
{"myLabel":"AFRICANA"}
{"myLabel":"africans"}
{"myLabel":"AFRICAN"}
{"myLabel":"Africa"}
Query : `cts:json-property-word-match("myLabel", "Africa*")`
Result:
{"myLabel":"Africa"}
Query returns only match case data not all relavent rows.
Query : `cts:json-property-word-match("myLabel", "Africa*", "case-insensitive")`
Result:
your query returned an empty sequence
If I use "case-insensitive" option it returns empty sequence.
I have set word lexicons as myLabel.
How do I search for JSON data case insensitively?
Both of the examples provided return the expected results for me. Did you intend to show the second query as a search with cts:json-property-value-query()?
If that is the case, then applying the wildcarded option will ensure that values are matched case-insenstive and as a wildcarded query:
cts:search(doc(),
cts:json-property-value-query("myLabel", "Africa*", ("wildcarded","case-insensitive")))
Double check to see if you have "trailing wildcard searches" enabled, or any of the three, two, or one character searches enabled for your content database. The rules for wildcard searches state that you need specific database indexes enabled for the query to automatically apply queries with wildcard patters as a wildcarded query:
If neither "wildcarded" nor "unwildcarded" is present, the database configuration and $text determine wildcarding. If the database has any wildcard indexes enabled ("three character searches", "two character searches", "one character searches", or "trailing wildcard searches") and if $text contains either of the wildcard characters '?' or '*', it specifies "wildcarded". Otherwise it specifies "unwildcarded".
With either of those index settings enabled, a query term with a * should automatically execute as a wildcard query, and you can remove the explicit wildcarded option:
cts:search(doc(),
cts:json-property-value-query("myLabel", "Africa*", "case-insensitive"))
I am using Jena's SPARQL engine and trying to write a query to filter on a date range as I need to find the value of a property after a fixed date.
My date property is in the following format:
Fri May 23 10:20:13 IST 2014
How do I write a SPARQL query to get other properties with dates greater than this?
With your data in that format you can't filter on a range of it without adding a custom extension function to ARQ (which is intended for advanced users) since you would need to parse and interpret the date time string.
What you should instead be doing is translating your data into the standard date time format xsd:dateTime that all SPARQL implementations are required to support. See the XML Schema Part 2: Datatypes specification for details of this format.
Your specific example date would translate as follows:
2014-05-23T10:20:13+05:30
And you must ensure that you declare it to be a typed literal of type xsd:dateTime when you use it in data and queries. For example in the readable Turtle RDF syntax:
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix : <http://example.org> .
:subject :date "2014-05-23T10:20:13+05:30"^^xsd:dateTime .
You could then write a SPARQL query that filters by range of dates like so:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX : <http://example.org>
SELECT *
WHERE
{
?s :date ?date .
FILTER (?date > "2014-05-23T10:20:13+05:30"^^xsd:dateTime)
}
This finds all records where ?date is after the given date
The following query i have tried, is working fine while running in sqlite manager using the database, But while i try to execute the same in my C program the query is not being executed.
Query: "SELECT * FROM Object WHERE Path like ? "
Order of query execution:
sqlite3_prepare_v2
sprintf(buf,"'/%d -%%%%'",objNum); (buf= '/x -%%')
sqlite3_bind_text
sqlite3_step
An example row in the table(object)
Path artist album genre
/0 - xxxx.mp3 xxxxx yyyyy zzzzz
/1 - aaaa.mp3 wwwww yyyyy qqqqq
I have to use the number in the start of the path to get the rest of the details in the table. any help is much appreciated. :)
Don't use single quotes for parameters strings; all data in parameters is taken directly without any changes.
Use:
sprintf(buf, "/%d -%%", objNum);