User:Patrick/ask

From semanticweb.org

Jump to: navigation, search

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 existing pages and presents info about them: existing and non-existing pages and/or attribute values. 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. See Help:Selection for the selection. The queries do not have to be all in one line, but may be spread for readability and easier maintenance.

[edit] Display of just the selected pages

Without specifying what should be displayed or how, we get the results as on the page Help:Selection:

  • no results: nothing
  • 1 result: a linked page
  • 2 or more results: linked pages in the format ".., .., and .."; even with two results we get a comma.

The result can be used in-line, e.g.

Adam had the children <ask>[[child of::Adam]]</ask>.

gives:

Adam had the children .

[edit] Specifying items to be displayed

We can use:

  • [[relation::*]] to show for each selected page all pages to which the selected page has the specified relation; if the relation is a function with a r b written as b=f(a) this is the image of the set with respect to the function; in terms of links: the targets of the links of a specified kind, from a set of pages.
  • [[attribute:=*]] to show all values of the specified attribute for each selected page
  • [[attribute:=*unit]] to show all values of the specified attribute in the specified unit, for each selected page; multiple columns for the same attribute are not possible, not even if different units are specified
  • [[Category:*]] to show all categories that the selected page has directly been stated to be in.

In the case that the selection set is just a specific page, this is the most basic retrieval of info annotated on the same or another page.

Example of extracting info from the page itself:

[[a:=3]]pqr<ask headers=hide>{{PAGENAME}}[[help:+]][[a:=*]]</ask> gives 3pqrwarning.pngThe part "Patrick/ask" of the query was not understood. Results might not be as expected. . Compare the use of a template:a containing 3: {{a}}pqr{{a}} would give the same.

Other example:

Adam had the children <ask headers=hide>[[:+]]Adam[[father of::*]]</ask>.

gives:

Adam had the children warning.pngThe part "Adam" of the query was not understood. Results might not be as expected. .

or, making use of the relation name:

Adam was <ask>[[:+]]Adam[[father of::*]]</ask>.

giving

Adam was warning.pngThe part "Adam" of the query was not understood. Results might not be as expected. .

Similarly:

  • Seth was warning.pngThe part "Seth" of the query was not understood.

Results might not be as expected. .

  • Seth was warning.pngThe part "Seth" of the query was not understood.

Results might not be as expected. .

Note that in these lists we do not have "and" before the last item.

A maximum of 10 items can be displayed, excluding the selected page itself: warning.pngThe following query conditions could not be considered due to the wikis restrictions in query size or depth: [[*]], [[F::*]], [[G::*]], [[H::*]], [[I::*]], [[J::*]], [[K::*]], [[L::*]]. The part "Adam" of the query was not understood. Results might not be as expected.

warning.pngThe following query conditions could not be considered due to the wikis restrictions in query size or depth: [[E::*]], [[F::*]], [[G::*]], [[H::*]], [[I::*]], [[J::*]], [[K::*]], [[L::*]].

[edit] Inverse relations

If two relations are each other's inverse (see Relation:Inverse and [1]) and all existing pages have all applicable annotations then there are two methods to obtain almost the same; however, they differ (apart from the "and") in the way non-existence of pages (hence absence of tags) restricts the result: the method without "*" produces only existing pages, the method with "*" requires the given page to exist:

  • <ask>[[child of::Adam]]</ask> gives .
  • <ask headers=hide>Adam[[parent of::*]]</ask> gives warning.pngThe part "Adam" of the query was not understood.

Results might not be as expected. - this is very similar to what the factbox on the page Adam shows, apart from the order, but can be put anywhere in the page and on any other page

  • <ask>[[child of::Adah]]</ask> gives .
  • <ask headers=hide>Adah[[parent of::*]]</ask> gives warning.pngThe part "Adah" of the query was not understood.

Results might not be as expected. .

  • <ask>[[parent of::Jubal]]</ask> gives .
  • <ask headers=hide>Jabal[[child of::*]]</ask> gives warning.pngThe part "Jabal" of the query was not understood.

