Шаблон:ПарсерСемантическихДанных

Материал из Викимультии — энциклопедии мультипликации
Это старая версия этой страницы, сохранённая Alexandr Efremov (обсуждение | вклад) в 01:24, 4 марта 2020. Она может серьёзно отличаться от текущей версии.
Перейти к навигации Перейти к поиску


Документация

Этот шаблон предназначен для ввода единого набора данных в одно значение семантических свойств. Он позволяет настраивать такие правила, как регулярные выражения, разделители данных и 9 типов ссылок.

Переменные (по умолчанию)

{{ПарсерСемантическихДанных
 |value=
 |SemanticPropertyName=
 |SemanticPropertyUnit=
 |SearchByProperty=false
 |linkOptions=default
 |RegexLineCondition=
 |SemanticPropertyRegexOverride=
 |RegexPrepend=
 |RegexPrependTemplate=
 |RegexAppend=
 |RegexAppendTemplate=
 |PrependText=
 |PrependTemplate=
 |AppendText=
 |AppendTemplate=
}}

Описание

  • 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.
  • 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
    • hide, store data only, do not show
    • always, always 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.
    • Query Form:FormName:TemplateName[FieldName]
    • 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.
    • SemanticPropertyRegexOverride: Setting this to 'yes', will always displays the input; but it will prevent an improper value from being entered into the semantic property.
  • RegexPrepend: This sets a regex condition for the beginning part of the line to not include in the parsing.
    • 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.
    • 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.

