Forum:(SMW) Getting distinct values
From Fallen London Wiki (Staging)
(SMW) Getting distinct values[edit]
Is there any way to get a list of all distinct values a property has? For example, if there is
- page A setting the value to 1 ,
- pages B, C and D setting the value to 2 and
- pages E and F setting the value to 7,
I would like a list with the three values 1, 2 and 7. Ideally with the number of occurrences, but that is optional. - -- RagCall (talk) 13:54, 16 February 2022 (UTC)
- You can use the Arrays Extension (which we luckily already have), see smw:Help:List the set of unique values for a property! There's also Special:SearchByProperty if you just want a peek. CarrONoir (talk) 14:19, 16 February 2022 (UTC)
- The answer depends on the datatype of the property. Your example uses Numbers, which are difficult to de-duplicate, as is Text.
If the properties point to Pages, then de-duplicating is much easier. I think the only trick is to reverse the relationship. Example with "Located in".
-}} PSGarak (talk) 14:37, 16 February 2022 (UTC)
- If your property values never contain
|
, you can:- Call something like
{{#ask:[[Property::+]]|?Property|link=none|format=plainlist|sep={{!}}}}
(the query might be inaccurate) to get a list of property values, separated by the|
character - Pass this output to
{{#invoke:Pipes|call_unescaped|YourTemplate|<query>}}
to get{{YourTemplate|1|2|2|2|7|7}}
- In YourTemplate, use
#fornumargs
to collect statistics and format the output
- Call something like
- Yestarhumeler (talk) 15:10, 1 March 2022 (UTC)