PHP code example of edgaras / strsim

1. Go to this page and download the library: Download edgaras/strsim library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

edgaras / strsim example snippets




use Edgaras\StrSim\Levenshtein;
use Edgaras\StrSim\DamerauLevenshtein;
use Edgaras\StrSim\Hamming;
use Edgaras\StrSim\Jaro;
use Edgaras\StrSim\JaroWinkler;
use Edgaras\StrSim\LCS;
use Edgaras\StrSim\SmithWaterman;
use Edgaras\StrSim\NeedlemanWunsch;
use Edgaras\StrSim\Cosine;
use Edgaras\StrSim\Jaccard;
use Edgaras\StrSim\MongeElkan;

// Detecting spelling error distance in user input
Levenshtein::distance("kitten", "sitting");  

// Detecting typo distance with transposition correction
DamerauLevenshtein::distance("abcd", "acbd");  

// Bit-level error detection (equal-length only)
Hamming::distance("1011101", "1001001");  

// Comparing short strings with transposition support
Jaro::distance("dixon", "dicksonx");  

// Matching names with common prefixes
JaroWinkler::distance("martha", "marhta");  

// Finding common subsequence in DNA fragments
LCS::length("ACCGGTCGAGTGCGCGGAAGCCGGCCGAA", "GTCGTTCGGAATGCCGTTGCTCTGTAAA"); 

// Local alignment score for substring match
SmithWaterman::score("ACACACTA", "AGCACACA");  

// Global alignment score for complete sequence match
NeedlemanWunsch::score("GATTACA", "GCATGCU");  

// Comparing word frequency in short texts
Cosine::similarity("night", "nacht");  

// Comparing embedding vectors from NLP model
Cosine::similarityFromVectors([0.1, 0.2, 0.3], [0.1, 0.3, 0.4]);  

// Comparing token overlap in short strings
Jaccard::index("abc", "bcd"); 

// Fuzzy match between two multi-word names
MongeElkan::similarity("john smith", "jon smythe");