Module:PublicationShowAbstract: Difference between revisions

From MaRDI portal
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 10: Line 10:
function p.queryAbstractDB(QID)
function p.queryAbstractDB(QID)
local abstract = ""
local abstract = ""
local safeID = QID:gsub("^Q", "")
 
if not QID or QID == '' then
return abstract
end
--mw.log(safeID)  
local safeID = tostring(QID):gsub("^Q", "")
 
mw.log(safeID)  


     local row = mw.ext.externaldata.getDbData {
     local row = mw.ext.externaldata.getDbData {
Line 19: Line 24:
}
}
mw.log( row )
-- mw.log( row )
                  
                  
if row then
if row then
abstract = row.abstract
abstract = row.abstract
-- mw.log( abstract )
end
end


Line 36: Line 42:
         return "No records found"
         return "No records found"
     end     
     end     
   
local abstract = p.queryAbstractDB(target1)
-- mw.log(abstract)


local abstract = p.queryAbstractDB(target1)
if not abstract or abstract == '' then
        return ""
end
-- mw.log(abstract)  
    -- Replace inline LaTeX in $...$ with <math>...</math>
    abstract = abstract:gsub('%$(.-)%$', function(mathContent)
        return frame:extensionTag{
            name = "math",
            content = mathContent
        }
    end)
 
-- Create container div
    local box = mwHtml.create('div')
        :addClass('abstract-box')
        :css({
            ['border'] = '1px solid #ccc',
            ['border-radius'] = '8px',
            ['padding'] = '10px',
            ['background-color'] = '#f9f9f9',
            ['margin'] = '10px 0',
        })
       
    -- Add inline heading and text
    box:tag('span')
      :tag('strong')
      :wikitext('Abstract: ')
      :done()
      :wikitext(abstract)
     
    return tostring(box) .. '<br>'
    return abstract
end
end


return p
return p

Latest revision as of 11:02, 14 April 2025

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

-- Required module containing helper methods
local helper = require('Module:HelperMethods')

-- Required modules for SPARQL queries and HTML table generation
local sparql = require('SPARQL')
local mwHtml = require('mw.html')

local p = {}

function p.queryAbstractDB(QID)
	local abstract = ""

	if not QID or QID == '' then
		return abstract
	end	
	
	local safeID = tostring(QID):gsub("^Q", "")

	mw.log(safeID) 

    local row = mw.ext.externaldata.getDbData {
	    db = "AbstractDB",
	    parameters = safeID
	}
	
	-- mw.log( row )
                
	if row then
		abstract = row.abstract
		-- mw.log( abstract )
	end

    return abstract
end


function p.getAbstractForPaperQID(frame)
	
    -- Retrieve target1 from frame arguments or return error message if not set
	local target1 = frame.args[1]
    if not target1 or target1 == '' then
        return "No records found"
    end    
    
	local abstract = p.queryAbstractDB(target1)

	-- mw.log(abstract) 

	if not abstract or abstract == '' then
        return ""
	end
	
	
    -- Replace inline LaTeX in $...$ with <math>...</math>
    abstract = abstract:gsub('%$(.-)%$', function(mathContent)
        return frame:extensionTag{
            name = "math",
            content = mathContent
        }
    end)

	-- Create container div
    local box = mwHtml.create('div')
        :addClass('abstract-box')
        :css({
            ['border'] = '1px solid #ccc',
            ['border-radius'] = '8px',
            ['padding'] = '10px',
            ['background-color'] = '#f9f9f9',
            ['margin'] = '10px 0',
        })
        
    -- Add inline heading and text
    box:tag('span')
       :tag('strong')
       :wikitext('Abstract: ')
       :done()
       :wikitext(abstract)
       
    return tostring(box) .. '<br>'
	
end

return p