Query inverse relationships in Semantic MediaWiki
Asked Answered
D

2

6

In my semantic Scandalous Poets Wiki, I'd like to be able to query all pages with properties with a particular value, ideally grouped by property. For instance, given the value "Lord Byron" I'd like to receive a list like so:

Son of: Catherine Gordon, John "Mad Jack" Byron

Rumored lover of: Lady Caroline Lamb, Jane Elizabeth Scott "Lady Oxford", Augusta Leigh, Anne Isabella Milbanke, Nicolò Giraud, Augusta Leigh, Teresa Makri

Father of: Ada Lovelace, Clara Allegra Byron

Rumored father of: Elizabeth Medora Leigh

...and so on. I believe this functionality is demonstrated here: http://semantic-mediawiki.org/wiki/Special:Browse/California under the heading "hide properties that link here". It's also similar to http://semantic-mediawiki.org/w/index.php?title=Template:Invert-property – but this template will only return values for one known property name at a time.

According to http://semantic-mediawiki.org/wiki/Germany MediaWiki does not internally support inverse relationships, though the Special:Browse page seems to be managing; are there any extensions or other techniques which can do this?

Distributive answered 14/6, 2012 at 1:21 Comment(0)
S
4

You can query the inverse of a property by simply putting a "-" in front of the property in your query. For example:

{{#ask: [[Category:Poet]] 
| ?-hasSon=son of
}}

See http://semantic-mediawiki.org/wiki/Help:Inverse_properties

Survive answered 14/6, 2012 at 20:50 Comment(3)
Nice! That's really close to what I'm looking for – do you know whether it can do an inverse query for a property if it doesn't know what it's called?Distributive
I don't think that's possible in SMW, or at least I know of no way to do that using inline queries. AFAIK you can't print out a property value if you don't know the name of the property.Survive
Then assuming the answer to my OQ is "no", for now you get the green checkmark. Thanks!Distributive
A
0

This is how I address the collection of links to a particular page. The issue I had to deal with here was the fact that relations might be established on both the current page as well as on other pages. You might find this useful. Also, you might want to replace 'has supernode' with 'sun of' and 'has subnode' with 'father of'. I am also using Arrays extension of mediawiki to be able to merge duplicate values.

== Links ==
=== Super-Nodes ===
{{#arraydefine:key_1
|{{#ask:[[{{PAGENAME}}]]
|?has supernode
|mainlabel=-
|headers=hide
|format=array
|}}
}}
{{#arraydefine:key_2
|{{#ask:[[has subnode::{{PAGENAME}}]]
|format=array
|}}
}}
{{#arrayunion:key_mrg |key_1 |key_2 }}
{{#arraysort:key_mrg|nat}}
{{#arrayprint:key_mrg}}

=== Sub-Nodes ===
{{#arraydefine:key_1
|{{#ask:[[{{PAGENAME}}]]
|?has subnode
|mainlabel=-
|headers=hide
|format=array
|}}
}}
{{#arraydefine:key_2
|{{#ask:[[has supernode::{{PAGENAME}}]]
|format=array
|}}
}}
{{#arrayunion:key_mrg |key_1 |key_2 }}
{{#arraysort:key_mrg|nat}}
{{#arrayprint:key_mrg}}
Aerobiology answered 28/12, 2020 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.