[MediaWiki-commits] [Gerrit] Adapted GlobeCoordinateComparer - change (mediawiki...WikidataQualityExternalValidation)
Soeren.oldag has submitted this change and it was merged. Change subject: Adapted GlobeCoordinateComparer .. Adapted GlobeCoordinateComparer [cherry-picked from master] * removed string-based comparison * if the local precision is satisfied it's a match * if pi * precision is satisfied it's a patial-match Bug: T96856 Change-Id: I6b55d37a506e0b6203c30ac84e36de4aa6feb81a --- M includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php M tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php 2 files changed, 39 insertions(+), 6 deletions(-) Approvals: Soeren.oldag: Verified; Looks good to me, approved diff --git a/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php b/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php index c88a923..88b7488 100755 --- a/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php +++ b/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php @@ -3,7 +3,6 @@ namespace WikibaseQuality\ExternalValidation\CrossCheck\Comparer; use DataValues\DataValue; -use DataValues\Geo\Formatters\GlobeCoordinateFormatter; use DataValues\Geo\Parsers\GlobeCoordinateParser; use DataValues\GlobeCoordinateValue; use Doctrine\Instantiator\Exception\InvalidArgumentException; @@ -34,18 +33,27 @@ throw new InvalidArgumentException( 'GlobeCoordinateValueComparer can only compare GlobeCoordinateValue objects.' ); } - $globeFormatter = new GlobeCoordinateFormatter(); - $formattedLocalValue = $globeFormatter-format( $localValue ); - $externalValues = $this-parseExternalValues( $externalValues, $dumpMetaInformation ); if ( $externalValues ) { $status = CompareResult::STATUS_MISMATCH; foreach ( $externalValues as $externalValue ) { - $formattedExternalValue = $globeFormatter-format( $externalValue ); - if ( $formattedLocalValue === $formattedExternalValue ) { + + $precision = $localValue-getPrecision(); + $locLat = $localValue-getLatitude(); + $locLong = $localValue-getLongitude(); + $extLat = $externalValue-getLatitude(); + $extLong = $externalValue-getLongitude(); + $diffLat = abs( $locLat - $extLat ); + $diffLong = abs( $locLong - $extLong ); + if ( ( $diffLat = $precision ) ( $diffLong = $precision ) ) { $status = CompareResult::STATUS_MATCH; break; } + $daumen = $precision; + if ( ( $diffLat = pi() * $daumen ) ( $diffLong = pi() * $daumen ) ) { + $status = CompareResult::STATUS_PARTIAL_MATCH; + } + } return new CompareResult( $localValue, $externalValues, $status ); diff --git a/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php b/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php index f033240..3cee6a1 100755 --- a/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php +++ b/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php @@ -41,6 +41,7 @@ public function comparisonProvider() { $localValue = new GlobeCoordinateValue( new LatLongValue( 64, 26 ), 1 ); + $localPrecisionValue = new GlobeCoordinateValue( new LatLongValue( 42, 32 ), 0.1 ); return array( // Correct formatted external data @@ -97,6 +98,30 @@ '42.00 N, 32.00 E' ) ), + // Match with precision + array( + new CompareResult( + $localPrecisionValue, + array( + new GlobeCoordinateValue( new LatLongValue( 42.09, 31.91 ), 0.01 ) + ), + CompareResult::STATUS_MATCH + ), + $localPrecisionValue, + array( '42.09 N, 31.91 E' ) + ), + // Partial match with pi * daumen + array( + new CompareResult( + $localPrecisionValue, +
[MediaWiki-commits] [Gerrit] Adapted GlobeCoordinateComparer - change (mediawiki...WikidataQualityExternalValidation)
Soeren.oldag has submitted this change and it was merged. Change subject: Adapted GlobeCoordinateComparer .. Adapted GlobeCoordinateComparer [cherry-picked from master] * removed string-based comparison * if the local precision is satisfied it's a match * if pi * precision is satisfied it's a patial-match Bug: T96856 Change-Id: I6b55d37a506e0b6203c30ac84e36de4aa6feb81a --- M includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php M tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php 2 files changed, 41 insertions(+), 8 deletions(-) Approvals: Soeren.oldag: Verified; Looks good to me, approved diff --git a/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php b/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php index ef1dd56..f2b9e8b 100755 --- a/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php +++ b/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php @@ -3,7 +3,6 @@ namespace WikibaseQuality\ExternalValidation\CrossCheck\Comparer; use DataValues\DataValue; -use DataValues\Geo\Formatters\GlobeCoordinateFormatter; use DataValues\Geo\Parsers\GlobeCoordinateParser; use DataValues\GlobeCoordinateValue; use Doctrine\Instantiator\Exception\InvalidArgumentException; @@ -35,18 +34,27 @@ throw new InvalidArgumentException( 'GlobeCoordinateValueComparer can only compare GlobeCoordinateValue objects.' ); } - $globeFormatter = new GlobeCoordinateFormatter(); - $formattedLocalValue = $globeFormatter-format( $localValue ); - $externalValues = $this-parseExternalValues( $externalValues, $dumpMetaInformation ); if ( $externalValues ) { $status = CompareResult::STATUS_MISMATCH; foreach ( $externalValues as $externalValue ) { - $formattedExternalValue = $globeFormatter-format( $externalValue ); - if ( $formattedLocalValue === $formattedExternalValue ) { + + $precision = $localValue-getPrecision(); + $locLat = $localValue-getLatitude(); + $locLong = $localValue-getLongitude(); + $extLat = $externalValue-getLatitude(); + $extLong = $externalValue-getLongitude(); + $diffLat = abs( $locLat - $extLat ); + $diffLong = abs( $locLong - $extLong ); + if ( ( $diffLat = $precision ) ( $diffLong = $precision ) ) { $status = CompareResult::STATUS_MATCH; break; } + $daumen = $precision; + if ( ( $diffLat = pi() * $daumen ) ( $diffLong = pi() * $daumen ) ) { + $status = CompareResult::STATUS_PARTIAL_MATCH; + } + } return new CompareResult( $localValue, $externalValues, $status ); @@ -74,4 +82,4 @@ public function isComparerFor( $dataValueType ) { return $dataValueType === 'globecoordinate'; } -} \ No newline at end of file +} diff --git a/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php b/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php index 33b5bed..1e0d54a 100755 --- a/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php +++ b/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php @@ -40,6 +40,7 @@ public function comparisonProvider() { $localValue = new GlobeCoordinateValue( new LatLongValue( 64, 26 ), 1 ); + $localPrecisionValue = new GlobeCoordinateValue( new LatLongValue( 42, 32 ), 0.1 ); return array( // Correct formatted external data @@ -96,10 +97,34 @@ '42.00 N, 32.00 E' ) ), + // Match with precision + array( + new CompareResult( + $localPrecisionValue, + array( + new GlobeCoordinateValue( new LatLongValue( 42.09, 31.91 ), 0.01 ) + ), + CompareResult::STATUS_MATCH + ), + $localPrecisionValue, + array( '42.09 N, 31.91 E' ) + ), + // Partial
[MediaWiki-commits] [Gerrit] Adapted GlobeCoordinateComparer - change (mediawiki...WikidataQualityExternalValidation)
Tamslo has uploaded a new change for review. https://gerrit.wikimedia.org/r/216996 Change subject: Adapted GlobeCoordinateComparer .. Adapted GlobeCoordinateComparer * removed string-based comparison * if the local precision is satisfied it's a match * if pi * precision is satisfied it's a patial-match Bug: T96856 Change-Id: I6b55d37a506e0b6203c30ac84e36de4aa6feb81a --- M includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php M tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php 2 files changed, 39 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQualityExternalValidation refs/changes/96/216996/1 diff --git a/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php b/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php index e10adf7..7132e23 100755 --- a/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php +++ b/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php @@ -3,7 +3,6 @@ namespace WikibaseQuality\ExternalValidation\CrossCheck\Comparer; use DataValues\DataValue; -use DataValues\Geo\Formatters\GlobeCoordinateFormatter; use DataValues\Geo\Parsers\GlobeCoordinateParser; use DataValues\GlobeCoordinateValue; use Doctrine\Instantiator\Exception\InvalidArgumentException; @@ -34,18 +33,27 @@ throw new InvalidArgumentException( 'GlobeCoordinateValueComparer can only compare GlobeCoordinateValue objects.' ); } -$globeFormatter = new GlobeCoordinateFormatter(); -$formattedLocalValue = $globeFormatter-format( $localValue ); - $externalValues = $this-parseExternalValues( $externalValues, $dumpMetaInformation ); if( $externalValues ) { $status = CompareResult::STATUS_MISMATCH; foreach ( $externalValues as $externalValue ) { -$formattedExternalValue = $globeFormatter-format( $externalValue ); -if ( $formattedLocalValue === $formattedExternalValue ) { + +$precision = $localValue-getPrecision(); +$locLat = $localValue-getLatitude(); +$locLong = $localValue-getLongitude(); +$extLat = $externalValue-getLatitude(); +$extLong = $externalValue-getLongitude(); +$diffLat = abs( $locLat - $extLat ); +$diffLong = abs( $locLong - $extLong ); +if ( ( $diffLat = $precision ) ( $diffLong = $precision )) { $status = CompareResult::STATUS_MATCH; break; } +$daumen = $precision; +if ( ( $diffLat = pi() * $daumen ) ( $diffLong = pi() * $daumen )) { +$status = CompareResult::STATUS_PARTIAL_MATCH; +} + } return new CompareResult( $localValue, $externalValues, $status ); diff --git a/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php b/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php index 7fd5193..c61c1ed 100755 --- a/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php +++ b/tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php @@ -41,6 +41,7 @@ public function comparisonProvider() { $localValue = new GlobeCoordinateValue( new LatLongValue( 64, 26 ), 1 ); +$localPrecisionValue = new GlobeCoordinateValue( new LatLongValue( 42, 32 ), 0.1 ); return array( // Correct formatted external data @@ -97,6 +98,30 @@ '42.00 N, 32.00 E' ) ), +// Match with precision +array( +new CompareResult( +$localPrecisionValue, +array( +new GlobeCoordinateValue( new LatLongValue( 42.09, 31.91 ), 0.01 ) +), +CompareResult::STATUS_MATCH +), +$localPrecisionValue, +array( '42.09 N, 31.91 E' ) +), +// Partial match with pi * daumen +array( +new CompareResult( +$localPrecisionValue, +array( +new GlobeCoordinateValue( new LatLongValue( 42.3, 31.7 ), 0.1 ) +), +CompareResult::STATUS_PARTIAL_MATCH +), +$localPrecisionValue, +array( '42.30 N, 31.70 E' ) +) ); } -- To view, visit https://gerrit.wikimedia.org/r/216996 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6b55d37a506e0b6203c30ac84e36de4aa6feb81a Gerrit-PatchSet: 1 Gerrit-Project:
[MediaWiki-commits] [Gerrit] Adapted GlobeCoordinateComparer - change (mediawiki...WikidataQualityExternalValidation)
Tamslo has uploaded a new change for review. https://gerrit.wikimedia.org/r/217000 Change subject: Adapted GlobeCoordinateComparer .. Adapted GlobeCoordinateComparer [cherry-picked from master] * removed string-based comparison * if the local precision is satisfied it's a match * if pi * precision is satisfied it's a patial-match Bug: T96856 Change-Id: I6b55d37a506e0b6203c30ac84e36de4aa6feb81a --- M includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php M tests/phpunit/CrossCheck/Comparer/GlobeCoordinateValueComparerTest.php 2 files changed, 154 insertions(+), 120 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQualityExternalValidation refs/changes/00/217000/1 diff --git a/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php b/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php index c88a923..cf8f80e 100755 --- a/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php +++ b/includes/CrossCheck/Comparer/GlobeCoordinateValueComparer.php @@ -20,55 +20,64 @@ */ class GlobeCoordinateValueComparer extends DataValueComparerBase { - /** -* @see DataValueComparer::compare -* -* @param DataValue $localValue -* @param array $externalValues -* @param DumpMetaInformation $dumpMetaInformation -* @throws InvalidArgumentException -* @return CompareResult -*/ - public function compare( DataValue $localValue, array $externalValues, DumpMetaInformation $dumpMetaInformation ) { - if ( !( $localValue instanceof GlobeCoordinateValue ) ) { - throw new InvalidArgumentException( 'GlobeCoordinateValueComparer can only compare GlobeCoordinateValue objects.' ); - } +/** + * @see DataValueComparer::compare + * + * @param DataValue $localValue + * @param array $externalValues + * @param DumpMetaInformation $dumpMetaInformation + * @throws InvalidArgumentException + * @return CompareResult + */ +public function compare( DataValue $localValue, array $externalValues, DumpMetaInformation $dumpMetaInformation ) { +if ( !( $localValue instanceof GlobeCoordinateValue ) ) { +throw new InvalidArgumentException( 'GlobeCoordinateValueComparer can only compare GlobeCoordinateValue objects.' ); +} - $globeFormatter = new GlobeCoordinateFormatter(); - $formattedLocalValue = $globeFormatter-format( $localValue ); +$externalValues = $this-parseExternalValues( $externalValues, $dumpMetaInformation ); +if( $externalValues ) { +$status = CompareResult::STATUS_MISMATCH; +foreach ( $externalValues as $externalValue ) { - $externalValues = $this-parseExternalValues( $externalValues, $dumpMetaInformation ); - if ( $externalValues ) { - $status = CompareResult::STATUS_MISMATCH; - foreach ( $externalValues as $externalValue ) { - $formattedExternalValue = $globeFormatter-format( $externalValue ); - if ( $formattedLocalValue === $formattedExternalValue ) { - $status = CompareResult::STATUS_MATCH; - break; - } - } +$precision = $localValue-getPrecision(); +$locLat = $localValue-getLatitude(); +$locLong = $localValue-getLongitude(); +$extLat = $externalValue-getLatitude(); +$extLong = $externalValue-getLongitude(); +$diffLat = abs( $locLat - $extLat ); +$diffLong = abs( $locLong - $extLong ); +if ( ( $diffLat = $precision ) ( $diffLong = $precision )) { +$status = CompareResult::STATUS_MATCH; +break; +} +$daumen = $precision; +if ( ( $diffLat = pi() * $daumen ) ( $diffLong = pi() * $daumen )) { +$status = CompareResult::STATUS_PARTIAL_MATCH; +} - return new CompareResult( $localValue, $externalValues, $status ); - } - } +} - /** -* @see DataValueComparerBase::getExternalValueParser -* -* @param DumpMetaInformation $dumpMetaInformation -* @return GlobeCoordinateParser -*/ - protected function getExternalValueParser( DumpMetaInformation $dumpMetaInformation ) { - return new GlobeCoordinateParser(); - } +return new CompareResult( $localValue, $externalValues, $status ); +} +} - /** -* @see DataValueComparer::isComparerFor -* -* @param string