Difference between revisions of "Module:LuaExtractionDiscourseLayers"
Line 62: | Line 62: | ||
local category = metadata['category'] | local category = metadata['category'] | ||
category = category:lower() | category = category:lower() | ||
+ | category[1] = category[3] | ||
local selector = type(lookup[category]) == "function" and lookup[category]() or lookup[category] or "blubb" | local selector = type(lookup[category]) == "function" and lookup[category]() or lookup[category] or "blubb" | ||
local prefix = '<div class="' .. "box-layer2 " .. selector .. '">' | local prefix = '<div class="' .. "box-layer2 " .. selector .. '">' |
Revision as of 14:48, 29 May 2019
Documentation for this module may be created at Module:LuaExtractionDiscourseLayers/doc
local p = {}
function _annotationMetadataExtract(text)
if text == nil then
return 'No text supplied as parameter'
else
text = text:gsub("<div class=\"smwpre\">", "")
text = text:gsub("%^", "{")
text = text:gsub("%°", "}")
text = text:gsub("%Ӷ", "[")
text = text:gsub("%Ӻ", "]")
text = text:gsub(" ", " ")
text = text:gsub("</div>", "")
text = mw.text.decode(text)
local decodedJson = mw.text.jsonDecode(text, mw.text.JSON_TRY_FIXING)
return decodedJson
end
end
function _xpathToSortableIndex(s)
local result = ''
for num in s:gmatch("%d+") do
result = result .. " " .. num
end
return result
end
function p.ExtractDiscourseLayerContent(frame)
-- get title from arguments
local pagetitle = frame.args[1]
pagetitle = 'Text:' .. pagetitle:gsub("Annotationen:", "")
if pagetitle == nil then
return 'No title supplied as parameter'
else
local lookup = {
argumentation = "annotator-hl-blue",
innovationsdiskurs = "annotator-hl-red",
narrativ = "annotator-hl-green",
wissenschaftlichereferenz = "annotator-hl-yellow"
}
local title = mw.title.makeTitle('', pagetitle)
local pagecontent = title:getContent()
local query = '[[Annotation of::' .. pagetitle .. ']]|?=#|?AnnotationMetadata=#'
local result = mw.smw.ask(query)
local rv = ''
local t = {}
if result == nil then
return 'No annotions found for page ' .. pagetitle
end
for i=1,#result do
-- result[i][1] -> title of page
-- result[i]['#'] -> metadata
local metadata = result[i]['#']
metadata = _annotationMetadataExtract(metadata)
local start = metadata['ranges'][1]['start']
local startoffset = metadata['ranges'][1]['startOffset']
local category = metadata['category']
category = category:lower()
category[1] = category[3]
local selector = type(lookup[category]) == "function" and lookup[category]() or lookup[category] or "blubb"
local prefix = '<div class="' .. "box-layer2 " .. selector .. '">'
local suffix = "</div>"
local prefix_title = '<span class="box-layer2-title' .. '">'
local suffix_title = '</span>'
rv = rv .. prefix .. prefix_title .. metadata['category'] .. suffix_title .. '<br>' .. "" .. metadata['quote'] .. suffix
t[i] = _xpathToSortableIndex(start)
end
table.sort(t)
-- local page = mw.title.makeTitle('', annotationspage)
-- local content = page:getContent()
-- Todo: sort annotations by position in text by the use of XPATH info in metadata
-- local result = ""
--for i, e in ipairs(t) do
-- result = result .. e .. '<br>'
--end
return rv
end
return 'should not have reached this point'
end
return p