Query for banks in DBpedia - sparql

Using http://dbpedia.org/sparql, I want to receive the geographic coordinates of all bank buildings. The list of classes tells me that I should query for Bank.
Yet, the following code yields nothing:
SELECT DISTINCT ?label ?lat ?long
WHERE {
[]
rdf:type dbpedia-owl:Bank ;
geo:lat ?lat ;
geo:long ?long ;
rdfs:label ?label.
FILTER (LANGMATCHES(LANG(?label), 'en'))
}
If instead I query for any sibling to Bank, (e.g. Brewery or LawFirm), I see at least some results. What's wrong with above code?

If you look into a dbpedia page for a bank, you can see that instead on rdf:type, banks have a property dbpedia-owl:industry that has dbpedia:Bank (Refah bank) or dbpedia:Financial_services (Cyprus bank) as a value. So if you rewrite your query as the following, you will get some results:
SELECT DISTINCT ?label ?lat ?long
WHERE {
[] dbpedia-owl:industry dbpedia:Bank ;
geo:lat ?lat ;
geo:long ?long ;
rdfs:label ?label.
FILTER (LANGMATCHES(LANG(?label), 'en'))
}
If you add dbpedia:Financial_services, other organisations such as London stock exchange will also appear:
SELECT DISTINCT ?bank
WHERE {
?bank dbpedia-owl:industry ?place ;
geo:lat ?lat ;
geo:long ?long ;
rdfs:label ?label.
FILTER (?place in (dbpedia:Financial_services, dbpedia:Bank) &&
LANGMATCHES(LANG(?label), 'en'))
}
Again, by examining the London stock exchange, you can see that there is a product property that separates these financial institutions. So this will give you banks, but it might not cover all the banks available:
SELECT DISTINCT ?label ?lat ?long
WHERE {
[] dbpedia-owl:industry ?place ;
geo:lat ?lat ;
geo:long ?long ;
rdfs:label ?label;
dbpedia-owl:product ?product.
FILTER ( ?place in (dbpedia:Financial_services, dbpedia:Bank)
&& ?product in (dbpedia:Bank, dbpedia:Private_banking, dbpedia:Professional_Banking, dbpedia:Retail_banking, dbpedia:Investment_banking, dbpedia:Commercial_bank)
&& LANGMATCHES(LANG(?label), "en"))
} ORDER BY DESC(COUNT(DISTINCT ?product))

Related

transaction time out in sparql query

select distinct ?label ?resource count(distinct ?type) as ?score
where
{
values ?type
{ <http://dbpedia.org/class/yago/Abstraction100002137>
<http://dbpedia.org/class/yago/Company108058098>
<http://dbpedia.org/class/yago/ElectronicsCompany108003035>
<http://dbpedia.org/class/yago/Group100031264>
<http://dbpedia.org/class/yago/Institution108053576>
<http://dbpedia.org/class/yago/Organization108008335>
}
?resource rdfs:label ?label ;
foaf:name ?name ;
a ?type .
FILTER (lang(?label) = 'en').
}
ORDER BY DESC(?score)
limit 10
I am trying to run this query but it shows transaction timeout, I cut out many of these links from this query, but still it shows same issue

sparql query is not returning desired output

This is my sparql query to get all the country name with some property of that country.
SELECT distinct ?country ?capital ?currency ?lat ?long
WHERE {
?country rdf:type dbo:Country .
?country dbo:capital ?capital .
?country dbo:currency ?currency .
?country geo:lat ?lat.
?country geo:long ?long.
}
ORDER BY ?country
But the problem is, Some country is missing, like "Switzerland". You go to http://dbpedia.org/page/Switzerland this page you will see that it's type is country. you will also do not find exactly "Austria" rather "Austrian_Empire". Why? There is a entity called "Austria" and it is dbo:Country type.
Switzerland does not seem to have dbo:capital, which is why it's not included in the results of your query.
If you want to get even results that do not have some of the properties, use OPTIONAL:
SELECT distinct ?country ?capital ?currency ?lat ?long
WHERE {
?country rdf:type dbo:Country .
OPTIONAL
{
?country dbo:capital ?capital .
?country dbo:currency ?currency .
?country geo:lat ?lat.
?country geo:long ?long.
}
}
ORDER BY ?country
Though this query returns even entities that are not countries (but for some reason are dbo:Country), like Cinema of Switzerland.

How to use Sparql Contains to match similar String?

