- Introduction to Semantic MediaWiki
- Browsing and searching
- Semantic search
- Selecting pages
- Displaying information
- Result formats
- Inline queries
- Semantic Web
|Found errors or typos? Just edit the page or leave a message on the talk page.|
The English language documentation is canonical and most up to date.
Subqueries and property chains
Enumerating multiple pages for a property is cumbersome and hard to maintain. For instance, to select all actors that are born in an Italian city one could write:
[[Category:Actor]] [[born in::Rome||Milan||Turin||Florence||...]]
To generate a list of all these Italian cities one could run another query
[[Category:City]] [[located in::Italy]]
and copy and paste the results into the first query. What one would like to do is to use the city query as a subquery within the actor query to obtain the desired result directly. Instead of a fixed list of page names for the property's value, a new query enclosed in <q> and </q> is inserted within the property condition. In this example, one can thus write:
[[Category:Actor]] [[born in::<q>[[Category:City]] [[located in::Italy]]</q>]]
(limitation: you cannot add more than one category between <q> and </q>, except in the case of disjunctions)
Arbitrary levels of nesting are possible, though nesting might be restricted for a particular site to ensure performance. For another example, to select all cities of the European Union you could write:
[[Category:Cities]] [[located in::<q>[[member of::European Union]]</q>]]
In the above example, we essentially have constructed a chain of properties «located in» and «member of» to find things that are located in something which is a member of the EU. Queries can be written in a shorter form for this common case:
[[Category:Cities]] [[located in.member of::European Union]]
This query has the same meaning as above, but with much less special symbols required. In general, chains of properties are created by listing all properties separated by dots. In the rare case that a property should contain a dot in its name, one may start the query with a space to prevent SMW from interpreting this dot in a special way.
NOTE: It is not possible to use a subquery to obtain a list of properties that is then used in a query. See #Subqueries for properties below.