SPARQL examples: Difference between revisions

(Created page with "== Items == === Entities with labels === {{SPARQL|query= SELECT DISTINCT ?entity ?entityLabel WHERE { ?entity rdfs:label ?entityLabel. FILTER((LANG(?entityLabel)) = "en") } }} === Properties with labels, aliases, descriptions and datatypes === {{SPARQL|query= SELECT DISTINCT ?propertyWikibase ?propertyLabel ?propertyAlias ?propertyDescription ?propertyType WHERE { ?propertyWikibase wikibase:directClaim ?p; wikibase:propertyType ?propertyType; schema:d...")
 
(fix query with properties)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Items ==
== Companies ==
 
=== Companies with labels, ISINs and WKNs ===
 
{{SPARQL|query=
SELECT DISTINCT ?company ?companyLabel ?ISIN ?WKN WHERE {
  ?company rdfs:label ?companyLabel;
    wdt:P325 wd:Q1.
  OPTIONAL { ?company wdt:P127 ?ISIN. }
  OPTIONAL { ?company wdt:P4 ?WKN. }
  FILTER((LANG(?companyLabel)) = "de")
}
}}
 
=== Companies with official names and time ranges for them ===
 
{{SPARQL|query=
SELECT DISTINCT ?company ?official_name (year(?start_time) as ?start_year) (year(?end_time) as ?end_year) WHERE {
  ?company wdt:P325 wd:Q1.
  ?company p:P346 [ ps:P346 ?official_name; pq:P79 ?start_time ; pq:P76 ?end_time ]
 
}
}}
 
=== Companies with labels, ISINs, WKNs, BvD IDs, Crefo numbers, LEIs, ROR IDs, GND IDs and Wikidata IDs ===
 
{{SPARQL|query=
SELECT DISTINCT ?company ?companyLabel ?ISIN ?WKN ?BvD_ID ?CREFO ?LEI ?ROR_ID ?GND_ID ?WikidataID WHERE {
  ?company rdfs:label ?companyLabel;
    wdt:P325 wd:Q1.
  #OPTIONAL { ?company wdt:P3 ?AKF_ID. }
  OPTIONAL { ?company wdt:P127 ?ISIN. }
  OPTIONAL { ?company wdt:P4 ?WKN. }
  OPTIONAL { ?company wdt:P6 ?BvD_ID. }
  OPTIONAL { ?company wdt:P5 ?CREFO. }
  OPTIONAL { ?company wdt:P146 ?LEI. }
  OPTIONAL { ?company wdt:P126 ?ROR_ID. }
  OPTIONAL { ?company wdt:P179 ?GND_ID. }
  OPTIONAL { ?company wdt:P2 ?WikidataID. }
  FILTER((LANG(?companyLabel)) = "de")
}
ORDER BY ?companyLabel
}}
 
== Entities ==


=== Entities with labels  ===
=== Entities with labels  ===
Line 9: Line 53:
}
}
}}
}}
== Properties ==


=== Properties with labels, aliases, descriptions and datatypes  ===
=== Properties with labels, aliases, descriptions and datatypes  ===
Line 18: Line 64:
     schema:description ?propertyDescription;
     schema:description ?propertyDescription;
     rdfs:label ?propertyLabel.
     rdfs:label ?propertyLabel.
  FILTER((LANG(?propertyLabel)) = "en")
  FILTER((LANG(?propertyDescription)) = "en")
   OPTIONAL { ?propertyWikibase skos:altLabel ?propertyAlias. }
   OPTIONAL { ?propertyWikibase skos:altLabel ?propertyAlias. }
  FILTER((LANG(?propertyAlias)) = "en")
}
}
}}
}}

Latest revision as of 13:34, 3 April 2023

Companies

Companies with labels, ISINs and WKNs

SELECT DISTINCT ?company ?companyLabel ?ISIN ?WKN WHERE {
  ?company rdfs:label ?companyLabel;
    wdt:P325 wd:Q1.
  OPTIONAL { ?company wdt:P127 ?ISIN. }
  OPTIONAL { ?company wdt:P4 ?WKN. }
  FILTER((LANG(?companyLabel)) = "de")
}

Companies with official names and time ranges for them

SELECT DISTINCT ?company ?official_name (year(?start_time) as ?start_year) (year(?end_time) as ?end_year) WHERE {
  ?company wdt:P325 wd:Q1.
  ?company p:P346 [ ps:P346 ?official_name; pq:P79 ?start_time ; pq:P76 ?end_time ]

}

Companies with labels, ISINs, WKNs, BvD IDs, Crefo numbers, LEIs, ROR IDs, GND IDs and Wikidata IDs

SELECT DISTINCT ?company ?companyLabel ?ISIN ?WKN ?BvD_ID ?CREFO ?LEI ?ROR_ID ?GND_ID ?WikidataID WHERE {
  ?company rdfs:label ?companyLabel;
    wdt:P325 wd:Q1.
  #OPTIONAL { ?company wdt:P3 ?AKF_ID. }
  OPTIONAL { ?company wdt:P127 ?ISIN. }
  OPTIONAL { ?company wdt:P4 ?WKN. }
  OPTIONAL { ?company wdt:P6 ?BvD_ID. }
  OPTIONAL { ?company wdt:P5 ?CREFO. }
  OPTIONAL { ?company wdt:P146 ?LEI. }
  OPTIONAL { ?company wdt:P126 ?ROR_ID. }
  OPTIONAL { ?company wdt:P179 ?GND_ID. }
  OPTIONAL { ?company wdt:P2 ?WikidataID. }
  FILTER((LANG(?companyLabel)) = "de")
} 
ORDER BY ?companyLabel

Entities

Entities with labels

SELECT DISTINCT ?entity ?entityLabel WHERE {
  ?entity rdfs:label ?entityLabel.
  FILTER((LANG(?entityLabel)) = "en")
}

Properties

Properties with labels, aliases, descriptions and datatypes

SELECT DISTINCT ?propertyWikibase ?propertyLabel ?propertyAlias ?propertyDescription ?propertyType WHERE {
  ?propertyWikibase wikibase:directClaim ?p;
    wikibase:propertyType ?propertyType;
    schema:description ?propertyDescription;
    rdfs:label ?propertyLabel.
  OPTIONAL { ?propertyWikibase skos:altLabel ?propertyAlias. }
}