TranslationWordList Class Reference

List of all members.

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 33 of file TranslationWordList.php.

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


Constructor & Destructor Documentation

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:
$text string Text to parse and index. If empty, an object without actual wordlist is created.

Definition at line 52 of file TranslationWordList.php.

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


Member Function Documentation

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:
$id The ID of the word in the WordIndex database.
$count Occurences of the word in the current context, defaults to 1.
Returns:
Nothing.

Definition at line 192 of file TranslationWordList.php.

References FindByID().

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 450 of file TranslationWordList.php.

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

Referenced by SplitToWords().

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:
$word The text of the word.
$count Occurences of the word in the current context, defaults to 1.
Returns:
Nothing.

Definition at line 160 of file TranslationWordList.php.

References FindByName().

Referenced by SplitToWords().

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:
$otherWords Another TranslationWordList object to compare our words to.
Returns:
Percentage of the match.

Definition at line 406 of file TranslationWordList.php.

References SumCount().

TranslationWordList::current (  ) 

Iterator interface: current function.

Definition at line 95 of file TranslationWordList.php.

& 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:
$id The 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 338 of file TranslationWordList.php.

Referenced by AddID().

& 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:
$word The word to find in the internal array of Words.
Returns:
Reference to a TranslationWord object, null if not found.

Definition at line 310 of file TranslationWordList.php.

Referenced by AddWord(), and SetIDByName().

TranslationWordList::hasMore (  ) 

Iterator interface: hasMore function.

Definition at line 81 of file TranslationWordList.php.

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 126 of file TranslationWordList.php.

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

Referenced by CacheIndexes().

TranslationWordList::key (  ) 

Iterator interface: key function.

Definition at line 88 of file TranslationWordList.php.

TranslationWordList::next (  ) 

Iterator interface: next function.

Definition at line 102 of file TranslationWordList.php.

TranslationWordList::rewind (  ) 

Iterator interface: rewind function.

Definition at line 74 of file TranslationWordList.php.

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:
$length The fake length to set.

Definition at line 241 of file TranslationWordList.php.

Referenced by SplitToWords().

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:
$word The word string which will get the ID.
$id The ID to set to this word.

Definition at line 221 of file TranslationWordList.php.

References FindByName().

Referenced by AddToWordIndex().

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:
$text The sentence to split to words
Returns:
Nothing.

Definition at line 256 of file TranslationWordList.php.

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

Referenced by __construct().

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 368 of file TranslationWordList.php.

Referenced by CompareByID(), and SplitToWords().

TranslationWordList::valid (  ) 

Iterator interface: valid function.

Definition at line 109 of file TranslationWordList.php.


Member Data Documentation

TranslationWordList::$allWords [private]

Array containing our TranslationWords objects

Definition at line 35 of file TranslationWordList.php.

TranslationWordList::$currIndex [private]

Current item when using the internal Iterator

Definition at line 40 of file TranslationWordList.php.

TranslationWordList::$DB [private]

Database connection reference.

Definition at line 38 of file TranslationWordList.php.

Referenced by InitWordsCache().

TranslationWordList::$fakeLength [private]

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

Definition at line 36 of file TranslationWordList.php.

TranslationWordList::$Tables [private]

Database tables reference.

Definition at line 39 of file TranslationWordList.php.

Referenced by InitWordsCache().

TranslationWordList::$WordsCache [static]

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

Definition at line 42 of file TranslationWordList.php.

Referenced by AddToWordIndex(), and InitWordsCache().


The documentation for this class was generated from the following file:
Generated on Tue Mar 20 00:42:40 2007 for XarayaTranslationMemory by  doxygen 1.4.7