Documentation

LemmatizerFactory
in package

Factory for creating lemmatizers based on language configuration.

This factory implements a hybrid approach:

  1. Dictionary-based lookup (fast, predictable)
  2. NLP service fallback (spaCy, high accuracy)

The lemmatizer type can be configured per language in the database.

Table of Contents

Constants

TYPE_DICTIONARY  = 'dictionary'
TYPE_HYBRID  = 'hybrid'
TYPE_NONE  = 'none'
Lemmatizer types
TYPE_SPACY  = 'spacy'

Properties

$dictionaryLemmatizer  : DictionaryLemmatizer|null
$instances  : array<string, LemmatizerInterface>
$nlpLemmatizer  : NlpServiceLemmatizer|null

Methods

clearCache()  : void
Clear cached instances (useful for testing).
createHybridLemmatizer()  : LemmatizerInterface
Create a hybrid lemmatizer (dictionary + NLP fallback).
createLemmatizer()  : LemmatizerInterface
Create a lemmatizer by type.
getAllNlpLanguages()  : array<string|int, string>
Get all potentially supported NLP languages (including uninstalled).
getBestAvailable()  : LemmatizerInterface
Get the best available lemmatizer for a language code.
getDictionaryLemmatizer()  : DictionaryLemmatizer
Get the dictionary-based lemmatizer.
getForLanguage()  : LemmatizerInterface|null
Get the appropriate lemmatizer for a language.
getNlpServiceLemmatizer()  : NlpServiceLemmatizer
Get the NLP service lemmatizer (spaCy).
getNlpSupportedLanguages()  : array<string|int, string>
Get list of languages supported by the NLP service.
isNlpServiceAvailable()  : bool
Check if NLP service is available.
getLanguageLemmatizerType()  : string
Get the configured lemmatizer type for a language.

Constants

Properties

Methods

clearCache()

Clear cached instances (useful for testing).

public static clearCache() : void

getAllNlpLanguages()

Get all potentially supported NLP languages (including uninstalled).

public static getAllNlpLanguages() : array<string|int, string>
Return values
array<string|int, string>

getBestAvailable()

Get the best available lemmatizer for a language code.

public static getBestAvailable(string $languageCode) : LemmatizerInterface

Uses a fallback chain:

  1. Try NLP service (spaCy) if available for this language
  2. Fall back to dictionary-based lemmatizer
Parameters
$languageCode : string

ISO language code

Return values
LemmatizerInterface

getForLanguage()

Get the appropriate lemmatizer for a language.

public static getForLanguage(int $languageId[, string|null $type = null ]) : LemmatizerInterface|null
Parameters
$languageId : int

Language ID

$type : string|null = null

Force specific type (null = use language config)

Return values
LemmatizerInterface|null

Lemmatizer or null if none configured

getNlpSupportedLanguages()

Get list of languages supported by the NLP service.

public static getNlpSupportedLanguages() : array<string|int, string>
Return values
array<string|int, string>

isNlpServiceAvailable()

Check if NLP service is available.

public static isNlpServiceAvailable() : bool
Return values
bool

getLanguageLemmatizerType()

Get the configured lemmatizer type for a language.

private static getLanguageLemmatizerType(int $languageId) : string
Parameters
$languageId : int

Language ID

Return values
string

Lemmatizer type


        
On this page

Search results