PHPackages                             gpupo/similarity - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gpupo/similarity

AbandonedArchivedLibrary

gpupo/similarity
================

Calculate the similarity between strings and numbers working in a different way from a diff tool

2.0.0(6y ago)97.3k↓100%1MITPHPPHP ^7.0

Since Jun 12Pushed 6y agoCompare

[ Source](https://github.com/gpupo/similarity)[ Packagist](https://packagist.org/packages/gpupo/similarity)[ Docs](https://opensource.gpupo.com/similarity/)[ RSS](/packages/gpupo-similarity/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (7)Used By (0)

Similarity
==========

[](#similarity)

Calculate the similarity between strings or numbers

- Supports [Stopwords](http://en.wikipedia.org/wiki/Stop_words)
- Working in a different way from a diff tool

[![Paypal Donations](https://camo.githubusercontent.com/7b6de155df30b37b25eb5fec52f9213680c3dbf067dfb7d7e2850ac4096c7d05/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f534d2e676966)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=EK6F2WRKG7GNN&item_name=similarity)

Requisitos para uso
-------------------

[](#requisitos-para-uso)

- PHP &gt;= *5.6*
- [curl extension](http://php.net/manual/en/intro.curl.php)
- [Composer Dependency Manager](http://getcomposer.org)

Este componente **não é uma aplicação Stand Alone** e seu objetivo é ser utilizado como biblioteca. Sua implantação deve ser feita por desenvolvedores experientes.

**Isto não é um Plugin!**

As opções que funcionam no modo de comando apenas servem para depuração em modo de desenvolvimento.

A documentação mais importante está nos testes unitários. Se você não consegue ler os testes unitários, eu recomendo que não utilize esta biblioteca.

Direitos autorais e de licença
------------------------------

[](#direitos-autorais-e-de-licença)

Este componente está sob a [licença MIT](https://github.com/gpupo/common-sdk/blob/master/LICENSE)

Para a informação dos direitos autorais e de licença você deve ler o arquivo de [licença](https://github.com/gpupo/common-sdk/blob/master/LICENSE) que é distribuído com este código-fonte.

### Resumo da licença

[](#resumo-da-licença)

Exigido:

- Aviso de licença e direitos autorais

Permitido:

- Uso comercial
- Modificação
- Distribuição
- Sublicenciamento

Proibido:

- Responsabilidade Assegurada

---

Indicadores de qualidade
------------------------

[](#indicadores-de-qualidade)

[![Build Status](https://camo.githubusercontent.com/36fd78f8991d413370590587c756c4f66627f60f373cf22d77b1aaead688f0da/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f677075706f2f73696d696c61726974792e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/gpupo/similarity)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/dea0b338681866d6bebce2a5c05a44f152d6f43325efcf3152bc769729f230ec/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f677075706f2f73696d696c61726974792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gpupo/similarity/?branch=master)[![Code Climate](https://camo.githubusercontent.com/3cbf92c6a059d0b719d4c16b3e4decbf4a060bbb3ba30286e6e384aee64cc8b1/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f677075706f2f73696d696c61726974792f6261646765732f6770612e737667)](https://codeclimate.com/github/gpupo/similarity)[![Test Coverage](https://camo.githubusercontent.com/a47a01e7fac251ced3654fcb9f3f215f5c7a9fb5ccd732ab70ef82673013722d/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f677075706f2f73696d696c61726974792f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/gpupo/similarity/coverage)

---

Agradecimentos
--------------

[](#agradecimentos)

- A todos os que [contribuiram com patchs](https://github.com/gpupo/similarity/contributors);
- Aos que [fizeram sugestões importantes](https://github.com/gpupo/similarity/issues);
- Aos desenvolvedores que criaram as [bibliotecas utilizadas neste componente](https://github.com/gpupo/similarity/blob/master/Resources/doc/libraries-list.md).

*- [Gilmar Pupo](https://opensource.gpupo.com/)*

Usage
-----

[](#usage)

### Example 1, with stopwords:

[](#example-1-with-stopwords)

```
	$stringA = 'Av. Padre Anchieta 1873 - Champagnat - Curitiba - Brasil';
	$stringB = 'Brasil - Parana - Curitiba - Champagnat - '
		.'Rua Padre Anchieta 1873 - Perto da Avenida';
	$stopwordsList = explode(',', 'Av,Rua,Avenida,perto,da,de,e,em,o');
	$s = new Similarity();
    $s->setValues($stringA, $stringB);
    $s->setAccuracy(80); // 1-100 accuracy value
    $s->setStopwords($stopwordsList);
	$similar = $s->hasSimilarity(); //true
```

### Example 2, chain method calls:

[](#example-2-chain-method-calls)

```
	$s = new Similarity();
    $result = $s->setValues($stringA, $stringB)->setAccuracy(60)
    	->setStopwords($stopwordsList)->hasSimilarity();
```

### Example 3, numbers:

[](#example-3-numbers)

```
	$s = new Similarity();
    $resultA = $s->setNumberValues('1530D',1510)->hasSimilarity(); // true
	$resultB = $s->setNumberValues('3D',4)->hasSimilarity(); // true
	$resultC = $s->setNumberValues('100B',205)->hasSimilarity(); // false
	$resultD = $s->setNumberValues('20',2)->hasSimilarity(); // false
	$resultE = $s->setNumberValues('3 - D 4',34)->hasSimilarity(); // true
```

Install
-------

[](#install)

The recommended way to install is [through composer](http://getcomposer.org).

```
{
    "require": {
        "gpupo/similarity": "dev-master"
    }
}
```

Links
-----

[](#links)

- [Similarity Composer Package](https://packagist.org/packages/gpupo/similarity) on packagist.org

Tests
-----

[](#tests)

All tests are run automatically at each commit, on `OSx` and `Linux` environment in PHP versions `5.3`, `5.4`, `5.5`, `5.6`, `7.0` and `hhvm` using [Travis](http://travis-ci.org/gpupo/similarity).

To run localy the test suite:

```
$ phpunit

```

See the testdox output

```
$ phpunit --testdox

```

---

Propriedades dos objetos
------------------------

[](#propriedades-dos-objetos)

### Similarity\\Input\\Decorator

[](#similarityinputdecorator)

- Clean characters
- Clean numbers

### Similarity\\Input\\InputNumber

[](#similarityinputinputnumber)

- Clean ignored characters

### Similarity\\Input\\InputString

[](#similarityinputinputstring)

- Clean ignored characters
- Clean stopwords

### Similarity\\SimilarNumber

[](#similaritysimilarnumber)

- Success to find similarity
- Success to find proximity
- Success to find proximity with distant numbers

### Similarity\\SimilarText

[](#similaritysimilartext)

- Success to find percentage similarity
- Success to find percentage with texts with no similarity
- Success to find the levenshtein distance

### Similarity\\Similarity

[](#similaritysimilarity)

- Success on assert similarities with strings
- Success in asserting that the phrase is different
- Success on assert similarities with numbers
- Success on assert similarities with approximate numbers
- Success on assert with different numbers
- Ability to increase the accuracy
- Ability to decrease the accuracy
- Ability to inject stopwords

Lista de dependências (libraries)
---------------------------------

[](#lista-de-dependências-libraries)

NameVersionDescriptioncodeclimate/php-test-reporterv0.4.4PHP client for reporting test coverage to Code Climatedoctrine/instantiator1.0.5A small, lightweight utility to instantiate objects in PHP without invoking their constructorsgpupo/cache1.3.0Caching library that implements PSR-6gpupo/common1.7.6Common Objectsgpupo/common-sdk2.2.15Componente de uso comum entre SDKs para integração a partir de aplicações PHP com Restful webservicesguzzle/guzzlev3.9.3PHP HTTP client. This library is deprecated in favor of monolog/monolog1.22.1Sends your logs to files, sockets, inboxes, databases and various web servicesmyclabs/deep-copy1.6.0Create deep copies (clones) of your objectspadraic/humbug\_get\_contents1.0.4Secure wrapper for accessing HTTPS resources with file\_get\_contents for PHP 5.3+padraic/phar-updater1.0.3A thing to make PHAR self-updating easy and secure.phpdocumentor/reflection-common1.0Common reflection classes used by phpdocumentor to reflect the code structurephpdocumentor/reflection-docblock3.1.1With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.phpdocumentor/type-resolver0.2.1phpspec/prophecyv1.7.0Highly opinionated mocking framework for PHP 5.3+phpunit/php-code-coverage4.0.7Library that provides collection, processing, and rendering functionality for PHP code coverage information.phpunit/php-file-iterator1.4.2FilterIterator implementation that filters files based on a list of suffixes.phpunit/php-text-template1.2.1Simple template engine.phpunit/php-timer1.0.9Utility class for timingphpunit/php-token-stream1.4.11Wrapper around PHP's tokenizer extension.phpunit/phpunit5.7.17The PHP Unit Testing framework.phpunit/phpunit-mock-objects3.4.3Mock Object library for PHPUnitpsr/cache1.0.0Common interface for caching librariespsr/log1.0.2Common interface for logging librariessatooshi/php-coverallsv1.0.1PHP client library for Coveralls APIsebastian/code-unit-reverse-lookup 1.0.1Looks up which function or method a line of code belongs tosebastian/comparator1.2.4Provides the functionality to compare PHP values for equalitysebastian/diff1.4.1Diff implementationsebastian/environment2.0.0Provides functionality to handle HHVM/PHP environmentssebastian/exporter2.0.0Provides the functionality to export PHP variables for visualizationsebastian/global-state1.1.1Snapshotting of global statesebastian/object-enumerator2.0.1Traverses array structures and object graphs to enumerate all referenced objectssebastian/peek-and-pokedev-master a8295Proxy for accessing non-public attributes and methods of an objectsebastian/recursion-context2.0.0Provides functionality to recursively process PHP variablessebastian/resource-operations1.0.0Provides a list of PHP built-in functions that operate on resourcessebastian/version2.0.1Library that helps with managing the version number of Git-hosted PHP projectssymfony/configv3.2.6Symfony Config Componentsymfony/consolev3.2.6Symfony Console Componentsymfony/debugv3.2.6Symfony Debug Componentsymfony/event-dispatcherv2.8.18Symfony EventDispatcher Componentsymfony/filesystemv3.2.6Symfony Filesystem Componentsymfony/polyfill-mbstringv1.3.0Symfony polyfill for the Mbstring extensionsymfony/stopwatchv3.2.6Symfony Stopwatch Componentsymfony/yamlv3.2.6Symfony Yaml Componenttwig/twigv2.3.0Twig, the flexible, fast, and secure template language for PHPwebmozart/assert1.2.0Assertions to validate method input/output with nice error messages.

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~506 days

Total

5

Last Release

2324d ago

Major Versions

1.0.1 → 2.0.02019-12-27

PHP version history (2 changes)1.0.0PHP &gt;=5.3.2

2.0.0PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/946dbbebf8faf93b4c4e4796fd06f73c67e9fc78e678eda01c9d7b81f068ecaa?d=identicon)[gpupo](/maintainers/gpupo)

---

Top Contributors

[![gpupo](https://avatars.githubusercontent.com/u/126154?v=4)](https://github.com/gpupo "gpupo (34 commits)")

---

Tags

diffstringcomparedistancesimilaritylevenshtein

### Embed Badge

![Health badge](/badges/gpupo-similarity/health.svg)

```
[![Health](https://phpackages.com/badges/gpupo-similarity/health.svg)](https://phpackages.com/packages/gpupo-similarity)
```

###  Alternatives

[edgaras/strsim

Collection of string similarity and distance algorithms in PHP including Levenshtein, Damerau-Levenshtein, Jaro-Winkler, and more

2423.0k](/packages/edgaras-strsim)[oefenweb/damerau-levenshtein

Get text similarity level with Damerau-Levenshtein distance

40265.8k4](/packages/oefenweb-damerau-levenshtein)[lolli42/finediff

PHP implementation of a Fine granularity Diff engine

138.8M3](/packages/lolli42-finediff)[atomescrochus/laravel-string-similarities

Compare two string and get a similarity percentage

70160.1k2](/packages/atomescrochus-laravel-string-similarities)[d4h/finediff

PHP implementation of a Fine granularity Diff engine

141.3M1](/packages/d4h-finediff)[fza/mysql-doctrine-levenshtein-function

Provides the `LEVENSHTEIN()` and `LEVENSHTEIN\_RATIO()` MySQL functions for Doctrine2.

47115.8k1](/packages/fza-mysql-doctrine-levenshtein-function)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
