XarayaTranslationMemory  1.6
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
TranslationWordList Class Reference
Inheritance diagram for TranslationWordList:

Public Member Functions

 __construct ($text="")
 
 rewind ()
 
 hasMore ()
 
 key ()
 
 current ()
 
 next ()
 
 valid ()
 
 AddWord ($word, $count=1)
 
 AddID ($id, $count=1)
 
 SetIDByName ($word, $id)
 
 SetFakeLength ($length)
 
FindByName ($word)
 
FindByID ($id)
 
 SumCount ()
 
 CompareByID ($otherWords)
 

Static Public Member Functions

static InitWordsCache ()
 

Static Public Attributes

static $WordsCache
 

Private Member Functions

 SplitToWords ($text)
 
 AddToWordIndex ()
 

Private Attributes

 $allWords
 
 $fakeLength
 
 $DB
 
 $Tables
 
 $currIndex
 

Detailed Description

Class to manage all words for one sentence

This class basically just stores an array of words (TranslationWord objects), count of their appearances in the sentence, and can return these properties. The main function of this class is to compare itself with another instance, and return the contained words' match percentage for finding similar sentences. It can be initialized two ways: Adding words one by one or parse a sentence.

Definition at line 31 of file TranslationWordList.php.

Constructor & Destructor Documentation

◆ __construct()

TranslationWordList::__construct (   $text = "")

Creates a new TranslationWordList object, and parses the passed sentence if any.

While parsing sentence, this class adds all words to the WordIndex database or finds already existing ones. The class maintains an iterable list of TranslationWord objects.

Parameters
$textstring Text to parse and index. If empty, an object without actual wordlist is created.

Definition at line 50 of file TranslationWordList.php.

References GetDbConn(), GetTables(), and SplitToWords().

Member Function Documentation

◆ AddID()

TranslationWordList::AddID (   $id,
  $count = 1 
)

Add a word only by it's WordIndex ID to our internal Word list.

Adds a word which will not have actual text, just ID. Later, if necessary, the TranslationWord object can be extended to load it's text when ID is configured but word text is not. If the word already exist in this context, the number of occurences will be increased by $count.

Parameters
$idThe ID of the word in the WordIndex database.
$countOccurences of the word in the current context, defaults to 1.
Returns
Nothing.

Definition at line 190 of file TranslationWordList.php.

References FindByID().

◆ AddToWordIndex()

TranslationWordList::AddToWordIndex ( )
private

Adds the new words from the internal $this->allWords array to the word index table

Newly inserted words will get an index in the $this->allWords array, already existing words get their old ID from the table into the same array.

Returns
Nothing.

Definition at line 448 of file TranslationWordList.php.

References $WordsCache, fixstr(), and SetIDByName().

Referenced by SplitToWords().

◆ AddWord()

TranslationWordList::AddWord (   $word,
  $count = 1 
)

Add a word by it's actual text to our internal Word list.

Adds a word which will not have ID, just text. If the word already exist in this object, the number of occurences will be increased by $count.

Parameters
$wordThe text of the word.
$countOccurences of the word in the current context, defaults to 1.
Returns
Nothing.

Definition at line 158 of file TranslationWordList.php.

References FindByName().

Referenced by SplitToWords().

◆ CompareByID()

TranslationWordList::CompareByID (   $otherWords)

Comare our Words array to the one in another similar object.

This function comapres this and another TranslationWordList and returns a similarity percentage value. The value is 100% if this and the passed TranslationWordList object contains the same words and each appears the same times in both. Otherwise smaller than 100.

Parameters
$otherWordsAnother TranslationWordList object to compare our words to.
Returns
Percentage of the match.

Definition at line 404 of file TranslationWordList.php.

References SumCount().

◆ current()

TranslationWordList::current ( )

Iterator interface: current function.

Definition at line 93 of file TranslationWordList.php.

References $currIndex.

◆ FindByID()

& TranslationWordList::FindByID (   $id)

Find a word by its ID and return a REFERENCE to its TranslationWord object.

You can change Word object using the returned reference, be careful.

Parameters
$idThe ID of the word to find in the internal array of Words.
Returns
Reference to a TranslationWord object, null if not found.

Definition at line 336 of file TranslationWordList.php.

Referenced by AddID().

◆ FindByName()

