FANDOM


Export this template, then import, to install it.
Use edit summary: Copied from [[w:c:templates:Template:SemanticInputParser]] to properly attribute this template's editors.
This template is probably not already on your wiki.
Template documentation
Note: the template above may sometimes be partially or fully invisible.

View or edit this documentation. (How does this work?)

Editors can experiment with this template's sandbox and test case pages.

Summary

This template is a designed for inputting a single set of data into single value semantic properties. It allows for customizable rules such as Regular Expressions, data delimiters and 7 types of linking options. Check here for the most up to date version.

Variables (default)

{{SemanticInputParser
        |value=
        |SemanticPropertyName=
        |SemanticPropertyUnit=
        |SearchByProperty=false
        |linkOptions=default
        |ExtraInfoDelim=~
        |ExtraInfoTemplate=
        |RegexLineCondition=
        |RegexPrepend=
        |RegexPrependTemplate=
        |RegexAppend=
        |RegexAppendTemplate=
        |PrependText=
        |PrependTemplate=
        |AppendText=
        |AppendTemplate=
}}

Description

  • value: This is the value passed into the template to be parsed according to the variables LineDelim, SameLineDelim, RegexPrepend, RegexAppend. It also displays a error if the parsed data does not match RegexLineCodition.
    • This value uses the ~ as a default delimiter for additional information which is not part of the semantic value. The value after the first is put inside of ( ), and the value after the second is put inside of <sup>( )</sup>. The default delimiter can be overridden with the variable ExtraInfoDelim.
  • SemanticPropertyName: This is the name of the semantic property to assign the parsed data to
    • SearchByProperty: This boolean property creates a search icon if there are the same values for the this property
    • SemanticPropertyUnit: This is the unit of the semantic property to automatically add
  • linkOptions:
    • default, show no link if the page does not exist
    • none, never show a link
    • Semantic Unit, Show the input with the semantic unit using the display units on the property page.
    • Wikipedia, link to wikipedia if does not exist on this wiki
    • Form:FormName, if there is no page of this name on the wiki, create a form link.
    • Template:TemplateName, pass the parsed value directly into a template
  • RegexLineCondition: This sets a regex condition for each item on a line, this field is provided due to users ability to input in ways other than a regex form input.
  • RegexPrepend: This sets a regex condition for the beginning part of the line to not include in the parsing. There is a newline delimiter that parses each regex condition separately and each parse can be individually passed to a template.
    • RegexPrependTemplate: This is a optional user defined template (using the variable {{{1|}}}) to pass the prepended regex text through.
  • RegexAppend: This sets a regex condition for the ending part of the line to not include in the parsing. There is a newline delimiter that parses each regex condition separately and each parse can be individually passed to a template.
    • RegexAppendTemplate: This is a optional user defined template (using the variable {{{1|}}}) to pass the appended regex text through.
  • PrependText: This value is inserted in front of a line item
    • PrependTemplate: This is a optional user defined template to send the parsed data through, it is displayed before the parsed data. The first value passed is the parsed value, while the second value passed is the variable PrependText.
  • AppendText: This value is inserted behind a line item
    • AppendTemplate: This is a optional user defined template to send the parsed data through, it is displayed after the parsed data. The first value passed is the parsed value, while the second value passed is the variable AppendText.
  • ExtraInfoTemplate: This is a optional user defined template to send data after ExtraInfoDelim through.

Requirements

  1. http://www.mediawiki.org/wiki/Extension:Regex_Fun
  2. http://www.mediawiki.org/wiki/Extension:Variables
  3. http://www.mediawiki.org/wiki/Extension:Semantic_Forms (#arraymap parser)
  4. http://www.mediawiki.org/wiki/Extension:Semantic_MediaWiki
  5. Template:!

Samples

These are some samples using this template and its child template Template:SemanticInputParser/Array.