Results might not be as expected. .

The idea of putting all applicable annotations can be extended to creating a page just for the purpose of putting the applicable tag. However, some projects may have a policy against pages with only some tags.

When setting up annotations one may choose between (in this case) "parent of" and "child of", depending on requirements, or choose to annotate both in view of the additional query possibilities. The pairs of similar queries like above can be used for checking consistency.

Both methods allow extending to a list of given pages:

<ask mainlabel=child>[[child of::Cain||Seth]][[child of::*|parent]]</ask> gives

<ask mainlabel=parent>[[:+]]Cain||Seth[[parent of::*|child]]</ask> gives parentchild [[:|]], parentchild Faisal Alkhateeb, parentchild 'n Beetje Verliefd, parentchild ( 31) - 20 - 598 7731/7483, parentchild (+31) - 20 - 598 7678, parentchild (+44)(0)114 222 1891, parentchild (+44-161) 275-6176, parentchild (+45) 4674 3835, parentchild (302) 831-1959, parentchild (306) 585-5226, parentchild (310) 448-8472, parentchild (33)4 67 41 85 79, parentchild (33-1) 40 27 22 53, parentchild (351)911085353, parentchild (404) 3851139, parentchild (407) 380-1200, parentchild (412) 266-2492, parentchild (412) 268-5477, parentchild (509) 372-4946, parentchild (610) 758-6533, parentchild (617)440-4364, parentchild (65)6790-4802, parentchild (650) 723-6725, parentchild (650) 723-9770, parentchild (650) 859-6153, parentchild (805) 523-0193, parentchild (814) 865-6460, parentchild (animated), parentchild (testing 2), parentchild (testing), parentchild *, parentchild ++31 (0) 20 - 598 7753, parentchild ++49681/302-5358, parentchild +1 (215) 898-2665, parentchild +1 (650) 859-6058, parentchild +1 (703) 669 5510, parentchild +1 000 000 8080, parentchild +1 302.463.1354, parentchild +1 412 268 1357, parentchild +1 415 555 1212, parentchild +1 425 785 9995, parentchild +1 507-5388384, parentchild +1 613-321-2043, parentchild +1 617 258 6167, parentchild +1 951 710 1861, parentchild +1(973)386-6695, parentchild +1-410-455-2590, parentchild +1.410.455.3522, parentchild +12038094663, and parentchild +30 210 772 3040 … further resultswarning.pngThe part "Cain" of the query was not understood. Results might not be as expected. The part "Seth" of the query was not understood. Results might not be as expected.

[edit] Display format

  • If there are undefined items, then the table format is best to avoid excess commas and possibly excess headers.
  • Headers can be dispensed with if the nature of items is clear (unlike in this example where the distinction between e.g. children and husband is needed).
  • When enumerating the selected pages their names are not displayed unless mainlabel is specified.
  • Tables created by Semantic MediaWiki are connected by the delivered stylesheet to a Javascript program that allows the user to sort the displayed table by columns inside the browser.
  • An alternative header is obtained with [[relation::*|header]], or similar for an attribute.
  • Links produced by a query are not reported in "What links here".
  • When a page contains several queries (e.g. through a template) of which some are not applicable, sufficient separation when queries are applicable, and no clutter when they are not, is achieved with the formats table (header separates tables), ul (blank line separates lists) and ol (blank line and reset numbering shows a new list has started). With format=list we have either no separator between lists or a separator even between empty lists, and between an empty and a non-empty list. If we choose to have no separator between lists for this reason, at least we can distinguish where a new list starts by the absence of the separator between selected items (parameter sep, default ", "), provided that we can recognize the concatenation of two items as such (here Shem and Adah): . If we use the default sep we have the word "and" before the last item: . In that case we know which item is a concatenation of two items, and the link targets show the two parts. Deviation from the regular order (alphabetic or numeric) also indicates the start of a new list.
  • if a query result is just a list of attribute values (this can apply if pages are enumerated in the query) the same applies as before, except that these values are not linked, so the concatenation of two attribute values can not be separated by looking at link targets.