Требования

  1. mw:Extension:Regex Fun
  2. mw:Extension:Variables
  3. mw:Extension:Semantic Forms (#arraymap parser)
  4. mw:Extension:Semantic MediaWiki

Примеры

Ниже приведены примеры использования этого шаблона и его дочернего шаблона Шаблон:ПарсерСемантическихДанных/Массив.

Показывает одно значение, одновременно используя заданный значок.
{{ПарсерСемантическихДанных
   |value=Мужской
   |RegexLineCondition=(Мужской{{!}}Женский)
   |linkOptions=none
   |SemanticPropertyName=Пол
   |PrependText=Пол
   |PrependTemplate=Иконки
}}
Разрешены только числа (включая десятичные) (из любого скрипта)
{{ПарсерСемантическихДанных/Массив
   |value=50, 90.5, не число
   |RegexLineCondition=\p{N}+(\.\p{N}+)?
   |linkOptions=none
}}
Разрешены только японские кандзи, пробелы или знаки препинания
{{ПарсерСемантическихДанных/Массив
   |value=仙法・超大玉螺旋多連丸, какой-то русский текст
   |RegexLineCondition=[\p{Han}\p{P}\p{Zs}]+
   |linkOptions=none
}}
Не интерпретировать конец текста как часть значения
{{ПарсерСемантическихДанных/Массив
   |value=Имя страницы (Я не хочу, чтобы это значение анализировалось), Д(это будет разбираться)ругое название страницы
   |RegexAppend=\([^()\n\r]+\)
   |SemanticPropertyName=Имя страницы
}}
Не интерпретировать начало текста как часть разбираемого значения, также добавьте единицы измерения, используя семантическое свойство
{{ПарсерСемантическихДанных/Массив
   |value=5 x 5123, 5123, не.ряд
   |RegexPrepend=\d+\s+x
   |RegexLineCondition=\d+(\.\d+)?
   |SemanticPropertyName=Вес
   |SemanticPropertyUnit=кг
   |linkOptions=Semantic Unit
}}
Вы можете управлять данными перед отправкой в шаблон, это удаляет все данные после первого ~
{{ПарсерСемантическихДанных/Массив
   |value={{#arraymap:{{{value|}}}|,|_SemanticInputVariable_|{{#explode:_SemanticInputVariable_|~}}|\n}}
   |LineDelim=\n
}}
Вручную добавьте Часть I или Часть II по мере необходимости перед отдельными переменными
{{ПарсерСемантическихДанных/Массив
   |value={{#if:{{{рост1|}}}|Часть I: {{{рост1}}}}}
          {{#if:{{{рост2|}}}|Часть II: {{{рост2}}}}}
   |SemanticPropertyName=Height
   |SemanticPropertyUnit=cm
   |LineDelim=\n
   |SameLineDelim=-
   |RegexPrepend=Часть I{1,2}:\s
   |linkOptions=Semantic Unit
}}
Добавьте курсив вокруг разбираемого значения
{{ПарсерСемантическихДанных/Массив
   |value=Что-то, Еще что-то
   |PrependText=<i>
   |AppendText=</i>
}}
Добавить строку как Заголовок, используя ~ разделитель, также использует RegexPrepend для ul списков
{{ПарсерСемантическихДанных/Массив
   |value=~Header, *Some value, *Some other value, ~Second Header, *more info
   |RegexPrepend=(\**)
}}
Измените разделитель между данными, также использует RegexPrepend для списков ul
{{ПарсерСемантическихДанных/Массив
   |value=информация
*Другая информация
**Некоторая другая информация
   |LineDelim=\n
   |RegexPrepend=(\**)
}}
Вы можете определить шаблон и передать результат RegexAppend или RegexPrepend к нему
{{ПарсерСемантическихДанных/Массив
   |value=информация
   |RegexAppend=~[^~\r\n]*(~[^~\r\n]*)?
   |RegexAppendTemplate=SomeTemplateName
}}

From: "Шаблон:ИмяШаблона"

{{#if:{{#explode:{{{1|}}}|~|1}}| ({{#explode:{{{1|}}}|~|1}})}}{{#if:{{#explode:{{{1|}}}|~|2}}| <sup>({{#explode:{{{1|}}}|~|2}})</sup>}}


Вставьте шаблон в другой шаблон, чтобы создать два столбца для infobox (без css)
{{#if:{{{value|}}}|<nowiki/>
{{!}}-
!{{{label|}}}
{{!}}{{ПарсерСемантическихДанных/Массив
       |value={{{value|}}}  
       |SemanticPropertyName={{{SemanticPropertyName|}}}
       |SemanticPropertyUnit={{{SemanticPropertyUnit|}}}
       |SearchByProperty={{{SearchByProperty|}}}
       |linkOptions={{{linkOptions|default}}}
       |LineDelim={{{LineDelim|,}}}
       |NewLineDelim={{{NewLineDelim|\n\n*}}}
       |SameLineDelim={{{SameLineDelim|/}}}
       |RegexLineCondition={{{RegexLineCondition|}}}
       |RegexPrepend={{{RegexPrepend|}}}
       |RegexPrependTemplate={{{RegexPrependTemplate|}}}
       |RegexAppend={{{RegexAppend|}}}
       |RegexAppendTemplate={{{RegexAppendTemplate|}}}
       |PrependText={{{PrependText|}}}
       |PrependTemplate={{{PrependTemplate|}}}
       |AppendText={{{AppendText|}}}
       |AppendTemplate={{{AppendTemplate|}}}
    }}
}}
Вставьте шаблон в другой шаблон, чтобы создать два столбца для инфобокса
{{#if:{{{value|}}}|<nowiki/>
{{!}}-{{#if:{{{class|}}}|<nowiki/> class="{{{class|}}}"| }}
!{{#if:{{{labelclass|}}}|<nowiki/> class="{{{labelclass|}}}" <nowiki/>| }}{{!}} {{{label|}}}
   {{!}}{{#if:{{{valueclass|}}}|<nowiki/> class="{{{valueclass|}}}" <nowiki/>| }}{{!}}{{ПарсерСемантическихДанных/Массив
       |value={{{value|}}}  
       |SemanticPropertyName={{{SemanticPropertyName|}}}
       |SemanticPropertyUnit={{{SemanticPropertyUnit|}}}
       |SearchByProperty={{{SearchByProperty|}}}
       |linkOptions={{{linkOptions|default}}}
       |LineDelim={{{LineDelim|,}}}
       |NewLineDelim={{{NewLineDelim|\n\n*}}}
       |SameLineDelim={{{SameLineDelim|/}}}
       |RegexLineCondition={{{RegexLineCondition|}}}
       |RegexPrepend={{{RegexPrepend|}}}
       |RegexPrependTemplate={{{RegexPrependTemplate|}}}
       |RegexAppend={{{RegexAppend|}}}
       |RegexAppendTemplate={{{RegexAppendTemplate|}}}
       |PrependText={{{PrependText|}}}
       |PrependTemplate={{{PrependTemplate|}}}
       |AppendText={{{AppendText|}}}
       |AppendTemplate={{{AppendTemplate|}}}
    }}
}}