I'm trying to grab some definition in dbpedia inside my thesaurus.
Although can find country that have a label that match my country, i don't get all of them. So i try to match similar label with contains but it does not work.
Any idea why.
SELECT distinct ?idbcountry ?label ?labelDb ?def
WHERE {
?idbcountry a skos:Concept .
?idbcountry rdfs:label ?label .
?idbcountry skos:inScheme iadb:IdBCountries .
FILTER(lang(?label) = "en")
Service <http://dbpedia.org/sparql> {
?s a <http://dbpedia.org/ontology/Country> .
?s rdfs:label ?labelDb .
FILTER(CONTAINS (?labelDb, ?label)).
?s rdfs:comment ?def .
FILTER(lang(?def) = "en") .
FILTER(lang(?labelDb) = "en") .
}}
The exact matching query that works is as follows:
SELECT distinct ?idbcountry ?label ?def
WHERE {
?idbcountry a skos:Concept .
?idbcountry rdfs:label ?label .
?idbcountry skos:inScheme iadb:IdBCountries .
FILTER(lang(?label) = "en")
Service <http://dbpedia.org/sparql> {
?s a <http://dbpedia.org/ontology/Country> .
?s rdfs:label ?label .
?s rdfs:comment ?def
FILTER(lang(?def) = "en")
}
}
EDIT1
Data Samples:
<http://thesaurus.iadb.org/publicthesauri/10157002136735779158437>
rdf:type skos:Concept ;
dct:created "2015-03-27T16:43:48.052-04:00"^^xsd:dateTime ;
rdfs:label "BO"#en ;
rdfs:label "Bolivia"#en ;
rdfs:label "Bolivia"#es ;
rdfs:label "Bolivie"#fr ;
rdfs:label "Bolívia"#pt ;
skos:altLabel "BO"#en ;
skos:definition "Bolivia (/bəˈlɪviə/, Spanish: [boˈliβja], Quechua: Buliwya, Aymara: Wuliwya), officially known as the Plurinational State of Bolivia (Spanish: Estado Plurinacional de Bolivia locally: [esˈtaðo pluɾinasjoˈnal de βoˈliβja]), is a landlocked country located in western-central South America."#en ;
skos:inScheme :IdBCountries ;
skos:prefLabel "Bolivia"#en ;
skos:prefLabel "Bolivia"#es ;
skos:prefLabel "Bolivie"#fr ;
skos:prefLabel "Bolívia"#pt ;
skos:topConceptOf :IdBCountries ;
<http://xmlns.com/foaf/0.1/focus> <http://dbpedia.org/resource/Bolivia> ;
Without seeing your data, we can't know why your query isn't working. However, using contains is pretty straightforward. It's just a matter of contains(string,substring). As Jeen said, we can't reproduce your problem without knowing what your data looks like, but here's an example of contains in action:
select distinct ?country ?label {
?country a dbpedia-owl:Country ; #-- select countries
rdfs:label ?label . #-- and get labels
filter langMatches(lang(?label),"en") #-- but only English labels
filter contains(?label,"land") #-- containing "land"
}
SPARQL results

Printing matching properties in DBpedia query

The following query will search for matching subjects based on a list of properties and within a given distance. They are ranked by the number of matching properties (?numProperties), which is output as a number. How can I also print each of the properties that are matches?
Run query
select ?subject (count ( distinct ?property) as ?numProperties) ?label ?lat ?long where {
values ?property { dbpedia-owl:crosses dbpedia-owl:vehicle dbpedia-owl:reopened dbpedia-owl:years dbpedia-owl:access dbpedia-owl:third dbpedia-owl:time dbpedia-owl:construction dbpedia-owl:anniversary dbpedia-owl:series dbpedia-owl:length dbpprop:suspension dbpprop:bridge dbpprop:crosses dbpprop:City dbpprop:connecting dbpprop:last dbpprop:three dbpprop:suspension dbpprop:bridges dbpprop:built }
?subject ?property ?object .
?subject rdfs:label ?label .
?subject geo:lat ?lat .
?subject geo:long ?long .
FILTER (?long > -74.490898 && ?long < -73.490898 && ?lat > 40.207222 && ?lat < 41.207222 ) .
FILTER(langMatches(lang(?label),"EN")) .
}
group by ?subject ?label ?lat ?long
order by desc(?numProperties)
limit 15
#-- I took the liberty of tidying up your query a bit.
#-- The key is to use the GROUP_CONCAT aggregate function.
select
?subject
(count(distinct ?property) as ?numProperties)
?label
?lat
?long
#-- concatenate distinct properties into a ', ' separated string
(group_concat(distinct ?property;separator=', ') as ?properties)
where {
values ?property {
dbpedia-owl:crosses dbpedia-owl:vehicle dbpedia-owl:reopened
dbpedia-owl:years dbpedia-owl:access dbpedia-owl:third
dbpedia-owl:time dbpedia-owl:construction dbpedia-owl:anniversary
dbpedia-owl:series dbpedia-owl:length dbpprop:suspension
dbpprop:bridge dbpprop:crosses dbpprop:City dbpprop:connecting
dbpprop:last dbpprop:three dbpprop:suspension
dbpprop:bridges dbpprop:built
}
?subject ?property ?object ;
rdfs:label ?label ;
geo:lat ?lat ;geo:long ?long .
FILTER ( -74.490898 < ?long && ?long < -73.490898 &&
40.207222 < ?lat && ?lat < 41.207222 )
FILTER(langMatches(lang(?label),"EN"))
}
group by ?subject ?label ?lat ?long
order by desc(?numProperties)
limit 15
SPARQL results

