使用SPARQL查询DBPedia以查找右翼派对

时间:2014-03-17 10:17:57

标签: sparql dbpedia

我想找到欧盟的所有极右翼政党,此外我想要他们的领导人。在dbpedia for property中,是dbpedia-owl:party of ,我不知道如何使用它。

到目前为止,这是我的查询:

SELECT str(?Lparty) as ?Politicalparty str(?Lcountry) as ?EUCountry str(?Lleader) as     ?EUleader
WHERE
{
  ?Party dbpprop:position ?Position ;
         rdfs:label ?Lparty ;
         dbpedia-owl:country ?Country ;
         a dbpedia-owl:PoliticalParty ;

         # The following are the problematic lines

         dbpedia-owl:party ?Leader ;
         rdfs:label ?Lleader.

         # End problematic lines

  FILTER(LANGMATCHES(LANG(?Lleader), "en")).
  FILTER(?Position IN (dbpedia:Far-right_politics,dbpedia:Nazism, dbpedia:Nationalism)).
  FILTER(NOT EXISTS{?Party dbpprop:dissolved ?otherBalue}).
  FILTER(NOT EXISTS{?Party dbpprop:dissolution ?otherBalue}).
  FILTER(LANGMATCHES(LANG(?Lparty), "en")).
  ?Country dcterms:subject category:Member_states_of_the_European_Union;
           rdfs:label ?Lcountry.
  FILTER(LANGMATCHES(LANG(?Lcountry), "en")).
} 

1 个答案:

答案 0 :(得分:1)

我正在解决类似于你的查询,过了一段时间我意识到有些?Leaders已经是标签,有些则是需要提取标签的URI。例如,在您的情况下,如果您更改"有问题的部分"进入?Party dbpprop:leader ?Leader.,您可以同时获得Hendrik Eliashttp://dbpedia.org/resource/Wies_Moens等答案。因此,如果您在两种情况下都需要标签,则需要决定何时深入挖掘。由于我的版本是更大程序的一部分,因此以编程方式解决此问题更快。基于这些解释,我能写的最简单的查询是:

SELECT distinct str(?Lparty) as ?Politicalparty str(?Lcountry) as ?EUCountry str(?Leader) as     ?EUleader
WHERE
{
  ?Party dbpprop:position ?Position ;
  rdfs:label ?Lparty ;
  dbpedia-owl:country ?Country ;
  a dbpedia-owl:PoliticalParty.
  ?Party dbpprop:leader ?Leader.

  FILTER(?Position IN (dbpedia:Far-right_politics,dbpedia:Nazism, dbpedia:Nationalism)).
  FILTER(NOT EXISTS{?Party dbpprop:dissolved ?otherBalue}).
  FILTER(NOT EXISTS{?Party dbpprop:dissolution ?otherBalue}).
  FILTER(LANGMATCHES(LANG(?Lparty), "en")).
  ?Country dcterms:subject category:Member_states_of_the_European_Union;
       rdfs:label ?Lcountry.
  FILTER(LANGMATCHES(LANG(?Lcountry), "en")).

}