Module:PropertyPathTest

Lua
CodeDiscussionLinksLink count SubpagesDocumentationTestsResultsSandboxLive code All modules


Interface for Module:PropertyPath

Functions
To be used with #invoke in template
matches(frame)
A function to check if a target item is reachable with a property path from a source item
  • frame.args[1] : source item
  • frame.args[2] : a property path, see Module:PropertyPath
  • frame.args[3] : target item
returns true if the first item id is an instance of the second one, or false otherwise
isInstance(frame)
  • frame.args[1] : test instance item id
  • frame.args[2] : class item id
shortcurt for a test path of "P31/P279*"
returns "true" if the first item id is an instance of the second one, or "false" otherwise


Examples :

Is Pedro II of Brazil (Q156774)  View with Reasonator View with SQID a patrilinear child of John IV of Portugal (Q1060796)  View with Reasonator View with SQID
{{#invoke:PropertyPathTest|matches|http://www.wikidata.org/entity/Q156774|http://www.wikidata.org/entity/Q1060796|father*}}

  • true

Is Pedro II of Brazil (Q156774)  View with Reasonator View with SQID a patrilinear child of Douglas Adams (Q42)  View with Reasonator View with SQID
{{#invoke:PropertyPathTest|matches|http://www.wikidata.org/entity/Q156774|http://www.wikidata.org/entity/Q42|father*}}

  • false


{{#invoke:PropertyPathTest|isInstance|Q42|Q5}}

  • true

{{#invoke:PropertyPathTest|isInstance|Q1|Q5}}

  • false


Used by {{IsInstance}}, {{ReachableFrom}} or {{IsSubclass}}, {{HasOccupation}}.

Code

local ppath = require("Module:PropertyPath")
local ids = require("Module:IDs")


local p = {}

p.testInstance = function(item, class) 
	return ppath.matches( item, "P31/P279*", class)
end

p.isInstance = function(frame)
	local f = frame
	return p.testInstance(
		ids.qid_normalize(f.args[1]), 
		ids.qid_normalize(f.args[2])
	)
end

p.matches = function(frame)
	return ppath.matches(
		ids.qid_normalize(frame.args[1]), 
		frame.args[3], 
		ids.qid_normalize(frame.args[2]))
end


return p