Dror S.
Dror S.

Reputation: 1110

Querying by properties in Semantic MediaWiki

I have the following entities, that create a hierarchy:

  1. Town (Properties: name, in sub district)
  2. Sub-district (Properties: Name, in district)
  3. District

So: many towns in a sub-district, many sub-districts in a district.

Constraint: I wish to create these as subobjects/records or something similar, as there's no point (nor will it be acceptable) in creating a page for each town (there are about 1,400 of those). "Districts" can be actual pages, as there are only 6 of those, but probably will be in a different namespace ("Data:").

Then we have another entity, let's call it "Service", which has a "In town::" property. This is actually a multi-value property.

Because I tried using subobjects, "In town::" corresponds to Town.name, not to Town (as Town will be a subobject, say "Towns#HaHotrim").

What I wish to be able to do is retrieve all services that are in a certain district; I have not been able to do so at all.

My Town subobjects all reside on one page ("Towns") and look like this:

{{#subobject:HaHotrim
 | Name = HaHotrim
 | is in sub district: Hadera
 |@category=Towns
}}

Then I have my sub-districts on another page ("Sub districts") that looks like this:

{{#subobject:Hadera
 | name = Hadera
 | is in district = Haifa
 |@category=sub districts
}}

But I still have no idea how to do a query for all Services in a certain district (or even a sub-district). What am I missing?



Notes

I thought it might help if I created the list of towns as a property directly inside the sub-district / district, by adding a property like this to the subobject: | towns in sub district: {{#ASK:[[is in sub district::Hadera]] |?name | mainlabel=- | link = none | format=list | headers=hide}}|+sep=,

Upvotes: 1

Views: 187

Answers (1)

Alexander Mashin
Alexander Mashin

Reputation: 4554

To find all services in a sub-district, assuming the query is in a template with a {{{sub-district}}} parametre, using only SMW, try:

{{#ask:
    [[In town::{{#ask:
        [[is in sub district::{{{sub-district|none}}}]]
        | ?Name#-
        | mainlabel = -
        | headers = hide
        | format = list
        | sep = {{!}}
        | limit = 100
        | searchlabel =
    }}]]
    | ?Service name
    | format = ul
}}

The inner query will create a list of names for the towns in {{{sub-district}}}, separated with |, which will be a condition for the outer query.

P.S.

{{#subobject:HaHotrim
 | Name = HaHotrim
 | is in sub district: Hadera
 |@category=Towns
}}

contains a typo: is in sub district: Hadera should be is in sub district = Hadera.

Upvotes: 0

Related Questions