Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Repo\Maintenance\UpdateUnits Class Reference

Update the conversion table for units. More...

+ Inheritance diagram for Wikibase\Repo\Maintenance\UpdateUnits:
+ Collaboration diagram for Wikibase\Repo\Maintenance\UpdateUnits:

Public Member Functions

 __construct ()
 
 execute ()
 
 setBaseUri ( $uri)
 Set base URI.
 
 convertDerivedUnit ( $unit, $convertUnits)
 Convert unit that does not reduce to a basic unit.
 
 convertUnit ( $unit, $convertUnits, $baseUnits, $unitUsage, &$reconvert)
 Create conversion data for a single unit.
 

Public Attributes

 $silent
 

Protected Member Functions

 error ( $err, $die=0)
 

Private Member Functions

 reduceUnits ( $reconvert, &$convertUnits)
 Reduce units that are not in term of base units into base units.
 
 formatJSON (array $convertUnits)
 Format units as JSON.
 
 getUnitUsage ( $min)
 Get units that are used at least $min times.
 
 getIDs ( $sparql, $item)
 Get list of IDs from SPARQL.
 
 getBaseUnits ( $filter)
 Get base units.
 
 getConvertableUnits ( $filter)
 Retrieve the list of convertable units.
 
 formatCSV (array $convertUnits)
 Format units as CSV.
 

Private Attributes

 $baseUri
 
 $baseLen
 
 $client
 

Detailed Description

Update the conversion table for units.

Base unit types for Wikidata: Q223662,Q208469 SI base unit,SI derived unit TODO: add support to non-SI units Example run: mwscript extensions/WikidataBuildResources/extensions/Wikibase/repo/maintenance/updateUnits.php –wiki wikidatawiki –base-unit-types Q223662,Q208469 –base-uri http://www.wikidata.org/entity/ –unit-class Q1978718 > unitConversion.json

Author
Stas Malyshev

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\Maintenance\UpdateUnits::__construct ( )

Member Function Documentation

◆ convertDerivedUnit()

Wikibase\Repo\Maintenance\UpdateUnits::convertDerivedUnit (   $unit,
  $convertUnits 
)

Convert unit that does not reduce to a basic unit.

Parameters
string[]$unit
array[]$convertUnitsList of units already converted
Returns
string[]|null Converted data for the unit or null if no conversion possible.

◆ convertUnit()

Wikibase\Repo\Maintenance\UpdateUnits::convertUnit (   $unit,
  $convertUnits,
  $baseUnits,
  $unitUsage,
$reconvert 
)

Create conversion data for a single unit.

Parameters
string[]$unitUnit data
string[]$convertUnitsAlready converted data
array[]$baseUnitsBase unit list
string[] | null$unitUsageUnit usage data
string[][]&$reconvertArray collecting units that require re-conversion later, due to their target unit not being base.
Returns
string[]|null Produces conversion data for the unit or null if not possible.

◆ error()

Wikibase\Repo\Maintenance\UpdateUnits::error (   $err,
  $die = 0 
)
protected
Parameters
string$err
int$dieIf > 0, go ahead and die out using this int as the code

◆ execute()

Wikibase\Repo\Maintenance\UpdateUnits::execute ( )

◆ formatCSV()

Wikibase\Repo\Maintenance\UpdateUnits::formatCSV ( array  $convertUnits)
private

Format units as CSV.

Parameters
array[]$convertUnits
Returns
string

◆ formatJSON()

Wikibase\Repo\Maintenance\UpdateUnits::formatJSON ( array  $convertUnits)
private

Format units as JSON.

Parameters
array[]$convertUnits
Returns
string

◆ getBaseUnits()

Wikibase\Repo\Maintenance\UpdateUnits::getBaseUnits (   $filter)
private

Get base units.

Parameters
string$filterUnit filter
Returns
array[]

◆ getConvertableUnits()

Wikibase\Repo\Maintenance\UpdateUnits::getConvertableUnits (   $filter)
private

Retrieve the list of convertable units.

Parameters
string$filter
Returns
array[]|false List of units that can be converted

◆ getIDs()

Wikibase\Repo\Maintenance\UpdateUnits::getIDs (   $sparql,
  $item 
)
private

Get list of IDs from SPARQL.

Parameters
string$sparqlQuery
string$itemVariable name where IDs are stored
Returns
string[] List of entity ID strings

◆ getUnitUsage()

Wikibase\Repo\Maintenance\UpdateUnits::getUnitUsage (   $min)
private

Get units that are used at least $min times.

We don't care about units that have been used less than 10 times, for now. Only top 200 will be returned (though so far we don't have that many).

Parameters
int$minMinimal usage for the unit.
Returns
string[] Array of ['unit' => Q-id, 'c' => count]

◆ reduceUnits()

Wikibase\Repo\Maintenance\UpdateUnits::reduceUnits (   $reconvert,
$convertUnits 
)
private

Reduce units that are not in term of base units into base units.

If some units are not reducible to base units, warning will be issued.

Parameters
array$reconvertList of units to be reduced
array&$convertUnitsList of unit conversion configs, will be modified if it is possible to reduce the unit to base units.

◆ setBaseUri()

Wikibase\Repo\Maintenance\UpdateUnits::setBaseUri (   $uri)

Set base URI.

Parameters
string$uri

Member Data Documentation

◆ $baseLen

Wikibase\Repo\Maintenance\UpdateUnits::$baseLen
private

◆ $baseUri

Wikibase\Repo\Maintenance\UpdateUnits::$baseUri
private

◆ $client

Wikibase\Repo\Maintenance\UpdateUnits::$client
private

◆ $silent

Wikibase\Repo\Maintenance\UpdateUnits::$silent

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