& TranslationWordList::FindByName (   $word)

Find a word by its text and return a REFERENCE to its TranslationWord object.

You can change Word object using the returned reference, be careful.

Parameters
$wordThe word to find in the internal array of Words.
Returns
Reference to a TranslationWord object, null if not found.

Definition at line 308 of file TranslationWordList.php.

Referenced by AddWord(), and SetIDByName().

◆ hasMore()

TranslationWordList::hasMore ( )

Iterator interface: hasMore function.

Definition at line 79 of file TranslationWordList.php.

References $currIndex.

◆ InitWordsCache()

static TranslationWordList::InitWordsCache ( )
static

Loads all already indexed word from the database to the public static $WordsCache variable.

This function must be called before using any Translation functions. TODO: autoload on need?

Definition at line 124 of file TranslationWordList.php.

References $DB, $Tables, $WordsCache, GetDbConn(), and GetTables().

Referenced by CacheIndexes().

◆ key()

TranslationWordList::key ( )

Iterator interface: key function.

Definition at line 86 of file TranslationWordList.php.

References $currIndex.

◆ next()

TranslationWordList::next ( )

Iterator interface: next function.

Definition at line 100 of file TranslationWordList.php.

◆ rewind()

TranslationWordList::rewind ( )

Iterator interface: rewind function.

Definition at line 72 of file TranslationWordList.php.

◆ SetFakeLength()

TranslationWordList::SetFakeLength (   $length)

Set a fake value for the actual sentences' length, when the real lenght is known but not all words are loaded.

The SumCount function will return this value if set, otherwise it will really count the occurences of the actually loaded words.

Parameters
$lengthThe fake length to set.

Definition at line 239 of file TranslationWordList.php.

Referenced by SplitToWords().

◆ SetIDByName()

TranslationWordList::SetIDByName (   $word,
  $id 
)

Set ID for an already added word.

Sets the WordIndex ID of a word which is already added to our wordlist.

Parameters
$wordThe word string which will get the ID.
$idThe ID to set to this word.

Definition at line 219 of file TranslationWordList.php.

References FindByName().

Referenced by AddToWordIndex().

◆ SplitToWords()

TranslationWordList::SplitToWords (   $text)
private

Splits any string to human readable words and adds them to the internal $this->allWords array

Also counts how many times each word appears in the sentence. Also adds all missing words to the WordIndexes.

Parameters
$textThe sentence to split to words
Returns
Nothing.

Definition at line 254 of file TranslationWordList.php.

References AddToWordIndex(), AddWord(), SetFakeLength(), and SumCount().

Referenced by __construct().

◆ SumCount()

TranslationWordList::SumCount ( )

Return the number of all words in this sentence.

Counts all loaded words occurences in the internal Words array. If the SetFakeLength() function was used to configure a different real length, that will be returned instead.

Returns
Total number of words in our Words array.

Definition at line 366 of file TranslationWordList.php.

References $fakeLength.

Referenced by CompareByID(), and SplitToWords().

◆ valid()

TranslationWordList::valid ( )

Iterator interface: valid function.

Definition at line 107 of file TranslationWordList.php.

Member Data Documentation

◆ $allWords

TranslationWordList::$allWords
private

Array containing our TranslationWords objects

Definition at line 33 of file TranslationWordList.php.

◆ $currIndex

TranslationWordList::$currIndex
private

Current item when using the internal Iterator

Definition at line 38 of file TranslationWordList.php.

Referenced by current(), hasMore(), and key().

◆ $DB

TranslationWordList::$DB
private

Database connection reference.

Definition at line 36 of file TranslationWordList.php.

Referenced by InitWordsCache().

◆ $fakeLength

TranslationWordList::$fakeLength
private

Used to fake SumCount() if not all words are actually loaded

Definition at line 34 of file TranslationWordList.php.

Referenced by SumCount().

◆ $Tables

TranslationWordList::$Tables
private

Database tables reference.

Definition at line 37 of file TranslationWordList.php.

Referenced by InitWordsCache().

◆ $WordsCache

TranslationWordList::$WordsCache
static

Cache for words already indexed in the database, initialized by the InitWordsCache public static method of this class.

Definition at line 40 of file TranslationWordList.php.

Referenced by AddToWordIndex(), and InitWordsCache().


The documentation for this class was generated from the following file: