Robert Murphy wrote:
Dear Developers,

I run a wiki with a vast amount of N-ary data.  I have yet to hear
from anyone who has successfully figured out how to query N-ary data.
Some of you may have seen my many question on the User Mailing List,
but no has ever said anything other than "I hear someone somewhere at
sometime solved that with templates."  I have not been able to solve
it with templates and no semantic mediawiki I've found has either.
I'm afraid no one has seriously considered the possibility that N-ary
data is inaccessible from with Mediawiki.

Basically, if you do pass a query to templates, and one of the
parameters is N-ary, then a comma separated list of all fields is
passed and there seems to be no way to handle that data from within a
template, even if there's only one instances of the n-ary value.  If I
were just within Perl of PHP, splitting on regex's the passed N-ary
data would be a piece of cake.  However, such programming language
features as "split" and arrays are not possible within a template.  I
think this problem warrants serious developer attention.

I've been thinking about this, and I think that both N-aries and queries need some refinement, and soon. 

On the N-ary front, I'd recommend introducing field names so that individual fields can be referenced.  The simplest way to do this would be to allow "name=value" pairs anywhere that an N-ary currently permits a value.  (Note: "allow"; not "require".  This allows for full backward compatibility.)  One application of the "field name" concept would be the ability to use something like '[[Property::field=+]]' in a query to find only those pages where Property has 'field' as a field; or '?Property::field' to include the value of Property's field in the output. 

On the querying front, I think we need something akin to SQL's 'FROM' clause.  Right now, it's assumed that the query is always looking for pages that match the given criteria; the new feature would allow you to specify that you're looking for every instance of a given property where the criteria are satisfied.  This would be ideally suited for N-ary properties, but might be useful elsewhere. 

Here's what I envision:

on Page [[N-ary]]:
  [[Contributer::Robert Murphy,]]

on Page [[Property:Contributor]]:
  [[type of::text, email=text]]

on some other page:
  {{ask: [[Contributer::email=+]] | ?Contributer::email }}

this would produce something like:
  | [[N-ary]] ||

I'd like to implement this myself; but I'm having some difficulty puzzling out how the code for the N-ary type works.  Any advice would be appreciated. 

Jonathan "Dataweaver" Lang