0

All queries are tested on sparql virtuso endpoint
I want to find the categories of two dbpedia subject like here Bharatiya_Janata_Party and New_Delhi.
I want to match how the categories of these are similar to each other.

As here in the first query i got the categories of Bharatiya_Janata_Party.

In the Second query i got the categories of New_Delhi.

Now I want to match the result of category of Bharatiya_Janata_Party to that of New_Delhi. Like here

  1. Nationalist_parties---New_Delhi
  2. Nationalist_parties---New_Delhi_district
  3. Nationalist_parties---Populated_places_established_in_1911
  4. Nationalist_parties---Capitals_in_Asia
  5. Nationalist_parties---Capitals_in_Asia
  6. Nationalist_parties--Planned_capitals
  7. Political_parties_established_in_1980---New_Delhi
  8. Political_parties_established_in_1980---New_Delhi_district
  9. .....
  10. .... .. ..

I have fired a query III for making match between Nationalist_parties---New_Delhi. I got a match at level 4((^skos:broader){0,4}).

Similarly Again I have to do for Nationalist_parties---New_Delhi_district.

The real problem is that i want to combine these 3 queries so that i may get the direct result in a tabular form. Is there any way to automate the whole process.

Query I:

 SELECT *
    WHERE {
      dbpedia:Bharatiya_Janata_Party dcterms:subject ?x
    }

Result of Query I:

dbpedia.org/resource/Category:Nationalist_parties
dbpedia.org/resource/Category:Political_parties_established_in_1980
dbpedia.org/resource/Category:Conservative_parties_in_India
dbpedia.org/resource/Category:Hindu_political_parties
dbpedia.org/resource/Category:Hindutva
dbpedia.org/resource/Category:Bharatiya_Janata_Party
dbpedia.org/resource/Category:1980_establishments_in_India

Query II:

SELECT *
WHERE {
  dbpedia:New_Delhi dcterms:subject ?x
}

Result of Query II:

dbpedia.org/resource/Category:New_Delhi
dbpedia.org/resource/Category:New_Delhi_district
dbpedia.org/resource/Category:Populated_places_established_in_1911
dbpedia.org/resource/Category:Capitals_in_Asia
dbpedia.org/resource/Category:Indian_capital_cities
dbpedia.org/resource/Category:Planned_capitals
dbpedia.org/resource/Category:Urdu-speaking_countries_and_territories

QUERY III:

select distinct ?super where {
  ?super (^skos:broader){0,4} category:Nationalist_parties, category:New_Delhi
}

Result:

dbpedia.org/resource/Category:Government-related_organizations
dbpedia.org/resource/Category:Government

First Match at level 4 with 2 Super Classes

P.S: It is not necessary that the other query will match at (^skos:broader){0,4}. So i am manually firing the above query from (^skos:broader){0,0} and incrementing as (^skos:broader){0,1}->(^skos:broader){0,2)...to the first match.

select distinct ?super where {
  ?super (^skos:broader){0,6} category:Nationalist_parties, category:New_Delhi_district
}

Result:

dbpedia.org/resource/Category:Categories_by_topic
dbpedia.org/resource/Category:Government
dbpedia.org/resource/Category:Categories_by_parameter
dbpedia.org/resource/Category:Political_geography

First Match at level 6 with 4 Super Classes

===================================

Combining these 3 queries i want this type of result in a tabular form:-

==================================

**CategoryI(QueryI---Category(QuesryII)---Level --count matches*

  1. Nationalist_parties---New_Delhi---------------------------- 4------ 2
  2. Nationalist_parties---New_Delhi_district-------------------6--------4
  3. Nationalist_parties---Populated_places_established_in_1911
  4. Nationalist_parties---Capitals_in_Asia
  5. Nationalist_parties---Capitals_in_Asia ...
  6. .....
  7. ....

Please help me to automate and combine the above query. I have read several posts but not able to figure it how.

Rituraj Singh
  • 579
  • 1
  • 5
  • 16
  • possible duplicate of [How the pass the output of one sparql query as a input to another sparql query](http://stackoverflow.com/questions/28282463/how-the-pass-the-output-of-one-sparql-query-as-a-input-to-another-sparql-query) – Jeen Broekstra Feb 05 '15 at 23:28
  • No the question is about iterating the whole process..and automating them..Please have a view if you have the solution – Rituraj Singh Feb 06 '15 at 05:44

0 Answers0