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.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' )
+                       )
                );
        }
 
        protected function buildComparer() {
                return new GlobeCoordinateValueComparer();
        }
-}
\ No newline at end of file
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/216996
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6b55d37a506e0b6203c30ac84e36de4aa6feb81a
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/WikidataQualityExternalValidation
Gerrit-Branch: master
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

Reply via email to