Wikibase
MediaWiki Wikibase extension
Wikibase\Client\Usage\UsageAspectTransformer Class Reference

Transforms usage aspect based on a filter of aspects relevant in some context. More...

Public Member Functions

 setRelevantAspects (EntityId $entityId, array $aspects)
 
 getRelevantAspects (EntityId $entityId)
 
 getFilteredUsages (EntityId $entityId, array $aspects)
 Gets EntityUsage objects for each aspect in $aspects that is relevant according to getRelevantAspects( $entityId ). More...
 
 transformPageEntityUsages (PageEntityUsages $pageEntityUsages)
 Transforms the entity usages from $pageEntityUsages according to the relevant aspects defined by calling setRelevantAspects(). More...
 

Private Member Functions

 buildEntityUsages (EntityId $entityId, array $aspects)
 
 getFilteredAspects (array $aspectKeys, array $relevant)
 Filter $aspects based on the aspects provided by $relevant, according to the rules defined for combining aspects (see class level documentation). More...
 
 includeGeneralUsages (array $relevantKeys, array $aspectKeys, array &$aspects)
 Makes general (modifier less) usages trigger the associated relevant specialized aspects. More...
 

Private Attributes

 $relevantAspectsPerEntity
 

Detailed Description

Transforms usage aspect based on a filter of aspects relevant in some context.

Relevant aspects for each entity are collected using the setRelevantAspects() method.

Example: If a page uses the "label" (L) and "title" (T) aspects of item Q1, a UsageAspectTransformer that was set up to consider the label aspect of Q1 to be relevant will transform the usage Q1::L + Q1::T to the "relevant" usage Q1::L.

Example: The "all" (X) aspect is treated specially: If a page uses the X aspect, a UsageAspectTransformer that was constructed to consider e.g. the label and title aspects of Q1 to be relevant will transform the usage Q1::X to the "relevant" usage Q1::L + Q1::T. Conversely, if a page uses the "sitelink" (S) aspect, a UsageAspectTransformer that was constructed to consider all (X) usages relevant will keep the usage Q1::S usage as "relevant".

Author
Daniel Kinzler
Thiemo Kreuz

Member Function Documentation

◆ buildEntityUsages()

Wikibase\Client\Usage\UsageAspectTransformer::buildEntityUsages ( EntityId  $entityId,
array  $aspects 
)
private
Parameters
EntityId$entityId
string[]$aspects(may have modifiers applied)
Returns
EntityUsage[]

◆ getFilteredAspects()

Wikibase\Client\Usage\UsageAspectTransformer::getFilteredAspects ( array  $aspectKeys,
array  $relevant 
)
private

Filter $aspects based on the aspects provided by $relevant, according to the rules defined for combining aspects (see class level documentation).

Note
This basically returns the intersection of $aspects and $relevant, except for special treatment of ALL_USAGE and of modified aspects:
  • If X is present in $aspects, this method will return $relevant (if "all" is in the base set, the filtered set will be the filter itself).
  • If X is present in $relevant, this method returns $aspects (if all aspects are relevant, nothing is filtered out).
  • If a modified aspect A.xx is present in $relevant and the unmodified aspect A is present in $aspects, A.xx is included in the result.
  • If a modified aspect A.xx is present in $aspect and the unmodified aspect A is present in $relevant, neither A.xx nor A will be included in the result.
Parameters
string[]$aspectKeysArray of aspect keys, with modifiers applied.
string[]$relevantArray of aspect keys, with modifiers applied.
Returns
string[] Array of aspect keys, with modifiers applied.

◆ getFilteredUsages()

Wikibase\Client\Usage\UsageAspectTransformer::getFilteredUsages ( EntityId  $entityId,
array  $aspects 
)

Gets EntityUsage objects for each aspect in $aspects that is relevant according to getRelevantAspects( $entityId ).

Example: If was called with setRelevantAspects( $q3, [ 'T', 'L.de', 'L.en' ] ), getFilteredUsages( $q3, [ 'S', 'L' ] ) will return EntityUsage( $q3, 'L.de', 'L.en' ), while getFilteredUsages( $q3, [ 'X' ] ) will return EntityUsage( $q3, 'T' ) and EntityUsage( $q3, 'L' ).

Parameters
EntityId$entityId
string[]$aspects
Returns
EntityUsage[]

◆ getRelevantAspects()

Wikibase\Client\Usage\UsageAspectTransformer::getRelevantAspects ( EntityId  $entityId)
Parameters
EntityId$entityId
Returns
string[]

◆ includeGeneralUsages()

Wikibase\Client\Usage\UsageAspectTransformer::includeGeneralUsages ( array  $relevantKeys,
array  $aspectKeys,
array &  $aspects 
)
private

Makes general (modifier less) usages trigger the associated relevant specialized aspects.

For example matches 'L' in $aspectKeys to 'L.xx' in $relevantKeys.

Parameters
string[]$relevantKeysArray of potentially relevant aspect keys, with modifiers applied.
string[]$aspectKeysArray of actually used aspects keys, with modifiers applied.
array&$aspectsAssociative array of aspect keys (with modifiers) as keys, the values being meaningless (a.k.a. HashSet).

◆ setRelevantAspects()

Wikibase\Client\Usage\UsageAspectTransformer::setRelevantAspects ( EntityId  $entityId,
array  $aspects 
)
Parameters
EntityId$entityId
string[]$aspects

◆ transformPageEntityUsages()

Wikibase\Client\Usage\UsageAspectTransformer::transformPageEntityUsages ( PageEntityUsages  $pageEntityUsages)

Transforms the entity usages from $pageEntityUsages according to the relevant aspects defined by calling setRelevantAspects().

A new PageEntityUsages containing the filtered usage list is returned.

See also
getFilteredUsages()
Parameters
PageEntityUsages$pageEntityUsages
Returns
PageEntityUsages

Member Data Documentation

◆ $relevantAspectsPerEntity

Wikibase\Client\Usage\UsageAspectTransformer::$relevantAspectsPerEntity
private

The documentation for this class was generated from the following file: