Get all Countries Name from DBpedia using SPARQL - sparql

I want list of countries name from DBpedia.
I am using http://dbpedia.org/snorql/ to execute my query, but till now I have not found all countries name which are available in DBpedia.
For Example : dbr:United_Kingdom, dbr:India, dbr:United_States, etc.

Is the problem
You don't know how to write SPARQL in general? (That's OK, it's hard to get started.)
You don' know about the classes and predicates in DBpedia? (That's OK too. I have to check each time.)
Something else?
This gets all UN member nations. Getting "all countries" is probably just a matter of finding the right class in their ontology.
select distinct ?s
where { ?s a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> }
I happen to know that New York City is the largest city in the United States, and that DBpedia has a largestCity predicate and a New_York_City instance. So I wrote a query that should only get the United States as the subject, and then asked for all connected predicates and objects. You should look in that for an object that meets your exceptions for defining "all countries." If you don't find one, you may have to union a few other triple patterns into one query.
I have also filtered out objects that contain either of two terms that be relevant for you: "country" or "nation"
select distinct *
where { ?s a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> ;
dbo:largestCity dbr:New_York_City ;
?p ?o
filter(isURI(?o))
filter((regex(lcase(str(?o)), "country")) || (regex(lcase(str(?o)), "nation")))
}
Gives the foloowing, which should help you write a followup question that isn't specific to the United States.
+--------------------------------------------+---------------------------------------------------+------------------------------------------------------------------------------+
| s | p | o |
+--------------------------------------------+---------------------------------------------------+------------------------------------------------------------------------------+
| http://dbpedia.org/resource/United_States | http://dbpedia.org/ontology/wikiPageExternalLink | http://www.ifs.du.edu/ifs/frm_CountryProfile.aspx?Country=US |
| http://dbpedia.org/resource/United_States | http://dbpedia.org/ontology/wikiPageExternalLink | http://nationalatlas.gov/ |
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://dbpedia.org/class/yago/Country108544813 |
| http://dbpedia.org/resource/United_States | http://purl.org/dc/terms/subject | http://dbpedia.org/resource/Category:G7_nations |
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://schema.org/Country |
| http://dbpedia.org/resource/United_States | http://www.w3.org/2000/01/rdf-schema#seeAlso | http://dbpedia.org/resource/Anti-miscegenation_laws |
| http://dbpedia.org/resource/United_States | http://purl.org/dc/terms/subject | http://dbpedia.org/resource/Category:Member_states_of_the_United_Nations |
| http://dbpedia.org/resource/United_States | http://www.w3.org/2002/07/owl#sameAs | http://transparency.270a.info/classification/country/US |
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://dbpedia.org/ontology/Country |
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations |
| http://dbpedia.org/resource/United_States | http://purl.org/dc/terms/subject | http://dbpedia.org/resource/Category:G8_nations |
| http://dbpedia.org/resource/United_States | http://www.w3.org/2002/07/owl#sameAs | http://linked-web-apis.fit.cvut.cz/resource/united_states_of_america_country |
| http://dbpedia.org/resource/United_States | http://dbpedia.org/ontology/wikiPageExternalLink | http://www.nationalcenter.org/HistoricalDocuments.html |
| http://dbpedia.org/resource/United_States | http://dbpedia.org/ontology/wikiPageExternalLink | http://news.bbc.co.uk/2/hi/americas/country_profiles/1217752.stm |
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://umbel.org/umbel/rc/Country |
| http://dbpedia.org/resource/United_States | http://purl.org/dc/terms/subject | http://dbpedia.org/resource/Category:G20_nations |
+--------------------------------------------+---------------------------------------------------+------------------------------------------------------------------------------+

Related

Get similar employees based on their attribute values

