laragrad/str-trgm

Installs: 98

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:package

v1.1.0 2023-07-14 21:39 UTC

This package is auto-updated.

Last update: 2024-05-14 23:32:07 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.