本文整理汇总了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.')