From Wikipedia, the free encyclopedia

local p = {}

local plain = require("Module:Plain text")._main

local isInLead = require("Module:Is_infobox_in_lead")._main

local getArgs = require("Module:Arguments").getArgs

function p.shortdesc(text, frame)

    return frame:expandTemplate {title = "Short description", args = {text, "noreplace"}}

end

function p.firstToUpper(str)

    return (str:gsub("^%l", string.upper))

end

function p.main(frame)

    if (isInLead("[Ii]nfobox [Bb]ook")) then

        local args = getArgs(frame, {parentOnly = true})

        local short_description = plain(args.short_description)

        local output = ""

        -- add year

        local published = plain(args.pub_date or args.release_date or args.published)

        if published then

            if not (string.find(published, "–")) and string.len(published) < 40 then

                if string.match(published, "%d%d%d%d") then

                    output = string.match(published, "%d%d%d%d") .. " "

                end

            end

        end

        local type = "literary work"

        local specificfound = false

        local genres = {

            "encyclopedia",

            "memoir",

            "anthology",

            "autobiography",

            "biography",

            "collection of short stories",

            "collection of poems",

            "guide",

            "short story",

            "graphic novel",

            "dictionary",

            "short-story",

            "handbook",

            "reference work",

            "cookbook",

            "textbook",

            "essay",

            "novella",

            "novel",

            "book"

        }

        -- looping through the "genre" attribute of the infobox

        local i = 1

        if args.genre then

            local given = string.lower(plain(args.genre))

            while (i <= #genres and not (specificfound)) do

                if string.find(given, genresi], 1, true) then

                    specificfound = true

                    type = genresi

                end

                i = i + 1

            end

        end

        if not (specificfound) then

            local content = mw.title.getCurrentTitle():getContent()

            local start =

                string.find(

                content,

                "'''''" .. mw.title.getCurrentTitle().text:gsub("%s%([^)]*%)", "") .. "'''''",

                1,

                true

            )

            local fin = string.find(content, "==", 1, true)

            if start and fin then

                local lead = string.lower(mw.text.split(plain(string.sub(content, start, fin)), ".", true)[1])

                output = "(" .. lead .. ")" .. output

                -- looping through the first sentence of the article

                i = 1

                while (i <= #genres and not (specificfound)) do

                    if string.find(lead, genresi], 1, true) then

                        specificfound = true

                        type = genresi

                    end

                    i = i + 1

                end

            end

        end

        if (type == "dictionary" or type == "encyclopedia") and output ~= "" then

            output = type .. " first published in " .. output

        else

            output = output .. type

            -- add author

            local author = plain(args.author)

            if author and string.len(author) < 40 and not (string.find(author, "Various")) then

                output = output .. " by " .. author:gsub(",", " and"):gsub("&", "and")

            end

        end

        if output == "literary work" then

            return "Too vague"

        else

            return p.firstToUpper(output)

        end

    else

        return "N/A"

    end

end



return p
From Wikipedia, the free encyclopedia

local p = {}

local plain = require("Module:Plain text")._main

local isInLead = require("Module:Is_infobox_in_lead")._main

local getArgs = require("Module:Arguments").getArgs

function p.shortdesc(text, frame)

    return frame:expandTemplate {title = "Short description", args = {text, "noreplace"}}

end

function p.firstToUpper(str)

    return (str:gsub("^%l", string.upper))

end

function p.main(frame)

    if (isInLead("[Ii]nfobox [Bb]ook")) then

        local args = getArgs(frame, {parentOnly = true})

        local short_description = plain(args.short_description)

        local output = ""

        -- add year

        local published = plain(args.pub_date or args.release_date or args.published)

        if published then

            if not (string.find(published, "–")) and string.len(published) < 40 then

                if string.match(published, "%d%d%d%d") then

                    output = string.match(published, "%d%d%d%d") .. " "

                end

            end

        end

        local type = "literary work"

        local specificfound = false

        local genres = {

            "encyclopedia",

            "memoir",

            "anthology",

            "autobiography",

            "biography",

            "collection of short stories",

            "collection of poems",

            "guide",

            "short story",

            "graphic novel",

            "dictionary",

            "short-story",

            "handbook",

            "reference work",

            "cookbook",

            "textbook",

            "essay",

            "novella",

            "novel",

            "book"

        }

        -- looping through the "genre" attribute of the infobox

        local i = 1

        if args.genre then

            local given = string.lower(plain(args.genre))

            while (i <= #genres and not (specificfound)) do

                if string.find(given, genresi], 1, true) then

                    specificfound = true

                    type = genresi

                end

                i = i + 1

            end

        end

        if not (specificfound) then

            local content = mw.title.getCurrentTitle():getContent()

            local start =

                string.find(

                content,

                "'''''" .. mw.title.getCurrentTitle().text:gsub("%s%([^)]*%)", "") .. "'''''",

                1,

                true

            )

            local fin = string.find(content, "==", 1, true)

            if start and fin then

                local lead = string.lower(mw.text.split(plain(string.sub(content, start, fin)), ".", true)[1])

                output = "(" .. lead .. ")" .. output

                -- looping through the first sentence of the article

                i = 1

                while (i <= #genres and not (specificfound)) do

                    if string.find(lead, genresi], 1, true) then

                        specificfound = true

                        type = genresi

                    end

                    i = i + 1

                end

            end

        end

        if (type == "dictionary" or type == "encyclopedia") and output ~= "" then

            output = type .. " first published in " .. output

        else

            output = output .. type

            -- add author

            local author = plain(args.author)

            if author and string.len(author) < 40 and not (string.find(author, "Various")) then

                output = output .. " by " .. author:gsub(",", " and"):gsub("&", "and")

            end

        end

        if output == "literary work" then

            return "Too vague"

        else

            return p.firstToUpper(output)

        end

    else

        return "N/A"

    end

end



return p

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook