Status: | effective |
Progress: | 100% |
Version: | 2.4.0+ |
Inverse properties
Table of Contents | |
---|---|
Since Semantic MediaWiki 1.5.0Released on 7 March 2010 and compatible with MW 1.14.x - 1.17.x., it is possible to invert the direction of a property with datatype "Page"Holds names of wiki pages, and displays them as a link in semantic search (inline queries and concepts) and on browsing interfaces (special page "Ask"Provides an interface that assists users with creating and executing semantic queries and special page "Browse"Shows all properties and their values annotated to a page).
In order to achieve this, simply write "-
" in front of property name anywhere in Semantic MediaWiki to refer to the inverse direction of a property. Thus the property relates to the same pages but with annotated page and property value exchanged. For example, the inverse of "parent of" is "-parent of". This intuitively means "child of". Because of this a property with that name does not have to be created and annotated explicitly. However, note that "-father of" corresponds to "has male parent", not to "son of"!
Semantic MediaWiki does support naming of inverses, but it is not possible to assign a value to an inverse property (e.g. [[-Parent of::Michael]]
will not work). Semantic MediaWiki allows inverses to be used for retrieving data. This works in browsing interfaces, queries, and query output directives. In queries it works only for properties of datatype Page.
Starting with Semantic MediaWiki 2.4.0Released on 9 July 2016 and compatible with MW 1.19.0 - 1.27.x. it is moreover possible to use inverse properties in printout statements.1 The sandbox wiki provides an example demonstrating this.2
Examples[edit]
Inverse property in query condition[edit]
To convert inverse property syntax to English, you can read [[-Has mother::Michael]]
as get value of "has mother" from page "Michael".
For example, let's say the page "Michael" has the following wikitext:
Michael's mother is [[Has mother::Carol]].
Then on another page you could do:
{{#ask: [[-Has mother::Michael]] }}
Since get value of property "Has mother" from page "Michael" equates to "Carol", the output of this "#ask" inline query would be just:
Carol
Remember that the value for property "Has mother" must be a page name. Inverse properties do not work on properties of type number, date, etc. Moreover it only works within inline queries using the "#ask
" parser function. It does not work using the "#show
" parser function since it only takes pages as selection criterion.3
Inverse property in printout statement[edit]
Additionally, it is possible to printout inverse properties. For example, if you had a category for countries, and then had separate pages for cities, and those city pages had a property Has country
that pointed to their country, you could query for countries and list all the cities in that country by doing the following:
{{#ask: [[Category:Countries]] |?Has name=Country name |?-Has country=Cities in country }}
See also[edit]
- Help page on inferencing
References
- ^ | Semantic MediaWiki: GitHub pull request gh:smw:1270
- ^ | Semantic MediaWiki: Sandbox example sb:smw:1270
- ^ | Semantic MediaWiki: GitHub issue gh:smw:2548