User:Jeblad/wb

From mediawiki.org

There are two working sets, one global for cached items and one for matched items. The matched items are local for the instance. All access loading an item puts the item into the global set.

The proposal assumes a w:XQuery-like API.

Path and identifiers[edit]

The identifier is a property if using the form "Pnum", an item if using the form "Qnum". A path consist of a sequence of identifiers, where an initial @ signifies a property or item used as a claim at the reified statement. Note that a claim is reified at several locations, most notable at the qualifiers, the references, and the values.

If path identifies a claim, and it is a "no value" or "unknown value", then it can't be traversed and will be silently removed if traversal goes further. Note that such a claim might have qualifiers and references.

Methods[edit]

find()
This filter on the given path. Could be used as:find 'P31/Q192299' or :find( 'P31/Q192299', true ) to do an implicit select of matched item. Returns self.
next()
Matches any node one step forward from the current matched nodes. Note that as this steps on nodes a match on property or item could always fail. Could be used as :next(), :next 'P18' or :next( 'P18', true ) to do an implicit select of matched item. Returns self.
nextItem()
Matches any item node one step forward from the current matched nodes. Note that as this steps on nodes of type item and a match on property will always fail. Could be used as :nextItem(), :nextItem 'Q20' or :nextItem( 'Q20', true ) to do an implicit select of matched item. Returns self.
nextClaim()
Matches any claim node one step forward from the current matched nodes. Note that as this steps on nodes of type claim and a match on item will always fail. Could be used as :nextClaim(), :nextClaim 'P18' or :nextClaim( 'P18', true ) to do an implicit select of matched item. Returns self.
nextUntil()
Matches any node forward from the current matched nodes. Will use all available expensive calls if misconfigured. Could be used as :nextUntil(), :nextUntil 'P18' or :nextUntil( 'P18', true ) to do an implicit select of matched item. Returns self.
prev()
Matches any node one step backward from the current matched nodes. Note that as this steps on nodes a match on property or item could always fail. Could be used as :prev(), :prev 'P18' or :prev( 'P18', true ) to do an implicit select of matched item. Returns self.
prevItem()
Matches any item node one step backward from the current matched nodes. Note that as this steps on nodes of type item and a match on property will always fail. Could be used as :prevItem(), :prevItem 'Q20' or :prevItem( 'Q20', true ) to do an implicit select of matched item. Returns self.
prevClaim()
Matches any claim node one step backward from the current matched nodes. Note that as this steps on nodes of type claim and a match on item will always fail. Could be used as :prevClaim(), :prevClaim 'P18' or :prevClaim( 'P18', true ) to do an implicit select of matched item. Returns self.
prevUntil()
Matches any node backward from the current matched nodes. Will use all available expensive calls if misconfigured. Could be used as :prevUntil(), :prevUntil 'P18' or :prevUntil( 'P18', true ) to do an implicit select of matched item. Returns self.
hasClaim()
This is a test. Returns boolean if any backtracked selected item has a claim.
hasQualifier()
This is a test. Returns boolean if any backtracked selected item has a qualifier.
hasReference()
This is a test. Returns boolean if any backtracked selected item has a reference.
isNovalue()
This is a test. Returns boolean if any backtracked selected item is a "no value".
isUnknown()
This is a test. Returns boolean if any backtracked selected item is a "unknown value".
each()
This process the current nodes, and call the provided function for each entry. The provided functions return result is thrown away. Returns self.
filter()
This process the current nodes, and filter by calling the provided function. The provided function should return a boolean result. Returns self.
types()
This process the current nodes, and filter on the given type. Could be used as :types() or :types 'item'. Returns the actual type or types.
items()
This process the current nodes, if they are items, or unwinds them until an item is found, and filter on the given item id. Could be used as :items() or :items 'Q192299'. Returns the actual item or items.
claims()
This process the current nodes, if they are claims, or unwinds them until a claim is found, and then filter on the given property id. Could be used as :claims() or :claims 'P18'. Returns the actual item or items.
qualifiers()
This dives into the qualifiers for the current nodes, if they are claims, or unwinds them until a claim is found, and filter on the given property id. Could be used as :qualifiers() or :qualifiers 'P18'. Returns the actual qualifier or qualifiers.
references()
This dives into the references for the current nodes, if they are claims, or unwinds them until a claim is found, and filter on the given property id. Could be used as :references() or :references 'P18'. Returns the actual reference or references.

Example[edit]

local wb = require 'wikibase'
local nodes = wb( 'Q20/P150/*' )                         -- finds nodes of Norwegian contains administrative territorial entity
local items = nodes:find( 'P31/Q192299' ):prevItem():items() -- finds items of solely Norwegian counties
local counties = wb( 'Q20/P150/*/P31/Q192299' ):prevItem():items() -- Do both