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

From TDWG Terms Wiki
Jump to: navigation, search
m (fix namespace prefix)
m (attempt to fix ending #-URIs)
 
(17 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 24: Line 23:
 
else namespace URI may one of:
 
else namespace URI may one of:
 
   two (import + defined) / just the defined / just the import / none
 
   two (import + defined) / just the defined / just the import / none
-->|<div style="display:none;">debug: case is "{{#if: {{#var: importNamespaceUri}}|importURI}}<!--
+
-->|{{#switch: <!--
  -->{{#if: {{#var: namespaceURIpageList}}<!--
+
    return switch string for cases
      check e.g. "(http://rs.tdwg.org/ac/terms/)"
+
  -->{{#vardefineecho: caseOfNamespace |<!--
    -->|{{#if: {{#pos: ({{#var: importNamespaceUri}})|{{#var: namespaceURIpageList}} }}<!--
+
    -->{{#if: {{#var: importNamespaceUri}}|importURI}}<!--
       -->|_is_definedURI<!--
+
    -->{{#if: {{#var: namespaceURIpageList}}<!--
        -->|{{#if: {{#var: importNamespaceUri}} <!--
+
        check e.g. "Simple Knowledge Organization System (http://www.w3.org/2004/02/skos/core) | (http://www.w3.org/2004/02/skos/core#)"
        -->|_conflicts_with_definedURI<!--
+
       -->|{{#ifexpr: {{#rpos: {{#replace:<!-- bug fix cutted # on uri ending -->{{#var: namespaceURIpageList}}|#)|)}} | {{#replace:<!-- bug fix cutted # on uri ending -->({{#var: importNamespaceUri}})|#)|)}} }} > -1<!--
          no importURI just a definedURI
+
        then-->|_is_definedURI<!--
        -->|definedURI}}
+
         else-->|{{#if: {{#var: importNamespaceUri}} <!--
        }}<!--
+
          -->|_conflicts_with_definedURI<!--
    -->|<!--
+
            no importURI just a definedURI
      no defined URI
+
          -->|definedURI}}
      -->}}"</div>{{#switch: <!--
+
          }}<!--
    return switch string for cases   
+
      -->|<!--
  -->{{#if: {{#var: importNamespaceUri}}|importURI}}<!--
+
        no defined URI
  -->{{#if: {{#var: namespaceURIpageList}}<!--
+
       -->}}<!--
      check e.g. "(http://rs.tdwg.org/ac/terms/)"
+
  -->}}
    -->|{{#if: {{#pos: ({{#var: importNamespaceUri}})|{{#var: namespaceURIpageList}} }}<!--
+
   |importURI = {{
      -->|_is_definedURI<!--
+
    #switch: {{lc: {{{return value|}}}}}
         -->|{{#if: {{#var: importNamespaceUri}} <!--
+
        -->|_conflicts_with_definedURI<!--  
+
          no importURI just a definedURI
+
        -->|definedURI}}  
+
        }}<!--
+
    -->|<!--  
+
      no defined URI  
+
       -->}}
+
   |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={{#var: importNamespaceUri}}{{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}
 
     |uri={{#var: importNamespaceUri}}{{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}
     }}{{Warning about conflict of concept URI with SMW import and Concept or Collection
+
     }}<nowiki></nowiki> {{{info message|}}}<div style="display:none;" class="debug-template-Validate-and-render-identifier-URI">importURI: {{lc: {{{return value|}}}}}</div>{{Warning about conflict of concept URI with SMW import and Concept or Collection
 
       |import namespace URI={{#var: importNamespaceUri}}
 
       |import namespace URI={{#var: importNamespaceUri}}
 
       |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}} ({{
 +
      #sub: {{#var: namespaceURIpageList}}
 +
        | 0 | {{#expr: {{#pos: {{#var: namespaceURIpageList}} | ] }} + {{#len: ]] }} }}
 +
      }}, <!--
 +
      -->[[MediaWiki:Smw import {{{namespace prefix|}}}]])
 
     |uri={{#var: importNamespaceUri}}{{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}
 
     |uri={{#var: importNamespaceUri}}{{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}
     }}
+
     }}<nowiki></nowiki> {{{info message|}}}
   |importURI_conflicts_with_definedURI={{Warning about conflict of concept URI with SMW import and Concept or Collection
+
   |importURI_conflicts_with_definedURI=<div style="display:none;" class="debug-template-Validate-and-render-identifier-URI">importURI_conflicts_with_definedURI: {{lc: {{{return value|}}}}}</div>{{Warning about conflict of concept URI with SMW import and Concept or Collection
 
       |import namespace URI={{#var: importNamespaceUri}}
 
       |import namespace URI={{#var: importNamespaceUri}}
 
       |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=<!-- URI from e.g. "[[:Audubon Core|Audubon Core]] (http://rs.tdwg.org/ac/terms/)"  
+
    |uri and page= {{#sub: {{#var: namespaceURIpageList}} | {{#expr: {{#rpos:{{#var: namespaceURIpageList}} | ( }} + 1 }} | -1 }} ({{
     -->{{#replace: {{#sub: {{#var: namespaceURIpageList}} | {{#expr: {{#pos:{{#var: namespaceURIpageList}} | ( }} + 1 }} | -1 }} | ) | {{#explode: {{{concept page|{{PAGENAME}}}}}|:|1}}) }}
+
      #sub: {{#var: namespaceURIpageList}}
     }}{{Warning about conflict of concept URI with SMW import and Concept or Collection
+
        | 0 | {{#expr: {{#pos: {{#var: namespaceURIpageList}} | ] }} + {{#len: ]] }} }}
 +
      }})
 +
     |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}}) }}
 +
     }}<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
 
       |import namespace URI={{#var: importNamespaceUri}}
 
       |import namespace URI={{#var: importNamespaceUri}}
 
       |concept namespace prefix={{{namespace prefix|}}}
 
       |concept namespace prefix={{{namespace prefix|}}}
 
     }}
 
     }}
   |#default={{#vardefine: hasConflict | 1 }}Warning: no namespace URI defined yet [[File:Warning_icon.svg|x10px|link=]]
+
   |#default={{#vardefine: hasConflict | 1 }}<div class="debug" style="display:none;">{{#var: caseOfNamespace}}</div> Warning: no namespace URI defined yet [[File:Warning_icon.svg|x10px|link=]]<nowiki></nowiki> {{{info message|}}}
 
   }}
 
   }}
 
}}{{
 
}}{{
   #if: {{#var: hasConflict}} | {{#switch: {{lc: {{{set management category|}}}}} | no | 0 | none|false=| #default=[[Category: Check semantic properties]] }}
+
   #if: {{#var: hasConflict}} | {{#switch: {{lc: {{{set management category|}}}}} | no | 0 | none|false=| #default=[[Category:Internal - URI conflict]] }}
 
}}<!--
 
}}<!--
  
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='''<!-- e.g. biorel -->
+
  {{!}}'''namespace prefix='''<span style="color:gray;">&lt;!-- e.g. biorel --></span>
  |concept page=<!-- optional (default is <nowiki>{{PAGENAME}}</nowiki>) -->
+
  {{!}}concept page=<span style="color:gray;">&lt;!-- optional (default is <nowiki>{{PAGENAME}}</nowiki>) --></span>
  |set management category=<!-- 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=<!-- optional: "page and URI" or "URI" (default return: void or a collapsible warning message box) -->
+
  "true", "1" ("0", "no", "false" is false) --></span>
  <nowiki>}}</nowiki></div>
+
  {{!}}return value=<span style="color:gray;">&lt;!-- optional:  
 +
  "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" or "URI" (default return: void or a collapsible warning message box) -->
+
  "true", "1" ("0", "no", "false" is false) --></span>
  <nowiki>}}</nowiki></div>
+
  {{!}}return value=<span style="color:gray;">&lt;!-- optional:  
}}
+
  "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>
  
Sets management category: [[:Category: Check semantic properties]] (suppressed by parameter "set management category=no")
+
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")
  
 
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