モジュール:Cite LSA

local p = {}
function p.cite(frame)
	local pframe = frame:getParent()
	local config = frame.args
	local args = pframe.args
	local authorfirst = {}
	local authorlast = {}
	local editorfirst = {}
	local editorlast = {}
	local title = args.title
	local journal = args.journal
	local chapter = args.chapter
	local series = args.seriestitle or args.series
	local year = args.year
	local volume = args.volume
	local edition = args.edition
	local pages = args.pages
	local publisher = args.publisher
	local author = args.last
	local url = args.url
	local accessdate = args.accessdate
	local editorlist = nil
	local place = args.place
	local citation = nil
	argTable = {title,journal,chapter,series, year, volume, edition,pages,publisher,editors,place}
	for k,v in pairs(args) do
		if string.find(k, "first") ~= nil then
			if string.find(k, "%d") ~= nil then
				i,j = string.find(k, "%d")
				num = string.sub(k,i,j)
				num = tonumber(num)
			else
				num = 1
			end
			if string.find(k, "editor") ~= nil then
				editorfirstnum = v
			else
				authorfirstnum = v
			end
		elseif string.find(k, "last") ~= nil then
			if string.find(k, "%d") ~= nil then
				i,j = string.find(k, "%d")
				num = string.sub(k,i,j)
				num = tonumber(num)
			else
				num = 1
			end
			if string.find(k, "editor") ~= nil then
				editorlastnum = v
			else
				authorlastnum = v
			end
		end
	end
	if table.getn(authorlast) " .. publisher .. ". "
		author=""
	elseif table.getn(authorlast) > 0 then
		alimit = table.getn(authorlast)
		for i,v in ipairs(authorlast) do
			if i == 1 then
				authorlist = "" .. authorlast1 .. ", " .. authorfirst1 .. ""
			elseif i > 1 and i " .. authorfirsti .. " " .. authorlasti .. ""
			end
			if i+1 == alimit then
				authorlist = authorlist .. ", and "
			elseif alimit == 1 then
				authorlist = authorlist .. ". "
			elseif alimit > 2 and i ~= alimit then
				authorlist = authorlist .. "; "
			elseif i == alimit then
				authorlist = authorlist .. ". "
			end
		end
	end
	if editorlast ~= {} then
		editorlist = ""
		elimit = table.getn(editorlast)
		for i,v in ipairs(editorlast) do
			editorlist = editorlist .. editorfirsti .. " " .. editorlasti
			if i+1 == elimit and editorlist ~= " " then
				editorlist = editorlist .. ", and "
			elseif elimit > i and editorlist ~= " " then
				editorlist = editorlist .. ", "
			end
		end
		if editorlist == "" or editorlist == " " then
			editorlist = ""
		end
	end
	if author ~= nil then
		authorlist = authorlist .. year .. ". "
	elseif author == nil then
		authorlist = "Missing author name" .. year .. ". "
	end
	if journal ~= nil then
		if url ~= nil then
			if accessdate ~= nil then
				citation = authorlist .. "" .. url .. " " .. title .. ". \'\'" .. journal .. "\'\' " .. volume .. ". " .. pages .. ". Accessed " .. accessdate .. "."
			else
				citation = authorlist .. "" .. url .. " " .. title .. ". \'\'" .. journal .. "\'\' " .. volume .. ". " .. pages .. ". Missing accessdate"
			end
		else
			citation = authorlist .. title .. ". \'\'" .. journal .. "\'\' " .. volume .. ". " .. pages .. ". "
		end
	elseif journal == nil then
		if chapter ~= nil then
			if url ~= nil then
				citation = authorlist .. "" .. url .. " " .. chapter .. "."
			else
				citation = authorlist .. chapter .. ". "
			end
			if title ~= nil then
				citation = citation .. "\'\'" .. title .. "\'\'"
				if editorlist ~= nil and editorlist ~= "" then
					citation = citation .. " ed. by " .. editorlist
				end
				if pages ~= nil then
					citation = citation .. ", " .. pages .. ". "
				else
					citation = citation .. ". "
				end
				if edition ~= nil and volume ~= nil then
					citation = citation .. edition .. ", " .. volume .. "; " 
				elseif edition ~= nil and volume == nil then
					citation = citation .. edition .. "; "
				elseif edition == nil and volume ~= nil then
					citation = citation .. volume .. "; "
				end
				if series ~= nil then
					citation = citation .. "(" .. series .. "). "
				end
				if place ~= nil and publisher ~= nil then
					citation = citation .. place .. ": " .. publisher .. "."
				elseif place ~= nil and publisher == nil then
					citation = citation .. place .. "."
				elseif place == nil and publisher ~= nil then
					citation = citation .. publisher .. "."
				end
				if url ~= nil then
					if accessdate ~= nil then
						citation = citation .. " Accessed " .. accessdate .. ". "
					else
						citation = citation .. "Missing accessdate"
					end
				end
			end
		else
			if title ~= nil then
				if url ~= nil then
					citation = authorlist .. "\'\'" .. url .. " " .. title .. "\'\'"
				else
					citation = authorlist .. "\'\'" .. title .. "\'\'"
				end
				if editorlist ~= nil and editorlist ~= "" then
					citation = citation .. ", ed. by " .. editorlist
				end
				if pages ~= nil then
					citation = citation .. ", " .. pages .. ". "
				else
					citation = citation .. ". "
				end
				if edition ~= nil and volume ~= nil then
					citation = citation .. edition .. ", " .. volume .. "; " 
				elseif edition ~= nil and volume == nil then
					citation = citation .. edition .. "; "
				elseif edition == nil and volume ~= nil then
					citation = citation .. volume .. "; "
				end
				if series ~= nil then
					citation = citation .. "(" .. series .. "). "
				end
				if place ~= nil and publisher ~= nil then
					citation = citation .. place .. ": " .. publisher .. "."
				elseif place ~= nil and publisher == nil then
					citation = citation .. place .. "."
				elseif place == nil and publisher ~= nil then
					citation = citation .. publisher .. "."
				end
				if url ~= nil then
					if accessdate ~= nil then
						citation = citation .. " Accessed " .. accessdate .. "."
					else
						citation = citation .. "Missing accessdate"
					end
				end
			end
		end
	end
	return citation
end
return p