本文整理匯總了Python中nltk.compat.get_im_class方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.get_im_class方法的具體用法?Python compat.get_im_class怎麽用?Python compat.get_im_class使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nltk.compat
的用法示例。
在下文中一共展示了compat.get_im_class方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: overridden
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import get_im_class [as 別名]
def overridden(method):
"""
:return: True if ``method`` overrides some method with the same
name in a base class. This is typically used when defining
abstract base classes or interfaces, to allow subclasses to define
either of two related methods:
>>> class EaterI:
... '''Subclass must define eat() or batch_eat().'''
... def eat(self, food):
... if overridden(self.batch_eat):
... return self.batch_eat([food])[0]
... else:
... raise NotImplementedError()
... def batch_eat(self, foods):
... return [self.eat(food) for food in foods]
:type method: instance method
"""
# [xx] breaks on classic classes!
if isinstance(method, types.MethodType) and compat.get_im_class(method) is not None:
name = method.__name__
funcs = [cls.__dict__[name]
for cls in _mro(compat.get_im_class(method))
if name in cls.__dict__]
return len(funcs) > 1
else:
raise TypeError('Expected an instance method.')