Modul:Entity/Location/Vocabulary
Aus Star Citizen Wiki
Weitere Optionen
< Modul:Entity | Location
Diese Dokumentation wird von Modul:Entity/Location/Vocabulary/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
| Function list |
|---|
| L 59 — p.affiliationCompounds L 72 — p.systemsCategory L 80 — p.spaceText L 89 — p.shortPrefix L 99 — p.affiliationEntry L 121 — p.affiliationFromText L 167 — p.systemTypeEntry L 304 — p.starTypeEntry L 318 — p.starTypeLabel L 334 — p.starTypeLink L 355 — p.bodyTypeEntry L 408 — p.beltTypeEntry L 424 — p.beltTypeFromText L 438 — p.bodyTypeFromText L 449 — p.vocabularyFromText L 477 — p.starTypeFromText L 503 — p.resolveSystemType L 520 — p.resolveAffiliation L 535 — p.storedAffiliation |
Die Vokabulare der RSI-Starmap, so wie das Wiki sie nennt: Zugehörigkeiten sowie System-, Stern-, Körper- und Asteroidenformationstypen, jeder mit Label, Indexseite und Kategorie, plus die Resolver, die einen Starmap-Wert oder eine Editor-Formulierung auf einen Eintrag abbilden.
Editoren rufen dieses Modul nie direkt auf; es läuft innerhalb von Vorlage:Location oder Vorlage:Entity. Modul:SystemMap liest affiliationEntry</code für seinen Kartenkopf.
Für Modul-Editoren
API
p.AFFILIATIONS: Starmap-Zugehörigkeitscode (kleingeschrieben) → { label, short }. short ist die kompakte Form, die als Zugehörigkeitswert gespeichert wird (UEE, Unclaimed).
p.affiliationEntry(starsystem): der erste Zugehörigkeitseintrag des Starmap-Datensatzes.
p.affiliationFromText(text): redaktioneller Zugehörigkeitstext, gegen AFFILIATIONS abgeglichen (Code, Label oder Short, nach Normalisierung); Unbekanntes geht als freier Text durch.
p.STAR_TYPES: Starmap-sub_type.name → { classification, label?, category, page?, maxRadiusKm? }. classification ist zugleich der Indexseitentitel; maxRadiusKm die physikalische Decke gegen Phanton-Größen.
p.starTypeEntry(subType), p.starTypeLabel(subType), p.starTypeFromText(text), p.starTypeLink(entry, text): die Lookups des Sternvokabulars; starTypeLink verlinkt die Indexseite und zeigt den Text des Aufrufers.
p.BODY_TYPES: Planet-sub_type.name → { classification, category }. Monde tragen einen uniformen sub_type und haben keinen Eintrag.
p.BELT_TYPES: sub_type.name → { classification, category, page }; jeder Eintrag nennt page, weil die Familie eine Konzeptseite statt Typindizes hat.
p.beltTypeEntry(subType, objectType): das Formationsvokabular, mit Fallback auf das bloße type-Token nur bei fehlendem sub_type; ein ungemappter sub_type ergibt nil.
p.beltTypeFromText(text), p.bodyTypeEntry(subType), p.bodyTypeFromText(text): dieselben Vokabulare aus Editor-Formulierung; bodyTypeFromText matcht Wiki-Klassifizierung, ARK-Schreibweise und den Singular des Kategorienamens.
p.SYSTEM_TYPES: Systemtyp-Code → { label, category }.
p.systemTypeEntry(text): redaktioneller Systemtyp-Text, normalisiert (Groß-/Kleinschreibung, Trenner) und nachgeschlagen; Unbekanntes löst zu nichts auf.
p.resolveSystemType(starsystem, resolved): der redaktionelle Wert schlägt den Starmap-Datensatz; ein ungemappter Datensatz-Code kehrt trotzdem zurück, damit treu gespeichert wird.
p.resolveAffiliation(starsystem, resolved), p.storedAffiliation(starsystem, resolved): dieselbe redaktionelle Präzedenz; storedAffiliation liefert das kompakte Token nur aus dem ersten <br>-Segment, weil die Spalte einwertig ist.
require('strict')
--- @module Entity/Location/Vocabulary
--- The RSI starmap's vocabularies as the wiki names them: affiliations, and
--- system, star, body and asteroid-formation types, each with the label, index
--- page and category the wiki uses, plus the resolvers that map a starmap value
--- or an editor's wording onto an entry. Shared by the Location leaves and
--- Module:SystemMap.
local editorial = require('Module:Entity/Editorial')
local p = {}
--- RSI starmap affiliation code (lowercased) -> display data. `label` is the
--- display/link name in the wiki's German article spelling where the article
--- exists (Banu Protektorat, Xi'an-Imperium, Vanduul); the UEE keeps its
--- English article title, the community's universal short form. `short`
--- (falling back to label) is the compact form used in short descriptions
--- AND stored as the `Affiliation` value - it matches the vocabulary the ~266
--- pre-Entity pages already store ('UEE', 'Unclaimed'), so queries keep one
--- bucket. `aliases` carries the further spellings the German template args
--- use, canonical and legacy English included, so editors may write either
--- language. 'Unknown' is canonical so the German composition words resolve;
--- `display` keeps it unlinked exactly as the free-text rule wants (an
--- auto-link would paint a red [[Unknown]]), and `link = false` does the
--- same for the labels without a German article (unc, dev).
p.AFFILIATIONS = {
uee = { label = 'United Empire of Earth', short = 'UEE', aliases = { 'Vereinigtes Imperium der Erde' } },
unc = { label = 'Unbeansprucht', link = false, aliases = { 'Unclaimed' } },
banu = { label = 'Banu Protektorat', aliases = { 'Banu Protectorate' } },
xian = { label = "Xi'an-Imperium", aliases = { "Xi'an Empire", "Xi'an-Reich", "Xi'an" } },
vncl = { label = 'Vanduul' },
dev = { label = 'In Entwicklung', link = false, aliases = { 'Developing' } },
unknown = { label = 'Unknown', display = 'Unbekannt', aliases = { 'Unbekannt' } },
}
--- German display compositions per affiliation code: the breadcrumb's space
--- tier, the systems browse category and the short-description prefix. The
--- entry words above stay English (link targets, stored values), so these
--- carry the German separately; adjectival affiliations spell their agreed
--- form out because German compounds do not take adjectives. A nil `prefix`
--- (developing) drops the short-description affix rather than mis-compose it.
--- Free text never reaches this table: callers compose it directly.
p.AFFILIATION_COMPOUNDS = {
uee = { space = 'UEE-Raum', systems = 'UEE-System', prefix = 'UEE-' },
unc = { space = 'Unbeanspruchter Raum', systems = 'Unbeanspruchtes System', prefix = 'Unbeanspruchtes ' },
banu = { space = 'Banu-Raum', systems = 'Banu-System', prefix = 'Banu-' },
xian = { space = "Xi'an-Raum", systems = "Xi'an-System", prefix = "Xi'an-" },
vncl = { space = 'Vanduul-Raum', systems = 'Vanduul-System', prefix = 'Vanduul-' },
dev = { space = 'Raum in Entwicklung', systems = 'System in Entwicklung' },
unknown = { space = 'Unbekannter Raum', systems = 'Unbekanntes System' },
}
--- The compounds for an affiliation entry, by table identity: resolveAffiliation
--- returns the entry without its code, and identity is the one reliable way
--- back to it. nil for a free-text entry.
--- @param entry table|nil
--- @return table|nil
function p.affiliationCompounds(entry)
for code, candidate in pairs(p.AFFILIATIONS) do
if candidate == entry then
return p.AFFILIATION_COMPOUNDS[code]
end
end
return nil
end
--- The German systems browse category for an affiliation entry: the canonical
--- word where one exists, else the free-text label compounds ("Kr'Thak-System").
--- @param entry table
--- @return string
function p.systemsCategory(entry)
local compounds = p.affiliationCompounds(entry)
return compounds and compounds.systems or (entry.label .. '-System')
end
--- The German breadcrumb tier-1 text ("UEE-Raum").
--- @param entry table
--- @return string
function p.spaceText(entry)
local compounds = p.affiliationCompounds(entry)
return compounds and compounds.space or ((entry.short or entry.label) .. '-Raum')
end
--- The German short-description prefix ("UEE-"), or nil where the affiliation
--- does not prefix (free text, developing, unknown).
--- @param entry table
--- @return string|nil
function p.shortPrefix(entry)
local compounds = p.affiliationCompounds(entry)
return compounds and compounds.prefix or nil
end
--- First affiliation entry for a starmap record, or nil. The single accessor
--- every consumer (link row, categories, structured data, short description) goes
--- through.
--- @param starsystem table|nil
--- @return { label: string, short: string|nil }|nil
function p.affiliationEntry(starsystem)
local affiliation = type(starsystem) == 'table'
and type(starsystem.affiliation) == 'table'
and starsystem.affiliation[1]
or nil
local code = affiliation and type(affiliation.code) == 'string' and affiliation.code:lower() or nil
return code and p.AFFILIATIONS[code] or nil
end
--- Editorial affiliation text → an AFFILIATIONS-shaped entry. Canonical names
--- resolve to their table entry, matched on code, label or short after
--- normalizing case and punctuation, so the legacy arg spellings land in one
--- bucket ('Xi'An' → the xian entry, 'UEE' → uee). Anything else passes
--- through as free text: the starmap vocabulary has no code for the
--- affiliations only lore knows (Kr'Thak), and the legacy template
--- accepted them, so the kind must too. A free-text entry keeps the editor's
--- markup for display (they choose whether [[Kr'Thak]] links; auto-linking
--- would paint free wording red) while `label` carries the delinked text for
--- the category and the stored value. `display` on a CANONICAL entry (unknown)
--- means the same thing: render this text instead of auto-linking the label.
--- @param text any
--- @return { label: string, short: string|nil, display: string|nil }|nil
function p.affiliationFromText(text)
if type(text) ~= 'string' or mw.text.trim(text) == '' then
return nil
end
text = mw.text.trim(text)
local plain = editorial.toStoredValue(text)
local key = plain:lower():gsub('[^%w]', '')
for code, entry in pairs(p.AFFILIATIONS) do
local forms = { code, entry.label }
if entry.short then
forms[#forms + 1] = entry.short
end
if entry.aliases then
for _, alias in ipairs(entry.aliases) do
forms[#forms + 1] = alias
end
end
for _, form in ipairs(forms) do
if key == form:lower():gsub('[^%w]', '') then
return entry
end
end
end
return { label = plain, display = text }
end
--- RSI starmap system type -> infobox display label + browse category. The
--- label doubles as the stored System type value, so it stays English; the
--- category is the German page name the wiki files under (singular, like the
--- rest of the tree).
p.SYSTEM_TYPES = {
SINGLE_STAR = { label = 'Single star system', category = 'Einsternsystem' },
BINARY = { label = 'Binary star system', category = 'Doppelsternsystem' },
-- Latent until the no-record trinary pages (GJ 667, UDS-2943-01-22)
-- migrated: no starmap-backed system is trinary.
TRINARY = { label = 'Trinary star system', category = 'Dreifachsternsystem' },
}
--- Editorial system-type text → normalized starmap code + SYSTEM_TYPES entry.
--- The legacy {{System}} pages hand-set the raw codes with case drift
--- ('SINGLE_STAR', 'TRINARY', 'Trinary'), so normalize case and separators
--- before the lookup. Unrecognized text resolves to nothing: a typo'd code
--- must not invent a type row, a category, or a stored value.
--- @param text any
--- @return string|nil code normalized starmap code ('TRINARY')
--- @return { label: string, category: string }|nil entry
function p.systemTypeEntry(text)
if type(text) ~= 'string' or text == '' then
return nil, nil
end
local trimmed = mw.text.trim(text)
local code = trimmed:upper():gsub('[%s%-]+', '_')
local entry = p.SYSTEM_TYPES[code]
if not entry then
-- The German browse nouns ('Dreifachsternsystem') and the English
-- labels ('Single star system') name the same codes as the raw codes.
local key = editorial.toStoredValue(trimmed):lower():gsub('[^%w]', '')
for candidateCode, candidate in pairs(p.SYSTEM_TYPES) do
local label = candidate.label:lower():gsub('[^%w]', '')
local category = candidate.category:lower():gsub('[^%w]', '')
if key == label or key == category then
return candidateCode, candidate
end
end
return nil, nil
end
return code, entry
end
--- RSI starmap `sub_type.name` -> star vocabulary: `classification` is the star
--- page's subtitle and stored value, `label` (default: classification) the
--- compact form the system's "Star type" row shows, `page` (default:
--- classification) the index page both link to, `category` the spectral-type
--- category. classification and label stay English (stored Subject type);
--- display sites localize them through msg(), and the categories are German
--- page names, singular like the rest of the tree.
---
--- `maxRadiusKm` is declared only where the physics pins the size down, because
--- Tanga's white dwarf carries 58,460,000 km — byte-identical to La'uo's M
--- giant, so a copy-paste — and would otherwise render as an 84-solar-radius
--- white dwarf. Main-sequence and giant ranges overlap too much to police.
---
--- 'Stellar' is black-hole vocabulary, not a star class: the ARK uses it as the
--- sub_type of its one BLACKHOLE-typed object (Tamsa).
---
--- Every white dwarf the ARK serves is `Degenerate-A`, and that letter is NOT
--- the temperature class the main-sequence letters are — on a degenerate
--- remnant it denotes atmospheric composition. "A-type white dwarf" would
--- invite exactly that confusion, so the class is simply "White dwarf".
p.STAR_TYPES = {
['Main Sequence-Dwarf-O'] = {
classification = 'O-type main-sequence star',
label = 'O-type main-sequence',
category = 'O-Hauptreihenstern',
},
['Main Sequence-Dwarf-B'] = {
classification = 'B-type main-sequence star',
label = 'B-type main-sequence',
category = 'B-Hauptreihenstern',
},
['Main Sequence-Dwarf-A'] = {
classification = 'A-type main-sequence star',
label = 'A-type main-sequence',
category = 'A-Hauptreihenstern',
},
['Main Sequence-Dwarf-F'] = {
classification = 'F-type main-sequence star',
label = 'F-type main-sequence',
category = 'F-Hauptreihenstern',
},
['Main Sequence-Dwarf-G'] = {
classification = 'G-type main-sequence star',
label = 'G-type main-sequence',
category = 'G-Hauptreihenstern',
},
['Main Sequence-Dwarf-K'] = {
classification = 'K-type main-sequence star',
label = 'K-type main-sequence',
category = 'K-Hauptreihenstern',
},
['Main Sequence-Dwarf-M'] = {
classification = 'M-type main-sequence star',
label = 'M-type main-sequence',
category = 'M-Hauptreihenstern',
},
['Giants-Giant-M'] = { classification = 'M-type giant', category = 'M-Riese' },
['White Dwarf-Degenerate-A'] = {
classification = 'White dwarf',
category = 'Weißer Zwerg',
maxRadiusKm = 20000,
},
Subgiant = {
classification = 'Subgiant star',
label = 'Subgiant',
page = 'Subgiant',
category = 'Unterriese',
},
Neutron = { classification = 'Neutron star', category = 'Neutronenstern', maxRadiusKm = 50 },
Variable = { classification = 'Variable star', category = 'Veränderlicher Stern' },
Stellar = { classification = 'Stellar black hole', page = 'Black hole', category = 'Schwarzes Loch' },
}
--- RSI starmap planet `sub_type.name` -> body vocabulary, the planet counterpart
--- of STAR_TYPES. `classification` doubles as the index page title and stays
--- English (the stored Subject type; display sites localize through msg());
--- `category` is the German page name, singular like the rest of the tree.
--- The ARK spells its sub_types in Title Case while the wiki uses sentence case
--- ('Smog Planet' -> 'Smog planet'), so these cannot be derived from the ARK
--- string. 'Artificial', 'Super Jupiter' and 'Terrestrial Rocky' are the three
--- the ARK does not name the way the wiki does at all. Moons carry a uniform
--- 'Planetary Moon' sub_type and so have no type tree; the Body leaf handles
--- them from the record type instead.
p.BODY_TYPES = {
['Artificial'] = { classification = 'Artificial planet', category = 'Künstlicher Planet' },
['Carbon Planet'] = { classification = 'Carbon planet', category = 'Kohlenstoffplanet' },
['Chthonian Planet'] = { classification = 'Chthonian planet', category = 'Chthonischer Planet' },
['Coreless Planet'] = { classification = 'Coreless planet', category = 'Kernloser Planet' },
['Desert Planet'] = { classification = 'Desert planet', category = 'Wüstenplanet' },
['Dwarf Planet'] = { classification = 'Dwarf planet', category = 'Zwergplanet' },
['Evaporating Planet'] = { classification = 'Evaporating planet', category = 'Verdampfender Planet' },
['Gas Dwarf'] = { classification = 'Gas dwarf', category = 'Gaszwerg' },
['Gas Giant'] = { classification = 'Gas giant', category = 'Gasriese' },
['Ice Giant'] = { classification = 'Ice giant', category = 'Eisriese' },
['Ice Planet'] = { classification = 'Ice planet', category = 'Eisplanet' },
['Iron Planet'] = { classification = 'Iron planet', category = 'Eisenplanet' },
['Lava Planet'] = { classification = 'Lava planet', category = 'Lavaplanet' },
['Mesoplanet'] = { classification = 'Mesoplanet', category = 'Mesoplanet' },
['Ocean Planet'] = { classification = 'Ocean planet', category = 'Ozeanplanet' },
['Protoplanet'] = { classification = 'Protoplanet', category = 'Protoplanet' },
['Puffy Planet'] = { classification = 'Puffy planet', category = 'Aufgeblähter Planet' },
['Rogue Planet'] = { classification = 'Rogue planet', category = 'Waisenplanet' },
['Smog Planet'] = { classification = 'Smog planet', category = 'Smogplanet' },
['Super Jupiter'] = { classification = 'Super-Jupiter', category = 'Superjupiter' },
['Super-Earth'] = { classification = 'Super-Earth', category = 'Supererde' },
['Terrestrial Rocky'] = { classification = 'Terrestrial rocky planet', category = 'Terrestrischer Gesteinsplanet' },
}
--- The STAR_TYPES entry for a celestial object's sub_type, accepting either the
--- sub_type table the starmap serves or its bare name. nil for an unmapped or
--- absent class — callers decide whether that means the raw upstream name
--- (the system's star-type row) or no claim at all (the star page's subtitle).
--- @param subType table|string|nil
--- @return { classification: string, label: string|nil, category: string }|nil
function p.starTypeEntry(subType)
local name = type(subType) == 'table' and subType.name or subType
if type(name) ~= 'string' or name == '' then
return nil
end
return p.STAR_TYPES[name]
end
--- The compact "Star type" label for a sub_type: the vocabulary's short form,
--- its classification where it has none, else the raw upstream name — an
--- unmapped ARK class degrades to a visible string instead of vanishing, and
--- self-heals once STAR_TYPES learns it.
--- @param subType table|string|nil
--- @return string|nil
function p.starTypeLabel(subType)
local entry = p.starTypeEntry(subType)
if entry then
return entry.label or entry.classification
end
local name = type(subType) == 'table' and subType.name or subType
return type(name) == 'string' and name ~= '' and name or nil
end
--- A star or body type linked to its index page. `text` is the caller's own
--- wording (the leaf's classification, the system row's label, an editor's
--- phrasing), so one target serves every surface. Plain text when the entry
--- names no page, which keeps an unmapped ARK class from linking at nothing.
--- @param entry table|nil a STAR_TYPES or BODY_TYPES entry
--- @param text string|nil display wording
--- @return string|nil
function p.starTypeLink(entry, text)
if type(text) ~= 'string' or text == '' then
return nil
end
-- category is the German page name the German wiki links; page and
-- classification stay as .tools-era fallbacks for entries without one.
local page = entry and (entry.category or entry.page or entry.classification) or nil
if type(page) ~= 'string' or page == '' then
return text
end
if page == text then
return '[[' .. page .. ']]'
end
return '[[' .. page .. '|' .. text .. ']]'
end
--- The BODY_TYPES entry for a planet's sub_type, accepting the sub_type table or
--- its bare name. nil for a moon (uniform 'Planetary Moon', no type tree) and
--- for an unmapped class.
--- @param subType table|string|nil
--- @return { classification: string, category: string }|nil
function p.bodyTypeEntry(subType)
local name = type(subType) == 'table' and subType.name or subType
if type(name) ~= 'string' or name == '' then
return nil
end
return p.BODY_TYPES[name]
end
--- RSI starmap `sub_type.name` -> asteroid-formation vocabulary, the third of
--- these tables. `classification` is the display noun and doubles as the index
--- page title (English: stored Subject type, localized at display sites);
--- `category` is the German page name, singular like the rest of the tree.
---
--- All three sit under the Asteroidenformation container category. No entry
--- here names it, because a page belongs in its own leaf category; only
--- getTypeInfo's fallback emits it, for an object no entry resolves.
---
--- Every entry names `page` because this family has ONE concept page, not the
--- per-type index pages planets and stars have, and the page targets stay
--- English with the display localized: without `page` the subtitle would link
--- at nothing on every page this leaf renders.
p.BELT_TYPES = {
['System Belt'] = {
classification = 'Asteroid belt',
category = 'Asteroidengürtel',
page = 'Asteroid formation',
},
['System Cluster'] = {
classification = 'Asteroid cluster',
category = 'Asteroidenhaufen',
page = 'Asteroid formation',
},
-- 'Planetary ring system', not 'Planetary ring': the wording all ten pages
-- already carry, and the exact singular of their category.
['Planetary Ring'] = {
classification = 'Planetary ring system',
category = 'Planetares Ringsystem',
page = 'Asteroid formation',
},
}
--- The ARK object type to read when an object carries no sub_type. Only
--- ASTEROID_BELT ever lacks one, on 3 objects against the 55 that name 'System
--- Belt', so the token names the class rather than inventing it. Every
--- ASTEROID_FIELD names a sub_type, which is why none is mapped here.
local BELT_OBJECT_TYPE_CLASS = { ASTEROID_BELT = 'System Belt' }
--- The BELT_TYPES entry for a starmap object, from its sub_type where it has
--- one and its bare type token otherwise. Accepts the sub_type table or its
--- name. nil for an object with neither, which keeps the bare kind noun.
--- @param subType table|string|nil
--- @param objectType string|nil the object's ARK `type`, read only without a sub_type
--- @return { classification: string, category: string, page: string }|nil
function p.beltTypeEntry(subType, objectType)
local name = type(subType) == 'table' and subType.name or subType
if type(name) ~= 'string' or name == '' then
name = type(objectType) == 'string' and BELT_OBJECT_TYPE_CLASS[objectType] or nil
end
if type(name) ~= 'string' or name == '' then
return nil
end
return p.BELT_TYPES[name]
end
--- The BELT_TYPES entry an editor's classification text names, matching the
--- classification, the ARK's own spelling and the singular of the category, the
--- same three forms bodyTypeFromText accepts.
--- @param text string|nil
--- @return { classification: string, category: string, page: string }|nil
function p.beltTypeFromText(text)
return p.vocabularyFromText(p.BELT_TYPES, text)
end
--- The BODY_TYPES entry an editor's classification text names, the body
--- counterpart of starTypeFromText. It matches the wiki classification, the
--- ARK's own spelling and the singular of the category name, so 'Gas giant',
--- 'Gas Giant' and 'Terrestrial rocky planet' all resolve. The category form
--- is the one the corpus actually writes for several classes.
---
--- Without this a page whose ARK object is missing lands in no type category
--- while its subtitle still reads the class.
--- @param text string|nil
--- @return { classification: string, category: string }|nil
function p.bodyTypeFromText(text)
return p.vocabularyFromText(p.BODY_TYPES, text)
end
--- The entry an editor's wording names in one of these vocabularies, matching
--- the classification, the ARK's own spelling, or the English plural (the
--- category's former spelling, which the corpus writes on several classes).
--- Comparison is on alphanumerics only, so punctuation and case do not matter.
--- @param vocab table one of BODY_TYPES / BELT_TYPES / STAR_TYPES
--- @param text string|nil
--- @return table|nil
function p.vocabularyFromText(vocab, text)
if type(text) ~= 'string' or mw.text.trim(text) == '' then
return nil
end
local key = editorial.toStoredValue(mw.text.trim(text)):lower():gsub('[^%w]', '')
for arkName, entry in pairs(vocab) do
-- The plural is parenthesised because gsub also returns a count, which
-- the constructor would otherwise take as a fourth form. The category
-- is the German browse noun: the German template args carry it, so an
-- editor's 'Gasriese' resolves to the same entry as 'Gas giant'.
local forms = { entry.classification, arkName, (entry.classification .. 's'), entry.category }
for _, form in ipairs(forms) do
if key == form:lower():gsub('[^%w]', '') then
return entry
end
end
end
return nil
end
--- Editorial classification text → a STAR_TYPES entry, matched on either
--- wording after normalizing case and punctuation. The reverse of starTypeEntry,
--- and the only way a record-less star page reaches a spectral-type category.
--- Deliberately exact rather than fuzzy: Pyro's editorial "K-type main sequence
--- flare star" must NOT resolve here, because the starmap already classes Pyro
--- and the record wins the category (see the Star leaf's getCategories).
--- @param text any
--- @return { classification: string, label: string|nil, category: string }|nil
function p.starTypeFromText(text)
if type(text) ~= 'string' or mw.text.trim(text) == '' then
return nil
end
local key = editorial.toStoredValue(mw.text.trim(text)):lower():gsub('[^%w]', '')
for _, entry in pairs(p.STAR_TYPES) do
local classification = entry.classification:lower():gsub('[^%w]', '')
local label = entry.label and entry.label:lower():gsub('[^%w]', '') or nil
-- The category is the German browse noun, so the German template args
-- ('Weißer Zwerg') resolve like the English spellings.
local category = entry.category:lower():gsub('[^%w]', '')
if key == classification or key == label or key == category then
return entry
end
end
return nil
end
--- The system-type entry for a page: the editorial value when one resolved
--- (hand value beats starmap, the house rule), else the starmap record's.
--- Single accessor so the type row, categories, structured data and short description
--- cannot disagree.
--- @param starsystem table|nil
--- @param resolved table|nil
--- @return string|nil code
--- @return { label: string, category: string }|nil entry
function p.resolveSystemType(starsystem, resolved)
local code, entry = p.systemTypeEntry(editorial.view(resolved):value('systemtype'))
if entry then
return code, entry
end
-- The record's raw code is returned even when SYSTEM_TYPES has no entry
-- for it: an unmapped code still stores faithfully (a future ARK type
-- should degrade to no label/category, not vanish from the store).
local recordType = type(starsystem) == 'table' and starsystem.type or nil
return recordType, recordType and p.SYSTEM_TYPES[recordType] or nil
end
--- The affiliation entry for a page: editorial first (same precedence as
--- resolveSystemType), else the starmap record's.
--- @param starsystem table|nil
--- @param resolved table|nil
--- @return { label: string, short: string|nil, display: string|nil }|nil
function p.resolveAffiliation(starsystem, resolved)
return p.affiliationFromText(editorial.view(resolved):value('affiliation')) or p.affiliationEntry(starsystem)
end
--- The affiliation to STORE: the compact token, from the FIRST <br>-delimited
--- segment of the page's own value, else the system's.
---
--- The split is only for the stored side. A page may name two affiliations in
--- one arg ('[[Vanduul]]<br/>Independent' on Armitage) against a single-valued
--- column, and Editorial.toStoredValue strips the tag with no separator, so the
--- raw value would store as the unqueryable 'VanduulIndependent'. The DISPLAY
--- row keeps both, through resolveAffiliation, because the page said both.
--- @param starsystem table|nil
--- @param resolved table|nil
--- @return string|nil
function p.storedAffiliation(starsystem, resolved)
local stated = editorial.view(resolved):value('affiliation')
if type(stated) == 'string' then
stated = mw.text.split(stated, '<%s*[bB][rR]%s*/?%s*>')[1]
end
local entry = p.affiliationFromText(stated) or p.affiliationEntry(starsystem)
return entry and (entry.short or entry.label) or nil
end
return p

