Obtain country from wikidata item using SPARQL - 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?

Related

Get all properties and related ID of an item using SPARQL query

I want to retrieve all properties and their ID of one item from Wikidata by using SPARQL. I have two queries.
This query only can retrieve properties without their IDs:
The result of it is shown like this:
This query only can retrieve two-level properties with ID:
And this is the result:
Is there any way to mix them to show all properties with their IDs?

API to List of all Suburbs in a City or country

Is there an API i can use to fetch all cities in a Country or country state using its name
e.g https://api.domain/?q=suburbs&country=US.
I need results shown like these except that their documentation API only shows limited results as compared to the actual data returned here

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

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.

how to add dyanmic parent child relationship in jira custom field?

I am trying to migrate some of my bugzilla data to JEERA. I have some custom fields in bugzilla which has dynamic parent-child relationship. for exa-
Suppose I have Labels "India" "China" "Russia",
when I click on Label lets say "India", then it should fetch and show only cities from India and not all cities.
Right now , I am able to create Labels and cities custome fields in jeera but lacking dynamic nature.
I will be thankful, if anyone has any idea over this.
Perhaps Select List (cascading) custom field type would best solution here.
As a bit workaround for relate two custom fields between each other you can use ScriptRunner Behaviours. It's like a Groovy definition for frontend logic. Conceptually:
City field must contains all Cities for all Countries.
Create a Behaviour for a Country field. It means when user will change/select a Country field a Behaviour will be run.
In behaviour write code that will get currently selected country and then fulfil a Cities field based on selected country.
Useful methods: getFieldById(fieldId), formField.getValue(), formField.setFieldOptions(Iterable). API Documentation.
I think #sintasy is right.
If you want N-countries have their own cities, cascading select list just fit your requrement.
If you want N-countries * M-other-things, which have no relation with countries, two select lists will fit your requrement.
If you want more complex feature, then I don't known.

Apache SOLR search by category

I am using apache-solr-1.4.1 and jdk1.6.0_14.
I have the following scenario.
I have 3 categories of data indexed in SOLR i.e. CITIES, STATES, COUNTRIES.
When I query data from SOLR I need the search result from SOLR based on the following criteria:
In a single query to SOLR I need data fetched from SOLR grouped by each category with a predefined results count for each category.
How can I specify this condition in SOLR?
I have tried to use SOLR Field Collapsing feature, but I am not able to get the desired output from SOLR.
Please suggest.
My solution is not exactly what you have asked but is my take on what SOLR does best, which is full text search. Instead of grouping the results by "category", I'd suggest you order the results by relevance score but also provide a facet count for the category values. In my experience users expect a "search" to behave like Google, with the best matches at the top. Deviating form this norm confuses the user in most cases.
If you want exactly as you have asked (actual results grouped by category) then you could use a relational database and do a group_by or write a custom function query with SOLR (I cannot advise on this as I've never done it).
More info: index the data with the appropriate fields, e.g. name, population, etc. But also add a field called "category", which would have a value of either CITIES, STATES or COUNTRIES. Then perform a standard SOLR search, which will return results in order of relevance - i.e. best matches at the top. As part of the request, you can specify a facet.field=category, which will return counts for the search results for each of the given categories (in the "facet" results section). In the UI you can then create links for each category facet which performs the original search plus &fq=category:CITIES, etc., thus restricting results to just that category. See the facetting overview on the SOLR wiki for more info.