merge_machine/preprocess_fields_v3.py
def chngrams(string="", n=3, top=None, threshold=0, exclude=[], **kwargs):
	""" Returns a dictionary of (character n-gram, count)-`s.
		N-grams in the exclude list are not counted.
		N-grams whose count falls below (or equals) the given threshold are excluded.
		N-grams that are not in the given top most counted are excluded.
	"""
	# An optional dict-parameter can be used to specify a subclass of dict,
	# e.g., count(words, dict=readonlydict) as used in Document.
	count = defaultdict(int)
	if n > 0:
		for i in xrange(len(string)-n+1):
			w = string[i:i+n]
			if w not in exclude:
				count[w] += 1
	if threshold > 0:
		count = dict((k, v) for k, v in count.items() if v > threshold)
	if top is not None:
		count = dict(heapq.nsmallest(top, count.items(), key=lambda kv: (-kv[1], kv[0])))
	return kwargs.get("dict", dict)(count)
 Returns a dictionary of (character n-gram, count)-`s.
		N-grams in the exclude list are not counted.
		N-grams whose count falls below (or equals) the given threshold are excluded.
		N-grams that are not in the given top most counted are excluded.
	
Returns a dictionary of (character n-gram, count)-`s.
N-grams in the exclude list are not counted.
N-grams whose count falls below (or equals) the given threshold are excluded.
N-grams that are not in the given top most counted are excluded.
Returns a dictionary of ( character n - gram count ) - ` s . N - grams in the exclude list are not counted . N - grams whose count falls below ( or equals ) the given threshold are excluded . N - grams that are not in the given top most counted are excluded .
def chngrams(string="", n=3, top=None, threshold=0, exclude=[], **kwargs):
	count = defaultdict(int)
	if n > 0:
		for i in xrange(len(string)-n+1):
			w = string[i:i+n]
			if w not in exclude:
				count[w] += 1
	if threshold > 0:
		count = dict((k, v) for k, v in count.items() if v > threshold)
	if top is not None:
		count = dict(heapq.nsmallest(top, count.items(), key=lambda kv: (-kv[1], kv[0])))
	return kwargs.get("dict", dict)(count)
def chngrams ( string = "" , n = 3 , top = None , threshold = 0 , exclude = [ ] , ** kwargs ) : count = defaultdict ( int ) if n > 0 : for i in xrange ( len ( string ) - n + 1 ) : w = string [ i : i + n ] if w not in exclude : count [ w ] += 1 if threshold > 0 : count = dict ( ( k , v ) for k , v in count . items ( ) if v > threshold ) if top is not None : count = dict ( heapq . nsmallest ( top , count . items ( ) , key = lambda kv : ( - kv [ 1 ] , kv [ 0 ] ) ) ) return kwargs . get ( "dict" , dict ) ( count )
Returns a dictionary of (character n-gram, count)-`s.
N-grams in the exclude list are not counted.
Returns a dictionary of ( character n - gram count ) - ` s . N - grams in the exclude list are not counted .
""" Returns a dictionary of (character n-gram, count)-`s.
		N-grams in the exclude list are not counted.
		N-grams whose count falls below (or equals) the given threshold are excluded.
		N-grams that are not in the given top most counted are excluded.
	""" # An optional dict-parameter can be used to specify a subclass of dict, # e.g., count(words, dict=readonlydict) as used in Document.
string
n
top
threshold
exclude