Semantic mediawiki capture all values of a property in the current page

1k views Asked by At

I'd like to summarize data entered using a template which can occur multiple times per page. I want this summary to be based only on the current page.

I can't seem to figure out how to capture all the values assigned to a property set by the multiple times per page template though. All of the semantic queries I have tried only return the unique values for the property on a given page.

For example if my template has three fields and properties:

</noinclude><includeonly>
'''GeneralFoodF:'''  [[GeneralFoodP::{{{GeneralFoodF|}}}]] 

'''SpecificFoodF:'''  [[SpecificFoodP::{{{SpecificFoodF|}}}]] 

'''RatingFoodF:'''  [[RatingFoodP::{{{RatingFoodF|}}}]] 
</includeonly>

and I add four occurrences of this template to a particular page with these values:

   {{FoodT
   |GeneralFoodF=Fruit
   |SpecificFoodF=Apple
   |RatingFoodF=4
   }}
   {{FoodT
   |GeneralFoodF=Vegetable
   |SpecificFoodF=Spinach
   |RatingFoodF=5
   }}
   {{FoodT
   |GeneralFoodF=Fruit
   |SpecificFoodF=Pear
   |RatingFoodF=5
   }}
   {{FoodT
   |GeneralFoodF=Fruit
   |SpecificFoodF=Apple
   |RatingFoodF=3
   }}

Then I perform a #show query:

{{#show: {{PAGENAME}} | mainlabel =- | headers = hide | link=none | ?GeneralFoodP}}

It returns: Fruit, Vegetable when I expected it to return: Fruit, Vegetable, Fruit, Fruit. The wiki page text is correct and shows all four entries but I can't seem to capture duplicate entries with a semantic query. How can I capture all (including duplicates) of the property values as entered on a given page?

1

There are 1 answers

0
leo On

Think about what a property means: If a car has the property is red, it doesn't get more red if your state it twice. The color is still red, not “red red”. Hence, the result you show us is perfectly expected.

For your need, you might want to consider using subobjects. They are objects, just like pages, but without their own page, and they can have one or more properties:

{{#subobject:
 |GeneralFoodF=Fruit
 |SpecificFoodF=Apple
 |RatingFoodF=3
 |Belongs to={{PAGENAME}}
}}

You can then query for all the subobjects of that page like this:

{{#ask: [[Belongs to::{{PAGENAME}}]]
 |?GeneralFoodF
 |?SpecificFoodF
 |?RatingFoodF
}}

or for similar subobjects on all pages:

{{#ask: [[SpecificFoodF::+]]
 |?GeneralFoodF
 |?SpecificFoodF
 |?RatingFoodF
}}

Subobjects can also be named, but in your case you want them anonymous (effectively giving them all unique, automatically created names).

See: