Module:Infobox categorizer/doc

From Soyjak Wiki, the free ensoyclopedia
Jump to navigationJump to search

This is the documentation page for Module:Infobox categorizer

This module is a shared toolkit metamodule for modules that assign categories from infobox parameters. It provides the ability to "read" infobox fields, matching aliases, handling overrides and suppression, and creating category links. This module does not decide what the information it reads means, instead, submodules specifically tailored for an infobox must supply that logic and interpretation. Submodules must also decide which configuration(s) to load[a][b], and which categories to add. The toolkit does not render an infobox, nor does it have a main function. Therefore, it cannot be invoked directly, per design.

reading infobox values

[edit source]
You need to have some experience with Lua to be able to understand anything below this section, or if you want to make a submodule.
function result
trim(value) Converts a value to trimmed text. nil becomes an empty string.
normalize(value, mode) Lowercases text. Default or compact removes nonword characters. spaced replaces runs of them with spaces, if you need that.
clean(value) Returns text for matching. It will remove references, hidden markers, comments, and tags. It substitutes displayed wikilink text and external link labels removes bare HTTP(S) urls and decodes entities. It is an analysis aid only.
findYears(value) finds distinct[c] four-digit years in the cleaned text, in encounter order.
findYearRanges(value) if the parameter you want to read recommends years be entered as YYYY - YYYY, use this function. It will find all distinct pairs, returning, for example, {{'2020', '2022'}, ...} . It does not expand or interpret ranges. -, em dash, whatever dash, all are supported.
findLinkTargets(value, opts) Returns distinct wikilink targets as prefixed page titles, ignoring display labels, refs, and fragments. Defaults to namespace 0, opts.namespaces changes the allowed list. It does not resolve redirects[d]
readDataAttr(value, name) Reads all data-cat-name attribute values produced by Module:CatMark. Returns a list of decoded strings. The name argument may only contain letters, digits, and hyphens. Read CatMark to learn more about using it.
parseNumber(value) Parses a signed decimal number after removing commas and whitespace. Returns nil if invalid.
pickBand(number, bands) Finds the eligible "band" with the greatest min and returns its name. Returns nil if none qualifies.

For pickBand, keep in mind that bands are records such as {min=100, name = '100 SoyBooru posts'}. In other words, the subject module decides which number to read and whether a band category applies.

Alias set handling

[edit source]

compileAliasSet(sets, options) (reported as CAS in errors) compiles an ordered list of sets. Each set is a list of category records, with aliases and, optionally, domains identifying each category. For CAS to function, sets must be wrapped, even if there is just one. Wrap them like this:

local subjectSites = {

{ category = '4chan', aliases = { '4chan', '4cuck' }, domains = { '4chan.org' } },

{ category = 'Soyjak.party', aliases = { 'sharty', 'soyjak.party' } },

}

local sharedSites = mw.loadData('Module:Infobox categorizer/sites')
local sites = core.compileAliasSet({ subjectSites, sharedSites })
local matches = core.matchAliasSets(args.frequented_sites, sites)

The order of the sets determine priority. The first set to claim an alias or domain will own that claim, later sets cannot assign the same claim to another category, in other words, that claim is occupied. Putting a subject's records before shared records lets the subject override "global" records. As an example, if a country set assigns "Frog" as an alias to France, and NAS sets "Frog" to Pepe, and both are loaded with the same matching mode & case setting (defaults mean this is likely, read more below), whichever set comes first will own "Frog". Keep this in mind with complicated infoboxes, since as time passes the list of aliases will grow and conflicting sets will become inevitable. You must choose what are the appropriate sets to load and their order.

After compilation, matchAliasSets(value, compiled) (reported as MAS in errors) searches an input for the compiled aliases and domains. It returns every matching category once. For example, an input containing "4cuck" and "sharty" can return both "4chan" and "soyjak.party". MAS returns allow the subject module to categorize a field containing several sites, countries, or other recognized values. Record with the same category label are merged during compilation.

Within a single set, two different categories cannot claim the same alias after normalization[e] or the same normalized domain. This is because each alias claim within a set must have one owner. Assigning "Frog" to both France and Pepe is contradictory, so CAS rejects the set with a config error. To fix this, remove or reassign the duplicate alias. If the competing sets are intentional, place them in separate sets and sort them by priority. In separately loaded sets, the conflicts are resolved by load order.

An alias can be a string or a record containing additional matching settings if the situation calls for it. For example, the country code for the United States is "US". To avoid false flag detection of "us", making "US" case sensitive prevents lowercase "us" from matching and exact matching requires the entire field to be "US" only. This is done with {'US', match = 'exact', caseSensitive = true}[f] The matching mode setting can be supplied through options.match, set.match, or entry.match, or the individual alias match setting. The more specific setting wins, the individual alias always has the highest priority. The default mode is word. Case sensitive-matching is enabled through caseSensitive = true on a record.

more snca to add later

Notes

  1. ↑ No records are loaded automatically. You can find a "registrar list" of records as subpages of this module or in a list below.
  2. ↑ When compiling provided alias sets, earlier sets will have priority over later sets for the same alias or domain, "ownership". Beware!
  3. ↑ Read more on Lua frontier patterns to understand what this means exactly.
  4. ↑ Avoid redirects with this thing like the plague, avoid redirects in general
  5. ↑ Under the same matching mode and case setting.
  6. ↑ Remember, wiki content is extremely unpredictable and things that seem minute as this are still a key issue that you have to consider.