我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用nltk.org()。
def descape_entity(m, defs=htmlentitydefs.entitydefs): """ Translate one entity to its ISO Latin value. Inspired by example from effbot.org """ #s = 'mcglashan_&_sarrail' #l = ['mcglashan', '&', 'sarrail'] #pattern = re.compile("&(\w+?);") #new = list2sym(l) #s = pattern.sub(descape_entity, s) #print s, new try: return defs[m.group(1)] except KeyError: return m.group(0) # use as is
def _show_plot(x_values, y_values, x_labels=None, y_labels=None): try: import matplotlib.pyplot as plt except ImportError: raise ImportError('The plot function requires matplotlib to be installed.' 'See http://matplotlib.org/') plt.locator_params(axis='y', nbins=3) axes = plt.axes() axes.yaxis.grid() plt.plot(x_values, y_values, 'ro', color='red') plt.ylim(ymin=-1.2, ymax=1.2) plt.tight_layout(pad=5) if x_labels: plt.xticks(x_values, x_labels, rotation='vertical') if y_labels: plt.yticks([-1, 0, 1], y_labels, rotation='horizontal') # Pad margins so that markers are not clipped by the axes plt.margins(0.2) plt.show() #//////////////////////////////////////////////////////////// #{ Parsing and conversion functions #////////////////////////////////////////////////////////////
def __getattr__(self, attr): # Fix for inspect.isclass under Python 2.6 # (see http://bugs.python.org/issue1225107). # Without this fix tests may take extra 1.5GB RAM # because all corpora gets loaded during test collection. if attr == '__bases__': raise AttributeError("LazyCorpusLoader object has no attribute '__bases__'") self.__load() # This looks circular, but its not, since __load() changes our # __class__ to something new: return getattr(self, attr)