pycl/Code/LID/lid.py
def checkText(self, text):
		"""Check which language a text is."""
		self.createTrigrams(text) # create trigrams of submitted text
		self.calcProb()           # calculate probabilities

		result = []               # storage for the matches with the models
		for x in range(len(self.languages)):
			result.append(0)
		# for all keys in trigrams
		for x in self.trigrams.keys():
			# for 0 to number language models
			for i in range(len(self.models)):
				# get the current model
				mymodel = self.models[i]
				if mymodel.has_key(x):
					# if the model contains the key, get the deviation
					value = mymodel[x] - self.trigrams[x]
					if value < 0:
						value = value * -1
					result[i] += value
				else:
					# otherwise set the resulting value to 1 = max. deviation
					result[i] += 1
		value = float(1.0)
		element = 0
		for x in range(len(result)):
			result[x] = float(result[x])/float(self.num)
			if value > result[x]:
				value = float(result[x])
				element = x
		return self.languages[element]
Check which language a text is.
Check which language a text is.
Check which language a text is .
def checkText(self, text):
		self.createTrigrams(text) 
		self.calcProb()           
		result = []               
		for x in range(len(self.languages)):
			result.append(0)
		for x in self.trigrams.keys():
			for i in range(len(self.models)):
				mymodel = self.models[i]
				if mymodel.has_key(x):
					value = mymodel[x] - self.trigrams[x]
					if value < 0:
						value = value * -1
					result[i] += value
				else:
					result[i] += 1
		value = float(1.0)
		element = 0
		for x in range(len(result)):
			result[x] = float(result[x])/float(self.num)
			if value > result[x]:
				value = float(result[x])
				element = x
		return self.languages[element]
def checkText ( self , text ) : self . createTrigrams ( text ) self . calcProb ( ) result = [ ] for x in range ( len ( self . languages ) ) : result . append ( 0 ) for x in self . trigrams . keys ( ) : for i in range ( len ( self . models ) ) : mymodel = self . models [ i ] if mymodel . has_key ( x ) : value = mymodel [ x ] - self . trigrams [ x ] if value < 0 : value = value * - 1 result [ i ] += value else : result [ i ] += 1 value = float ( 1.0 ) element = 0 for x in range ( len ( result ) ) : result [ x ] = float ( result [ x ] ) / float ( self . num ) if value > result [ x ] : value = float ( result [ x ] ) element = x return self . languages [ element ]
Check which language a text is.
Check which language a text is .
"""Check which language a text is.""" # create trigrams of submitted text # calculate probabilities # storage for the matches with the models # for all keys in trigrams # for 0 to number language models # get the current model # if the model contains the key, get the deviation # otherwise set the resulting value to 1 = max. deviation
self
text