laragrad / str-trgm
Installs: 98
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^7.1|^8.0
This package is auto-updated.
Last update: 2025-04-15 01:35:19 UTC
README
A package to compare two string with trigramm algorithm like as PostgreSql pg_trgm package similarity() function.
Installing
Run command in console
composer require laragrad/str-trgm
Functions
All functions are static.
similarity()
Return similarity value (0..1) for two strings.
Syntax:
similarity(string $text1, string $text2) : float
Arguments:
- $text1 - First word or sentense
- $text2 - Second word or sentense
Returns a value of similarity in range from 0 to 1.
getSentenceTrgms
Returns an array of trigramms for sentense.
Syntax:
getSentenceTrgms(string $text) : array
Arguments:
- $text - Sentense string
Returns an array of trigramms.
getWordTrgms
Returns an array of trigramms for word.
Syntax:
getWordTrgms(string $text) : array
Arguments:
- $text - Word string
Returns array of trigramms.
normalizeSentense()
Function normalizes a string.
- convert string to lower case,
- replace any symbols by space,
- replace double spaces by single space.
Syntax:
normalizeSentence(string $text) : string
Arguments:
- $text - Source string
Returns normalized string.