Specify a single value, a single time while also incorporating a icon with the given value.
{{SemanticInputParser
   |value=Male
   |RegexLineCondition=(Male{{!}}Female)
   |linkOptions=none
   |SemanticPropertyName=Gender
   |PrependTemplate=GenderIcon
}}
Only allow digits (including decimal) (from any script)
{{SemanticInputParser/Array
   |value=50, 90.5, not a number
   |RegexLineCondition=\p{N}+(\.\p{N}+)?
   |linkOptions=none
}}
Only allow Japanese Kanji, Spaces or Punctuation
{{SemanticInputParser/Array
   |value=仙法・超大玉螺旋多連丸, some english text
   |RegexLineCondition=[\p{Han}\p{P}\p{Zs}]+
   |linkOptions=none
}}
Do not interpret end of text as part of value
{{SemanticInputParser/Array
   |value=Some Page Name (I don't want this value to be parsed), O(this will get parsed)ther page name
   |RegexAppend=\([^()\n\r]+\)
   |SemanticPropertyName=Page Name
}}
Do not interpret start of text as part of parsed value, also add measurement units using semantic property
{{SemanticInputParser/Array
   |value=5 x 5123, 5123, not.anumber
   |RegexPrepend=\d+\s+x
   |RegexLineCondition=\d+(\.\d+)?
   |SemanticPropertyName=Vernier Thrusters
   |SemanticPropertyUnit=kg
   |linkOptions=Semantic Unit
}}
You can manipulate the data before sending it to the template, this removes all data after the first ~
{{SemanticInputParser/Array
   |value={{#arraymap:{{{value|}}}|,|_SemanticInputVariable_|{{#explode:_SemanticInputVariable_|~}}|\n}}
   |LineDelim=\n
}}
Manually add Part I, or Part II as needed in front of separate variables
{{SemanticInputParser/Array
   |value={{#if:{{{height1|}}}|Part I: {{{height1}}}}}
          {{#if:{{{height2|}}}|Part II: {{{height2}}}}}
   |SemanticPropertyName=Height
   |SemanticPropertyUnit=cm
   |LineDelim=\n
   |SameLineDelim=-
   |RegexPrepend=Part I{1,2}:\s
   |linkOptions=Semantic Unit
}}
Add italics around parsed value
{{SemanticInputParser/Array
   |value=Something, Another something
   |PrependText=<i>
   |AppendText=</i>
}}
Add a line as a title using the ~ delimiter, also uses RegexPrepend for ul lists
{{SemanticInputParser/Array
   |value=~Header, *Some value, *Some other value, ~Second Header, *more info
   |RegexPrepend=(\**)
}}
Change the delimiter between data, also uses RegexPrepend for ul lists
{{SemanticInputParser/Array
   |value=information
*Other information
**Some other information
   |LineDelim=\n
   |RegexPrepend=(\**)
}}
You can define a template and pass the result of a RegexAppend or RegexPrepend to it
{{SemanticInputParser/Array
   |value=information
   |RegexAppend=\[([\w]{3,12})\](/\[([\w]{3,12})\])*
   |RegexAppendTemplate=SomeTemplateName
}}

From: "Template:SomeTemplateName"

<sup>({{#arraymap:{{{1|}}}|/|_VarItem_|[[{{#sub:_VarItem_|1|-1}}]]| / }})</sup>


Insert template inside another template to create two columns for infobox (no css)
{{#if:{{{value|}}}|<nowiki/>
{{!}}-
!{{{label|}}}
{{!}}{{SemanticInputParser/Array
       |value={{{value|}}}  
       |SemanticPropertyName={{{SemanticPropertyName|}}}
       |SemanticPropertyUnit={{{SemanticPropertyUnit|}}}
       |SearchByProperty={{{SearchByProperty|}}}
       |linkOptions={{{linkOptions|default}}}
       |LineDelim={{{LineDelim|,}}}
       |NewLineDelim={{{NewLineDelim|\n\n*}}}
       |SameLineDelim={{{SameLineDelim|/}}}
       |ExtraInfoDelim={{{ExtraInfoDelim|~}}}
       |RegexLineCondition={{{RegexLineCondition|}}}
       |RegexPrepend={{{RegexPrepend|}}}
       |RegexPrependTemplate={{{RegexPrependTemplate|}}}
       |RegexAppend={{{RegexAppend|}}}
       |RegexAppendTemplate={{{RegexAppendTemplate|}}}
       |PrependText={{{PrependText|}}}
       |PrependTemplate={{{PrependTemplate|}}}
       |AppendText={{{AppendText|}}}
       |AppendTemplate={{{AppendTemplate|}}}
    }}
}}
Insert template inside another template to create two columns for infobox
{{#if:{{{value|}}}|<nowiki/>
{{!}}-{{#if:{{{class|}}}|<nowiki/> class="{{{class|}}}"| }}
!{{#if:{{{labelclass|}}}|<nowiki/> class="{{{labelclass|}}}" <nowiki/>| }}{{!}} {{{label|}}}
   {{!}}{{#if:{{{valueclass|}}}|<nowiki/> class="{{{valueclass|}}}" <nowiki/>| }}{{!}}{{SemanticInputParser/Array
       |value={{{value|}}}  
       |SemanticPropertyName={{{SemanticPropertyName|}}}
       |SemanticPropertyUnit={{{SemanticPropertyUnit|}}}
       |SearchByProperty={{{SearchByProperty|}}}
       |linkOptions={{{linkOptions|default}}}
       |LineDelim={{{LineDelim|,}}}
       |NewLineDelim={{{NewLineDelim|\n\n*}}}
       |SameLineDelim={{{SameLineDelim|/}}}
       |ExtraInfoDelim={{{ExtraInfoDelim|~}}}
       |RegexLineCondition={{{RegexLineCondition|}}}
       |RegexPrepend={{{RegexPrepend|}}}
       |RegexPrependTemplate={{{RegexPrependTemplate|}}}
       |RegexAppend={{{RegexAppend|}}}
       |RegexAppendTemplate={{{RegexAppendTemplate|}}}
       |PrependText={{{PrependText|}}}
       |PrependTemplate={{{PrependTemplate|}}}
       |AppendText={{{AppendText|}}}
       |AppendTemplate={{{AppendTemplate|}}}
    }}
}}
Community content is available under CC-BY-SA unless otherwise noted.