Модуль:Sequence/Helpers
Материал из проекта «Повелитель Тайн Вики»
Дополнительные действия
Helper functions for Module:Sequence and anything related to it.
List of Properties
- DELIM: String - A separator value for
generateSequenceCardBlockand theModule:Sequence.sequenceCard.
List of Functions
Lookup Helpers
findSequence
Takes a sequence from Module:Sequence/standard or Module:Sequence/non-standard, and outputs the data followed from those two.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| name | name | String | Sequence name. Case-insensitive and allows alternate sequence names. | required |
| do_throw | do_throw | Boolean | Throws if no sequence is found. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| seq_data | Table/nil | An item taken from Module:Sequence/standard or Module:Sequence/non-standard. Nil if no such name. | ||
findPathway
Takes a data from Module:Sequence/pathways and outputs it.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| name | name | String | Pathway name. This is indiscriminate if it has "pathway" at the end of it. | required |
| not_search_seq | not_search_seq | Boolean | Should it not search by Sequence 9? | Default: false |
| do_throw | do_throw | Boolean | Throws if no pathway is found. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| path_data | Table/nil | An item taken from Module:Sequence/pathways. | ||
findAts
Looks for Module:Sequence/ATS and outputs it. This is for both Great Old Ones, including pre-awakening like Son of Chaos, and Sefirots.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| name | name | String | ATS name. Case-insensitive. | required |
| do_throw | do_throw | Boolean | Throws if no sequence is found. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| ats_data | Table/nil | An item taken from Module:Sequence/ATS. Nil if no such name. | ||
atsGroupOf
Looks for the ATS group of the corresponding Sequence, Pathways, or ATS name. Currently, it does not work with Sefirot names.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| name | name | String | Sequence, Pathways, or ATS name. | required |
| do_throw | do_throw | Boolean | Throws if no sequence is found. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| ats_data | Table/nil | An item taken from Module:Sequence/ATS. Nil if failed. | ||
Operational Aid
seqNamesToDatas
Uses a set of Sequence names to their corresponding set of sequence datas. This function is intended to make it easier for iterating
sequence_ids of the Pathways data.Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| seq_id_set | seq_id_set | Array | The array of sequence ids. | required |
| dont_throw_invalids | dont_throw_invalids | Boolean | If false, any sequence name that aren't valid causes an error. | Default: false |
| pathway_name | pathway_name | String | Added content for error message. | optional |
| Return Value | ||||
| Label | Type | Description | ||
| seq data set | Array [Table] | Sequence datas of the same order as the ids. If any are invalid, it's taken out. This is a new table. | ||
compileAdvancementBacklash
Compiles the Backlash data from Module:Sequence/Backlash to an html format. More information there.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| sequence_name | sequence_name | String | Name of the required sequence. | required |
| use_headers | use_headers | Boolean | Use headers or simply use a bold text. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| seq backlash | String/nil | The html format of the sequence backlash. Nil if it has nothing. | ||
printMainIngr
Compiles the main ingredient info of the specified sequence.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| data | data | Table | The Sequence data table. | required |
| seq_name | seq_name | String | Not necessary, the name can be taken from the data. | Default: data["@name_id"] |
| Return Value | ||||
| Label | Type | Description | ||
| seq main ingr | String/nil | The html format of the sequence main ingredient. | ||
dataNames
Compiles the various alternate and primary names of the specified Sequence.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| data | data | Table | The Sequence data table. | required |
| exclude_primary | exclude_primary | Boolean | Exclude the primary name of the item, only returning the alternate names. | Default: false |
| include_annotation | include_annotation | Boolean | Whether to include the various notes of the names. | Default: false |
| cards_name_handling | cards_name_handling | String | Create a format that makes the Sequence Card. If left nil, it doesn't. You can also choose how to name them; it can be "use_common" or "use_alt". | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| Sequence Names | Array[String] | The names of the specified sequence. | ||
dataNameInfos
Helper function that lists out the various name meta data of a sequence and also gives a list.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| data | data | Table | The sequence data. | required |
| exclude_primary | exclude_primary | Boolean | Whether to incude the name of the key being used. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| name_infos | Array | The list of name infos. It contains a nested table containing the below: | ||
| ["name"] | String | The name of the sequence. | ||
| ["annotation"] | String | Can be a note in the ref format. This may be depcreciated. | ||
| ["flag"] | String | The flag of the name. | ||
| ["ref"] | String | The reference of where the name came from. | ||
| ["cn"] | String | The Chinese text of the name. | ||
| ["romanised"] | String | The romanised Chinese text. | ||
trimPathwayText
Removes the "Pathway" in the string and trims off any extra whitespace.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| pathway_name | pathway_name | String | required | |
| Return Value | ||||
| Label | Type | Description | ||
| pathway name | String | The pathway name, without the "Pathway" | ||
generateSequenceCardBlock
Wraps the text in a span with class "sequence-tooltip" with the corresponding
"data-seq" and "data-text" attribute values. This allows the modified text to display the Sequence Card. That feature is designed in Module:Sequence.sequenceCardFunction Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| data_arguments | data_arguments | String | The Sequence name. Or a list, with the Sequence as the first and other flags separated by a DELIM. | required |
| display_name | display_name | String | The display name within the Sequence Card. This property is unused within the Sequence Card. | required |
| link | link | String | The displayed text outside the Card. | Default: display_name |
| Return Value | ||||
| Label | Type | Description | ||
| formatted html | String | The wrapped up text that can generate the Sequence card. | ||
List Generators
pathwaySequences
Iterates the sequence datas of the specified pathway.
Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| pathway_name | pathway_name | String | The pathway name to iterate sequences to. | optional |
| dont_throw_if_not_found | dont_throw_if_not_found | Boolean | If false, if the pathawy name is not valid then it is an error. | Default: false |
| dont_throw_invalids | dont_throw_invalids | Boolean | If false, any sequence name that aren't valid causes an error. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| seq data set | Array [Table] | Sequence datas of the pathway, from 9-0 if the sequence_ids is correct. | ||
atsList
Helper function to iterate over Great Old Ones titles. This only covers the currently existing Above the Sequence groups. So Son of Chaos is not included. The order of this is constant, based on the
canonical_order property in Module:Sequence/ATS.Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| filter_group | filter_group | String/nil | Filters the result to certain attributes. This can be AtS title or earth or outer groups. If it's nil, then it simply includes everything. | Default: false |
| include_subordinates | include_subordinates | Boolean | Not meant for user. It converts filter_group from Sequence or Pathway to the AtS, including the group. This is meant for nested iterations. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| list | Array | The list of AtS groups. It contains a nested table containing the below: | ||
| ["name"] | String | The ats_title of the AtS group. | ||
| ["ref_name"] | String | The primary key index of the AtS group. | ||
| ["data"] | Table | The actual ats_data. | ||
| ["canonical_order"] | Number | An additional property for sorting. Not relevant. | ||
| ["fully-valid"] | Boolean | This property only exists if include_subordinates is true. It indicates if the AtS group is fully valid, meaning that the filter_group actually covers the item, or if it is only brought in because the AtS data includes the Sequence or Pathway specified in the filter_group, requiring further checks. | ||
pathwayListData
Helper function to iterate over Great Old Ones titles and the subsequence Pathways related to the Above the Sequence. This only covers the currently existing Above the Sequence groups. So Son of Chaos is not included. The order of this is constant, based on the
canonical_order property in Module:Sequence/ATS.Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| filter_group | filter_group | String/nil | Filters the result to certain attributes. This can be AtS title or earth or outer groups or the pathway name. If it's nil, then it simply includes everything. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| path data set | Array [Table] | List of pathway datas, according to the filters. | ||
pathwayList
Helper function to iterate over Great Old Ones titles and the subsequence Pathways related to the Above the Sequence. This only covers the currently existing Above the Sequence groups. So Son of Chaos is not included. The order of this is constant, based on the
canonical_order property in Module:Sequence/ATS.Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| filter_group | filter_group | String/nil | Filters the result to certain attributes. This can be AtS title or earth or outer groups or the pathway name. If it's nil, then it simply includes everything. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| path data set | Array [String] | List of pathway names, according to the filters. | ||
sequenceListData
Helper function to iterate over Great Old Ones titles and the subsequent Pathways related to the Above the Sequence and the subsequence Sequence of the Pathways, starting from 9-0. This only covers the currently existing Above the Sequence groups. So Son of Chaos is not included. The order of this is constant, based on the
canonical_order property in Module:Sequence/ATS.Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| filter_group | filter_group | String/nil | Filters the result to certain attributes. This can be AtS title or earth or outer groups or the pathway name. If it's nil, then it simply includes everything. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| seq data set | Array [Table] | List of sequence datas, according to the filters. | ||
sequenceList
Helper function to iterate over Great Old Ones titles and the subsequent Pathways related to the Above the Sequence and the subsequence Sequence of the Pathways, starting from 9-0. This only covers the currently existing Above the Sequence groups. So Son of Chaos is not included. The order of this is constant, based on the
canonical_order property in Module:Sequence/ATS.Function Parameters | ||||
|---|---|---|---|---|
| Parameters | Type | Description | Status | |
| Id | Label | |||
| filter_group | filter_group | String/nil | Filters the result to certain attributes. This can be AtS title or earth or outer groups or the pathway name. If it's nil, then it simply includes everything. | Default: false |
| Return Value | ||||
| Label | Type | Description | ||
| seq data set | Array [String] | List of sequence names, according to the filters. | ||
local sequenceATS = mw.loadData('Module:Sequence/ATS')
local sequenceBacklash = mw.loadData('Module:Sequence/Backlash')
local sequences_data = mw.loadData("Module:Sequence/seqPostProcess")
local pathways_data = mw.loadData("Module:Sequence/pathwaysPostProcess")
local helpers = require("Module:Helpers")
local p = {}
p.DELIM = "@;;@"
local function trimAndLower(text)
if text == nil then
return nil
end
text = helpers.trimWhitespace(text)
text = string.lower(text)
return text
end
----- Finder Methods -----
-- Helper function to find sequence in standard or non-standard data
function p.findSequence(name, do_throw)
name = trimAndLower(name)
local result = sequences_data[name]
if result ~= nil then return result end
if do_throw then error(string.format("Unknown Sequence '%s'.", name)) end
return nil
end
function p.findPathway(name, not_search_seq, do_throw)
name = trimAndLower(name)
local result = pathways_data[name]
if result ~= nil then return result end
-- Fallback to search the sequence.
-- Breaks away from recursion if it fails.
if not not_search_seq then
local sequence_data = p.findSequence(name, false)
-- Make sure there's something first.
if sequence_data ~= nil and sequence_data['pathway'] ~= nil then
-- Yeah it only does recursion once.
result = p.findPathway(sequence_data['pathway'], true, do_throw)
if result ~= nil then return result end
if do_throw then
error(string.format(
"Unknown Pathway '%s' of Sequence '%s'.",
name,
sequence_data['pathway']
))
end
end
end
if do_throw then error(string.format("Unknown Pathway '%s'.", name)) end
return nil
end
function p.findAts(name, do_throw)
name = trimAndLower(name)
local result = sequenceATS[name]
if result ~= nil then return result end
if do_throw then error(string.format("Unknown AtS '%s'.", name)) end
return nil
end
function p.atsGroupOf(name) -- Compatible with the sequence name, pathway name, or the ats name.
local seq_data = p.findSequence(name)
if seq_data ~= nil and seq_data['pathway'] ~= nil then
name = seq_data['pathway']
end
local pathway_data = p.findPathway(name)
if pathway_data ~= nil and pathway_data['ats'] ~= nil then
name = pathway_data['ats']
end
local ats_data = p.findAts(name)
if ats_data ~= nil ~= nil then
return ats_data
else
return nil
end
end
function p.seqNamesToDatas(seq_id_set, dont_throw_invalids, pathway_name)
local sequences = {}
-- This is way way better than the old, I'm iterating over the sequences from pathway data itself now.
-- Unlike last time where I index through most of the sequence data.
for i, seq_name in ipairs(seq_id_set) do
local seq_data = p.findSequence(seq_name)
if seq_data == nil and not dont_throw_invalids then
local err_str = string.format("Unknown sequence '%s'", seq_name)
if pathway_name ~= nil then
err_str = err_str .. string.format(" of '%s Pathway'", pathway_name)
end
err_str = err_str .. "."
error(err_str)
end
table.insert(sequences, seq_data)
end
-- Sort sequences by rank in descending order (from 9 to 0)
table.sort(sequences, function(a, b)
return tonumber(a.seq_rank) > tonumber(b.seq_rank) -- Sort by rank in descending order
end)
return sequences
end
function p.pathwaySequences(pathway_name, dont_throw_if_not_found, dont_throw_invalids)
local pathway_data = p.findPathway(pathway_name)
if pathway_data == nil and (not dont_throw_if_not_found) then
error(string.format("Unknown pathway '%s'", pathway_name))
end
local seq_id_set = pathway_data['sequence_ids']
if seq_id_set == nil then return {} end
return p.seqNamesToDatas(seq_id_set, dont_throw_invalids, pathway_name)
end
----- Helper Functions for List Methods -----
function p.checkEntiretyGroup(filter_group)
local everything = { [".all"] = true, [".everything"] = true, ["nil"] = true, [""] = true }
if filter_group == nil then return true end
if everything[filter_group] then return true end
end
function p.checkAtsGroup(filter_group, item, include_subordinates)
if p.checkEntiretyGroup(filter_group) then return true end
local earth_only = { ["earth"] = true, ["oc"] = true, ["original creator"] = true, ["original_creator"] = true, ["standard"] = true, }
local outer_deity = { ["outer"] = true, ["outer deity"] = true, ["outer_deity"] = true, ["od"] = true, ["nonstandard"] = true, ["non-standard"] = true, ["non standard"] = true, }
if item.from_earth and earth_only[filter_group] then return true end
if not item.from_earth and outer_deity[filter_group] then return true end
local ats = p.findAts(filter_group)
if ats == nil and include_subordinates then
ats = p.atsGroupOf(filter_group)
end
if ats ~= nil then
local ats_title = ats['ats_title']
local ats_title2 = item['ats_title']
if ats_title ~= nil and ats_title == ats_title2 then return true end
end
return false
end
-- This function is incomplete, it needs to be complemented by the function above.
function p.checkPathwayGroup(filter_group, pathway_item)
local function bytes(s)
return (s:gsub(".", function(c)
return string.byte(c) .. " "
end))
end
if filter_group == nil then return true end
local pathway_filter = p.findPathway(filter_group)
if pathway_filter ~= nil then
local name_id1 = pathway_filter["@name_id"]
local name_id2 = pathway_item["@name_id"]
if name_id1 ~= nil and name_id1 == name_id2 then return true end
end
return false
end
function p.atsList(filter_group, include_subordinates)
filter_group = trimAndLower(filter_group)
local ats = {}
local known_titles = {}
for key, ats_item in pairs(sequenceATS) do
if ats_item.canonical_order ~= nil and p.checkAtsGroup(filter_group, ats_item, include_subordinates) and not known_titles[ats_item.ats_title] then
local to_insert = {
name = ats_item.ats_title,
ref_name = key,
data = ats_item,
canonical_order = tonumber(ats_item.canonical_order)
}
if include_subordinates then
to_insert["fully-valid"] = p.checkAtsGroup(filter_group, ats_item, false)
end
table.insert(ats, to_insert)
known_titles[ats_item.ats_title] = true
end
end
table.sort(ats, function(a, b)
return a.canonical_order < b.canonical_order
end)
return ats
end
-- Returns a set of names.
function p.pathwayListData(filter_group)
filter_group = trimAndLower(filter_group)
local pathways = {}
for _, ats_item in ipairs(p.atsList(filter_group, true)) do
local is_valid = ats_item["fully-valid"]
if is_valid == nil then
errror("Function error. Property 'fully-valid' should not be nil.")
end
for _, pathway_name in ipairs(ats_item.data['related_pathway'] or {}) do
local pathway_data = p.findPathway(pathway_name)
local is_valid_pathway = is_valid or p.checkPathwayGroup(filter_group, pathway_data)
if is_valid_pathway then
table.insert(pathways, pathway_data)
end
end
end
return pathways
end
function p.pathwayList(filter_group)
local pathway_datas = p.pathwayListData(filter_group)
for i, data in ipairs(pathway_datas) do
pathway_datas[i] = data["@name_id"]
end
return pathway_datas
end
-- This one is uncapable of filtering by sequence. Would be a pain to do because validation had to be redone.
function p.sequenceListData(filter_group)
filter_group = trimAndLower(filter_group)
local sequences = {}
for _, pathway_item in ipairs(p.pathwayListData(filter_group)) do
for _, sequence_name in ipairs(pathway_item['sequence_ids'] or {}) do
local sequence_item = p.findSequence(sequence_name)
if sequence_item ~= nil then
table.insert(sequences, sequence_item)
end
end
end
return sequences
end
function p.sequenceList(filter_group)
local sequence_datas = p.sequenceListData(filter_group)
for i, data in ipairs(sequence_datas) do
sequence_datas[i] = data["@name_id"]
end
return sequence_datas
end
function p.compileAdvancementBacklash(sequence_name, use_headers)
function compileInternal(subitem)
local paragraphs = subitem["p"]
function paragraph_connect(curr_p)
local lines_out = {}
table.insert(lines_out, '<blockquote style="text-align: justify;">')
local flag = nil -- Unused feature for now, planning to do something with it.
for _, t in ipairs(curr_p) do
if type(t) == "number" then
flag = t
-- Unused feature. Numbers are index to flag the next paragraph.
elseif type(t) == "string" then
local s = t:match("^%s*(.-)%s*$")
if #s > 0 then
if s:sub(1, 2) == "{{" and s:sub(-2) == "}}" then
table.insert(lines_out, s)
elseif s:sub(1, 1) == "<" and s:sub(-1) == ">" then
table.insert(lines_out, s)
else
table.insert(lines_out, string.format("<p>%s</p>", s))
end
end
elseif type(t) == "table" then
local str_subparagraph = paragraph_connect(t)
table.insert(lines_out, str_subparagraph)
end
if type(t) ~= "number" then
flag = nil
end
end
table.insert(lines_out, '</blockquote>')
return table.concat(lines_out, "\n")
end
local str_paragraph = paragraph_connect(paragraphs)
if #str_paragraph == 0 then
return nil
end
local heading = subitem["header"] or "—"
if use_headers then
heading = string.format('<h3>%s</h3>', heading)
else
heading = string.format('<b><i>%s</i></b>', heading)
end
return heading .. "\n" .. str_paragraph
end
local set = {}
local backlash = sequenceBacklash[sequence_name]
if backlash == nil then
return nil
end
for _, description_group in ipairs(backlash) do
local result = compileInternal(description_group)
if result ~= nil then
table.insert(set, result)
end
end
if #set == 0 then
return nil
end
return table.concat(set, "\n<br/>\n")
end
function p.printMainIngr(data, seq_name)
local main_ingr_input = data.main_ingr
local seq_rank = tonumber(data.seq_rank)
seq_name = data['@name_id'] or seq_name
if not seq_rank then
return nil
end
local main_ingr = ""
local additional_text = '[[Beyonder Characteristic|Потусторонняя черта]] <b>{{seq|' .. seq_name .. '}}</b>'
if seq_rank ~= 0 then
if main_ingr_input ~= nil then
main_ingr = string.format([=[
<div>%s</div>
<ul>
<div style="font-style: italic; color:gray;margin-top:-1.2em">Или</div>
<li>%s.</li>
</ul>
]=],
main_ingr_input,
additional_text)
else
main_ingr = string.format("<ul><li>%s</li></ul>", additional_text)
end
else
-- Find the Seq 1 name of this pathway
local pathway_name = data['pathway']
local pathway_data = p.findPathway(pathway_name)
local seq_1_name = pathway_data['sequence_ids'][9]
main_ingr = string.format([=[
<ul>
<li>%s</li>
<li>%s</li>
</ul>
]=],
"{{Uniqueness|" .. seq_name .. "}}.",
"Три [[Beyonder Characteristics|потусторонние черты]] <b>{{Seq|" .. seq_1_name .. "}}</b>.")
end
return main_ingr
end
function p.dataNameFormat(data, key_name, alt_name_handling)
local name_id = data["@name_id"] or key_name
local alt_name_id = nil
if data["@key_to_alt_name"] ~= nil then
alt_name_id = data["@key_to_alt_name"][string.lower(key_name)]
end
if alt_name_handling == "use_common" then
return name_id
elseif alt_name_handling == "parenthesis" then
if alt_name_id == nil or name_id == alt_name_id then
return name_id
else
return string.format("%s (%s)", name_id, alt_name_id)
end
else
return alt_name_id or name_id
end
end
-- [ru] Russian display helpers
p.SEQ_LABEL = "Последовательность"
p.ATS_TYPE_RU = { ["Great Old One"] = "Великий Древний", ["Sefirah"] = "Сефира", ["Outer Deity"] = "Внешнее Божество" }
-- Display name of a sequence: prefers the Russian name, falls back to the English (or alt) name.
function p.dataDisplayName(data, key_name, alt_name_handling)
if data ~= nil and data["name_ru"] ~= nil then
return data["name_ru"]
end
return p.dataNameFormat(data, key_name or data["@name_id"], alt_name_handling)
end
function p.atsDisplayName(ats_data)
if ats_data == nil then return nil end
return ats_data["ats_title_ru"] or ats_data["ats_title"]
end
function p.atsTypeDisplay(ats_type)
if ats_type == nil then return nil end
return p.ATS_TYPE_RU[ats_type] or ats_type
end
-- "Путь Шута" for a pathway data table (or a pathway name string).
function p.pathwayDisplayName(pathway)
if type(pathway) == "string" then
local data = p.findPathway(pathway)
if data == nil then return pathway end
pathway = data
end
if pathway == nil then return nil end
return pathway["name_ru_full"] or ((pathway["@name_id"] or "?") .. " Pathway")
end
function p.dataNames(data, exclude_primary, include_annotation, cards_name_handling)
local name_list = {}
function appendToList(name, annotation)
if name == nil then return end
if cards_name_handling == "use_common" or
cards_name_handling == "use_alt"
then
local card_name = p.dataNameFormat(data, name, cards_name_handling)
name = p.generateSequenceCardBlock(card_name, name, name)
end
if include_annotation and annotation ~= nil then
name = name .. annotation
end
table.insert(name_list, name)
end
if not exclude_primary then
appendToList(data["@name_id"], data['name_annotation'])
end
local alt_names = data['alt_names']
if alt_names ~= nil then
for _, item in ipairs(alt_names) do
if type(item) == 'string' then
appendToList(item, nil)
elseif type(item) == 'table' then
appendToList(item['name'], item['annotation'])
end
end
end
return name_list
end
function p.dataNameInfos(data, exclude_primary)
local infos_list = {}
if not exclude_primary then
table.insert(
infos_list,
{
["name"] = data["@name_id"],
["annotation"] = data['name_annotation'],
['flag'] = data['name_flag'],
['ref'] = data['name_ref'],
['cn'] = data['name_cn'],
['romanised'] = data['name_romanised'],
}
)
end
local alt_names = data['alt_names']
if alt_names ~= nil then
for _, item in ipairs(alt_names) do
if type(item) == 'string' then
table.insert(infos_list, { ["name"] = name, })
elseif type(item) == 'table' then
table.insert(
infos_list,
{
["name"] = item['name'],
["annotation"] = item['annotation'],
['flag'] = item['flag'],
['ref'] = item['ref'],
['cn'] = item['cn'],
['romanised'] = item['romanised'],
}
)
end
end
end
return infos_list
end
function p.trimPathwayText(str)
str = str:gsub("[Pp][Aa][Tt][Hh][Ww][Aa][Yy]", "")
return helpers.trimWhitespace(str)
end
function p.generateSequenceCardBlock(data_arguments, display_name, link)
if type(data_arguments) == 'table' then
data_arguments = table.concat( data_arguments, p.DELIM )
end
link = link or display_name
return string.format([[<span class="sequence-tooltip" data-seq="%s" data-text="%s">%s</span>]], data_arguments, display_name, link)
end
return p