dbpedia SPARQL query to get certain value's for a given city

I am sure what I want to do is very easy, yet I cannot seem to get the query right. I have records in dataset which have values such as city name e.g. 'New York' and it's corresponding country code e.g 'US'. I also have access to the full country name and country ISO codes.
I would like to get the population and abstract value's for these cities off dbpedia, by using a where clause such as:
Get population where name = "New York" and isoCountryCode = "US"
I've searched for help on this to no avail.
so far I have been kindly helped by #rohk with this query, which does not fully work for all locations:
SELECT DISTINCT ?city ?abstract ?pop
WHERE {
?city rdf:type schema:City ;
rdfs:label ?label ;
dbpedia-owl:abstract ?abstract ;
dbpedia-owl:country ?country ;
dbpedia-owl:populationTotal ?pop .
?country dbpprop:countryCode "USA"#en .
FILTER ( lang(?abstract) = 'en' and regex(?label, "New York City"))
}
The above works for New York, however when I change it to:
SELECT DISTINCT ?city ?abstract ?pop
WHERE {
?city rdf:type schema:City ;
rdfs:label ?label ;
dbpedia-owl:abstract ?abstract ;
dbpedia-owl:country ?country ;
dbpedia-owl:populationTotal ?pop .
?country dbpprop:countryCode "THA"#en .
FILTER ( lang(?abstract) = 'en' and regex(?label, "Bangkok"))
}
It returns no results for Bangkok, Thailand.
I just cant seem to get the SPARQL query correct, I'm sure I am being silly with my query. If any guru's could provide me with help I'd appreciate it. Thanks!
I guess you want something like this:
SELECT * WHERE {
?x rdfs:label "New York City"#en.
?x dbpedia-owl:populationTotal ?pop.
?x dbpedia-owl:abstract ?abstract.
}
To get only the English abstract, add a FILTER:
SELECT * WHERE {
?x rdfs:label "New York City"#en.
?x dbpedia-owl:populationTotal ?pop.
?x dbpedia-owl:abstract ?abstract.
FILTER (LANG(?abstract) = 'en')
}
“New York” is the state and it doesn't have a populationTotal figure attached. “New York City” is the city.
This query is working
SELECT DISTINCT *
WHERE {
?city rdf:type schema:City ;
rdfs:label ?label ;
dbpedia-owl:abstract ?abstract ;
dbpedia-owl:country ?country ;
dbpprop:website ?website ;
dbpedia-owl:populationTotal ?pop .
?country dbpprop:countryCode "USA"#en .
FILTER ( lang(?abstract) = 'en' and regex(?label, "New York City"))
}
EDIT : For Bangkok, there are 2 problems :
No country code for Thailand : you can use rdfs:label "Thailand"#en instead.
rdf:type of Bangkok is not schema:City but dbpedia-owl:Settlement
Here is a working query for Bangkok
SELECT DISTINCT *
WHERE {
?city rdf:type dbpedia-owl:Settlement ;
rdfs:label "Bangkok"#en ;
dbpedia-owl:abstract ?abstract ;
dbpedia-owl:populationTotal ?pop ;
dbpedia-owl:country ?country ;
dbpprop:website ?website .
?country rdfs:label "Thailand"#en .
FILTER ( lang(?abstract) = 'en' )
}