Consider the following sample table("Customer") with these records
=========
Customer
=========
-----------------------------------------------------------------------------------------------
| customer-id | att-a | att-b | att-c | att-d | att-e | att-f | att-g | att-h | att-i | att-j |
--------------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| customer-1 | att-a-7 | att-b-3 | att-c-10 | att-d-10 | att-e-15 | att-f-11 | att-g-2 | att-h-7 | att-i-5 | att-j-14 |
--------------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| customer-2 | att-a-9 | att-b-7 | att-c-12 | att-d-4 | att-e-10 | att-f-4 | att-g-13 | att-h-4 | att-i-1 | att-j-13 |
--------------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| customer-3 | att-a-10 | att-b-6 | att-c-1 | att-d-1 | att-e-13 | att-f-12 | att-g-9 | att-h-6 | att-i-7 | tt-j-4 |
--------------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| customer-19 | att-a-7 | att-b-9 | att-c-13 | att-d-5 | att-e-8 | att-f-5 | att-g-12 | att-h-14 | att-i-13 | att-j-15 |
--------------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
I have these records and many more records dumped into SQL database and wanted to find top 10 similar customer based on the attribute value. For example customer-1 and customer-19 have atleast one column value matching .i.e "att-a-7" so the output should give me 2 customer-id's or top similar customer that are customer-1 and customer-19.
P.S - there can be one or more columns similar across rows.
I'm using windowing technique to find top 10 similar customer and im not sure if I'm correct.
following is my approach I used in my query :
row_number() over (partition by att-a, att-b,..,att-j order by customer-id) as customers
is this correct. ?

Retrieve closest road when given (lat, long) using OSM in Postgres with Postgis using SQL query

