Help:Chains of relations and attributes
This page expands on Help:Semantic search.
Contents |
[edit] Chain of two relations
For a given A, a set of A's, or unrestricted A, and two given relations R1 and R2, we can find C for which there is a B such that C R1 B and B R2 A (a "distance" between A and C of 2 relations). There are two ways, but neither of them gives the triples (C,B,A), nothing more, nothing less. The first method selects B, but includes those without a C, and shows excess A's. The second method selects the correct C's, but does not show A, and shows excess B's. Which method is better varies: if just one A is given, it need not be displayed; with one-to-one relations there are no "siblings" displayed in excess; excess rows are cumbersome if there are many, but rather harmless if there are few, empty cells in one column show that these rows are not applicable.
The first method requires annotations for R1inv and R2. The query is <ask>R2::A[[R1inv::*]][[R2::*]]</ask>. This produces a table with B and C, and all A1 such that B R2 A1. This may include A's not in the specified set. The table may contain excess rows without a C.
Examples:
- All grandparents: <ask>parent of::+[[child of::*]][[parent of::*]]</ask> gives parents of parents; on the left the parents, on the right their parents (the grandparents), if any, and the children of the parents (those in set A but also siblings):
<ask format=table>parent of::+**</ask>
- Grandparents of Cain, Irad, and Ham:<ask>parent of::Cain||Irad||Ham[[child of::*]][[parent of::*]]</ask> includes rows for each of the parents of Cain, showing that he had no grandparents, and includes the siblings of Ham:
<ask format=table>parent of::Cain||Irad||Ham**</ask>
The second method (which can be extended to a chain of three relations, see below) requires annotations for R1 and R2. The query is <ask>R1::<q>R2::A</q></ask>. This produces a list with C only. It is not possible to produce B; a partial workaround is to display all B1 such that C R1 B1, these include B: <ask>R1::<q>R2::A</q>[[R1::*]]</ask>. If for A a set of pages is given, another limitation is that A cannot be displayed. There is not even a workaround like for B, unless there are annotations for the composite relation R1.R2.
Examples:
- <ask>parent of::<q>parent of::+</q>[[parent of::*]]</ask> gives all grandparents, with their children (parents, uncles and aunts):
<ask format=table>parent of::<q>parent of::+</q>*</ask>
- Grandparents of Cain, Irad, and Ham: <ask>parent of::<q>parent of::Cain||Irad||Ham</q>[[parent of::*]]</ask> gives all grandparents of the specified people, with their children (parents, uncles and aunts, without distinguishing these), but without indicating the grandchild:
<ask format=table>parent of::<q>parent of::Cain||Irad||Ham</q>*</ask>
<ask>has stop::Haarlem (railway station)||Amsterdam Centraal</q>[[has stop::*]]</ask> gives <ask>has stop::Haarlem (railway station)||Amsterdam Centraal</q>*</ask>
<ask>stop of::NS line 10 hlm||NS line 11[[stop of::*]]</ask> gives <ask>stop of::NS line 10 hlm||NS line 11*</ask>
[edit] Chain of two attributes
For a given V, a set of V's, or unrestricted V, and given attributes A1 and A2, we can find W for which there is a B such that B A1 V and B A2 W
The query is <ask>A1::V[[A1:=*]][[A2:=*]]</ask>.
This produces a table with B and W, and all V1 such that B A1 V1. This may include V's not in the specified set. The table may contain excess rows without a W.
[edit] Chain with a relation and an attribute
For a given V, a set of V's, or unrestricted V, a given relation R, and a given attribute A, we consider finding triples (C, B, V) such that C R B and B A V. There are two ways, but neither of them gives nothing more, nothing less. The first method selects B, but includes those without a C, and shows excess V's. The second method selects the correct C's, but does not show V, and shows excess B's. Which method is better varies: if just one V is given, it need not be displayed; with a one-to-one relation there are no "siblings" displayed in excess; excess rows are cumbersome if there are many, but rather harmless if there are few, empty cells in one column show that these rows are not applicable.
The first method requires annotations for A and the inverse of R. The query is <ask>A::V[[A:=*]][[Rinv::*]]</ask>.
This produces a table with B and C, and all V1 such that B A V1. This may include V's not in the specified set. The table may contain excess rows without a C.
Example: <ask>Nr. of screens:=>13[[Nr. of screens:=*]][[located in::*]]</ask> gives:
<ask>nr. of screens:=>13**</ask>
The second method requires annotations for R and A. The query is <ask>R::<q>A:=V</q></ask>. This produces a list with C only. It is not possible to produce B; a partial workaround is to display all B1 such that C R B1, these include B: <ask>R::<q>A:=V</q>[[R::*]]</ask>. If for V a set of pages is given, another limitation is that V cannot be displayed. There is not even a workaround like for B, unless there are annotations for the composite attribute R.A.
Examples:
- <ask>is location of::<q>nr. of screens:=+</q>[[is location of::*]]</ask> gives all cities with a cinema with 13 or more screens, with all cinemas (not only those with that many screens), but without showing the numbers of screens:
<ask>is location of::<q>nr. of screens:=>13</q>*</ask>
<ask>is location of::<q>nr. of screens:=+</q>[[is location of::*]]</ask> gives all cities with a cinema for which the number of screens is given, with all cinemas, but without showing the numbers of screens:
<ask>is location of::<q>nr. of screens:=+</q>*</ask>
[edit] Chain of three relations
For a given A and given relations R1, R2, and R3, we can find D for which there are C and B such that D R1 C and C R2 B and B R3 A (a "distance" between A and D of 3 relations, which is the maximum for a query). This requires annotations for R1inv, R2 and R3. The query is <ask>R2::<q>R3::A</q>[[R1inv::*]]</ask>. This produces a table with C and D. It is not possible to produce B; a partial workaround is to display all B1 such that C R2 B1, these include B: <ask>R2::<q>R3::A</q>[[R1inv::*]][[R2::*]]</ask>
Example:
- <ask>parent of::<q>parent of::+</q>[[child of::*]][[parent of::*]]</ask> gives parents of parents of parents; on the left the grandparents, on the right their parents (the grandgrandparents), if any, and the children of the grandparents (parents, uncles and aunts):
<ask format=table>parent of::<q>parent of::+</q>**</ask>
If for A a set of pages is given, another limitation is that A cannot be displayed. There is not even a workaround like above, unless there are annotations for the composite relation R2.R3.
This kind of query is typically used in conjunction with a query for C R2 B and B R3 A as explained above, to provide the lacking info.
Examples:
<ask>stop of::<q>has stop::Haarlem (railway station)||Amsterdam Centraal</q>[[stop of::*]]</ask> gives the stops with a direct connection with at least one of the given stops, but does not show which one; for each of the resulting stops shows all lines through that stop, but not which one connects to one of the given stops:
<ask>stop of::<q>has stop::Haarlem (railway station)||Amsterdam Centraal</q>*</ask>
<ask>has stop::<q>stop of::NS line 10||NS line 11</q>[[has stop::*]]</ask> gives the lines connecting to at least one of the given lines, but does not show which one; for each of the resulting lines shows all stops on that line, but not at which one the line connects to one of the given lines:
<ask>has stop::<q>stop of::NS line 10||NS line 11</q>*</ask>
[edit] Overview of queries based on a single relation
First method for a chain of 2, R1inv=R2=R:
For a given A, a set of A's, or unrestricted A, and a given relation R, we can find C for which there is a B such that B R A and A R C
The query is <ask>R::A[[R::*]]</ask>. This produces a table with B and C, and all A1 such that B R A1. This may include A's not in the specified set.
If, for a given A, a set of A's, or unrestricted A, we just want to know the pairs (B,A) such that B R A, the A's not in the specified set can either be seen as an extra, or as some unavoidable clutter.
Examples (we get the first, even if we only want the second):
- find the parents of A and for each, all their children / find for each A his/her parents
- find the lines with any of the given stops, and for each, all their stops / find for each stop all lines through that stop
- find the stops on any of the given lines, and for each, the crossing lines / find for each line all stops
<ask>[[has stop::Haarlem (railway station)||Amsterdam Centraal]][[has stop::*]]</ask> gives:
<ask>*</ask>
<ask>[[stop of::NS line 10 shl||NS line 11]][[stop of::*]]</ask> gives:
<ask>*</ask>
Second method for a chain of 2, R1=R2=R:
For a given A, a set of A's, or unrestricted A, we can find C for which there is a B such that C R B and B R A
The query is <ask>R::<q>R::A</q></ask>. This produces a list with C only. It is not possible to produce B; a partial workaround is to display all B1 such that C R B1, these include B: <ask>R::<q>R::A</q>[[R::*]]</ask>. If for A a set of pages is given, another limitation is that A cannot be displayed. There is not even a workaround like for B, unless there are annotations for the composite relation R.R.
Examples:
- Grandparents of Cain, Irad, and Ham: <ask>parent of::<q>parent of::Cain||Irad||Ham</q>[[parent of::*]]</ask> gives all grandparents of the specified people, with their children (parents, uncles and aunts, without distinguishing these), but without indicating the grandchild:
<ask format=table>parent of::<q>parent of::Cain||Irad||Ham</q>*</ask>
For the relations "has stop" and "stop of" this case is not applicable, because for both, a page cannot be both subject and object of the relation.
[edit]
Overview of info related to a given page P through relations and attributes, that can be obtained with queries:
- for all R apply query R P
- for all R1 and R2 apply query R1 R2 P
requesting for the selected pages as subject, all relations and attributes.
We can add page P itself to the selection, but in many cases this is not needed:
- if P is the current page, the info is already in the factbox;
- if there are R1, R2, and Q such that P R1 Q and Q R2 P, then P is already in the selection.
The results of these queries do not only provide much info, but also many links for quick navigation, where one takes up to three steps at a time.
Note however, that if e.g. only "parent of" is annotated and not "child of" the results take only 2 steps up and only one step down at a time in the ancestor tree.
[edit]
Overview of info related to a given attribute value V through relations and attributes, that can be obtained with queries:
- for all A apply query A V
- for all R and A apply query R A V
requesting for the selected pages as subject, all relations and attributes.
In view of the nature of V, it may be possible to dispense with some A's because for them having value V may be unlikely or irrelevant.
[edit] Chains with more links
While a query can reach pages at "a distance of 3", larger distances to a given page can be covered, of course, by making not the given page but related pages starting points of the queries. However, this gives a sequence of separate overviews with much duplication.
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