Changes

update from dev-wiki
Line 14: Line 14:  
if args['custom_id'] ~= nil and args['custom_id'] ~= "" and args['custom_id_pattern'] ~= nil and args['custom_id_replace'] then
 
if args['custom_id'] ~= nil and args['custom_id'] ~= "" and args['custom_id_pattern'] ~= nil and args['custom_id_replace'] then
 
args['custom_id'] = string.gsub(args['custom_id'], args['custom_id_pattern'], args['custom_id_replace'])
 
args['custom_id'] = string.gsub(args['custom_id'], args['custom_id_pattern'], args['custom_id_replace'])
 +
end
 +
 +
if args['label'] ~= nil and args['label'] ~= "" and args['name'] ~= nil and args['name'] then
 +
args['label'] = args['name']
 
end
 
end
 
 
Line 51: Line 55:  
        'LabProcessOutput'
 
        'LabProcessOutput'
 
    }
 
    }
 +
    properties['IsOutputOf'] = page.fullText
 
else
 
else
 
properties['@category'] = {
 
properties['@category'] = {
Line 56: Line 61:  
        'LabProcessObject'
 
        'LabProcessObject'
 
    }
 
    }
end
+
    end
 +
   
 +
    -- calculate consumed/remaining quantity
 +
properties["HasQuantifyingQuantity"] = "Property:HasNumberOfEntities" --default
 +
properties["HasNumberOfEntities"] = 1 - p.getConsumedQuantity(page.fullText .. "#" .. subobjectId)
    
mw.logObject(properties)
 
mw.logObject(properties)
Line 130: Line 139:  
local label_offset = 0
 
local label_offset = 0
 
 
if count > 1 then
+
if count > 1 or (args['custom_id_offset'] ~= nil and args['custom_id_offset'] ~= "") or (args['offset'] ~= nil and args['offset'] ~= "") then  
 +
--set offset for arrays or if an offset is defined
 
if args['custom_id'] ~= nil and args['custom_id'] ~= "" then
 
if args['custom_id'] ~= nil and args['custom_id'] ~= "" then
 
if string.match(args['custom_id'], "%d+") == nil then args['custom_id'] = args['custom_id'] .. "0" end -- e. g. "O" -> "O0"
 
if string.match(args['custom_id'], "%d+") == nil then args['custom_id'] = args['custom_id'] .. "0" end -- e. g. "O" -> "O0"
 +
if args['offset'] == nil or args['offset'] == "" then
 +
custom_id_offset = custom_id_offset + tonumber(string.reverse(string.match(string.reverse("" .. args['custom_id']), "%d+")))
 +
else custom_id_offset = custom_id_offset + tonumber(args['offset']) end
 
end
 
end
if string.match(args['id'], "%d+") == nil then args['id'] = args['id'] .. "0" end
+
end
 +
if count > 1 or (args['offset'] ~= nil and args['offset'] ~= "") then --set offset for arrays or if an offset is defined
 +
if string.match(args['id'], "%d+") == nil then args['id'] = args['id'] .. "0" end -- e. g. "O" -> "O0"
 
if string.match(args['label'], "%d+") == nil then args['label'] = args['label'] .. "0" end
 
if string.match(args['label'], "%d+") == nil then args['label'] = args['label'] .. "0" end
 
 
 
if args['offset'] == nil or args['offset'] == "" then
 
if args['offset'] == nil or args['offset'] == "" then
if args['custom_id'] ~= nil and args['custom_id'] ~= "" then
  −
if args['custom_id_offset'] == nil or args['custom_id_offset'] == "" then
  −
custom_id_offset = tonumber(string.reverse(string.match(string.reverse("" .. args['custom_id']), "%d+")))
  −
end
  −
end
   
id_offset = tonumber(string.reverse(string.match(string.reverse("" .. args['id']), "%d+")))
 
id_offset = tonumber(string.reverse(string.match(string.reverse("" .. args['id']), "%d+")))
 
label_offset = tonumber(string.reverse(string.match(string.reverse("" .. args['label']), "%d+")))
 
label_offset = tonumber(string.reverse(string.match(string.reverse("" .. args['label']), "%d+")))
 
else  
 
else  
if args['custom_id_offset'] == nil or args['custom_id_offset'] == "" then custom_id_offset = tonumber(args['offset']) end
   
id_offset = tonumber(args['offset'])
 
id_offset = tonumber(args['offset'])
 
label_offset = tonumber(args['offset'])
 
label_offset = tonumber(args['offset'])
Line 153: Line 162:  
 
 
for index = 0, count - 1 do
 
for index = 0, count - 1 do
if count > 1 then
+
if count > 1 or (args['offset'] ~= nil and args['offset'] ~= "") then --generate indexed strings for arrays or if an offset is defined
 +
args['id'] = p.indexed_string( args['id'], index + id_offset)
 +
args['label'] = p.indexed_string( args['label'], index + label_offset)
 +
end
 +
if count > 1 or (args['custom_id_offset'] ~= nil and args['custom_id_offset'] ~= "") then --generate indexed strings for arrays or if an offset is defined
 
if args['custom_id'] ~= nil and args['custom_id'] ~= "" then
 
if args['custom_id'] ~= nil and args['custom_id'] ~= "" then
args['custom_id'] = p.indexed_string( args['custom_id'], index + custom_id_offset + 1)
+
args['custom_id'] = p.indexed_string( args['custom_id'], index + custom_id_offset)
 
end
 
end
args['id'] = p.indexed_string( args['id'], index + id_offset)
  −
args['label'] = p.indexed_string( args['label'], index + label_offset)
   
end
 
end
 
--object_ids = object_ids .. args['id']
 
--object_ids = object_ids .. args['id']
Line 183: Line 194:  
end
 
end
 
return result
 
return result
 +
end
 +
 +
function p.getConsumedQuantity(obj)
 +
--mw.logObject(obj)
 +
local query = "[[HasPredecessor::" .. obj .. "]] |headers=hide |?#-=page |mainlabel=- |format=plain"
 +
local result = mw.smw.ask( query )
 +
local consumed = 0
 +
if result ~= nil then
 +
--mw.logObject(result)
 +
for num, row in pairs( result ) do
 +
--mw.logObject(row['page'])
 +
consumed = consumed + 1
 +
end
 +
--mw.logObject(result)
 +
end
 +
return consumed
 
end
 
end
  
Bots, bulkpusher, Bureaucrats, checkuser, filepusher, Interface administrators, oversight, pusher, rdfioadministrator, rdfiocurator, Administrators (Semantic MediaWiki), Curators (Semantic MediaWiki), Editors (Semantic MediaWiki), Administrators
5,452

edits