Text_LanguageDetect (Constructor) [line 127]
Text_LanguageDetect Text_LanguageDetect(
)
|
|
Constructor
Will attempt to load the language database. If it fails, you will get a PEAR_Error object returned when you try to use detect()
clusteredSearch [line 1066]
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 techniqueis 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 895]
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 612]
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 other and the mbstring extension is present it will try to detect and convert.
Parameters:
detectConfidence [line 736]
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 690]
string detectSimple(
string
$sample)
|
|
Returns only the most similar language to the text sample
Calls $this->detect() and returns only the top result
Parameters:
getLanguageCount [line 284]
Returns the number of languages that this object can detect
getLanguages [line 335]
Returns the list of detectable languages
languageExists [line 303]
bool languageExists(
mixed
$lang)
|
|
Returns true if a given language exists
If passed an array of names, will return true only if all exist
Parameters:
languageSimilarity [line 796]
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 227]
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:
setPerlCompatible [line 350]
void setPerlCompatible(
[bool
$setting = true])
|
|
Make this object behave like Language::Guess
Parameters: