@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * @param StringNormalizer $stringNormalizer |
| 28 | 28 | */ |
| 29 | - public function __construct( StringNormalizer $stringNormalizer ) { |
|
| 29 | + public function __construct(StringNormalizer $stringNormalizer) { |
|
| 30 | 30 | $this->stringNormalizer = $stringNormalizer; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -37,16 +37,16 @@ discard block |
||
| 37 | 37 | * @param string $comparativeValue |
| 38 | 38 | * @return string |
| 39 | 39 | */ |
| 40 | - public function compare( $value, $comparativeValue ) { |
|
| 41 | - Assert::parameterType( 'string', $value, '$value' ); |
|
| 42 | - Assert::parameterType( 'string', $comparativeValue, '$comparativeValue' ); |
|
| 40 | + public function compare($value, $comparativeValue) { |
|
| 41 | + Assert::parameterType('string', $value, '$value'); |
|
| 42 | + Assert::parameterType('string', $comparativeValue, '$comparativeValue'); |
|
| 43 | 43 | |
| 44 | - $value = $this->cleanDataString( $value ); |
|
| 45 | - $comparativeValue = $this->cleanDataString( $comparativeValue ); |
|
| 44 | + $value = $this->cleanDataString($value); |
|
| 45 | + $comparativeValue = $this->cleanDataString($comparativeValue); |
|
| 46 | 46 | |
| 47 | - if ( $value === $comparativeValue ) { |
|
| 47 | + if ($value === $comparativeValue) { |
|
| 48 | 48 | return ComparisonResult::STATUS_MATCH; |
| 49 | - } elseif ( $this->checkSimilarity( $value, $comparativeValue ) ) { |
|
| 49 | + } elseif ($this->checkSimilarity($value, $comparativeValue)) { |
|
| 50 | 50 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
| 51 | 51 | } else { |
| 52 | 52 | return ComparisonResult::STATUS_MISMATCH; |
@@ -60,19 +60,19 @@ discard block |
||
| 60 | 60 | * @param array $comparativeValues |
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | - public function compareWithArray( $value, array $comparativeValues ) { |
|
| 64 | - Assert::parameterType( 'string', $value, '$value' ); |
|
| 65 | - Assert::parameterElementType( 'string', $comparativeValues, '$comparativeValues' ); |
|
| 63 | + public function compareWithArray($value, array $comparativeValues) { |
|
| 64 | + Assert::parameterType('string', $value, '$value'); |
|
| 65 | + Assert::parameterElementType('string', $comparativeValues, '$comparativeValues'); |
|
| 66 | 66 | |
| 67 | - $value = $this->cleanDataString( $value ); |
|
| 68 | - $comparativeValues = $this->cleanDataArray( $comparativeValues ); |
|
| 67 | + $value = $this->cleanDataString($value); |
|
| 68 | + $comparativeValues = $this->cleanDataArray($comparativeValues); |
|
| 69 | 69 | |
| 70 | - if ( in_array( $value, $comparativeValues ) ) { |
|
| 70 | + if (in_array($value, $comparativeValues)) { |
|
| 71 | 71 | return ComparisonResult::STATUS_MATCH; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - foreach ( $comparativeValues as $comparativeValue ) { |
|
| 75 | - if ( $this->checkSimilarity( $comparativeValue, $value ) ) { |
|
| 74 | + foreach ($comparativeValues as $comparativeValue) { |
|
| 75 | + if ($this->checkSimilarity($comparativeValue, $value)) { |
|
| 76 | 76 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | * @param string $comparativeValue |
| 88 | 88 | * @return bool |
| 89 | 89 | */ |
| 90 | - private function checkSimilarity( $value, $comparativeValue ) { |
|
| 90 | + private function checkSimilarity($value, $comparativeValue) { |
|
| 91 | 91 | return |
| 92 | - $this->percentagePrefixSimilarity( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD || |
|
| 93 | - $this->percentageSuffixSimilarity( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD || |
|
| 94 | - $this->percentageLevenshteinDistance( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD; |
|
| 92 | + $this->percentagePrefixSimilarity($value, $comparativeValue) > self::SIMILARITY_THRESHOLD || |
|
| 93 | + $this->percentageSuffixSimilarity($value, $comparativeValue) > self::SIMILARITY_THRESHOLD || |
|
| 94 | + $this->percentageLevenshteinDistance($value, $comparativeValue) > self::SIMILARITY_THRESHOLD; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -101,10 +101,10 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | - private function cleanDataString( $value ) { |
|
| 105 | - $value = $this->stringNormalizer->trimToNFC( $value ); |
|
| 104 | + private function cleanDataString($value) { |
|
| 105 | + $value = $this->stringNormalizer->trimToNFC($value); |
|
| 106 | 106 | |
| 107 | - return mb_strtolower( $value ); |
|
| 107 | + return mb_strtolower($value); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -114,10 +114,10 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @return array |
| 116 | 116 | */ |
| 117 | - private function cleanDataArray( array $array ) { |
|
| 117 | + private function cleanDataArray(array $array) { |
|
| 118 | 118 | |
| 119 | 119 | return array_map( |
| 120 | - [ $this, 'cleanDataString' ], |
|
| 120 | + [$this, 'cleanDataString'], |
|
| 121 | 121 | $array ); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -129,19 +129,19 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return float |
| 131 | 131 | */ |
| 132 | - private function percentagePrefixSimilarity( $value, $comparativeValue ) { |
|
| 132 | + private function percentagePrefixSimilarity($value, $comparativeValue) { |
|
| 133 | 133 | $prefixLength = 0; // common prefix length |
| 134 | - $localLength = strlen( $value ); |
|
| 135 | - $externalLength = strlen( $comparativeValue ); |
|
| 136 | - while ( $prefixLength < min( $localLength, $externalLength ) ) { |
|
| 134 | + $localLength = strlen($value); |
|
| 135 | + $externalLength = strlen($comparativeValue); |
|
| 136 | + while ($prefixLength < min($localLength, $externalLength)) { |
|
| 137 | 137 | $c = $value[$prefixLength]; |
| 138 | - if ( $externalLength > $prefixLength && $comparativeValue[$prefixLength] !== $c ) { |
|
| 138 | + if ($externalLength > $prefixLength && $comparativeValue[$prefixLength] !== $c) { |
|
| 139 | 139 | break; |
| 140 | 140 | } |
| 141 | 141 | $prefixLength++; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - return $prefixLength / max( $localLength, $externalLength ); |
|
| 144 | + return $prefixLength / max($localLength, $externalLength); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -152,19 +152,19 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @return float |
| 154 | 154 | */ |
| 155 | - private function percentageSuffixSimilarity( $value, $comparativeValue ) { |
|
| 155 | + private function percentageSuffixSimilarity($value, $comparativeValue) { |
|
| 156 | 156 | $suffixLength = 0; // common suffix length |
| 157 | - $localLength = strlen( $value ); |
|
| 158 | - $externalLength = strlen( $comparativeValue ); |
|
| 159 | - while ( $suffixLength < min( $localLength, $externalLength ) ) { |
|
| 157 | + $localLength = strlen($value); |
|
| 158 | + $externalLength = strlen($comparativeValue); |
|
| 159 | + while ($suffixLength < min($localLength, $externalLength)) { |
|
| 160 | 160 | $c = $value[$localLength - 1 - $suffixLength]; |
| 161 | - if ( $externalLength > $suffixLength && $comparativeValue[$externalLength - 1 - $suffixLength] !== $c ) { |
|
| 161 | + if ($externalLength > $suffixLength && $comparativeValue[$externalLength - 1 - $suffixLength] !== $c) { |
|
| 162 | 162 | break; |
| 163 | 163 | } |
| 164 | 164 | $suffixLength++; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - return $suffixLength / max( $localLength, $externalLength ); |
|
| 167 | + return $suffixLength / max($localLength, $externalLength); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -175,9 +175,9 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @return float |
| 177 | 177 | */ |
| 178 | - private function percentageLevenshteinDistance( $value, $comparativeValue ) { |
|
| 179 | - $distance = levenshtein( $value, $comparativeValue ); |
|
| 180 | - $percentage = 1.0 - $distance / max( strlen( $value ), strlen( $comparativeValue ) ); |
|
| 178 | + private function percentageLevenshteinDistance($value, $comparativeValue) { |
|
| 179 | + $distance = levenshtein($value, $comparativeValue); |
|
| 180 | + $percentage = 1.0 - $distance / max(strlen($value), strlen($comparativeValue)); |
|
| 181 | 181 | |
| 182 | 182 | return $percentage; |
| 183 | 183 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @param TermIndex $termIndex |
| 33 | 33 | * @param StringComparer $stringComparer |
| 34 | 34 | */ |
| 35 | - public function __construct( TermIndex $termIndex, StringComparer $stringComparer ) { |
|
| 35 | + public function __construct(TermIndex $termIndex, StringComparer $stringComparer) { |
|
| 36 | 36 | $this->termIndex = $termIndex; |
| 37 | 37 | $this->stringComparer = $stringComparer; |
| 38 | 38 | } |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return string|null One of the ComparisonResult::STATUS_... constants. |
| 47 | 47 | */ |
| 48 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
| 49 | - Assert::parameterType( EntityIdValue::class, $value, '$value' ); |
|
| 50 | - Assert::parameterType( MonolingualTextValue::class, $comparativeValue, '$comparativeValue' ); |
|
| 48 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
| 49 | + Assert::parameterType(EntityIdValue::class, $value, '$value'); |
|
| 50 | + Assert::parameterType(MonolingualTextValue::class, $comparativeValue, '$comparativeValue'); |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @var EntityIdValue $value |
@@ -56,10 +56,10 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | $entityId = $value->getEntityId(); |
| 58 | 58 | $language = $comparativeValue->getLanguageCode(); |
| 59 | - $terms = $this->getTerms( $entityId, $language ); |
|
| 59 | + $terms = $this->getTerms($entityId, $language); |
|
| 60 | 60 | |
| 61 | - if ( $terms ) { |
|
| 62 | - return $this->stringComparer->compareWithArray( $comparativeValue->getText(), $terms ); |
|
| 61 | + if ($terms) { |
|
| 62 | + return $this->stringComparer->compareWithArray($comparativeValue->getText(), $terms); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return null; |
@@ -73,18 +73,18 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return array |
| 75 | 75 | */ |
| 76 | - private function getTerms( EntityId $entityId, $language ) { |
|
| 76 | + private function getTerms(EntityId $entityId, $language) { |
|
| 77 | 77 | $terms = $this->termIndex->getTermsOfEntity( |
| 78 | 78 | $entityId, |
| 79 | 79 | [ |
| 80 | 80 | TermIndexEntry::TYPE_LABEL, |
| 81 | 81 | TermIndexEntry::TYPE_ALIAS |
| 82 | 82 | ], |
| 83 | - [ $language ] |
|
| 83 | + [$language] |
|
| 84 | 84 | ); |
| 85 | 85 | |
| 86 | 86 | return array_map( |
| 87 | - function( TermIndexEntry $term ) { |
|
| 87 | + function(TermIndexEntry $term) { |
|
| 88 | 88 | return $term->getText(); |
| 89 | 89 | }, |
| 90 | 90 | $terms |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param DataValue $comparativeValue |
| 99 | 99 | * @return bool |
| 100 | 100 | */ |
| 101 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
| 101 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
| 102 | 102 | return $value instanceof EntityIdValue && $comparativeValue instanceof MonolingualTextValue; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -24,23 +24,23 @@ discard block |
||
| 24 | 24 | * @param PropertyId[] $propertyIds |
| 25 | 25 | * @return array |
| 26 | 26 | */ |
| 27 | - public function getExternalData( array $dumpIds, array $externalIds, array $propertyIds ) { |
|
| 28 | - Assert::parameterElementType( 'string', $dumpIds, '$dumpIds' ); |
|
| 29 | - Assert::parameterElementType( 'string', $externalIds, '$externalIds' ); |
|
| 30 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
| 31 | - Assert::parameter( count( $dumpIds ) > 0, '$dumpIds', '$dumpIds has to contain at least one element.' ); |
|
| 32 | - Assert::parameter( count( $externalIds ) > 0, '$externalIds', '$externalIds has to contain at least one element.' ); |
|
| 27 | + public function getExternalData(array $dumpIds, array $externalIds, array $propertyIds) { |
|
| 28 | + Assert::parameterElementType('string', $dumpIds, '$dumpIds'); |
|
| 29 | + Assert::parameterElementType('string', $externalIds, '$externalIds'); |
|
| 30 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
| 31 | + Assert::parameter(count($dumpIds) > 0, '$dumpIds', '$dumpIds has to contain at least one element.'); |
|
| 32 | + Assert::parameter(count($externalIds) > 0, '$externalIds', '$externalIds has to contain at least one element.'); |
|
| 33 | 33 | |
| 34 | 34 | $conditions = [ |
| 35 | 35 | 'dump_id' => $dumpIds, |
| 36 | 36 | 'external_id' => $externalIds |
| 37 | 37 | ]; |
| 38 | - if ( $propertyIds ) { |
|
| 38 | + if ($propertyIds) { |
|
| 39 | 39 | $conditions['pid'] = $propertyIds; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $externalData = []; |
| 43 | - $db = wfGetDB( DB_REPLICA ); |
|
| 43 | + $db = wfGetDB(DB_REPLICA); |
|
| 44 | 44 | $result = $db->select( |
| 45 | 45 | self::TABLE_NAME, |
| 46 | 46 | [ |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $conditions |
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | - foreach ( $result as $row ) { |
|
| 55 | + foreach ($result as $row) { |
|
| 56 | 56 | $externalData[$row->dump_id][$row->external_id][$row->pid][] = $row->external_value; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | * @param string $externalValue |
| 69 | 69 | * @return bool |
| 70 | 70 | */ |
| 71 | - public function insert( $dumpId, $externalId, PropertyId $propertyId, $externalValue ) { |
|
| 72 | - Assert::parameterType( 'string', $dumpId, '$dumpId' ); |
|
| 73 | - Assert::parameterType( 'string', $externalId, '$externalId' ); |
|
| 74 | - Assert::parameterType( 'string', $externalValue, '$externalValue' ); |
|
| 71 | + public function insert($dumpId, $externalId, PropertyId $propertyId, $externalValue) { |
|
| 72 | + Assert::parameterType('string', $dumpId, '$dumpId'); |
|
| 73 | + Assert::parameterType('string', $externalId, '$externalId'); |
|
| 74 | + Assert::parameterType('string', $externalValue, '$externalValue'); |
|
| 75 | 75 | |
| 76 | - $externalDataBatch = [ func_get_args() ]; |
|
| 77 | - return $this->insertBatch( $externalDataBatch ); |
|
| 76 | + $externalDataBatch = [func_get_args()]; |
|
| 77 | + return $this->insertBatch($externalDataBatch); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | * @throws DBError |
| 85 | 85 | * @return bool |
| 86 | 86 | */ |
| 87 | - public function insertBatch( array $externalDataBatch ) { |
|
| 88 | - $db = wfGetDB( DB_MASTER ); |
|
| 87 | + public function insertBatch(array $externalDataBatch) { |
|
| 88 | + $db = wfGetDB(DB_MASTER); |
|
| 89 | 89 | $accumulator = array_map( |
| 90 | - function ( $externalData ) use ( $db ) { |
|
| 90 | + function($externalData) use ($db) { |
|
| 91 | 91 | return [ |
| 92 | 92 | 'dump_id' => $externalData[0], |
| 93 | 93 | 'external_id' => $externalData[1], |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | try { |
| 102 | 102 | $db->begin(); |
| 103 | - $result = $db->insert( self::TABLE_NAME, $accumulator ); |
|
| 103 | + $result = $db->insert(self::TABLE_NAME, $accumulator); |
|
| 104 | 104 | $db->commit(); |
| 105 | - } catch ( DBError $ex ) { |
|
| 105 | + } catch (DBError $ex) { |
|
| 106 | 106 | $db->rollback(); |
| 107 | 107 | throw $ex; |
| 108 | 108 | } |
@@ -117,21 +117,21 @@ discard block |
||
| 117 | 117 | * @param int $batchSize |
| 118 | 118 | * @throws \DBUnexpectedError |
| 119 | 119 | */ |
| 120 | - public function deleteOfDump( $dumpId, $batchSize = 1000 ) { |
|
| 121 | - Assert::parameterType( 'string', $dumpId, '$dumpId' ); |
|
| 122 | - Assert::parameterType( 'integer', $batchSize, 'batchSize' ); |
|
| 120 | + public function deleteOfDump($dumpId, $batchSize = 1000) { |
|
| 121 | + Assert::parameterType('string', $dumpId, '$dumpId'); |
|
| 122 | + Assert::parameterType('integer', $batchSize, 'batchSize'); |
|
| 123 | 123 | |
| 124 | - $db = wfGetDB( DB_MASTER ); |
|
| 125 | - if ( $db->getType() === 'sqlite' ) { |
|
| 126 | - $db->delete( self::TABLE_NAME, [ 'dump_id' => $dumpId ] ); |
|
| 124 | + $db = wfGetDB(DB_MASTER); |
|
| 125 | + if ($db->getType() === 'sqlite') { |
|
| 126 | + $db->delete(self::TABLE_NAME, ['dump_id' => $dumpId]); |
|
| 127 | 127 | } else { |
| 128 | 128 | do { |
| 129 | - $db->commit( __METHOD__, 'flush' ); |
|
| 129 | + $db->commit(__METHOD__, 'flush'); |
|
| 130 | 130 | wfGetLBFactory()->waitForReplication(); |
| 131 | - $table = $db->tableName( self::TABLE_NAME ); |
|
| 132 | - $condition = 'dump_id = ' . $db->addQuotes( $dumpId ); |
|
| 133 | - $db->query( sprintf( 'DELETE FROM %s WHERE %s LIMIT %d', $table, $condition, $batchSize ) ); |
|
| 134 | - } while ( $db->affectedRows() > 0 ); |
|
| 131 | + $table = $db->tableName(self::TABLE_NAME); |
|
| 132 | + $condition = 'dump_id = '.$db->addQuotes($dumpId); |
|
| 133 | + $db->query(sprintf('DELETE FROM %s WHERE %s LIMIT %d', $table, $condition, $batchSize)); |
|
| 134 | + } while ($db->affectedRows() > 0); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
|
| 4 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
| 3 | +if (is_readable(__DIR__.'/vendor/autoload.php')) { |
|
| 4 | + require_once __DIR__.'/vendor/autoload.php'; |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | -call_user_func( function () { |
|
| 7 | +call_user_func(function() { |
|
| 8 | 8 | // Set credits |
| 9 | 9 | $GLOBALS['wgExtensionCredits']['wikibase'][] = [ |
| 10 | 10 | 'path' => __FILE__, |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | ]; |
| 18 | 18 | |
| 19 | 19 | // Initialize localization and aliases |
| 20 | - $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__ . '/i18n'; |
|
| 21 | - $GLOBALS['wgExtensionMessagesFiles']['WikibaseQualityExternalValidationAlias'] = __DIR__ . '/WikibaseQualityExternalValidation.alias.php'; |
|
| 20 | + $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__.'/i18n'; |
|
| 21 | + $GLOBALS['wgExtensionMessagesFiles']['WikibaseQualityExternalValidationAlias'] = __DIR__.'/WikibaseQualityExternalValidation.alias.php'; |
|
| 22 | 22 | |
| 23 | 23 | // Initalize hooks for creating database tables |
| 24 | 24 | $GLOBALS['wgHooks']['LoadExtensionSchemaUpdates'][] = |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | // Define API modules |
| 38 | 38 | $GLOBALS['wgAPIModules']['wbqevcrosscheck'] = [ |
| 39 | 39 | 'class' => WikibaseQuality\ExternalValidation\Api\RunCrossCheck::class, |
| 40 | - 'factory' => function( ApiMain $main, $action ) { |
|
| 41 | - return WikibaseQuality\ExternalValidation\Api\RunCrossCheck::newFromGlobalState( $main, $action ); |
|
| 40 | + 'factory' => function(ApiMain $main, $action) { |
|
| 41 | + return WikibaseQuality\ExternalValidation\Api\RunCrossCheck::newFromGlobalState($main, $action); |
|
| 42 | 42 | } |
| 43 | 43 | ]; |
| 44 | 44 | |