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.000000 N, 32.000000 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.090000 N, 31.910000 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.300000 N, 31.700000 E' ) + ) ); } -- To view, visit https://gerrit.wikimedia.org/r/217000 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6b55d37a506e0b6203c30ac84e36de4aa6feb81a Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/WikidataQualityExternalValidation Gerrit-Branch: v1 Gerrit-Owner: Tamslo <tamaraslosa...@gmail.com> Gerrit-Reviewer: Soeren.oldag <soeren_ol...@freenet.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits