Semantic MediaWikiDit bericht verdwijnt nadat alle relevante taken zijn afgerond.

Er is één onvoltooide of openstaande taak, die nodig is om het bijwerken van Semantic MediaWiki te voltooien. Een beheerder of gebruiker met voldoende rechten kan deze uitvoeren. Dit moet worden gedaan voordat nieuwe gegevens worden toegevoegd om tegenstrijdigheden te voorkomen.

Geen bewerkingssamenvatting
Er kan kennelijk meer dan één originele titel zijn: string -> table
 
(10 tussenliggende versies door 2 gebruikers niet weergegeven)
Regel 1: Regel 1:
--[[
--[[
@todo rename to Class/Title
Module for taking and processing parameters for set in Template:Title
Module for taking and processing parameters for set in Template:Title
Work in progress
Work in progress


{{#invoke:Title/SMW |set
{{#invoke:Class/Title |set
|page={{FULLPAGENAME}}
|page={{FULLPAGENAME}}
|slot=ws-page-props
|slot=ws-page-props
Regel 37: Regel 35:
local mFormatForSorting = require("Module:Format for sorting")
local mFormatForSorting = require("Module:Format for sorting")
local mCspFunctions = require('Module:CspFunctions')
local mCspFunctions = require('Module:CspFunctions')
local mSlot = require("Module:Slot")
local mPerson = require("Module:Class/Person")


p.set = function(frame)
p.set = function(frame)
Regel 74: Regel 74:
local initial = p.getUppercaseInitial( titleBiblioFlattened )
local initial = p.getUppercaseInitial( titleBiblioFlattened )


-- create two identical tables because it appears we cannot reuse the variable for a second property
local authors = {}
local authors = {}
if SchrijverNr ~= nil then  
local authors2 = {}
authors = mw.text.split( SchrijverNr, "," )
if SchrijverNr ~= nil then
authors = mw.text.split( SchrijverNr, ",", true )
authors2 = mw.text.split( SchrijverNr, ",", true )
end
end
local authorNameTbl = p.buildAuthorNameTbl( authors ) or {}
local authorNameTbl = mPerson.buildAuthorNameTbl( authors ) or {}
local authorNameStrInTitle = p.formatAuthorNameString( #authors, authorNameTbl, "---" )
local authorNameStrInTitle = mPerson.formatAuthorNameString( #authors, authorNameTbl, "---" )


local titlePlain = TitelGew .. " - " .. authorNameStrInTitle
local titlePlain = TitelGew .. " - " .. authorNameStrInTitle
Regel 93: Regel 96:
local isTitleSeriesAvailable = "false"
local isTitleSeriesAvailable = "false"
local seriesLabel = Reeks
local seriesLabel = Reeks
-- create two identical tables because it appears we cannot reuse the variable for a second property
local Titelreeksen = {}
local Titelreeksen = {}
local Titelreeksen2 = {}
if Titelreeks ~= nil and Titelreeks ~= "" then
if Titelreeks ~= nil and Titelreeks ~= "" then
Titelreeksen = mw.text.split( Titelreeks, "," )
Titelreeksen = mw.text.split( Titelreeks, ",", true )
Titelreeksen2 = mw.text.split( Titelreeks, ",", true )
isTitleSeriesAvailable = "true"
isTitleSeriesAvailable = "true"
local seriesLabels = {}
local seriesLabels = {}
for _,r in ipairs( Titelreeksen ) do  
for _,r in ipairs( Titelreeksen ) do  
-- {{#if:{{{Titelreeks|}}}|{{#show:{{{Titelreeks|}}}|?Title plain}}|{{#var:@reeks}} }}
-- {{#if:{{{Titelreeks|}}}|{{#show:{{{Titelreeks|}}}|?Title plain}}|{{#var:@reeks}} }}
table.insert( seriesLabels, p.getValueFromTemplateParam( r, "Title series", "TitelGew" ) )
table.insert( seriesLabels, mSlot.getValueFromTemplateParam( r, "Title series", "TitelGew" ) )
table.insert( seriesOrWorld, r )
table.insert( seriesOrWorld, r )
end
end
Regel 136: Regel 142:
if Type ~= nil then labelType = " (" ..  Type .. ")" else labelType = "" end
if Type ~= nil then labelType = " (" ..  Type .. ")" else labelType = "" end
set["Has label for form"] = TitelGew .. " - " .. authorNameStrInTitle .. labelType
set["Has label for form"] = TitelGew .. " - " .. authorNameStrInTitle .. labelType
set["Has original title"] = OrigTitel or ""
set["Has original title"] = mw.text.split( OrigTitel or "", "," )
-- table
-- table
set["Has author"] = authors
set["Has author"] = authors
set["Has author (text)"] = authors2
-- string version, used to preserve the order of appearance
-- string version, used to preserve the order of appearance
set["Has author string"] = SchrijverNr
set["Has author string"] = SchrijverNr
Regel 144: Regel 151:
set["Title series available"] = isTitleSeriesAvailable
set["Title series available"] = isTitleSeriesAvailable
set["Has title series"] = Titelreeksen
set["Has title series"] = Titelreeksen
set["Has title series (text)"] = Titelreeksen2
--set["Has title series (text)"] = Titelreeksen or {}
set["Has series label"] = seriesLabel
set["Has series label"] = seriesLabel
set["Has series volume"] = ReeksNr
set["Has series volume"] = ReeksNr
Regel 169: Regel 178:
end
end


local setResult = nil
if mw.smw then
if mw.smw then
local setResult = mw.smw.set( set )
setResult = mw.smw.set( set )
end
end
Regel 176: Regel 186:
frame:callParserFunction( 'DEFAULTSORT', { sortLabel } )
frame:callParserFunction( 'DEFAULTSORT', { sortLabel } )


end
--[[
@title string - pagename of title
Should mirror approach by set supra
]]--
p.getSortLabelByAuthor = function( title )
if title == nil then return "" end
-- 1 title
local titelBiblio = mSlot.getValueFromTemplateData( "ws-page-props", title, "Title", "TitelBiblio" )
local titleBiblioFlattened = p.flattenBibliographicTitle( titelBiblio )
-- 2 get author names
local SchrijverNr = mSlot.getValueFromTemplateData( "ws-page-props", title, "Title", "SchrijverNr" )
local authors = mw.text.split( SchrijverNr, "," )
local authorNameTbl = mPerson.buildAuthorNameTbl( authors ) or {}
local firstAuthorBiblioName = ""
if authorNameTbl[1] ~= nil then firstAuthorBiblioName = authorNameTbl[1]["NaamBiblio"] or "" end
-- 3 postprocess and return
local sortLabelByAuthor = string.lower( firstAuthorBiblioName .. " - " .. titleBiblioFlattened )
return string.sub( sortLabelByAuthor, 1, 200 ) .. "¶"
end
end


Regel 192: Regel 225:
--local stripped = frame:expandTemplate{ title = "Strip title for sorting", args = { subbed } }
--local stripped = frame:expandTemplate{ title = "Strip title for sorting", args = { subbed } }
return stripped
return stripped
end
--[[ used by Class/Book ]]--
p.createSortLabelByAuthor = function( titelBiblio, firstAuthorBiblioName )
-- NaamBiblio
local titleBiblioFlattened = p.flattenBibliographicTitle( titelBiblio )
local firstAuthorBiblioName = ""
return string.lower( firstAuthorBiblioName .. " - " .. titleBiblioFlattened )
end
end


Regel 205: Regel 230:
local initial = string.sub( str, 1, 1 )
local initial = string.sub( str, 1, 1 )
return string.upper(initial)
return string.upper(initial)
end
--[[
@TODO: move to Module:Class/Person?
Create table with names for no more than two authors
@SchrijverNr string|nil - table of author pages
@return table
]]--
p.buildAuthorNameTbl = function( authors )
if authors == nil or #authors == 0 then
return {}
end
local res = {}
res[1] = {
["page"] = authors[1],
["NaamGew"] = p.getValueFromTemplateParam( authors[1], "Person", "NaamGew" ) or "",
["NaamBiblio"] = p.getValueFromTemplateParam( authors[1], "Person", "NaamBiblio" ) or ""
}
if authors[2] ~= nil then
res[2] = {
["page"] = authors[2],
["NaamGew"] = p.getValueFromTemplateParam( authors[2], "Person", "NaamGew" ) or "",
["NaamBiblio"] = p.getValueFromTemplateParam( authors[2], "Person", "NaamBiblio" ) or ""
}
end
return res
end
--[[
Format name string for no more than two authors
@authorCount int - total number of authors
@authors table - one or two authors
@return string
]]--
p.formatAuthorNameString = function( authorCount, authors, defaultStr )
local authorNameStr = defaultStr
if ( authorCount > 0 ) and type(authors[1]["NaamGew"]) == nil then
mw.log( "Author name could not be retrieved" )
end
if ( authorCount == 1 ) then
authorNameStr = authors[1]["NaamGew"]
elseif ( authorCount == 2 ) then
authorNameStr =  authors[1]["NaamGew"] .. " & " .. authors[2]["NaamGew"]
elseif ( authorCount > 2 ) then
authorNameStr =  authors[1]["NaamGew"] .. " & " ..  authors[2]["NaamGew"] .. ", e.a."
end
return authorNameStr
end
end


Regel 271: Regel 244:
end
end


--[[
@deprecated
]]--
p.getValueFromTemplateParam = function( pagename, templateName, templateParam )
p.getValueFromTemplateParam = function( pagename, templateName, templateParam )
if pagename == "" then
return mSlot.getValueFromTemplateParam( pagename, templateName, templateParam )
mw.log( "pagename is empty" )
return ""
end
-- pre-check, just in case
local title = mw.title.new( pagename )
if title == nil or not title.exists then
mw.log( "title does not exist" )
return ""
end
 
local slotContent = p.getSlotContent( pagename, "ws-page-props", templateName )
if slotContent == nil or slotContent[1] == nil or slotContent[1][templateParam] == nil then
mw.log( "No value retrieved from page. Template param: " .. templateParam )
return ""
end
if type( slotContent[1][templateParam]["_text"] ) == "string" then
return slotContent[1][templateParam]["_text"]
else
return "?"
end
end
end


--[[
--[[ used by Class/Book, maybe todo : Class/Title ]]--
@deprecated - see Module:Slot for same function
p.createSortLabelByAuthor = function( titelBiblio, firstAuthorBiblioName )
]]--
local titleBiblioFlattened = p.flattenBibliographicTitle( titelBiblio )
p.getSlotContent = function( page, slot, template )
return string.lower( firstAuthorBiblioName .. " - " .. titleBiblioFlattened )
local template = template or nil
if ( template == "" or template == nil ) then
-- Assuming JSON
if slot == "main" then
--loadJsonData does not alway work. Use WSSlots instead
--return mw.loadJsonData( page )
end
local str = mw.slots.slotContent( slot, page )
if type(str) == "table" then
-- @todo VERY unlikely
return str
end
if str ~= nil then
return mw.text.jsonDecode( str )
else
return {}
end
end
 
-- template
local slotData = mw.slots.slotData( slot, page )
if ( slotData == nil ) then
return type(slotData)
end
return slotData[template]
 
end
end


return p
return p

Huidige versie van 23 mei 2026 13:57

Module:Class/Title




Meergewicht - Peter Andriesse

+ fictieve velden

{"Has title series or world":["Titelreeks/1004203","Titelreeks/1025879","Wereld/1294611"],"Has initial":"M","Has original title":[""],"Title series available":"true","Has ID":"300","Title plain":"Meergewicht - Peter Andriesse","Has title":"Meergewicht","Has sort label by author":"andriesse, peter - meergewicht¶","Has author (text)":["Persoon/96"],"Has author":["Persoon/96"],"Has medium form":["Gedrukt"],"Has bibliographic title":"Meergewicht","Has world":["Wereld/1294611"],"Has category":"Science Fiction","Has sort label":"meergewicht - peter andriesse¶","Has label for form":"Meergewicht - Peter Andriesse (Verhaal)","Has series label":"De Kronieken van Narnia, Meriumbe","Has author string":"Persoon/96","Has format":"Verhaal","Title":"Meergewicht - Peter Andriesse","Klasse":"Titel","Has title series (text)":["Titelreeks/1004203","Titelreeks/1025879"],"Has title series":["Titelreeks/1004203","Titelreeks/1025879"],"Has title series sortkey":"99999"}

--[[
Module for taking and processing parameters for set in Template:Title
Work in progress

{{#invoke:Class/Title |set
|page={{FULLPAGENAME}}
|slot=ws-page-props
|debugmode=true

|ID={{{ID|}}}
|TitelBiblio={{{TitelBiblio|}}}
|TitelGew={{{TitelGew|}}}
|OrigTitel={{{OrigTitel|}}}
|SchrijverNr={{{SchrijverNr|}}}
|Type={{{Type|}}}
|Titelreeks={{{Titelreeks|}}}
|Reeks={{{Reeks|}}}
|ReeksNr={{{ReeksNr|}}}
|Behoord={{{Behoord|}}}
|Soort={{{Soort|}}}
|Wereld={{{Wereld|}}}
|Medium vorm={{{Medium vorm|}}}
|ZieOokBij={{{ZieOokBij|}}}
|subcategorie={{{subcategorie|}}}
|KInhoud={{{KInhoud|}}}
|GUID={{{GUID|}}}
|Verwijderd={{{Verwijderd|}}}
|Opmerking={{{Opmerking|}}}
|Aantekening={{{Aantekening|}}}
}}

]]--

local p = {}
local mFormatForSorting = require("Module:Format for sorting")
local mCspFunctions = require('Module:CspFunctions')
local mSlot = require("Module:Slot")
local mPerson = require("Module:Class/Person")

p.set = function(frame)
	local page = frame.args.page or nil
	local slot = frame.args.slot or "ws-page-props"
	local debugmode = frame.args.debugmode or "false"

	-- Wiki template argumentsa
	local ID = frame.args.ID or nil
	local TitelBiblio = frame.args.TitelBiblio or nil
	local TitelGew = frame.args.TitelGew or ""
	local OrigTitel = frame.args.OrigTitel or nil
	local SchrijverNr = frame.args.SchrijverNr or nil
	local Type = frame.args.Type or nil

	-- Reeks (oud, string) => Titelreeks (nieuw, things)
	local Titelreeks = frame.args.Titelreeks or nil
	local Reeks = frame.args.Reeks or nil
	local ReeksNr = frame.args.ReeksNr or nil
	
	-- 'Behoord' (oud, string) => 'Wereld' (nieuw, things)
	local Behoord = frame.args.Behoord or nil
	local Wereld = frame.args.Wereld or nil
	
	local Soort = frame.args.Soort or nil
	local Mediumvorm = frame.args["Medium vorm"] or nil
	local ZieOokBij = frame.args.ZieOokBij or nil
	local subcategorie = frame.args.subcategorie or nil
	local KInhoud = frame.args.KInhoud or nil
	local GUID = frame.args.GUID or nil
	local Verwijderd = frame.args.Verwijderd or nil
	local Opmerking = frame.args.Opmerking or nil
	local Aantekening = frame.args.Aantekening or nil

	-- processing
	local titleBiblioFlattened = p.flattenBibliographicTitle( TitelBiblio )
	local initial = p.getUppercaseInitial( titleBiblioFlattened )

	-- create two identical tables because it appears we cannot reuse the variable for a second property
	local authors = {}
	local authors2 = {}
	if SchrijverNr ~= nil then
		authors = mw.text.split( SchrijverNr, ",", true )
		authors2 = mw.text.split( SchrijverNr, ",", true )
	end
	local authorNameTbl = mPerson.buildAuthorNameTbl( authors ) or {}
	local authorNameStrInTitle = mPerson.formatAuthorNameString( #authors, authorNameTbl, "---" )

	local titlePlain = TitelGew .. " - " .. authorNameStrInTitle

	-- {{lc:{{#var:@titelbiblio}} - {{#var:@naamgew}} }}
	local sortLabel = string.lower( titleBiblioFlattened .. " - " .. authorNameStrInTitle )
	-- {{lc:{{#var:@naambiblioschrijver1}} - {{#var:@titelbiblio}} }} 
	local firstAuthorBiblioName = ""
	if authorNameTbl[1] ~= nil then firstAuthorBiblioName = authorNameTbl[1]["NaamBiblio"] or "" end
	local sortLabelByAuthor = string.lower( firstAuthorBiblioName .. " - " .. titleBiblioFlattened )

	local seriesOrWorld = {}
	local isTitleSeriesAvailable = "false"
	local seriesLabel = Reeks
	-- create two identical tables because it appears we cannot reuse the variable for a second property
	local Titelreeksen = {}
	local Titelreeksen2 = {}
	if Titelreeks ~= nil and Titelreeks ~= "" then
		Titelreeksen = mw.text.split( Titelreeks, ",", true )
		Titelreeksen2 = mw.text.split( Titelreeks, ",", true )
		isTitleSeriesAvailable = "true"
		local seriesLabels = {}
		for _,r in ipairs( Titelreeksen ) do 
			-- {{#if:{{{Titelreeks|}}}|{{#show:{{{Titelreeks|}}}|?Title plain}}|{{#var:@reeks}} }}
			table.insert( seriesLabels, mSlot.getValueFromTemplateParam( r, "Title series", "TitelGew" ) )
			table.insert( seriesOrWorld, r )
		end
		seriesLabel = table.concat( seriesLabels, ", " )
	end
	local Werelden = {}
	if Wereld ~= nil and Wereld ~= "" then
		Werelden = mw.text.split( Wereld, "," )
		for _,w in ipairs(Werelden) do
			table.insert( seriesOrWorld, w )
		end
	end

	local mediumVormen = { "Gedrukt" } -- default
	if Mediumvorm ~= nil then
		mediumVormen = mw.text.split( Mediumvorm, "," )
	end

	-- set
	local set = {}
	-- Dutch-language label
	set["Klasse"] = "Titel"
	set["Has ID"] = ID or ""
	set["Title"] = titlePlain
	--|Title plain={{{TitelGew|}}} - {{#var:@naamgew|---}}
	set["Title plain"] = titlePlain
	set["Has title"] = TitelGew
	set["Has bibliographic title"] = titleBiblioFlattened
	set["Has initial"] = initial
	
	-- |Has sort label={{#sub:{{#var:@sort title}}|0|150}}¶
	set["Has sort label"] = string.sub( sortLabel, 1, 150 ) .. "¶"
	-- |Has sort label by author={{#sub:{{#var:@sort title 2}}|0|200}}¶<!-- author first -->
	set["Has sort label by author"] = string.sub( sortLabelByAuthor, 1, 200 ) .. "¶"
	if Type ~= nil then labelType = " (" ..  Type .. ")" else labelType = "" end
	set["Has label for form"] = TitelGew .. " - " .. authorNameStrInTitle .. labelType
	set["Has original title"] = mw.text.split( OrigTitel or "", "," )
	-- table
	set["Has author"] = authors
	set["Has author (text)"] = authors2
	-- string version, used to preserve the order of appearance
	set["Has author string"] = SchrijverNr

	set["Title series available"] = isTitleSeriesAvailable
	set["Has title series"] = Titelreeksen
	set["Has title series (text)"] = Titelreeksen2
	--set["Has title series (text)"] = Titelreeksen or {}
	set["Has series label"] = seriesLabel
	set["Has series volume"] = ReeksNr
	-- Has title series sortkey={{#invoke:Format for sorting|textString|1={{#var:@reeksnr|99999}}}}
	set["Has title series sortkey"] = mFormatForSorting.textStringFormat( ReeksNr or "99999" )
	set["Belongs to world"] = Behoord
	set["Has world"] = Werelden
	set["Has title series or world"] = seriesOrWorld

	set["Has format"] = Type
	set["Has medium form"] = mediumVormen
	set["Has category"] = Soort
	if subcategorie ~= nil then
		set["Has subcategory"] = mw.text.split( subcategorie, "," )
	end
	set["Has summary"] = KInhoud
	if ZieOokBij ~= nil then
		set["Has related title"] = mw.text.split( ZieOokBij, ",")
	end
	set["Has comment"] = Opmerking
	set["Has private note"] = Aantekening

	if debugmode == "true" then
		return "<pre>" .. mw.text.jsonEncode( set ) .. "</pre>"
	end

	local setResult = nil
	if mw.smw then
		setResult = mw.smw.set( set )
	end
	
	mw.ext.displaytitle.set( titlePlain)
	frame:callParserFunction( 'DEFAULTSORT', { sortLabel } )

end

--[[
@title string - pagename of title
Should mirror approach by set supra
]]--
p.getSortLabelByAuthor = function( title )
	if title == nil then return "" end

	-- 1 title
	local titelBiblio = mSlot.getValueFromTemplateData( "ws-page-props", title, "Title", "TitelBiblio" )
	local titleBiblioFlattened = p.flattenBibliographicTitle( titelBiblio )

	-- 2 get author names
	local SchrijverNr = mSlot.getValueFromTemplateData( "ws-page-props", title, "Title", "SchrijverNr" )
	local authors = mw.text.split( SchrijverNr, "," )
	local authorNameTbl = mPerson.buildAuthorNameTbl( authors ) or {}
	local firstAuthorBiblioName = ""
	if authorNameTbl[1] ~= nil then firstAuthorBiblioName = authorNameTbl[1]["NaamBiblio"] or "" end

	-- 3 postprocess and return
	local sortLabelByAuthor = string.lower( firstAuthorBiblioName .. " - " .. titleBiblioFlattened )
	return string.sub( sortLabelByAuthor, 1, 200 ) .. "¶"
end

--[[
@titelBiblio string|nil
@return string
]]--
p.flattenBibliographicTitle = function( titelBiblio )
	if titelBiblio == nil then return "" end
	-- {{Strip title for sorting|{{#sub:{{{TitelBiblio|}}}|0|75}} }}
	-- {{#sub:{{{TitelBiblio|}}}|0|75}} 
	local subbed = string.sub( titelBiblio, 1, 75 )
	local stripped = mFormatForSorting.minimalStripForSorting( subbed )
	-- previously:
	--local frame = mw.getCurrentFrame()
	--local stripped = frame:expandTemplate{ title = "Strip title for sorting", args = { subbed } }
	return stripped
end

p.getUppercaseInitial = function( str )
	local initial = string.sub( str, 1, 1 )
	return string.upper(initial)
end

--[[
UNUSED
titleBiblioFlattened
@title 'flattened' title
]]--
p.getSortkeyByTitleAndAuthor = function( title, firstAuthorName )
	local firstAuthorName = ""
	local str = title .. " - " .. firstAuthorName
	-- {{lc:{{#var:@titelbiblio}} - {{#var:@naamgew}} }} 
	-- string.lowercase( )
end

--[[
@deprecated
]]--
p.getValueFromTemplateParam = function( pagename, templateName, templateParam )
	return mSlot.getValueFromTemplateParam( pagename, templateName, templateParam )
end

--[[ used by Class/Book, maybe todo : Class/Title ]]--
p.createSortLabelByAuthor = function( titelBiblio, firstAuthorBiblioName )
	local titleBiblioFlattened = p.flattenBibliographicTitle( titelBiblio )
	return string.lower( firstAuthorBiblioName .. " - " .. titleBiblioFlattened )
end

return p