[edit] Parameters

You enter these in the opening <ask> tag.

  • limit -- max number of pages selected (in the case of a table: rows). It will be capped by 500 anyway.
  • sort -- see Help:Sorting
  • order -- "ascending" (equal to "asc", default) or "descending" (equal to "desc" or "reverse")
  • sep -- in a list, the highest-level separator (between the info about a selected page, and that about the next selected page); the default is ", ", except that for the last separator it is ", and "
  • format -- either list (separated by sep), ul (for unordered bullet list), ol (ordered and numbered list) or table
  • headers=hide (see below)
  • link=all, head, none; default:head -- none: resulting pages are not linked; all: all resulting pages (not resulting attribute values) are linked; non-existing pages have css class "new" as usual, but the link is to the empty page itself, not to the edit page.
  • default -- if, for any reason, no result is being created, this will be returned
  • debug=true -- gives SQL statement instead of the query results

[edit] Summary of display format

If the set of pages selected in a query is empty, no header row or blank line, not even any blank space, is produced. As a result, queries which are not applicable do not clutter the output.

If the set of pages selected in a query is non-empty, we get in format "table" a table header, and in the formats "ul" and "ol" a blank line. Between query results in format "list", there is no automatic separation at all; if we specify sep (see next paragraph) and separate queries with the same, the result looks like a single list, apart from the ordering, and provided that no query gives an empty result.

In format "list", parameter sep is the highest-level separator (between the info about a selected page, and that about the next selected page); the default is ", ", except that for the last separator it is ", and "; thus the whole list is of the form "B, C, and D" or "BsepCsepD".

The highest-level sub-item is a table row, or in the formats "ul", "ol", and "list" a list of medium-level sub-items. Either way, the selected page is displayed unless the selected pages are enumerated in the query. In the formats "ul", "ol", and "list", if the selected page is displayed, the rest of the info about it is put in parentheses after it; in these formats the bits of info on the displayed items (medium-level sub-items) are separated by commas; thus each of B, C and D are of the form "E (F, G, H)" or "F, G, H". The commas appear even if some of the items are empty strings.

The medium-level sub-items (in a table: the cells) start in the formats "ul", "ol", and "list" with the header, unless we put "headers=hide". The rest is a list of low-level subitems. separated by commas. Thus E is of the form L I or I, with L specified with "mainlabel=L" (default: empty string) and each of F, G and H are of the form "M J, K, N" or "J, K, N", with M the specified header (default: the relation or attribute name); this header is displayed even if the list is empty. With "headers=hide", any specified L and M are ignored.

[edit] Using the variable PAGENAME in queries

Referring to the page itself using the variable PAGENAME allows:

  • easily doing the same on another page by just copying the wikitext
  • renaming the page without having to edit the page
  • referring in a template to the page that includes the template

