| 第1行: |
第1行: |
| | + | local SMWUtils = require("Module:SMWUtils") |
| | + | local ListUtils = require("Module:ListUtils") |
| | local p = {} | | local p = {} |
| − |
| |
| − | function _table_to_keys(tb)
| |
| − | local res = {}
| |
| − | for i, k in ipairs(tb) do
| |
| − | res[k] = true
| |
| − | end
| |
| − | return res
| |
| − | end
| |
| | | | |
| | function _merge_keys(a, b) | | function _merge_keys(a, b) |
| 第20行: |
第14行: |
| | end | | end |
| | | | |
| − | function _keys_to_table(set)
| |
| − | local res = {}
| |
| − | local ctr = 1
| |
| − | for k, v in pairs(set) do
| |
| − | res[ctr] = k
| |
| − | ctr = ctr + 1
| |
| − | end
| |
| − | return res
| |
| − | end
| |
| | | | |
| − | function p.query_inherited_property(anchor_property, query_property, parent_list) | + | function p.query_inherited_property(query_property, parent_list) |
| | local results = {} | | local results = {} |
| | for idx, parent in ipairs(parent_list) do | | for idx, parent in ipairs(parent_list) do |
| − | local anchor_query = "[["..anchor_property.."::"..parent.."]]" | + | local anchor_query = "[["..parent.."]]" |
| | local property_query = "[[" .. query_property .. "::+]]" | | local property_query = "[[" .. query_property .. "::+]]" |
| − | local content_query = "?"..query_property
| + | local query = anchor_query .. property_query |
| − | local query = anchor_query .. property_query .. "|" ..content_query .. "|format=plainlist" | + | local res = SMWUtils.query_page_properties(query, {query_property}) |
| − | local res = mw.smw.getQueryResult(query) | + | for j, r in ipairs(res) do |
| − | for j, r in ipairs(res.results) do | + | results[r.properties[query_property]] = true |
| − | for k, t in ipairs(r.printouts[query_property]) do | |
| − | results[t.fulltext] = true
| |
| − | end
| |
| | end | | end |
| | end | | end |
| 第47行: |
第29行: |
| | end | | end |
| | | | |
| − | function p.query_reversed_inherited_property(name, anchor_property, query_property) | + | function p.query_by_reference(name, query_property) |
| − | return p.query_inherited_property(query_property, anchor_property, {name}) | + | local query = "[["..query_property.."::"..name.."]]" |
| | + | return ListUtils.list_to_set(SMWUtils.query_pages(query)) |
| | end | | end |
| | | | |
| − | function p.query_children(name, anchor_property, parent_property)
| |
| − | return p.query_inherited_property(parent_property, anchor_property, {name})
| |
| − | end
| |
| | | | |
| | function _create_list(root, title, list) | | function _create_list(root, title, list) |
| 第77行: |
第57行: |
| | local parent_property = frame.args.parent_property | | local parent_property = frame.args.parent_property |
| | local parent_title = frame.args.parent_title | | local parent_title = frame.args.parent_title |
| − | local anchor_property = frame.args.anchor_property
| |
| | local properties = mw.text.split(frame.args.properties, ",") | | local properties = mw.text.split(frame.args.properties, ",") |
| | local children_title = frame.args.children_title | | local children_title = frame.args.children_title |
| 第84行: |
第63行: |
| | | | |
| | _create_list(root, parent_title, parents) | | _create_list(root, parent_title, parents) |
| − | mw.smw.set({[anchor_property]=name})
| |
| | for i, parent in ipairs(parents) do | | for i, parent in ipairs(parents) do |
| | mw.smw.set({[parent_property]=parent}) | | mw.smw.set({[parent_property]=parent}) |
| 第93行: |
第71行: |
| | local values = _split_or_empty(frame.args[prop.."_values"]) | | local values = _split_or_empty(frame.args[prop.."_values"]) |
| | local reversed = frame.args[prop.."_reversed"] | | local reversed = frame.args[prop.."_reversed"] |
| − | local values_set = _table_to_keys(values) | + | local values_set = ListUtils.list_to_set(values) |
| − | local inherited_values = p.query_inherited_property(anchor_property, prop, parents) | + | local inherited_values = p.query_inherited_property(prop, parents) |
| | local final_values = _merge_keys(values_set, inherited_values) | | local final_values = _merge_keys(values_set, inherited_values) |
| | if reversed then | | if reversed then |
| − | local reversed_values = p.query_reversed_inherited_property(name, anchor_property, reversed) | + | local reversed_values = p.query_by_reference(name, reversed) |
| | final_values = _merge_keys(final_values, reversed_values) | | final_values = _merge_keys(final_values, reversed_values) |
| | end | | end |
| − | local final_list = _keys_to_table(final_values) | + | local final_list = ListUtils.set_to_list(final_values) |
| | _create_list(root, title, final_list) | | _create_list(root, title, final_list) |
| | for i, k in ipairs(final_list) do | | for i, k in ipairs(final_list) do |
| 第108行: |
第86行: |
| | | | |
| | if children_title then | | if children_title then |
| − | local children = p.query_children(name, anchor_property, parent_property) | + | local children = p.query_by_reference(name, parent_property) |
| − | local children_list = _keys_to_table(children) | + | local children_list = ListUtils.set_to_list(children) |
| | _create_list(root, children_title, children_list) | | _create_list(root, children_title, children_list) |
| | end | | end |