Difference between revisions of "Template:ListEdgesWIP"

From AtlasWiki
Jump to: navigation, search
(remove XCSG templates category from the WIP version)
(Preliminary version, handles only "permitted" in edges (both inherited and directly specified))
Line 2: Line 2:
  
 
If the parameter "parents" is given a comma-separated list of the parents of the node, inherited edges will also be listed.
 
If the parameter "parents" is given a comma-separated list of the parents of the node, inherited edges will also be listed.
</noinclude>{{#ask: [[edge to {{PAGENAME}}::+]]
+
</noinclude>{{#ask: [[permitted edge to {{PAGENAME}}::+]]
| ?edge to {{PAGENAME}}
+
| ?permitted edge to {{PAGENAME}}
 
| format=array
 
| format=array
 
| headers=hide
 
| headers=hide
| name=inEdges
+
| name=permittedInEdges
 +
}}{{#ask: [[spedified edge to {{PAGENAME}}::+]]
 +
| ?specified edge to {{PAGENAME}}
 +
| format=array
 +
| headers=hide
 +
| name=specifiedInEdges
 
}}<noinclude><!--
 
}}<noinclude><!--
  
Above, we've stored all the in edges in an array named "inEdges".
+
Above, we've stored all the in edges in an arrays named "permittedInEdges" and "specifiedInEdges".
  
Each entry in the array is in this format:
+
Each entry in each array is in this format:
  
 
[name of edge]<PROP>[name of predecessor]$SEP$[multiplicity]$SEP$[edge description]
 
[name of edge]<PROP>[name of predecessor]$SEP$[multiplicity]$SEP$[edge description]
Line 21: Line 26:
 
[name of edge]<PROP>[name of predecessor]$SEP$[multiplicity]$SEP$[edge description]<MANY>[name of other predecessor]$SEP$[multiplicity]
 
[name of edge]<PROP>[name of predecessor]$SEP$[multiplicity]$SEP$[edge description]<MANY>[name of other predecessor]$SEP$[multiplicity]
  
...now we parse those into an "In Edge" table, if and only if there is at least one in edge:
+
...now we want similar information about inherited in edges:
  
