Module:locutio

E Victionario

Documentation for this module may be created at Module:locutio/doc

-- Copy of the [[:fr:Module:locution]]
-- Modified and maintained by: Usor:DenisWasRight

local p = {}

local loc_languages = mw.loadData('Module:locutio/data')

function p.contains_space(word)
    if word==nil then return nil end
    if (mw.ustring.find(word, ". .") ~= nil) then
        return true
    else
        return false
    end
end

function p.is_phrase(args, article, lang)
	if article == nil or article.text == nil or args == nil then return false end
	local title = article.text
	
	-- Annexe ? Ne garde que la dernière sous-page
	if article.namespace==100 then
		title = mw.ustring.gsub(title, ".+\/", "")
	end
	
    -- Forcé par un paramètre
    if args['phrase'] then
    	_add_category('Victionarium:Section types with forced phrases')
 
    	if args['phrase'] == 'oui' then
    		return true
    	elseif args['phrase'] == 'non' then
    		return false
    	else
	    	_add_category('Victionarium:Sections with invalid phrase parameters')
    	end
	end
	
	-- Liste blanche : on peut deviner automatiquement
	if loc_languages[lang] then
		return p.guess_phrase(args, article, lang)
	else
		return false
	end
end

function p.guess_phrase(args, article, lang)
	if article == nil or article.text == nil or args == nil then return false end
	local title = article.text
	
    -- Cas spéciaux (par langue)
	if args[1] ~= nil and args[2] ~= nil then
		-- Verbes pronominaux français
		if args[2] == 'fr' and typ.get_name_singular(args[1]) == 'verbum' and mw.ustring.find(title, "^se ") then
			if mw.ustring.find(title, "^se [^ ]+ ") then
				return true
			else
				return false
			end
		-- Verbes pronominaux néerlandais
		elseif args[2] == 'nl' and typ.get_name_singular(args[1]) == 'verbum' and mw.ustring.find(title, "^zich ") then
			if mw.ustring.find(title, "^zich [^ ]+ ") then
					return true
				else
					return false
				end
		-- Verbes à particule néerlandais
		elseif args[2] == 'nl' and typ.get_name_singular(args[1]) == 'verbum'
		-- est-ce que le verbe finit par " aan", " achter", " af", etc ?
		and (mw.ustring.find(title, " aan$")
		or mw.ustring.find(title, " aaneen$")
		or mw.ustring.find(title, " achter") 
		or mw.ustring.find(title, " achterna$")
		or mw.ustring.find(title, " achterover$")
		or mw.ustring.find(title, " achteruit$")
		or mw.ustring.find(title, " achteruit$")
		or mw.ustring.find(title, " af$")
		or mw.ustring.find(title, " beet$")
		or mw.ustring.find(title, " bij$")  
		or mw.ustring.find(title, " bijeen$")
		or mw.ustring.find(title, " binnen$")
		or mw.ustring.find(title, " bloot$")
		or mw.ustring.find(title, " boven$")
		or mw.ustring.find(title, " buiten$")
		or mw.ustring.find(title, " deel$")
		or mw.ustring.find(title, " dicht$")
		or mw.ustring.find(title, " dood$")
		or mw.ustring.find(title, " door$")
		or mw.ustring.find(title, " droog$")
		or mw.ustring.find(title, " fijn$")
		or mw.ustring.find(title, " gaar$")
		or mw.ustring.find(title, " gelijk$")
		or mw.ustring.find(title, " glad$")
		or mw.ustring.find(title, " goed$")
		or mw.ustring.find(title, " groot$")
		or mw.ustring.find(title, " hard$")
		or mw.ustring.find(title, " in$")
		or mw.ustring.find(title, " ineen$")
		or mw.ustring.find(title, " klein$")
		or mw.ustring.find(title, " kort$")
		or mw.ustring.find(title, " kwijt$")
		or mw.ustring.find(title, " lang$")
		or mw.ustring.find(title, " langs$")
		or mw.ustring.find(title, " leeg$")
		or mw.ustring.find(title, " los$")
		or mw.ustring.find(title, " mede$")
		or mw.ustring.find(title, " mee$")
		or mw.ustring.find(title, " mis$")
		or mw.ustring.find(title, " na$")
		or mw.ustring.find(title, " neer$")
		or mw.ustring.find(title, " om$")
		or mw.ustring.find(title, " omver$")
		or mw.ustring.find(title, " onder$")
		or mw.ustring.find(title, " op$")
		or mw.ustring.find(title, " open$")
		or mw.ustring.find(title, " opeen$")
		or mw.ustring.find(title, " over$")
		or mw.ustring.find(title, " raak$")
		or mw.ustring.find(title, " recht$")
		or mw.ustring.find(title, " rond$")
		or mw.ustring.find(title, " samen$")
		or mw.ustring.find(title, " scheef$")
		or mw.ustring.find(title, " schoon$")
		or mw.ustring.find(title, " stil$")
		or mw.ustring.find(title, " stuk$")
		or mw.ustring.find(title, " tegen$")
		or mw.ustring.find(title, " terecht$")
		or mw.ustring.find(title, " terug$")
		or mw.ustring.find(title, " toe$")
		or mw.ustring.find(title, " uit$")
		or mw.ustring.find(title, " vast$")
		or mw.ustring.find(title, " vlak$")
		or mw.ustring.find(title, " vol$")
		or mw.ustring.find(title, " voor$")
		or mw.ustring.find(title, " voort$")
		or mw.ustring.find(title, " voorbij$")
		or mw.ustring.find(title, " vooruit$")
		or mw.ustring.find(title, " vrij$")
		or mw.ustring.find(title, " weg$")
		or mw.ustring.find(title, " warm$")
		or mw.ustring.find(title, " zwart$")) then
			-- On teste la présence d'une seule espace
			if mw.ustring.find(title, "^[^ ]+ [^ ]+$") then
				return false
			else
				return true
			end
		end
	end
	
    -- Par défaut : espaces = locution
    if p.contains_space(title) then
        return true
    else
    	return false
    end
end

return p