Working With MediaWiki
example:
{{#show:Brazil |?Has capital |link=none}}
Linked properties andsubqueries
It’s usually a good idea to avoid data redundancy. For every museum, you could store both its city and country, but if every city page already has its country stored, then that’s unnecessary: you could just store the city, and query on the rest.
Let’s take a practical example: say your wiki museum only stores the city for each museum, with the property “Has city”; and the country for each city is then stored on pages for each city, with the property “Has country”. (We’ll ignore for now the problem of different cities with the same name in different countries, and assume that a museum tagged as being in, say, “Moscow” is always in the one in Russia, as opposed to in another city with the same name.) With such a structure, how can you find all the museums in a certain country? You could do it with a query like:
{{#ask:[[Category:Museums]][[Has city.Has country::Nepal]]}}
Here, “Has city” and “Has country” are what’s known as linked properties — the period between the names defines the linking. The query looks for pages that have the property “Has city” pointing to a page that in turn has the property “Has country” with the value “Nepal”.
You can even do more complex queries using subqueries, which are queries contained within a tag. Here’s one example:
{{#ask:[[Category:Museums]][[Has city::[[Has population::>100000]][[Has country::Argentina]]
]]}}
This query will find all museums in any city with 100,000 or more people in Argentina.
Unfortunately, both linked properties and subqueries work only on the “filter” part of the query, and not on the “display” part — so your query can’t contain a property printout like “? Has city.Has country”. That limitation is there for performance reasons, but it has definitely caused problems.
Display formats
Display formats, also known as result formats and query formats, are extremely important: they’re a way to set the display of the data returned by queries, if you want to show it in a way more interesting than just lists or tables. To set the display format, you just need to add the parameter “format=...” to the #ask query.
There’s a whole extension devoted to just holding various display formats, Semantic Result Formats, and another one, Semantic Maps, which holds formats related to mapping; both are described in Chapter 18 . But there are various basic formats that are defined within Semantic MediaWiki itself:
list - displays results as a simple list, separated by default by commas. This is the default display when only page names are queried.
ul - a bulleted list.
ol - a numbered list (“ul” and “ol” are both the names of the relevant HTML tags used — they stand for “unordered list” and “ordered list”, respectively).
table - a table of data. This is the default display when there are additional printouts in the query.
broadtable - a broadtable. This is identical to the “table” format, except that the width of the table is 100% of the page.
category - displays results in the format that pages appear in on category pages, with a separate header for each new starting letter.
template - applies a template to set the display of each query result; see below.
csv , dsv , json , rss , rdf - machine-readable data formats; these are discussed here .
count - simply displays the number of pages that match the query criteria.
embedded - displays each page that matches the query criteria, in full, one after the other. (This format unfortunately causes each of those pages’ categories to be applied to the page that holds the query.)
debug - displays a printout of the database queries used for this query; useful only for debugging.
Some of these formats have their own custom parameters that can be used, in addition to all the standard parameters. The “category” format, for instance, allows for a “columns=” parameter, which sets the number of columns into which to split results. The best way to see the entire set of parameters for each format is to go to the page Special:Ask on the wiki, which shows the name and a brief description for each one. Special:Ask is described in the upcoming section, “Semantic search page”.
Query templates
Using templates to display query results is a very versatile approach, which lets you apply custom formatting and text around the set of properties displayed
Weitere Kostenlose Bücher