[SPARQL][WIKIDATA] prefixies
SPARQL prefixes
How did I encounter this?
GTPS uses Wikidata as a source of game data, and it uses SPARQL. To use SPRAQL, I needed to understand its basic syntax. In SPARQL, there are 2 types of codes: one for property, starting with P and the other for contents starting with 'Q'.
For example, God of War Ragnarök, its own code is Q99397916. This code is directly included in its page's URL: https://www.wikidata.org/wiki/Q99397916. Within the page, there are different properties such as title, publication date and so on. Each property has their own property code. For example, publication date has a code of P577.
?item wdt:P577 ?publicationDateLabel.
Note: sometimes, a statement contains other statements. For example, publication date has multiple dates with different platforms.
List of prefixes
wd:
It refers to specific items or entities in Wikidata, such as a video game or platform. This is used to access a full statement node, which might contain multiple sub-statement
example:
?item wd:Q116255876 ?jedi
This retrieves the whole entity of the item with Q116255876 code into ?jedi
wdt:
It's to retrieve the simple and direct value from a statement (e.g., all publication dates) without qualifiers. It is used to access a specific property directly from a full statement node.
example:
?item wdt:P136 ?genres.
This retrieves the value of genres. Even though there are sub statement under genres, only the direct and simple value of genres is obtained.
p:
it's to retrieve the whole statement including the main values, qualifiers and references.
example:
?item p:P577 ?publicationDateNode.
This retrieves the whole statement of publication date. This is useful when there are sub-statements are present, and they need to be accessed.
ps:
it's to retrieve the main value of a property with the given code in a statement.
example:
?publicationDateNode ps:P577 ?publicationDateLabel.
Along with the example of p:, the actual value of publication date label is retrieved from its node.
pq:
it's to retrieve qualifiers for a property. Qualifiers are a property code that is included in a statement. Using this, it's allowed to access sub-statement.example:
?publicationDateNode pq:P291 ?placeOfDistribution.
Along with the example of p:, the sub-statement of distribution region statement under the statement of publication date.
rdfs:label
In Wikidata, the actual values are called label. This is because some values are also stored in the format of code. For example, PlayStation 5 itself is stored as Q63184502. If the value from the genres statement is retrieved by using ps: prefix, it would return the code, not the label. In this case, the value should be retrieved using rdfs:label.
example:
?platformCode rdfs:label ?platformLabel.
skos:altLabel
In Wikidata, some entities could have aliases. They can be retrieved via skos:altLabel.
example
SELECT DISTINCT ?alias
WHERE {
wd:Q123456 skos:altLabel ?alias.
FILTER(LANG(?alias) = "en").
}
Comments
Post a Comment