本文整理汇总了Python中nltk.internals.slice_bounds函数的典型用法代码示例。如果您正苦于以下问题:Python slice_bounds函数的具体用法?Python slice_bounds怎么用?Python slice_bounds使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slice_bounds函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
def index(self, value, start=None, stop=None):
"""Return the index of the first occurance of C{value} in this
list that is greater than or equal to C{start} and less than
C{stop}. Negative start & stop values are treated like negative
slice bounds -- i.e., they count from the end of the list."""
start, stop = slice_bounds(self, slice(start, stop))
for i, elt in enumerate(islice(self, start, stop)):
if elt == value: return i+start
raise ValueError('index(x): x not in list')
示例2: index
def index(self, value, start=None, stop=None):
"""Return the index of the first occurrence of ``value`` in this
list that is greater than or equal to ``start`` and less than
``stop``. Negative start and stop values are treated like negative
slice bounds -- i.e., they count from the end of the list."""
start, stop = slice_bounds(self, slice(start, stop))
for i, elt in enumerate(islice(self, start, stop)):
if elt == value:
return i + start
raise ValueError("index(x): x not in list")
示例3: __getitem__
def __getitem__(self, i):
"""
Return the C{i}th token in the corpus file underlying this
corpus view. Negative indices and spans are both supported.
"""
if isinstance(i, slice):
start, stop = slice_bounds(self, i)
return LazySubsequence(self, start, stop)
else:
# Handle negative indices
if i < 0: i += len(self)
if i < 0: raise IndexError('index out of range')
# Use iterate_from to extract it.
try:
return self.iterate_from(i).next()
except StopIteration:
raise IndexError('index out of range')
示例4: __getitem__
def __getitem__(self, i):
if isinstance(i, slice):
start, stop = slice_bounds(self, i)
# Check if it's in the cache.
offset = self._cache[0]
if offset <= start and stop <= self._cache[1]:
return self._cache[2][start-offset:stop-offset]
# Construct & return the result.
return LazySubsequence(self, start, stop)
else:
# Handle negative indices
if i < 0: i += len(self)
if i < 0: raise IndexError('index out of range')
# Check if it's in the cache.
offset = self._cache[0]
if offset <= i < self._cache[1]:
return self._cache[2][i-offset]
# Use iterate_from to extract it.
try:
return next(self.iterate_from(i))
except StopIteration:
raise IndexError('index out of range')