Module:Sandbox/AbstractWikipedia/Relations
This is the relatons module of the Abstract Wikipedia template-renderer prototype.
You can define here new relations to be used in the template language.
A relation always takes two arguments, source
and target
, of type lexeme
, as defined in the Module:Sandbox/AbstractWikipedia/Lexemes module. Then it can verify the lexemes' part of speech using the verifyPOS
function and unify features of the two lexemes using the unifyFeatures
function defined in the Module:Sandbox/AbstractWikipedia/UnifiableFeatures module.
The relations used should normally be defined as corresponding to Universal Dependencies or Surface-Syntactic Universal Dependencies but there is no formal limitation.
Language-specific implementations
[edit]You may override and define language-specific relations language sub-modules. Currently the following are implemented:
- Module:Sandbox/AbstractWikipedia/Relations/he for Hebrew.
- Module:Sandbox/AbstractWikipedia/Relations/zu for Zulu.
local p = {}
l = require("Module:Sandbox/AbstractWikipedia/Lexemes")
-- In this file we define relations to be applied on slot of templates
-- Each relation takes two lexeme arguments (source and target) and applies a
-- a sequence of unification instructions on them.
-- In this proto-type version there are no embedded templates, so we don't need
-- to deal with extracting the root from a sub-tree of lexemes.
-- There should also be language-specific implementation of relations, but this
-- is not implemented yet
-- Verifies that the lexeme's part of speech matches the desired one (TODO: implement using unification)
local function verifyPOS( lexeme, part_of_speech)
-- We allow non-set POS (as well as plain text) to match everything
if (lexeme.pos and lexeme.pos ~= '' and lexeme.pos ~= 'text' and lexeme.pos ~= part_of_speech ) then
error("Lexeme's part of speech "..lexeme.pos.." is not "..part_of_speech, 2)
end
return
end
-- Cross reference
function p.cross ( source, target )
l.unifyFeatures("number", source, target)
l.unifyFeatures("gender", source, target)
end
-- General agreement relation
function p.agr ( source, target)
p.cross ( source, target )
l.unifyFeatures("case", source, target)
end
-- Attributive/adjectival complement
-- A complement of a copula that should agree with the subject
function p.acomp ( source, target )
verifyPOS(source, "verb")
l.unifyFeatures("number", source, target)
l.unifyFeatures("gender", source, target)
-- Many mark the attribute as nominative but some (e.g. Arabic) mark it
-- as accusative. Sometimes a special predicative form is used.
l.unifyWithFeature("case", target, "nominative")
end
-- Adjectival modifier
function p.amod ( source, target)
-- Some adjectives are classified as Nouns in Wikidata, hence this is disabled.
-- verifyPOS(target, "adjective")
p.agr(source, target)
end
-- Relation between the first element in a list of conjunctions, and any other
-- element in the list. We assume that by default this requires agreement; if
-- not, don't use this relation.
function p.conj (source, target)
p.agr(source, target)
end
-- Relation between a noun and its determiner
function p.det (source, target)
verifyPOS(source, "noun")
p.agr (source, target)
l.unifyFeatures("definiteness", source, target)
end
-- Relation that enforces number agreement only between source and target
function p.num ( source, target )
l.unifyFeatures("number", source, target)
end
-- Relation between a numeral modifier (e.g. cardinal number) and a noun
function p.nummod ( source, target)
verifyPOS(source, "noun")
verifyPOS(target, "numeral")
l.unifyFeatures("number", source, target)
end
function p.subj ( source, target )
verifyPOS(source, "verb")
-- verifyPOS(target, "noun") -- Activate this once we allow subsumption of parts-of-speech, as it can also be a pronoun
l.unifyFeatures("person", source, target )
l.unifyFeatures("number", source, target )
l.unifyFeatures("gender", source, target )
l.unifyWithFeature("case", target, "nominative")
end
-- Tensed subject, for cases where the subject may have a nominal tense attached
-- to it.
function p.tsubj ( source, target )
p.subj ( source, target )
l.unifyFeatures("tense", source, target, "nominal_tense")
end
return p