Difference between revisions of "Template:Validate and render identifier URI"

From TDWG Terms Wiki
Jump to: navigation, search
m (+debug)
m (attempt to fix ending #-URIs)
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
-->{{#vardefine: importNamespaceUri | {{Namespace prefix to imported namespace URI | {{{namespace prefix|}}} }} }}<!--
 
-->{{#vardefine: importNamespaceUri | {{Namespace prefix to imported namespace URI | {{{namespace prefix|}}} }} }}<!--
 
   namespaceURIpageList e.g. "[[:Audubon Core|Audubon Core]] (http://rs.tdwg.org/ac/terms/)"
 
   namespaceURIpageList e.g. "[[:Audubon Core|Audubon Core]] (http://rs.tdwg.org/ac/terms/)"
-->{{#vardefine: namespaceURIpageList | {{#ask:  
+
-->{{#vardefine: namespaceURIpageList | {{#ask: [[vann:preferredNamespacePrefix::{{{namespace prefix|}}}]]
  [[vann:preferredNamespacePrefix::{{{namespace prefix|}}}]]  
+
   | ?vann:preferredNamespaceUri#= | format=list | link=none}}
   | ?vann:preferredNamespaceUri#= | format=list}}
+
 
}}<!--
 
}}<!--
  
 
   check URI definitions: multiple or single once
 
   check URI definitions: multiple or single once
 
+
 
 
-->{{#if: {{#pos: {{#var: namespaceURIpageList}}|,}} <!--
 
-->{{#if: {{#pos: {{#var: namespaceURIpageList}}|,}} <!--
 
then multiple ns URI: ERROR message
 
then multiple ns URI: ERROR message
Line 17: Line 16:
 
| toggle position=left
 
| toggle position=left
 
| content=Namespace URIs are defined multiple times on:<ul>
 
| content=Namespace URIs are defined multiple times on:<ul>
<li>{{#replace: {{#var: namespaceURIpageList}} |,|</li><li>}}</li>{{
+
<li>{{#var: namespaceURIpageList}}</li>{{
 
#if: {{#var: importNamespaceUri}} | <li>SMW-import-page [[MediaWiki:Smw import {{{namespace prefix|}}}]] ({{#var: importNamespaceUri}}), e.g. for RDF export</li>
 
#if: {{#var: importNamespaceUri}} | <li>SMW-import-page [[MediaWiki:Smw import {{{namespace prefix|}}}]] ({{#var: importNamespaceUri}}), e.g. for RDF export</li>
 
}}</ul>
 
}}</ul>
Line 25: Line 24:
 
   two (import + defined) / just the defined / just the import / none
 
   two (import + defined) / just the defined / just the import / none
 
-->|{{#switch: <!--
 
-->|{{#switch: <!--
     return switch string for cases  
+
     return switch string for cases
 
   -->{{#vardefineecho: caseOfNamespace |<!--
 
   -->{{#vardefineecho: caseOfNamespace |<!--
 
     -->{{#if: {{#var: importNamespaceUri}}|importURI}}<!--
 
     -->{{#if: {{#var: importNamespaceUri}}|importURI}}<!--
 
     -->{{#if: {{#var: namespaceURIpageList}}<!--
 
     -->{{#if: {{#var: namespaceURIpageList}}<!--
         check e.g. "(http://rs.tdwg.org/ac/terms/)"
+
         check e.g. "Simple Knowledge Organization System (http://www.w3.org/2004/02/skos/core) | (http://www.w3.org/2004/02/skos/core#)"
       -->|{{#if: {{#rpos: {{#var: namespaceURIpageList}} | ({{#var: importNamespaceUri}}) }}<!--
+
       -->|{{#ifexpr: {{#rpos: {{#replace:<!-- bug fix cutted # on uri ending -->{{#var: namespaceURIpageList}}|#)|)}} | {{#replace:<!-- bug fix cutted # on uri ending -->({{#var: importNamespaceUri}})|#)|)}} }} > -1<!--
         -->|_is_definedURI<!--
+
         then-->|_is_definedURI<!--
          -->|{{#if: {{#var: importNamespaceUri}} <!--
+
        else-->|{{#if: {{#var: importNamespaceUri}} <!--
           -->|_conflicts_with_definedURI<!--  
+
           -->|_conflicts_with_definedURI<!--
 
             no importURI just a definedURI
 
             no importURI just a definedURI
           -->|definedURI}}  
+
           -->|definedURI}}
 
           }}<!--
 
           }}<!--
       -->|<!--  
+
       -->|<!--
         no defined URI  
+
         no defined URI
 
       -->}}<!--
 
       -->}}<!--
 
   -->}}
 
   -->}}
   |importURI = {{#switch: {{lc: {{{return value|}}}}}
+
   |importURI = {{
 +
    #switch: {{lc: {{{return value|}}}}}
 
     |page and uri= [[MediaWiki:Smw import {{{namespace prefix|}}}]] ({{#var: importNamespaceUri}}{{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}})
 
     |page and uri= [[MediaWiki:Smw import {{{namespace prefix|}}}]] ({{#var: importNamespaceUri}}{{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}})
 
     |uri and page= {{#var: importNamespaceUri}} {{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}} ([[MediaWiki:Smw import {{{namespace prefix|}}}]])
 
     |uri and page= {{#var: importNamespaceUri}} {{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}} ([[MediaWiki:Smw import {{{namespace prefix|}}}]])
Line 49: Line 49:
 
       |concept namespace prefix={{{namespace prefix|}}}
 
       |concept namespace prefix={{{namespace prefix|}}}
 
     }}{{#vardefine: hasConflict | 1 }}
 
     }}{{#vardefine: hasConflict | 1 }}
   |importURI_is_definedURI={{#switch: {{lc: {{{return value|}}}}}
+
   |importURI_is_definedURI={{
 +
    #switch: {{lc: {{{return value|}}}}}
 
     |page and uri= {{#replace: {{#var: namespaceURIpageList}} | ) | {{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}) }}
 
     |page and uri= {{#replace: {{#var: namespaceURIpageList}} | ) | {{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}) }}
 
     |uri and page= <!-- TODO: check if neccessary → {{#var: importNamespaceUri}} --> {{#sub: {{#var: namespaceURIpageList}} | {{#expr: {{#rpos:{{#var: namespaceURIpageList}} | ( }} + 1 }} | -1 }}{{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}} ({{
 
     |uri and page= <!-- TODO: check if neccessary → {{#var: importNamespaceUri}} --> {{#sub: {{#var: namespaceURIpageList}} | {{#expr: {{#rpos:{{#var: namespaceURIpageList}} | ( }} + 1 }} | -1 }}{{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}} ({{
       #sub: {{#var: namespaceURIpageList}}  
+
       #sub: {{#var: namespaceURIpageList}}
         | 0 | {{#expr: {{#pos: {{#var: namespaceURIpageList}} | ] }} + {{#len: ]] }} }}  
+
         | 0 | {{#expr: {{#pos: {{#var: namespaceURIpageList}} | ] }} + {{#len: ]] }} }}
 
       }}, <!--
 
       }}, <!--
 
       -->[[MediaWiki:Smw import {{{namespace prefix|}}}]])
 
       -->[[MediaWiki:Smw import {{{namespace prefix|}}}]])
Line 62: Line 63:
 
       |concept namespace prefix={{{namespace prefix|}}}
 
       |concept namespace prefix={{{namespace prefix|}}}
 
     }}{{#vardefine: hasConflict | 1 }}
 
     }}{{#vardefine: hasConflict | 1 }}
   |definedURI={{#switch: {{lc: {{{return value|}}}}}
+
   |definedURI={{
 +
    #switch: {{lc: {{{return value|}}}}}
 
     |page and uri= {{#replace: {{#var: namespaceURIpageList}} | ) | {{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}) }}
 
     |page and uri= {{#replace: {{#var: namespaceURIpageList}} | ) | {{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}) }}
 
     |uri and page= {{#sub: {{#var: namespaceURIpageList}} | {{#expr: {{#rpos:{{#var: namespaceURIpageList}} | ( }} + 1 }} | -1 }} ({{
 
     |uri and page= {{#sub: {{#var: namespaceURIpageList}} | {{#expr: {{#rpos:{{#var: namespaceURIpageList}} | ( }} + 1 }} | -1 }} ({{
       #sub: {{#var: namespaceURIpageList}}  
+
       #sub: {{#var: namespaceURIpageList}}
         | 0 | {{#expr: {{#pos: {{#var: namespaceURIpageList}} | ] }} + {{#len: ]] }} }}  
+
         | 0 | {{#expr: {{#pos: {{#var: namespaceURIpageList}} | ] }} + {{#len: ]] }} }}
 
       }})
 
       }})
     |uri=<!-- URI from e.g. "[[:Audubon Core|Audubon Core]] (http://rs.tdwg.org/ac/terms/)"  
+
     |uri=<!-- URI from e.g. "[[:Audubon Core|Audubon Core]] (http://rs.tdwg.org/ac/terms/)"
 
     -->{{#replace: {{#sub: {{#var: namespaceURIpageList}} | {{#expr: {{#rpos:{{#var: namespaceURIpageList}} | ( }} + 1 }} | -1 }} | ) | {{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}) }}
 
     -->{{#replace: {{#sub: {{#var: namespaceURIpageList}} | {{#expr: {{#rpos:{{#var: namespaceURIpageList}} | ( }} + 1 }} | -1 }} | ) | {{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}) }}
 
     }}<div style="display:none;" class="debug-template-Validate-and-render-identifier-URI">definedURI: {{lc: {{{return value|}}}}}</div>{{Warning about conflict of concept URI with SMW import and Concept or Collection
 
     }}<div style="display:none;" class="debug-template-Validate-and-render-identifier-URI">definedURI: {{lc: {{{return value|}}}}}</div>{{Warning about conflict of concept URI with SMW import and Concept or Collection
Line 87: Line 89:
 
|text=This template checks for namespace URIs and returns it optionally. In case of multiple definitions or conflicting URIs it will print a warning message for this This template has the following parameter (mandatory is '''bold'''), use it in the format:
 
|text=This template checks for namespace URIs and returns it optionally. In case of multiple definitions or conflicting URIs it will print a warning message for this This template has the following parameter (mandatory is '''bold'''), use it in the format:
 
<div class="no-pre-border no-pre-margin no-pre-padding" style="margin-left:1.5em;">
 
<div class="no-pre-border no-pre-margin no-pre-padding" style="margin-left:1.5em;">
  <nowiki>{{</nowiki>Check URI conflict
+
  <nowiki>{{</nowiki>Validate and render identifier URI
  {{!}}'''namespace prefix='''&lt;!-- e.g. biorel -->
+
  {{!}}'''namespace prefix='''<span style="color:gray;">&lt;!-- e.g. biorel --></span>
  {{!}}concept page=&lt;!-- optional (default is <nowiki>{{PAGENAME}}</nowiki>) -->
+
  {{!}}concept page=<span style="color:gray;">&lt;!-- optional (default is <nowiki>{{PAGENAME}}</nowiki>) --></span>
  {{!}}set management category=&lt;!-- optional: value may be any string, e.g. "true", "1" ("0", "no", "false" is false) -->
+
  {{!}}set management category=<span style="color:gray;">&lt;!-- optional: value may be any string, e.g.
  {{!}}return value=&lt;!-- optional: "page and URI", "URI and page" or "URI" (default return: void or a collapsible warning message box) -->
+
  "true", "1" ("0", "no", "false" is false) --></span>
  {{!}}info message=&lt;!-- optional: message that appears after URI but before any warnings, e.g. for forms with <nowiki>{{#info: message=text}}</nowiki> -->
+
  {{!}}return value=<span style="color:gray;">&lt;!-- optional:  
  <nowiki>}}</nowiki></div>
+
  "page and URI",
 +
  "URI and page" or  
 +
  "URI" (default return: void or a collapsible warning message box) --></span>
 +
  {{!}}info message=<span style="color:gray;">&lt;!-- optional: message that appears after URI but before any warnings, e.g. for forms with <nowiki>{{#info: message=text}}</nowiki> --></span>
 +
<nowiki>}}</nowiki>
 +
</div>
 
}}
 
}}
 
}}</includeonly><noinclude><!--
 
}}</includeonly><noinclude><!--
  
 
   template documentation itself
 
   template documentation itself
 
+
 
-->{{TemplateError
+
-->
|text=This template checks for namespace URIs and returns them optionally. In case of multiple definitions or conflicting URIs it will print a warning message. This template has the following parameter (mandatory is '''bold'''), use it in the format:
+
This template checks for namespace URIs and returns them optionally. In case of multiple definitions or conflicting URIs it will print a warning message. This template has the following parameter (mandatory is '''bold'''), use it in the format:
 
<div class="no-pre-border no-pre-margin no-pre-padding" style="margin-left:1.5em;">
 
<div class="no-pre-border no-pre-margin no-pre-padding" style="margin-left:1.5em;">
 
  <nowiki>{{</nowiki>{{#titleparts: {{PAGENAME}} | 1 }}
 
  <nowiki>{{</nowiki>{{#titleparts: {{PAGENAME}} | 1 }}
  {{!}}'''namespace prefix='''&lt;!-- e.g. biorel -->
+
  {{!}}'''namespace prefix='''<span style="color:gray;">&lt;!-- e.g. biorel --></span>
  {{!}}concept page=&lt;!-- optional (default is <nowiki>{{PAGENAME}}</nowiki>) -->
+
  {{!}}concept page=<span style="color:gray;">&lt;!-- optional (default is <nowiki>{{PAGENAME}}</nowiki>) --></span>
  {{!}}set management category=&lt;!-- optional: value may be any string, e.g. "true", "1" ("0", "no", "false" is false) -->
+
  {{!}}set management category=<span style="color:gray;">&lt;!-- optional: value may be any string, e.g.  
  {{!}}return value=&lt;!-- optional: "page and URI", "URI and page" or "URI" (default return: void or a collapsible warning message box) -->
+
  "true", "1" ("0", "no", "false" is false) --></span>
  {{!}}info message=&lt;!-- optional: message that appears after URI but before any warnings, e.g. for forms with <nowiki>{{#info: message=text}}</nowiki> -->
+
  {{!}}return value=<span style="color:gray;">&lt;!-- optional:  
  <nowiki>}}</nowiki></div>
+
  "page and URI",
}}
+
  "URI and page" or  
 +
  "URI" (default return: void or a collapsible warning message box) --></span>
 +
  {{!}}info message=<span style="color:gray;">&lt;!-- optional: message that appears after URI but before any warnings, e.g. for forms with <nowiki>{{#info: message=text}}</nowiki> --></span>
 +
<nowiki>}}</nowiki>
 +
</div>
 +
 
 
== Technical documentation ==
 
== Technical documentation ==
  
Dependent on: [[Template:Warning about conflict of concept URI with SMW import and Concept or Collection]]
+
Note that #-ending URIs, like http://www.w3.org/2009/08/skos-reference/skos.html#, are cut off of the ending #, hence this templates eliminates ending #-URIs when testing. SemanticMediaWiki would show a <code>vann:preferredNamespaceUri::http://www.w3.org/2004/02/skos/core#</code> cut to
 +
<syntaxhighlight lang="xml"><vann:preferredNamespaceUri rdf:resource="http://www.w3.org/2004/02/skos/core"/></syntaxhighlight>
 +
… and not as trailing #
 +
<syntaxhighlight lang="xml" style="text-decoration: line-through;"><vann:preferredNamespaceUri rdf:resource="http://www.w3.org/2004/02/skos/core#"/></syntaxhighlight>
 +
 
 +
Dependent on:  
 +
* [[Template:Warning about conflict of concept URI with SMW import and Concept or Collection]]
 +
* [[template: TemplateError]]
 +
* [[template: Hidden]]
  
 
Sets management category: [[:Category: Internal - URI conflict]] (suppressed by parameter "set management category=no")
 
Sets management category: [[:Category: Internal - URI conflict]] (suppressed by parameter "set management category=no")
  
 
Uses variables: <code>hasConflict</code>, <code>importNamespaceUri</code>, <code>namespaceURIpageList</code>
 
Uses variables: <code>hasConflict</code>, <code>importNamespaceUri</code>, <code>namespaceURIpageList</code>
 +
 +
 
[[Category: Helper tool for ontologies]]</noinclude>
 
[[Category: Helper tool for ontologies]]</noinclude>

Latest revision as of 23:39, 7 September 2016

This template checks for namespace URIs and returns them optionally. In case of multiple definitions or conflicting URIs it will print a warning message. This template has the following parameter (mandatory is bold), use it in the format:

{{Validate and render identifier URI
|namespace prefix=<!-- e.g. biorel -->
|concept page=<!-- optional (default is {{PAGENAME}}) -->
|set management category=<!-- optional: value may be any string, e.g. 
  "true", "1" ("0", "no", "false" is false) -->
|return value=<!-- optional: 
  "page and URI",
  "URI and page" or 
  "URI" (default return: void or a collapsible warning message box) -->
|info message=<!-- optional: message that appears after URI but before any warnings, e.g. for forms with {{#info: message=text}} -->
}}

Technical documentation

Note that #-ending URIs, like http://www.w3.org/2009/08/skos-reference/skos.html#, are cut off of the ending #, hence this templates eliminates ending #-URIs when testing. SemanticMediaWiki would show a vann:preferredNamespaceUri::http://www.w3.org/2004/02/skos/core# cut to

<vann:preferredNamespaceUri rdf:resource="http://www.w3.org/2004/02/skos/core"/>

… and not as trailing #

<vann:preferredNamespaceUri rdf:resource="http://www.w3.org/2004/02/skos/core#"/>

Dependent on:

Sets management category: Category: Internal - URI conflict (suppressed by parameter "set management category=no")

Uses variables: hasConflict, importNamespaceUri, namespaceURIpageList