How to use the nlp.counter.Counter function in nlp

To help you get started, we’ve selected a few nlp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nuance / python-nlp / nlp / counter.py View on Github external
def __mul__(self, other):
			if isinstance(other, (int, long, float)):
				return Counter((key, value * other) for (key, value) in self.iteritems())

			keys = set(self.iterkeys())
			keys.update(other.iterkeys())

			lval = Counter((key, self.d_get(key) * other.d_get(key)) for key in keys)
			lval.default = self.default * other.default

			return lval
github nuance / python-nlp / nlp / counter.py View on Github external
def __div__(self, other):
			if isinstance(other, (int, long, float)):
				return Counter((key, value / other) for (key, value) in self.iteritems())

			keys = set(self.iterkeys())
			keys.update(other.iterkeys())

			lval = Counter((key, self.d_get(key) / other.d_get(key)) for key in keys)
			if other.default:
				lval.default = self.default / other.default
			else:
				lval.default = self.default

			return lval
github nuance / python-nlp / nlp / counter.py View on Github external
def __add__(self, other):
			if isinstance(other, (int, long, float)):
				return Counter((key, value + other) for (key, value) in self.iteritems())

			new = Counter()

			keys = set(self.iterkeys())
			keys.update(other.iterkeys())

			for key in keys:
				new[key] = self.d_get(key) + other.d_get(key)

			new.default = self.default + other.default

			return new
github nuance / python-nlp / nlp / counter.py View on Github external
def __sub__(self, other):
			if isinstance(other, (int, long, float)):
				return Counter((key, value - other) for (key, value) in self.iteritems())

			keys = set(self.iterkeys())
			keys.update(other.iterkeys())

			new = Counter((key, self.d_get(key) - other.d_get(key)) for key in keys)
			new.default = self.default - other.default

			return new
github nuance / python-nlp / nlp / counter.py View on Github external
def __add__(self, other):
			if isinstance(other, (int, long, float)):
				return Counter((key, value + other) for (key, value) in self.iteritems())

			new = Counter()

			keys = set(self.iterkeys())
			keys.update(other.iterkeys())

			for key in keys:
				new[key] = self.d_get(key) + other.d_get(key)

			new.default = self.default + other.default

			return new
github nuance / python-nlp / nlp / counter.py View on Github external
def __div__(self, other):
			if isinstance(other, (int, long, float)):
				return Counter((key, value / other) for (key, value) in self.iteritems())

			keys = set(self.iterkeys())
			keys.update(other.iterkeys())

			lval = Counter((key, self.d_get(key) / other.d_get(key)) for key in keys)
			if other.default:
				lval.default = self.default / other.default
			else:
				lval.default = self.default

			return lval
github nuance / python-nlp / nlp / counter.py View on Github external
def __setitem__(self, key, value):
			if not isinstance(value, (int, long, float)):
				raise ValueError("Counters can only hold numeric types")
			return super(Counter, self).__setitem__(key, value)
github nuance / python-nlp / nlp / counter.py View on Github external
def __sub__(self, other):
			if isinstance(other, (int, long, float)):
				return Counter((key, value - other) for (key, value) in self.iteritems())

			keys = set(self.iterkeys())
			keys.update(other.iterkeys())

			new = Counter((key, self.d_get(key) - other.d_get(key)) for key in keys)
			new.default = self.default - other.default

			return new
github nuance / python-nlp / nlp / counter.py View on Github external
def __mul__(self, other):
			if isinstance(other, (int, long, float)):
				return Counter((key, value * other) for (key, value) in self.iteritems())

			keys = set(self.iterkeys())
			keys.update(other.iterkeys())

			lval = Counter((key, self.d_get(key) * other.d_get(key)) for key in keys)
			lval.default = self.default * other.default

			return lval