User:Patrick/selection
User space unless indicated otherwise:
annotation | ask | Help:Attribute name | Help:Browsing and searching | category | Help:Chains of relations and attributes | Help:Custom units | Help:Namespace | Help:Relation name | selection | Help:SearchTriple | sorting | Help:Templates in SMW | this page on sandbox.semantic-mediawiki.org | this page on Wikible
Contents |
[edit] Introduction
The ask function selects pages and presents info about them. Between the tags <ask> and </ask> a list of items is put, partly for selection, partly for specifying info to be displayed. The two types of items can be mixed. This page deals with the selection.
Parameters can be entered in the opening <ask> tag. There is one concerning the selection of pages:
- <ask limit=..>
specifies the maximum number of pages selected. It will be capped by 500 anyway.
Special:Ask with a sufficienly large limit shows the number n of selected pages in the phrase " Results 1 – n "
[edit] Intersection
The selection is the intersection of the sets defined by the selection items. To avoid ambiguity, of adjacent items at least one is put in double square brackets.
A selection item may involve a union of sets, but only in the cases specified below.
[edit] Namespace
If no namespace restriction such as [[Relation:+]] is specified (Relation:pagename does not count), results are restricted to the main namespace and namespace 6 (images). This is an exception of the intersection principle.
[edit] Direct conditions on pages
Two types of sets can be specified:
1. A specific page, e.g. <ask>Berlin</ask> gives <ask>Berlin</ask>
<ask debug=yes>Berlin</ask>
<ask>Talk:Berlin</ask> gives "<ask>Talk:Berlin</ask>", the page Talk:Berlin.
<ask debug=yes>Talk:Berlin</ask>
<ask>[[Talk:+]]Berlin</ask> gives "<ask>Talk:+Berlin</ask>". <ask debug>Talk:+Berlin</ask>
<ask>[[Talk:+]]Talk:Berlin</ask> gives "<ask>Talk:+Talk:Berlin</ask>" which is the page Talk:Berlin. <ask debug>Talk:+Talk:Berlin</ask>
Note that the namespace prefixes are not displayed, see the hover box or status bar of the browser, or follow the links.
The full name of a category page denotes the set of pages in the category, while with a colon in front it denotes the category page.
2. A namespace prefix with the colon, followed by "+" indicates the namespace, e.g.
<ask>:+</ask> gives <ask>:+</ask>
<ask debug=yes>:+</ask>
<ask>Help:+</ask> gives <ask>Help:+</ask>
<ask debug=yes>Help:+</ask>
- <ask limit=5>:Category:+</ask> (note the colon in front again) gives the category pages: <ask limit=5>:Category:+</ask>, i.e., the categories, including empty ones, but excluding those which have not been created as a page.
For any collection of these sets, we can take the union with "||". E.g.:
<ask>Berlin||Help:+</ask>
gives
<a sk>Berlin||Help:+</ask>
[edit] Pages in categories
<ask>[[:+||:Category:+]]Category:Country in European Union</ask>
gives all pages directly or indirectly (through a sub-, subsub-, etc. category) in Category:Country in European Union (including the subcategories themselves):
<a sk>|:Category:+Category:Country in European Union</ask>
<a sk debug=yes>|:Category:+Category:Country in European Union</ask>
<ask>Category:Country in European Union</ask>
gives the same without the subcategories themselves:
<ask>Category:Country in European Union</ask>
<ask debug=yes>Category:Country in European Union</ask>
<ask>[[:Category:+]]Category:Country in European Union</ask>
gives just the sub-, subsub-, etc. categories:
<ask>Category:+Category:Country in European Union</ask>
<ask>Category:Country in European Union||Continent</ask>
gives all pages directly or indirectly (through a sub-, subsub-, etc. category) in Category:Continent or Category:Country in European Union:
<a sk>Category:Continent||Country in European Union</ask>
A query cannot produce just the pages and subcategories which are directly in a category.
<ask>category:Country in European Union</ask>
(with lowercase c) gives nothing:
<ask>category:Country in European Union</ask>
[edit] Attempts to take invalid unions
<ask limit=5>Genesis||Category:Bible characters</ask>
takes the category page instead of the content of the category:
<a sk limit=5>Genesis||Category:Bible characters</ask>
<ask limit=5>Category:Bible characters||Help:BibleWiki</ask>
takes the union of the content of Category:Bible characters and Category:BibleWiki ignoring the help prefix:
<a sk limit=5>Category:Bible characters||Help:BibleWiki</ask>
<ask limit=5>Help:+||Category:Bible characters</ask>
takes the category page instead of the content of the category:
<a sk limit=5>Help:+||Category:Bible characters</ask>
<ask limit=5>Category:Bible characters||Help:+</ask>
seems to take just the content of Category:Bible characters:
<a sk limit=5>Category:Bible characters||Help:+</ask>
<ask limit=5>[[Ask]]||[[Help:+]]</ask> gives "<a sk limit=5>Ask||Help:+</ask>", i.e. not even the intersection <ask limit=5>AskHelp:+</ask>.
[edit] Conditions with relations
relation::set gives the set of pages with the given relation to any page in the given set ("+" for the set of all pages):
- <ask intro="See also the page about a parent:_">parent of::Tessa Schram </ask> gives "<ask intro="See also the page about a parent:_">parent of::Tessa Schram </ask>"
- <ask limit=5>parent of::+</ask> gives <ask limit=5>parent of::+</ask>.
- <ask>has capital::Amsterdam||Berlin</ask> gives <a sk>has capital::Amsterdam||Berlin</ask> (note that the order is not corresponding but alphabetic, so in a case like this a table form with two columns is better).
For other given sets the nested tags <q> and </q> are needed (restricted to one level):
- <ask limit=5>parent of::<q>Category:Bible characters</q></ask> gives <ask limit=5>parent of::<q>Category:Bible characters</q></ask>.
- <ask limit=5>parent of::<q>:+</q></ask> gives <ask limit=5>parent of::<q>:+</q></ask> (parents of people with existing pages).
Compare the last example with:
- <ask limit=5>parent of::<q>+</q></ask> gives <ask limit=5>parent of::<q>+</q></ask> (all parents, the same as without q-tags).
Within the q-tags we can use any set that does not require inner tags itself, e.g. one involving a relation again:
- <ask limit=5>parent of::<q>parent of::+</q></ask> gives <ask limit=5>parent of::<q>parent of::+</q></ask> (parents of parents).
- <ask mainlabel="locations of Pathé movie theaters" format=table>location of::<q>Category:Pathé movie theater]]</q>[[located in::*]][[location of::*]]</ask> gives <ask mainlabel="locations of Pathé movie theaters" format=table>location of::<q>Category:Pathé movie theater]]</q>**</ask>
<ask>location of::<q>location of::<q>location of::<q>location of::<q>location of::<q>location of::+</q></q></q></q></q></ask>
<ask>located in::<q>located in::<q>located in::<q>located in::Netherlands</q></q></q></ask>
[edit] Conditions with attributes
We can check for being defined (:=+), for equality (:=), also for multiple values, and for being less or equal (:=<) and greater or equal (:=>):
- <ask>start date:=+</ask> gives <ask>start date:=+</ask>
- <ask>start date:=2006-10-05</ask> gives <ask>start date:=2006-10-05</ask>
- <ask>start date:=2006-10-05||2006-12-04</ask> gives <a sk>start date:=2006-10-05||2006-12-04</ask>
- <ask>start date:=>2007-01-06</ask> gives <ask>start date:=>2007-01-06</ask>
- <ask>nr. of screens:=14</ask> gives <ask>nr. of screens:=14</ask>
- <ask>nr. of screens:=>13</ask> gives <ask>nr. of screens:=>13</ask>
When needed, automatic unit conversion is applied for the purpose of the test.
If a datatype has no natural linear ordering, inequalities are based on alphabetical order of the normalized datavalues as they are used in the RDF export.
In all cases the result is limited to pages for which the attribute value is defined. However, if the query contains an invalid comparison value, the result is like putting "+", i.e. it gives all these pages:
- <ask>nr. of screens:=a</ask> gives <ask>nr. of screens:=a</ask>
- <ask>start date:=>2007</ask> gives <ask>start date:=>2007</ask>
All categories | properties | types
Advice on Annotation | Ask | Attribute name | Browsing and searching | Category | Chains of relations and attributes | Custom units | Namespace | Relation name | Selection | SearchTriple | Sorting | Templates in SMW