Possibilities in queries:

  • refer to the current page as subject of a given relation or attribute (the result is similar to the line concerned in the factbox, but it can be put at the desired position on the page; a difference is that the factbox sorts the objects alphabetically, and the values according to the type, while the factbox lists them in the order of the annotations):
    • {{PAGENAME}}[[:+]][[relation::*]]
    • {{PAGENAME}}[[:+]][[attribute:=*]]
  • refer to the current page as object of a given relation (see e.g. [2])
    • [[relation::{{PAGENAME}}]] - on page P, select all Q with Q R P; one can add [[relation::*]] to get, for each Q, all P1 with Q R P1 (we can do this for the same relation, then for each Q the list of P1's includes P, and/or for another relation). For example: find the other items located in the same area, find the other stops on the lines this stop is on, find the lines crossing this line.
  • refer to a given relation or attribute, on its page, in particular (see Template:ask):
    • {{PAGENAME}}::+
    • {{PAGENAME}}::*
    • {{PAGENAME}}:=+
    • {{PAGENAME}}:=*

[edit] Use of a query result

See also the examples on [3].

Relations:

  • Patrick/annotation Patrick/annotation Patrick/annotation - formatting works
  • de fgh de fgh - a query result can be part of a template parameter
  • {{de}} - a query result cannot be part of a template name
  • Expression error: Unrecognised punctuation character "" - a query result cannot be used in a numeric expression

Attributes:

  1. Expression error: Unrecognised punctuation character ""
  2. Expression error: Unrecognised punctuation character ""
  3. non-empty
  4. non-empty
  5. not equal 3
  6. not equal to itself

Conclusion: a query result cannot be used in a numeric expression, and apparently not usefully in any parser function.

  • 1st occurrence of attribute value (definition): pqrs 111
  • 2nd occurrence of attribute values: warning.pngThe part "Patrick/ask" of the query was not understood.

Results might not be as expected.

Compare with including the include part of the page: { { User:Patrick/ask|b }}, { { User:Patrick/ask|c }}; c/3=Expression error: Unrecognised punctuation character "{"/3}}.

Another example that a query result cannot be used in a computation:

<ask headers=hide>[[:+]]Rehoboam[[rule start:=*]]</ask> gives "warning.pngThe part "Rehoboam" of the query was not understood. Results might not be as expected. ".

{{#expr:2*<ask headers=hide>[[:+]]Rehoboam[[rule start:=*]]</ask>}}

gives:

Expression error: Unrecognised punctuation character ""

New: in the latest SMW version a displayed header (except a header, specified with parameter mainlabel, of the selected pages) is linked to the page of the applicable relation or attribute. (For relations and attributes involved in the selection but not among the displayed items there is no link.)

[edit] Examples

Table format with link=all, subject (or head), none, and default, and format=list with and without headers=hide:

link=all: warning.pngThe part ":+" of the query was not understood. Results might not be as expected.

link=subject: warning.pngThe part ":+" of the query was not understood. Results might not be as expected.

link=none: warning.pngThe part ":+" of the query was not understood. Results might not be as expected.

no parameters: warning.pngThe part ":+" of the query was not understood. Results might not be as expected.

format=list headers=hide link=all:

warning.pngThe part ":+" of the query was not understood. Results might not be as expected.

format=list link=all:

warning.pngThe part ":+" of the query was not understood. Results might not be as expected.

format=ol headers=hide link=all: warning.pngThe part ":+" of the query was not understood. Results might not be as expected.

format=ol link=all: warning.pngThe part ":+" of the query was not understood. Results might not be as expected.

link=all limit=1 warning.pngThe part ":+" of the query was not understood. Results might not be as expected.

The URL of the "further results" link is

http://ontoworld.org/index.php?title=Special:ask&query=%3A%2B%5B%5Bmass%3A%3D%2B%5D%5D+%5B%5Bmass%3A%3D%2A%5D%5D%5B%5Bhas+brand%3A%3A%2A%5D%5D&sort=&order=ASC

(see wikipedia:ASCII).

[edit] External links in query results

A URL in a query result is not rendered as link, e.g.:

  • <ask headers=hide>category:wikipedia[[homepage:=*]]</ask>, gives warning.pngThe part "category:wikipedia" of the query was not understood.

Results might not be as expected.

while using the template technique a working link is obtained. This can even be done without a separate template, with a kind of annotation on the page concerned, inside includeonly tags, with the rest of the page in noinclude tags:

[edit] Special:Ask

With Special:Ask a query can be submitted in a text box. Advantages over preview are:

  • no ask tags are needed
  • ascending/descending can be selected from a drop-down list
  • the sortkey property can be typed in a box without the need to type "sort=" and without quotation marks around a multi-word property
  • one can select a maximum number of results with one click instead of typing "limit=500", etc.



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


Personal tools