Wikibase
MediaWiki Wikibase extension
Wikibase\Repo\Maintenance\UpdateUnits Class Reference

Generate the conversion table for units, optionally filtered to units of a certain type. More...

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

Public Member Functions

 __construct ()
 
 execute ()
 
 setBaseUri ( $uri)
 
 convertDerivedUnit ( $unit, $convertUnits)
 Convert unit that does not reduce to a coherent unit. More...
 
 convertUnit ( $unit, $convertUnits, $coherentUnits, $unitUsage, &$reconvert)
 Create conversion data for a single unit. More...
 

Public Attributes

 $silent
 

Protected Member Functions

 error ( $err, $die=0)
 

Private Member Functions

 reduceUnits ( $reconvert, &$convertUnits)
 Reduce units that are not in term of coherent units into coherent units. More...
 
 formatJSON (array $convertUnits)
 Format units as JSON. More...
 
 getUnitUsage ( $min)
 Get units that are used at least $min times. More...
 
 getIDs ( $sparql, $item)
 Get list of IDs from SPARQL. More...
 
 getCoherentUnits ( $filter)
 Get coherent units (those with a conversion factor of 1 to themselves). More...
 
 getConvertableUnits ( $filter)
 Retrieve the list of convertable units. More...
 
 formatCSV (array $convertUnits)
 Format units as CSV. More...
 

Private Attributes

 $baseUri
 
 $baseLen
 
 $client
 

Detailed Description

Generate the conversion table for units, optionally filtered to units of a certain type.

This script retrieves and emits the conversion data into coherent units. For instance, the millimetre is equal to 1/1000 of the coherent unit metre (also an SI base unit), while the ampere hour is equal to 3600 of the coherent unit coulomb, the product of the SI base units ampere and second.

Example usage: mwscript extensions/WikidataBuildResources/extensions/Wikibase/repo/maintenance/updateUnits.php –wiki wikidatawiki –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 coherent 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,
  $coherentUnits,
  $unitUsage,
$reconvert 
)

Create conversion data for a single unit.

Parameters
string[]$unitUnit data
string[]$convertUnitsAlready converted data
array[]$coherentUnitsUltimate target units
string[] | null$unitUsageUnit usage data
string[][]&$reconvertArray collecting units that require re-conversion later, due to their target unit not being coherent.
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

◆ getCoherentUnits()

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

Get coherent units (those with a conversion factor of 1 to themselves).

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 coherent units into coherent units.

If some units are not reducible to coherent units, warnings are 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 coherent units.

◆ setBaseUri()

Wikibase\Repo\Maintenance\UpdateUnits::setBaseUri (   $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: