# Creating a Wikibase
The participants of this project, in random order, are:
* Sadik
* Marija
* Egon Willighagen ([0000-0001-7542-0286](https://orcid.org/0000-0001-7542-0286))
The goal of this Open Science Retreat 2024 project was explore what needs to be
done to set up a custom Wikibase. We chose the topic research waste. Research waste is... The Wikibase can be found at https://research-waste.wikibase.cloud/
The following sections explain how to set up and populated content of the Wikibase.
## Setting up Template|Q and Template|P
Templates are Wikimedia (the software behind Wikipedia, Wikidata, and Wikibar) concepts to be able to reuse page content. It is used, for example, for the Wikipedia info boxes. Wikidata uses templates also to link to items (with a Q identifiers) and properties (with a P identifiers), making them show up on a traditional page as a link to the Q or P page including the label.
That is, when on such a page you add the wikisource `{{Q|1}}`, it will tell the Wikimedia processor to translate this to the text `Article (Q1)` (for the new Wikibase), linked to https://research-waste.wikibase.cloud/wiki/Item:Q1.
### How to set this up
To set this up in a a fresh Wikibase, the following templates need to be created.
#### Template:Label
The page https://research-waste.wikibase.cloud/wiki/Template:Label should have this content:
```
{{#if:{{{item|{{{1|}}} }}}|
{{#invoke:Wikidata label|getLabel
|item={{{item|{{{1|}}} }}}
|lang={{{lang|{{{2|}}} }}}
|link={{{link|-}}}
|capitalization={{{capitalization|none}}}
|show_id={{{show_id|}}}
}}
}}<noinclude>
{{documentation}}</noinclude>
```
#### Module:Wikidata_label
The page https://research-waste.wikibase.cloud/wiki/Module:Wikidata_label should be copied from https://www.wikidata.org/w/index.php?title=Module:Wikidata_label&action=edit .
#### Template:P
The page https://research-waste.wikibase.cloud/wiki/Template:P should have this content:
```
<noinclude>{{documentation}}</noinclude><includeonly>{{#ifeq: {{str left|{{{1|}}}|1}} | P
| {{#if:{{{anchor|}}}|{{anchor|Property:{{{1|}}}}}}}[[Property:{{{1|}}}|{{label|{{{1|}}}}}{{#ifeq:{{{show_p|}}}|no|| <small dir="ltr">{{int:parentheses|{{{1|}}}}}</small>}}]]
| {{#if:{{{anchor|}}}|{{anchor|Property:P{{{1|}}}}}}}[[Property:P{{{1|}}}|{{label|P{{{1|}}}}}{{#ifeq:{{{show_p|}}}|no|| <small dir="ltr">{{int:parentheses|P{{{1|}}}}}</small>}}]]
}}</includeonly>
```
#### Template:Q
The page https://research-waste.wikibase.cloud/wiki/Template:Q should have this content:
```
{{label|{{{1|}}}|capitalization={{{capitalization|}}} |show_id=1 |link=wikidata}}<noinclude>{{documentation}}</noinclude>
```
## exact match
The `exact match` property has been used in Wikidata to show that some item or property (semantically) exactly matches an item in a different knowledge graph or database. This is useful to express the interoperability between two databases.
The mapping between Wikibase and Wikidata properties enables the interoperability need to automatically translate SPARQL queries, copy data from Wikidata into the Wikibase, etc.
We set up [P17]() in our new Wikibase and use this, for example, to show the equivalence between our [P5]() for ORCID identifers and the Wikidata [P496](http://wikidata.org/entity/P496).
## Setting up Synia
Synia is a system developed by Finn Nielsen using a combination of a simple HTML
website and a set of SPARQL queries embedded in the Wikibase
(https://arxiv.org/abs/2303.15133). For the Research Waste Wikidata we have
set up a Synia page, with the web interface source code at https://github.com/egonw/synia4sadik summarize the content of the Wikibase:
SCREENSHOT
The Research Waste Synia website is configured with the content in the Wikibase.
This content is organized on
https://research-waste.wikibase.cloud/wiki/ResearchWaste:Synia and its subpages,
such as https://research-waste.wikibase.cloud/wiki/ResearchWaste:Synia:article
Each page lists content that is displayed for this type of aspect. For example,
the [ResearchWaste:Synia:article](https://research-waste.wikibase.cloud/wiki/ResearchWaste:Synia:article)
page defines the content of https://egonw.github.io/synia4sadik/#article/Q8
Here, Synia uses the `#article/Q8` to decide which SPARQL to use, and injects
the `Q8` into the SPARQL query, where it uses the `target` prefix as queue.
This is what the content of such a Synia Wikibase configuration page can
look likt. Below is an example content for the `article` page listing
the waste defined by this article. The section header is wrapped in the
`==` tags and the SPARQL is using the `{{SPARQL}}` template, with the
`query` parameter. The SPARQL is actually a template, even if it does
have an example Wikibase entity listed for the `target` prefix. The
`Q8` in this could gets replaced by Synia on the fly:
```
== Waste ==
{{SPARQL | query =
PREFIX target: <https://research-waste.wikibase.cloud/entity/Q8>
PREFIX p: <https://research-waste.wikibase.cloud/prop/>
PREFIX pq: <https://research-waste.wikibase.cloud/prop/qualifier/>
PREFIX ps: <https://research-waste.wikibase.cloud/prop/statement/value/>
PREFIX wd: <https://research-waste.wikibase.cloud/entity/>
PREFIX wdt: <https://research-waste.wikibase.cloud/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT DISTINCT ?property ?propertyLabel (CONCAT("#waste/", SUBSTR(STR(?property), 46)) AS ?propertyUrl)
?value ?units ?unitsLabel ?lossType ?lossTypeLabel
WHERE {
VALUES ?p { p:P32 p:P33 p:P35 }
BIND(target: as ?article)
target: ?propp ?statement .
?statement a wikibase:BestRank ;
?proppsv [
wikibase:quantityAmount ?value ;
wikibase:quantityUnit ?units
] .
OPTIONAL { ?statement pq:P34 ?lossType }
?property wikibase:claim ?propp ;
wikibase:statementValue ?proppsv .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
}}
```