--></noinclude>{{#switch:{{#arraysize:inEdges}}| 0 = | #default =
+
--></noinclude>{{#arraydefine:parentsArray|{{{parents|}}}|,|}}<noinclude>
 +
 +
</noinclude>{{#arraydefine:inheritedPermittedInEdges|{{#arrayprint:parentsArray|<PARENT_SEP>|@@@@|{{#if:{{EdgesTo|@@@@|permitted}}|@@@@<PARENT>{{EdgesTo|@@@@|permitted}}}} }}|<PARENT_SEP>|}}<noinclude>
 +
 +
</noinclude>{{#arraydefine:inheritedSpecifiedInEdges|{{#arrayprint:parentsArray|<PARENT_SEP>|@@@@|{{#if:{{EdgesTo|@@@@|specified}}|@@@@<PARENT>{{EdgesTo|@@@@|specified}}}} }}|<PARENT_SEP>|}}<noinclude><!--
 +
 +
We now have all the information about inherited edges in arrays as well, in the format specified by Template:EdgesTo, with the addition of the parent node name tacked on to the front, followed by <PARENT>.
 +
 +
So we can now decide whether the tables should exist, and whether they should have the extra cell at left for listing parent nodes that edges were inherited from.
 +
 +
First, we check whether there are edges in the category at all:
 +
 +
{{#switch:{{#expr:{{#arraysize:permittedInEdges}}+{{#arraysize:inheritedPermittedInEdges}}}}| 0 = | #default =
 +
 
 +
... if there are, we start the table
 +
 +
{{{!}} class="xcsgtable"
 +
 +
... we decide on the width based on whether we'll need a column for our parents
 +
 +
! colspan="{{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = 4 | #default = 5 }}" {{!}} Known Possible In Edges
 +
 +
... printing the headers, we add an empty cell if needed, whose height is based on the number of non-inherited edges + 1 (since it needs to cover the header as well).
 +
 +
! {{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = | #default = rowspan="{{#expr:1+{{#arrayprint:permittedInEdges|+|####|{{#arraydefine:findSize|####|<MANY>}}{{#arraysize:findSize}}}}}}" {{!}} !!}} In Edge !! <abbr title="comes from">Predecessor</abbr> !! Multiplicity !! Description
 +
 
 +
That's a bit involved, so let's just look at the calculation:
 +
 +
{{#expr:1+{{#arrayprint:permittedInEdges|+|####|{{#arraydefine:findSize|####|<MANY>}}{{#arraysize:findSize}}}}}}
 +
 +
...to calculate the height, we use an expression. The expression calculates the size via #arrayprint with + as the delimiter, with each printed element being the number of origins for a particular edge kind, counted using arraysize: with a temporary array.
 +
 +
Hopefully that's enough to go on to figure out what's going on, I'm not going to take the time to break the whole thing down.
 +
 +
One other technique worth noting: there are lot of cases where we have to treat the first row of something differently than we treat the later rows, because e.g. we want the name of an edge to span several rows, meaning we must print the row with the name of the edge separately from the rows listing other possible origins/destinations. For this we use arraysplit: to give us a version with the first row removed, so we can treat the rest of the rows identically via arrayprint:.
 +
 +
--></noinclude>{{#switch:{{#expr:{{#arraysize:permittedInEdges}}+{{#arraysize:inheritedPermittedInEdges}}}}| 0 = | #default =  
 
{{{!}} class="xcsgtable"
 
{{{!}} class="xcsgtable"
! In Edge !! Predecessor (Comes From) !! Multiplicity !! Description
 
 
{{!}}-
 
{{!}}-
{{!}}{{#arrayprint:inEdges|&#32;
+
! colspan="{{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = 4 | #default = 5 }}" {{!}} Known Possible In Edges
 +
{{#switch:{{#arraysize:permittedInEdges}}| 0 = | #default = {{!}}-
 +
! {{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = | #default = rowspan="{{#expr:1+{{#arrayprint:permittedInEdges|+|####|{{#arraydefine:findSize|####|<MANY>}}{{#arraysize:findSize}}}}}}" {{!}} !!}} In Edge !! <abbr title="comes from">Predecessor</abbr> !! Multiplicity !! Description
 
{{!}}-
 
{{!}}-
{{!}}|var|{{#arraydefine:edgeRelationships|var|<PROP>|}}{{#arraydefine:relationships|{{#arrayindex:edgeRelationships|1}}|<MANY>|}}{{#arrayprint:relationships|&#32;
+
{{!}}{{#arrayprint:permittedInEdges|&#32;
 
{{!}}-
 
{{!}}-
{{!}}|@@@@|[[{{#arrayindex:edgeRelationships|0}}]] {{!}}{{!}} [[{{#explode:@@@@|$SEP$|0}}]] {{!}}{{!}} {{#explode:@@@@|$SEP$|1}} {{!}}{{!}} {{ReconstructLinks|{{#explode:@@@@|$SEP$|2}}}} }} }}
+
{{!}}|var|{{#arraydefine:edgeRelationships|var|<PROP>|}}{{#arraydefine:relationships|{{#arrayindex:edgeRelationships|1}}|<MANY>|}} rowspan="{{#arraysize:relationships}}" {{!}} [[{{#arrayindex:edgeRelationships|0}}]] {{!}}{{!}} [[{{#explode:{{#arrayindex:relationships|0}}|$SEP$|0}}]] {{!}}{{!}} {{#explode:{{#arrayindex:relationships|0}}|$SEP$|1}} {{!}}{{!}} rowspan="{{#arraysize:relationships}}" {{!}} {{ReconstructLinks|{{#explode:{{#arrayindex:relationships|0}}|$SEP$|2}}}} {{#arrayslice:relationships|relationships|1}} {{#arrayprint:relationships||@@@@|&#32;
{{!}}}  
+
{{!}}-
}}<noinclude><!--
+
{{!}} [[{{#explode:@@@@|$SEP$|0}}]] {{!}}{{!}} {{#explode:@@@@|$SEP$|1}} }} }} }}
 
+
{{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = | #default =
If we were given inheritance information, discover and list the inherited edges as well...if there are any inherited edges.
+
{{!}}-
 
+
! Inherited From !! In Edge  !! <abbr title="comes from">Predecessor</abbr> !! Multiplicity !! Description
--></noinclude>{{#if:{{{parents|}}}|{{#arraydefine:parents|{{{parents}}}|,|}}{{#if:{{#arrayprint:parents||@@@@|{{InheritEdgesTo|@@@@}}}}|
+
{{!}}-
{{{!}} class="xcsgtable"
+
{{!}}{{#arrayprint:inheritedPermittedInEdges|&#32;
 +
{{!}}-
 +
{{!}} |@@@@| {{#arraydefine:edges|{{#explode:@@@@|<PARENT>|1}}|<EDGE_SEP>|}} rowspan="{{#expr:{{#arrayprint:edges|+|####|{{#arraydefine:findSize|####|<MANY>}}{{#arraysize:findSize}}}}}}" {{!}} {{#explode:@@@@|<PARENT>|0}} {{!}}{{!}} {{#arraydefine:firstEdge|{{#arrayindex:edges|0}}|<EDGE_PROP>}} {{#arraydefine:firstOrigins|{{#arrayindex:firstEdge|2}}|<MANY>}} rowspan="{{#arraysize:firstOrigins}}" {{!}} {{#arrayindex:firstEdge|0}} {{!}}{{!}} {{#explode:{{#arrayindex:firstOrigins|0}}|<VAL>|0}} {{!}}{{!}} {{#explode:{{#arrayindex:firstOrigins|0}}|<VAL>|1}} {{!}}{{!}} rowspan="{{#arraysize:firstOrigins}}" {{!}} {{#arrayindex:firstEdge|1}} {{#arrayslice:restOfFirstOrigins|firstOrigins|1}} {{#arrayprint:restOfFirstOrigins||$$$$|&#32;
 
{{!}}-
 
{{!}}-
! colspan="5" {{!}} Inherited In Edges
+
{{!}} {{#explode:$$$$|<VAL>|0}} {{!}}{{!}} {{#explode:$$$$|<VAL>|1}} }} {{#arrayslice:restOfEdges|edges|1}}
 +
{{#arrayprint:restOfEdges||####|&#32;
 
{{!}}-
 
{{!}}-
! Inherited From !! In Edge  !! Predecessor (Comes From) !! Multiplicity !! Description
+
{{!}}{{#arraydefine:edge|####|<EDGE_PROP>}} {{#arraydefine:origins|{{#arrayindex:edge|2}}|<MANY>}} rowspan="{{#arraysize:origins}}" {{!}} {{#arrayIndex:edge|0}} {{!}}{{!}} {{#explode:{{#arrayindex:origins|0}}|<VAL>|0}} {{!}}{{!}} {{#explode:{{#arrayindex:origins|0}}|<VAL>|1}} {{!}}{{!}} rowspan="{{#arraysize:origins}}" {{!}} {{#arrayIndex:edge|1}}
{{#arrayprint:parents||@@@@|&#32;
+
{{#arrayslice:restOfOrigins|origins|1}} {{#arrayprint:restOfOrigins||$$$$|{{!}}-
{{InheritEdgesTo|@@@@}}}}
+
{{!}} {{#explode:$$$$|<VAL>|0}} {{!}}{{!}} {{#explode:$$$$|<VAL>|1}} }} }} }} }}
{{!}}} }} }}<noinclude><!--
+
{{!}}}
 +
}}<!--
 +
 +
The rest of this template still needs updating, we need stuff like the above for specified in edges, permitted out edges, and specified out edges...but first, to test it...
  
 
Next we get the out edges:
 
Next we get the out edges:

Revision as of 11:31, 12 May 2014

For use on node kind pages, automatically lists edges declared on the current page.

If the parameter "parents" is given a comma-separated list of the parents of the node, inherited edges will also be listed.