Documentation

LocalDictionaryService

Service class for managing local dictionaries.

Handles CRUD operations for local dictionaries and entries, as well as term lookups.

Tags
category

Lwt

author

HugoFara hugo.farajallah@protonmail.com

license

Unlicense http://unlicense.org/

link
https://hugofara.github.io/lwt/docs/php/
since
3.0.0

Table of Contents

Constants

BATCH_SIZE  = 1000
Batch size for bulk inserts.

Methods

addEntriesBatch()  : int
Add multiple entries to a dictionary in batches.
addEntry()  : int
Add a single entry to a dictionary.
clearEntries()  : int
Delete all entries from a dictionary.
create()  : int
Create a new local dictionary.
delete()  : bool
Delete a dictionary and all its entries.
deleteEntry()  : bool
Delete a single entry.
getAllForLanguage()  : array<string|int, LocalDictionary>
Get all dictionaries for a language (including disabled).
getById()  : LocalDictionary|null
Get a dictionary by ID.
getEntries()  : array{entries: array, total: int, page: int, perPage: int}
Get entries for a dictionary (paginated).
getEntryCount()  : int
Get entry count for a dictionary.
getForLanguage()  : array<string|int, LocalDictionary>
Get all dictionaries for a language.
getLocalDictMode()  : int
Get the local dictionary mode for a language.
hasLocalDictionaries()  : bool
Check if a language has any local dictionaries.
lookup()  : array<string|int, array{term: string, definition: string, reading: ?string, pos: ?string, dictionary: string}>
Look up a term in local dictionaries for a language.
lookupPrefix()  : array<string|int, array{term: string, definition: string}>
Look up a term with prefix matching (for autocomplete).
update()  : bool
Update a dictionary.
updateEntry()  : bool
Update a single entry.
hydrateFromRecord()  : LocalDictionary
Hydrate a LocalDictionary entity from a database record.
insertBatch()  : void
Insert a batch of entries.
updateEntryCount()  : void
Update the entry count for a dictionary.

Constants

Methods

addEntriesBatch()

Add multiple entries to a dictionary in batches.

public addEntriesBatch(int $dictId, iterable<string|int, array{term: string, definition: string, reading?: ?string, pos?: ?string}> $entries) : int
Parameters
$dictId : int

Dictionary ID

$entries : iterable<string|int, array{term: string, definition: string, reading?: ?string, pos?: ?string}>

Entries to add

Return values
int

Number of entries added

addEntry()

Add a single entry to a dictionary.

public addEntry(int $dictId, string $term, string $definition[, string|null $reading = null ][, string|null $pos = null ]) : int
Parameters
$dictId : int

Dictionary ID

$term : string

Term/headword

$definition : string

Definition

$reading : string|null = null

Pronunciation/reading

$pos : string|null = null

Part of speech

Return values
int

Entry ID

clearEntries()

Delete all entries from a dictionary.

public clearEntries(int $dictId) : int
Parameters
$dictId : int

Dictionary ID

Return values
int

Number of entries deleted

create()

Create a new local dictionary.

public create(int $languageId, string $name[, string $sourceFormat = 'csv' ][, string|null $description = null ]) : int
Parameters
$languageId : int

Language ID

$name : string

Dictionary name

$sourceFormat : string = 'csv'

Source format (csv, json, stardict)

$description : string|null = null

Optional description

Return values
int

The new dictionary ID

delete()

Delete a dictionary and all its entries.

public delete(int $dictId) : bool
Parameters
$dictId : int

Dictionary ID

Return values
bool

Success

deleteEntry()

Delete a single entry.

public deleteEntry(int $entryId) : bool
Parameters
$entryId : int

Entry ID

Return values
bool

Success

getAllForLanguage()

Get all dictionaries for a language (including disabled).

public getAllForLanguage(int $languageId) : array<string|int, LocalDictionary>
Parameters
$languageId : int

Language ID

Return values
array<string|int, LocalDictionary>

getEntries()

Get entries for a dictionary (paginated).

public getEntries(int $dictId[, int $page = 1 ][, int $perPage = 50 ]) : array{entries: array, total: int, page: int, perPage: int}
Parameters
$dictId : int

Dictionary ID

$page : int = 1

Page number (1-based)

$perPage : int = 50

Entries per page

Return values
array{entries: array, total: int, page: int, perPage: int}

getEntryCount()

Get entry count for a dictionary.

public getEntryCount(int $dictId) : int
Parameters
$dictId : int

Dictionary ID

Return values
int

getLocalDictMode()

Get the local dictionary mode for a language.

public getLocalDictMode(int $languageId) : int
Parameters
$languageId : int

Language ID

Return values
int

Mode (0=online only, 1=local first, 2=local only, 3=combined)

hasLocalDictionaries()

Check if a language has any local dictionaries.

public hasLocalDictionaries(int $languageId) : bool
Parameters
$languageId : int

Language ID

Return values
bool

lookup()

Look up a term in local dictionaries for a language.

public lookup(int $languageId, string $term) : array<string|int, array{term: string, definition: string, reading: ?string, pos: ?string, dictionary: string}>
Parameters
$languageId : int

Language ID

$term : string

Term to look up

Return values
array<string|int, array{term: string, definition: string, reading: ?string, pos: ?string, dictionary: string}>

lookupPrefix()

Look up a term with prefix matching (for autocomplete).

public lookupPrefix(int $languageId, string $prefix[, int $limit = 10 ]) : array<string|int, array{term: string, definition: string}>
Parameters
$languageId : int

Language ID

$prefix : string

Term prefix

$limit : int = 10

Maximum results

Return values
array<string|int, array{term: string, definition: string}>

updateEntry()

Update a single entry.

public updateEntry(int $entryId, string $term, string $definition[, string|null $reading = null ][, string|null $pos = null ]) : bool
Parameters
$entryId : int

Entry ID

$term : string

Term

$definition : string

Definition

$reading : string|null = null

Reading

$pos : string|null = null

Part of speech

Return values
bool

Success

insertBatch()

Insert a batch of entries.

private insertBatch(array<string|int, array<string, mixed>> $batch) : void
Parameters
$batch : array<string|int, array<string, mixed>>

Batch of entry data

updateEntryCount()

Update the entry count for a dictionary.

private updateEntryCount(int $dictId) : void
Parameters
$dictId : int

Dictionary ID


        
On this page

Search results