diff options
author | Brian Evans <grknight@gentoo.org> | 2020-10-02 15:24:06 -0400 |
---|---|---|
committer | Brian Evans <grknight@gentoo.org> | 2020-10-02 15:24:06 -0400 |
commit | 60dd5fd95847643eab04ce173f0774c9c584e795 (patch) | |
tree | 52299ac4e3c5c69df75997bfd7d62b71ef9e0089 /MLEB/Translate/src/Utilities/StringComparators | |
parent | Update Widgets to 1.35 (diff) | |
download | extensions-60dd5fd95847643eab04ce173f0774c9c584e795.tar.gz extensions-60dd5fd95847643eab04ce173f0774c9c584e795.tar.bz2 extensions-60dd5fd95847643eab04ce173f0774c9c584e795.zip |
Update MLEB to 2020.07
Signed-off-by: Brian Evans <grknight@gentoo.org>
Diffstat (limited to 'MLEB/Translate/src/Utilities/StringComparators')
-rw-r--r-- | MLEB/Translate/src/Utilities/StringComparators/SimpleStringComparator.php | 29 | ||||
-rw-r--r-- | MLEB/Translate/src/Utilities/StringComparators/StringComparator.php | 18 |
2 files changed, 47 insertions, 0 deletions
diff --git a/MLEB/Translate/src/Utilities/StringComparators/SimpleStringComparator.php b/MLEB/Translate/src/Utilities/StringComparators/SimpleStringComparator.php new file mode 100644 index 00000000..1c24d2c8 --- /dev/null +++ b/MLEB/Translate/src/Utilities/StringComparators/SimpleStringComparator.php @@ -0,0 +1,29 @@ +<?php +/** + * Contains a simple string compare class. + * @license GPL-2.0-or-later + */ + +namespace MediaWiki\Extensions\Translate\Utilities\StringComparators; + +/** + * A simple string comparator, that compares two strings and determines if they are an exact match. + * @since 2019.10 + */ +class SimpleStringComparator implements StringComparator { + /** + * @inheritDoc + */ + public function getSimilarity( $addedMessage, $deletedMessage ) { + if ( $addedMessage === $deletedMessage ) { + return 1; + } + + if ( trim( mb_strtolower( $addedMessage ) ) === trim( mb_strtolower( $deletedMessage ) ) ) { + // This is an arbitrarily chosen number to differentiate it from an exact match. + return 0.95; + } + + return 0; + } +} diff --git a/MLEB/Translate/src/Utilities/StringComparators/StringComparator.php b/MLEB/Translate/src/Utilities/StringComparators/StringComparator.php new file mode 100644 index 00000000..bbf9e96b --- /dev/null +++ b/MLEB/Translate/src/Utilities/StringComparators/StringComparator.php @@ -0,0 +1,18 @@ +<?php + +namespace MediaWiki\Extensions\Translate\Utilities\StringComparators; + +/** + * An interface to be implemented by comparators that will compare percentage + * of similarity between strings. + */ +interface StringComparator { + /** + * Compares the two messages and returns a similarity percentage + * + * @param string $a + * @param string $b + * @return float 0-1 with 1 being an exact match + */ + public function getSimilarity( $a, $b ); +} |