| Line 5: |
Line 5: |
| | function p.GetProcessesGraph() | | function p.GetProcessesGraph() |
| | local process_types = {"LabProcess:OSL9a645a64b15442398ad3c057e1b64d87", "LabProcess:OSL4c1f7444e389471a8250f53407191735", "LabProcess:OSLd0c734a239844a0d8820856add12aeca"} | | local process_types = {"LabProcess:OSL9a645a64b15442398ad3c057e1b64d87", "LabProcess:OSL4c1f7444e389471a8250f53407191735", "LabProcess:OSLd0c734a239844a0d8820856add12aeca"} |
| | + | --local process_types = {"LabProcess:OSL4c1f7444e389471a8250f53407191735", "LabProcess:OSLd0c734a239844a0d8820856add12aeca"} |
| | local result = p.GetProcesses(process_types) | | local result = p.GetProcesses(process_types) |
| | --mw.logObject(result) | | --mw.logObject(result) |
| Line 19: |
Line 20: |
| | local edges = "" | | local edges = "" |
| | for obj_id, obj in pairs(process['objects']) do | | for obj_id, obj in pairs(process['objects']) do |
| − | nodes = nodes .. '"' .. obj_id .. '" [label="' .. obj['local_id'] .. '" href="https://kiprobatt.de/wiki/' .. obj_id .. '"];' | + | |
| | + | --if p.IsGlobalObject(obj) then |
| | + | nodes = nodes .. '"' .. obj_id .. '" [label="' .. obj['local_id'] .. '" href="/wiki/' .. obj_id .. '"];' |
| | + | --end |
| | local successors = nil | | local successors = nil |
| − | if (obj['successor_object'] ~= nil) then | + | successors = p.concatTables(obj['successor_object'], obj['successor_object_semistatic']) |
| − | successors = p.NormalizePropertyValue(obj['successor_object']);
| + | successors = p.concatTables(successors, obj['successor_object_static']) |
| − | end | + | successors = p.removeDuplicates(successors) |
| − | if (obj['successor_process_output'] ~= nil) then | + | obj['successors'] = successors |
| − | _successors = p.NormalizePropertyValue(obj['successor_process_output']);
| + | successors = p.GetNextGlobalObject(result, obj); |
| − | if (p.tablelength(_successors) == 1) then successors = _successors end
| + | --if (obj['successor_object'] ~= nil) then |
| − | end | + | -- successors = p.toTable(obj['successor_object']); |
| | + | --end |
| | + | --if (obj['successor_process_output'] ~= nil) then |
| | + | -- _successors = p.toTable(obj['successor_process_output']); |
| | + | -- if (p.tablelength(_successors) == 1) then successors = _successors end |
| | + | --end |
| | if (successors ~= nil) then | | if (successors ~= nil) then |
| | for succ_id, succ in pairs(successors) do | | for succ_id, succ in pairs(successors) do |
| Line 33: |
Line 42: |
| | end | | end |
| | end | | end |
| | + | |
| | end | | end |
| | g = g .. [[ | | g = g .. [[ |
| Line 61: |
Line 71: |
| | results[process_type] = {} | | results[process_type] = {} |
| | results[process_type]['objects'] = {} | | results[process_type]['objects'] = {} |
| − | result = p.GetOutputs(process_type) | + | --result = p.GetOutputs(process_type) |
| | + | result = p.GetProcessObjects(process_type) |
| | if (result ~= nil) then | | if (result ~= nil) then |
| | for index, obj in pairs(result) do | | for index, obj in pairs(result) do |
| Line 85: |
Line 96: |
| | --mw.logObject(results) | | --mw.logObject(results) |
| | return results | | return results |
| | + | end |
| | + | |
| | + | function p.GetNextGlobalObject(dataset, src_obj) |
| | + | if (src_obj['successors'] == nil) then return nil end |
| | + | local result = {} |
| | + | for id,process in pairs(dataset) do |
| | + | for obj_id, obj in pairs(process['objects']) do |
| | + | for succ_id, succ in pairs(src_obj['successors']) do |
| | + | --mw.log("Compare " .. obj_id .. " with " .. succ) |
| | + | if obj_id == succ then |
| | + | local isGlobal = p.IsGlobalObject(obj) |
| | + | if isGlobal == false then |
| | + | mw.log("Follow " .. obj_id) |
| | + | p.concatTables(result,p.GetNextGlobalObject(dataset, obj)) |
| | + | elseif (succ ~= nil) then |
| | + | mw.log("Found " .. succ) |
| | + | table.insert(result, succ) |
| | + | end |
| | + | end |
| | + | end |
| | + | end |
| | + | end |
| | + | return result |
| | + | end |
| | + | |
| | + | function p.IsGlobalObject(obj) |
| | + | local isGlobal = false |
| | + | for type_id, type in pairs(obj['type']) do |
| | + | if (type == "Category:LabProcessOutput") then isGlobal = true end |
| | + | end |
| | + | return isGlobal |
| | end | | end |
| | | | |
| Line 104: |
Line 146: |
| | ]] | | ]] |
| | local result = mw.smw.ask( query ) | | local result = mw.smw.ask( query ) |
| − | mw.logObject(result) | + | --mw.logObject(result) |
| | + | return result |
| | + | end |
| | + | |
| | + | function p.GetProcessObjects(process_types) |
| | + | --local process_types = {"LabProcess:OSL9a645a64b15442398ad3c057e1b64d87", "LabProcess:OSL4c1f7444e389471a8250f53407191735", "LabProcess:OSLd0c734a239844a0d8820856add12aeca"} |
| | + | process_types = p.toTable(process_types) |
| | + | local query = "[[-HasObject.IsInstanceOf::" .. table.concat(process_types, "]] OR [[-HasObject.IsInstanceOf::") .. "]]" |
| | + | query = query .. [[ |
| | + | |?#-=id |
| | + | |?HasId#-=local_id |
| | + | |?-HasPredecessor.IsProcessParameterOf.HasOutput#-=successor_object_semistatic |
| | + | |?-HasPredecessor.IsObjectParameterOf#-=successor_object |
| | + | |?-HasInput.HasOutput#-=successor_object_static |
| | + | |?Category#-=type |
| | + | |format=plain |
| | + | |limit=10000 |
| | + | ]] |
| | + | local result = mw.smw.ask( query ) |
| | + | --mw.logObject(result) |
| | + | |
| | return result | | return result |
| | end | | end |
| | | | |
| | -- expands single values for properties to tables with len 1 | | -- expands single values for properties to tables with len 1 |
| − | function p.NormalizePropertyValue(v) | + | function p.toTable(v) |
| | + | if (v == nil) then return nil end |
| | if (type(v) ~= "table") then | | if (type(v) ~= "table") then |
| | v = {v} | | v = {v} |
| Line 120: |
Line 183: |
| | for _ in pairs(T) do count = count + 1 end | | for _ in pairs(T) do count = count + 1 end |
| | return count | | return count |
| | + | end |
| | + | |
| | + | function p.concatTables(t1,t2) |
| | + | t1 = p.toTable(t1) |
| | + | t2 = p.toTable(t2) |
| | + | if (t1 == nil) then |
| | + | t1 = t2 |
| | + | elseif (t2 ~= nil) then |
| | + | for _,v in ipairs(t2) do |
| | + | table.insert(t1, v) |
| | + | end |
| | + | end |
| | + | return t1 |
| | + | end |
| | + | |
| | + | function p.removeDuplicates(t) |
| | + | if (t == nil) then return nil end |
| | + | local hash = {} |
| | + | local res = {} |
| | + | for _,v in ipairs(t) do |
| | + | if (not hash[v]) then |
| | + | res[#res+1] = v |
| | + | hash[v] = true |
| | + | end |
| | + | end |
| | + | return res |
| | end | | end |
| | | | |
| | return p | | return p |