__construct (Constructor) [line 167]
Text_LanguageDetect __construct(
)
|
|
Constructor
Will attempt to load the language database. If it fails, you will get an exception.
Overridden in child classes as:
- Text_LanguageDetect_Parser::__construct()
- Constructor
clusteredSearch [line 1322]
array clusteredSearch(
string
$str)
|
|
Perform an intelligent detection based on clusterLanguages()
WARNING: this method is EXPERIMENTAL. It is not recommended for common use, and it may disappear or its functionality may change in future releases without notice.
This compares the sample text to top the top level of clusters. If the sample is similar to the cluster it will drop down and compare it to the languages in the cluster, and so on until it hits a leaf node.
this should find the language in considerably fewer compares (the equivalent of a binary search), however clusterLanguages() is costly and the loss of accuracy from this technique is significant.
This method may need to be 'fuzzier' in order to become more accurate.
This function could be more useful if the universe of possible languages was very large, however in such cases some method of Bayesian inference might be more helpful.
Parameters:
clusterLanguages [line 1131]
array clusterLanguages(
)
|
|
Cluster known languages according to languageSimilarity()
WARNING: this method is EXPERIMENTAL. It is not recommended for common use, and it may disappear or its functionality may change in future releases without notice.
Uses a nearest neighbor technique to generate the maximum possible number of dendograms from the similarity data.
detect [line 653]
mixed detect(
string
$sample, [int
$limit = 0])
|
|
Detects the closeness of a sample of text to the known languages
Calculates the statistical difference between the text and the trigrams for each language, normalizes the score then returns results for all languages in sorted order
If perl compatible, the score is 300-0, 0 being most similar. Otherwise, it's 0-1 with 1 being most similar.
The $sample text should be at least a few sentences in length; should be ascii-7 or utf8 encoded, if another and the mbstring extension is present it will try to detect and convert. However, experience has shown that mb_detect_encoding() *does not work very well* with at least some types of encoding.
Parameters:
detectConfidence [line 834]
array detectConfidence(
string
$sample)
|
|
Returns an array containing the most similar language and a confidence rating
Confidence is a simple measure calculated from the similarity score minus the similarity score from the next most similar language divided by the highest possible score. Languages that have closely related cousins (e.g. Norwegian and Danish) should generally have lower confidence scores.
The similarity score answers the question "How likely is the text the returned language regardless of the other languages considered?" The confidence score is one way of answering the question "how likely is the text the detected language relative to the rest of the language model set?"
To see how similar languages are a priori, see languageSimilarity()
Parameters:
detectSimple [line 794]
string detectSimple(
string
$sample)
|
|
Returns only the most similar language to the text sample
Calls $this->detect() and returns only the top result
Parameters:
detectUnicodeBlocks [line 881]
array detectUnicodeBlocks(
string
$str, bool
$skip_symbols)
|
|
Returns the distribution of unicode blocks in a given utf8 string
For the block name of a single char, use unicodeBlockName()
Parameters:
getLanguageCount [line 342]
Returns the number of languages that this object can detect
getLanguages [line 383]
Returns the list of detectable languages
languageExists [line 354]
bool languageExists(
mixed
$lang)
|
|
Checks if the language with the given name exists in the database
Parameters:
languageSimilarity [line 1039]
array languageSimilarity(
[string
$lang1 = null], [string
$lang2 = null])
|
|
Calculate the similarities between the language models
Use this function to see how similar languages are to each other.
If passed 2 language names, will return just those languages compared. If passed 1 language name, will return that language compared to all others. If passed none, will return an array of every language model compared to every other one.
Parameters:
omitLanguages [line 284]
int omitLanguages(
mixed
$omit_list, [bool
$include_only = false])
|
|
Omits languages
Pass this function the name of or an array of names of languages that you don't want considered
If you're only expecting a limited set of languages, this can greatly speed up processing
Parameters:
setNameMode [line 421]
void setNameMode(
integer
$name_mode)
|
|
Sets the way how language names are accepted and returned.
Parameters:
setPerlCompatible [line 397]
void setPerlCompatible(
[bool
$setting = true])
|
|
Make this object behave like Language::Guess
Parameters:
unicodeBlockName [line 910]
mixed unicodeBlockName(
mixed
$unicode)
|
|
Returns the block name for a given unicode value
If passed a string, will assume it is being passed a UTF8-formatted character and will automatically convert. Otherwise it will assume it is being passed a numeric unicode value.
Make sure input is of the correct type!
Parameters:
useUnicodeBlocks [line 438]
void useUnicodeBlocks(
[bool
$setting = true])
|
|
Whether to use unicode block ranges in detection
Should speed up most detections if turned on (detault is on). In some circumstances it may be slower, such as for large text samples (> 10K) in languages that use latin scripts. In other cases it should speed up detection noticeably.
Parameters:
utf8strlen [line 1448]
int utf8strlen(
string
$str)
|
|
UTF8-safe strlen()
Returns the numbers of characters (not bytes) in a utf8 string
Parameters:
_arr_rank [line 472]
array _arr_rank(
array
$arr)
|
|
Converts a set of trigrams from frequencies to ranks
Thresholds (cuts off) the list at $this->_threshold
Parameters:
_bub_sort [line 504]
void _bub_sort(
&$arr, array
$arr)
|
|
Sorts an array by value breaking ties alphabetically
Parameters:
_checkTrigram [line 247]
void _checkTrigram(
array
$trigram)
|
|
Checks if this object is ready to detect languages
Parameters:
_convertFromNameMode [line 1607]
string|array _convertFromNameMode(
string|array
$lang, [boolean
$convertKey = false])
|
|
Converts an $language input parameter from the configured mode to the language name that is used internally.
Works for strings and arrays.
Parameters:
_convertToNameMode [line 1647]
string|array _convertToNameMode(
string|array
$lang, [boolean
$convertKey = false])
|
|
Converts an $language output parameter from the language name that is used internally to the configured mode.
Works for strings and arrays.
Parameters:
_distance [line 582]
int _distance(
array
$arr1, array
$arr2)
|
|
Calculates a linear rank-order distance statistic between two sets of ranked trigrams
Sums the differences in rank for each trigram. If the trigram does not appear in both, consider it a difference of $this->_threshold.
This distance measure was proposed by Cavnar & Trenkle (1994). Despite its simplicity it has been shown to be highly accurate for language identification tasks.
Parameters:
_get_data_loc [line 190]
string _get_data_loc(
string
$fname)
|
|
Returns the path to the location of the database
Parameters:
_next_char [line 1515]
char _next_char(
string
$str,
&$counter, [bool
$special_convert = false], int
$counter)
|
|
UTF8-safe fast character iterator
Will get the next character starting from $counter, which will then be incremented. If a multi-byte char the bytes will be concatenated and $counter will be incremeted by the number of bytes in the char.
Parameters:
_normalize_score [line 614]
float _normalize_score(
int
$score, [int
$base_count = null])
|
|
Normalizes the score returned by _distance()
Different if perl compatible or not
Parameters:
_readdb [line 218]
array _readdb(
string
$fname)
|
|
Loads the language trigram database from filename
Trigram datbase should be a serialize()'d array
Parameters:
_read_unicode_block_db [line 1006]
array _read_unicode_block_db(
)
|
|
Brings up the unicode block database
_sort_func [line 543]
int _sort_func(
array
$a, array
$b)
|
|
Sort function used by bubble sort
Callback function for usort().
Parameters:
_trigram [line 453]
array _trigram(
string
$text)
|
|
Converts a piece of text into trigrams
Parameters:
_unicode_block_name [line 954]
mixed _unicode_block_name(
int
$unicode, array
$blocks, [int
$block_count = -1])
|
|
Searches the unicode block database
Returns the block name for a given unicode value. unicodeBlockName() is the public interface for this function, which does input checks which this function omits for speed.
Parameters:
_utf8char2unicode [line 1466]
int _utf8char2unicode(
string
$char)
|
|
Returns the unicode value of a utf8 char
Parameters: