What could be a good piece of SPARQL Code on DBPedia to Extract Agricultural Data? - sparql

I am trying create triplet dataset on Agriculture. I am new to SPARQL . I am trying build a query so that
I can fetch pest name, attacked corps and geo location of it's existence.
Corps name, region name where it grows and required weather
Etc.
Can anyone help me with the query or any resource from where I can learn to build them.

Related

Obtain country from wikidata item using SPARQL

I am trying to get the country of a Wikidata item using SPARQL. I am quite new and I am not able to obtain only the property country (P17) and its label.
I used this example and I am able to obtain all properties. Link.
In this case using the output of a previous query, for example, I get the item Q1492 corresponding to Barcelona. How can I obtain its country, Spain?

How to query a LUBM ontology?

How to query a LUBM ontology(extracted form given univ-bench.owl. given on the official site using generator) to find how many university it contains?

How to access weather data from all the stations in one country using openweathermap?

I am using Alteryx to extract weather data for a handful of cities and it works great. I'd like to expand this to able to download data for all weather stations in the UK. At the moment I am specifying which cities I want, e.g. London / Manchester.
Is there a way of specifying in the api call to download all stations in 'GB' or 'UK'?
Ideally I'd like to do this in one call rather than listing all locations which will be very laborious
Get a list of stations or cities that you want to retrieve weather data from. I found some good sources from openweather here: http://bulk.openweathermap.org/sample/
Then build a url request using the list of id's above that retrieves specific weather information. Using an id for the weather station in Cairns, id=2172797, the url ends up looking like:
http://api.openweathermap.org/data/2.5/weather?id=2172797&appid=843798874aac0ef138e6f77c72f3af80
Note that this url will return an error because this isn't a real appid. If you replace the appid with your own, this url will give you data for that station.
Putting this process into Alteryx lets you put the list of station id's together with the url and the appid to make many calls into openweather and then process all of the data together. I could not find information from the API on rate limits, so be conscious of how many requests you are posting to the service.
There is an example of this process here: https://www.dropbox.com/s/yoppbx3bw0p4rug/Get%20individual%20stations.yxzp?dl=0
Keep in mind that you have to update the Appid in the text input tool within this sample as well.

Link LSOA codes with ordnance survey postcodes and endpoint

I am new to linked data and trying to link ordnance survey postcodes to LSOA data.
I am using the OS linked Data Sparql API and the end point is:
http://data.ordnancesurvey.co.uk/datasets/os-linked-data/apis/sparql
I have a query which returns the postcodes, although I am trying to link LSOA codes with the postcodes to learn from. The code I have so far is:
SELECT ?postcode WHERE {
?postcodeUnit a <http://data.ordnancesurvey.co.uk/ontology/postcode/PostcodeUnit>
BIND (STRAFTER((STR(?postcodeUnit)),'postcodeunit/') as ?postcode)
}limit 10
This code brings back the postcodes, but I am trying to link to LSOA codes.
Thanks in Advance
You may be a bit stuck with this data source.
http://data.ordnancesurvey.co.uk/ontology/postcode/PostcodeUnit
Shows that there is no LSOA data associated with a postcode unit. And a quick look at the RDF for the site shows that they don't have a field called LSOA.

Django: access and update a variable on which to filter during a Django model query?

I'm hoping to build a Django query to my model that lets my filter change as the query progresses.
I have a model Activity that I'm querying for. Each object has a postal_code field and I'm querying for multiple zip codes stored in an array postal_codes_to_query across a date range. I'd like to ensure that I get an even spread of objects across each of the zip codes. My database has millions of Activities, so when I query with a limit, I only receive activities that match zip codes early on in postal_codes_to_query. My current query is below:
Activity.objects.filter(postal_code__in=postal_codes_to_query).filter(start_time_local__gte=startTime).filter(start_time_local__lte=endTime).order_by('start_time_local')[:10000]
If I'm searching for say 20 zip codes, Ideally I'd like to receive 10000 activities, with 500 activities for each zip code that I queried on.
Is this possible in Django? If not, is there some custom SQL I could write to achieve this? I'm using a Heroku Postgres database in case that matters.
You can't do this in a single query, either in Django nor (as far as I know) in SQL.
The best bet is simply to iterate through the list of zips, querying for max 500 in each one:
activities_by_zip = {}
for code in postal_codes_to_query:
activities = Activity.objects.filter(postal_code=code).filter(
start_time_local__gte=startTime).filter(
start_time_local__lte=endTime).order_by('start_time_local')[:500]
activities_by_zip[code] = activities
Of course, this is one query per zip, but I think that's the best you're going to do.