Given a set (lat, long) I am trying to find the maximum speed using "max_speed" and street type using "highway".
I have loaded my database (Postgres and Postgis) as follows:
$ osm2pgsql -c -d gis --slim -C 50000 /var/lib/postgresql/data/germany-latest.osm.pbf
The closest related question I could find was How to query all shops around a certain longitude/latitude using osm-postgis?. I have taken the query, and plugged in a (lat, long) that I found in google maps for the city center of Munich (as the post was also related to city center Munich and I have the map for Germany). The result turns up empty.
gis=# SELECT name, shop FROM planet_osm_point WHERE ST_DWithin(way ,ST_SetSrid(ST_Point(48.137969, 11.573829), 900913), 100);
name | shop
------+------
(0 rows)
Also when looking into the planet_osm_nodes, which contains (lat, long) pairs directly, I end up with no results:
gis=# SELECT * FROM planet_osm_nodes WHERE ((lat BETWEEN 470000000 AND 490000000) AND (lon BETWEEN 100000000 AND 120000000)) LIMIT 10;
id | lat | lon | tags
----+-----+-----+------
(0 rows)
I verified the data is in my database:
gis=# SELECT COUNT(*) FROM planet_osm_point;
count
---------
9924531
(1 row)
and
gis=# SELECT COUNT(*) FROM planet_osm_nodes;
count
-----------
288597897
(1 row)
So ideally, my question would be
Q: How can I find the "max speed" and "highway" given a set (lat, lon)
alternatively, my questions is:
Q: How do I get the query from the other stack overflow post to work?
My best guess is that I need to transform my (lat, lon) in some way, or that I simply have the wrong data for whatever reason.
Edit: added sample data as requested:
gis=# SELECT * FROM planet_osm_point LIMIT 1;
osm_id | access | addr:housename | addr:housenumber | addr:interpolation | admin_level | aerialway | aeroway | amenity | area | barrier | bicycle | brand | bridge | boundary | building | capital | construction | covered | culvert |
cutting | denomination | disused | ele | embankment | foot | generator:source | harbour | highway | historic | horse | intermittent | junction | landuse | layer | leisure | lock | man_made | military | motorcar | name | natural | off
ice | oneway | operator | place | poi | population | power | power_source | public_transport | railway | ref | religion | route | service | shop | sport | surface | toll | tourism | tower:type | tunnel | water | waterway | wetland | wi
dth | wood | z_order | way
-----------+--------+----------------+------------------+--------------------+-------------+-----------+---------+---------+------+---------+---------+-------+--------+----------+----------+---------+--------------+---------+---------+
---------+--------------+---------+-----+------------+------+------------------+---------+----------+----------+-------+--------------+----------+---------+-------+---------+------+----------+----------+----------+------+---------+----
----+--------+----------+-------+-----+------------+-------+--------------+------------------+---------+-----+----------+-------+---------+------+-------+---------+------+---------+------------+--------+-------+----------+---------+---
----+------+---------+----------------------------------------------------
304070863 | | | | | | | | | | | | | | | | | | | |
| | | | | | | | crossing | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
| | | 010100002031BF0D0048E17A94F19F2941CDCCCCDCC60D5741
(1 row)
and
gis=# SELECT * FROM planet_osm_nodes LIMIT 1;
id | lat | lon | tags
--------+-----------+----------+------
234100 | 666501948 | 80442755 |
(1 row)
Edit 2: There was a mention regarding "SRID", so I added example data from another table:
gis=# SELECT * FROM spatial_ref_sys LIMIT 1;
srid | auth_name | auth_srid | srtext
| proj4text
------+-----------+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------
3819 | EPSG | 3819 | GEOGCS["HD1909",DATUM["Hungarian_Datum_1909",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[595.48,121.69,515.35,4.115,-2.9383,0.853,-3.408],AUTHORITY["EPSG","1024"]],PR
IMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","3819"]] | +proj=longlat +ellps=bessel +towgs84=595.48,121.69,515.35,4.115,-2.9383,0.853,-3.408 +no_defs
(1 row)
Geometry in PostGIS has a different ordering of (lat long) first is going longitude then latitude.
Also if you want to transform a point from one SRID to another use st_transfrom(), not ST_SetSrid.
ST_Transform relly transform your data from one coordinates system to another.
select st_astext(st_transform(ST_SetSrid(ST_Point(11.573829,48.137969), 4326),900913))
ST_SetSrid - just change SRID for the object.
select st_astext((ST_SetSrid(ST_Point(11.573829,48.137969),900913)
So, you have to change your SQL that way
SELECT name, shop
FROM planet_osm_point
WHERE ST_DWithin(way,st_transform(ST_SetSrid(ST_Point(11.573829,48.137969), 4326),900913), 100);

Query from secondary index on aerospike

I'm considering aerospike for one of our projects. So I currently created a 3 node cluster and loaded some data on it.
Sample data
ns: imei
set: imei_data
+-------------------+-----------------------+-----------------------+----------------------------+--------------+--------------+
| imsi | fcheck | lcheck | msc | fcheck_epoch | lcheck_epoch |
+-------------------+-----------------------+-----------------------+----------------------------+--------------+--------------+
| "413010324064956" | "2017-03-01 14:30:26" | "2017-03-01 14:35:30" | "13d20b080011044917004100" | 1488358826 | 1488359130 |
| "413012628090023" | "2016-09-21 10:06:49" | "2017-09-16 13:54:40" | "13dc0b080011044917006100" | 1474432609 | 1505550280 |
| "413010130130320" | "2016-12-29 22:05:07" | "2017-10-09 16:17:10" | "13d20b080011044917003100" | 1483029307 | 1507546030 |
| "413011330114274" | "2016-09-06 01:48:06" | "2017-10-09 11:53:41" | "13d20b080011044917003100" | 1473106686 | 1507530221 |
| "413012629781993" | "2017-08-16 16:03:01" | "2017-09-13 18:10:48" | "13dc0b080011044917004100" | 1502879581 | 1505306448 |
Then I created a secondary index on lcheck_epoch using AQL since I want to query based on date.
create index idx_lcheck on imei.imei_data (lcheck_epoch) NUMERIC
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
| ns | bin | indextype | set | state | indexname | path | type |
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
| "imei" | "lcheck_epoch" | "NONE" | "imei_data" | "RW" | "idx_lcheck" | "lcheck_epoch" | "NUMERIC" |
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
When I execute
select imsi from imei.imei_data where idx_lcheck=1476165806
I'm getting
Error: (204) AEROSPIKE_ERR_INDEX
Please explain.
You're using the index name, not the bin name, in your query. Try this:
SELECT imsi FROM imei.imei_data WHERE lcheck_epoch=1476165806
Or
SELECT imsi FROM imei.imei_data WHERE lcheck_epoch BETWEEN 1490000000 AND 1510000000
Just a note, you can do much more complex queries using predicate filtering through several of the language clients (Java, C, C#, Go). For example the PredExp class of the Java client (see examples.)

Increment value when the field is the same

First, I'm sorry for the ambiguous title.
Here's my problem :
I'm using Access and I have this table :
+--------+-----------+
| PARENT | CHILD |
+--------+-----------+
| JOHN | TANIA |
| JOHN | ROBERT |
| JOHN | APRIL |
| HELEN | TOM |
| HELEN | GABRIELLE |
+--------+-----------+
And I would like to add a column like this with queries or VBA code :
+--------+-----------+---------+
| PARENT | CHILD | LIST |
+--------+-----------+---------+
| JOHN | TANIA | CHILD 1 |
| JOHN | ROBERT | CHILD 2 |
| JOHN | APRIL | CHILD 3 |
| HELEN | TOM | CHILD 1 |
| HELEN | GABRIELLE | CHILD 2 |
+--------+-----------+---------+
I want to do this because at the end, I want to run a cross tab query. I'm only missing that last column to create that query.
I tried to do it in a recordset, but my database starts bloating after a couple of rst.Update (I have 700k+ rows)
I created a temporary table and used UPDATE queries but it just takes too much time.
I think there might be a SQL code that would do what I need, but I just can't figure it out. I hope you could help me, thanks :)
You can do something like the below, but it would be much better with some sort of IDs:
SELECT Parent.PARENT,
Parent.CHILD,
(SELECT Count(*)
FROM Parent p
WHERE p.Parent=Parent.Parent
AND p.Child<=Parent.Child) AS ChildNo
FROM Parent
ORDER BY Parent.PARENT, Parent.CHILD;
Parent is the name of the table.

Duplicate output results with SPARQL [duplicate]

This question already has an answer here:
Aggregating results from SPARQL query
(1 answer)
Closed 9 years ago.
I'm new to the semantic web concept, and I have a diploma work based on the semantic web. In my OWL ontology, I have defined the individuals in he following manner:
<Announce rdf:ID="Ann1" ...>
<...>
<...>
<requiredTechnologies>
<Technology rdfs:resource="tech1"/>
</requiredTechnologies>
<requiredTechnologies>
<Technology rdfs:resource="tech2"/>
</requiredTechnologies>
</Announce>
...
Basically, there are some properties that appear only once for a given individual, but the property "required technologies" can be used multiple times in one record (for one individual). So, when I run a SPARQL query, selecting all the data (I use Jena), I get this output:
=====================================
| "Ann1" | ... | ... | "tech1" |
| "Ann1" | ... | ... | "tech2" |
| "Ann2" | ... | ... | "tech3" |
| "Ann3" | ... | ... | "tech4" |
| "Ann3" | ... | ... | "tech5" |
| "Ann3" | ... | ... | "tech6" |
| ... | ... | ... | ... |
=====================================
The records where multiple "requiredTechnologies" attribute is present appear more then once. My question is how to get all the technologies that belong to a given individual in one line (something like this):
===================================================
| "Ann1" | ... | ... | "tech1, tech2" |
| "Ann2" | ... | ... | "tech2" |
| "Ann3" | ... | ... | "tech4, tech5, tech6" |
| ... | ... | ... | ... |
===================================================
Is there a way in SPARQL to get the multiple attribute in a list? Or any other workaround?
Yes, use the GROUP BY clause in conjunction with the GROUP_CONCAT aggregate.
Here's a generic example, you should easily be able to adapt to your data model:
SELECT ?s (GROUP_CONCAT(?value ; SEPARATOR = ",") AS ?values)
WHERE
{
?s <http://somePredicate> ?value .
}
GROUP BY ?s