本文整理汇总了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')
开发者ID:ciju,项目名称:yql_hash,代码行数:9,代码来源:util.py
示例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")
开发者ID:Reagankm,项目名称:KnockKnock,代码行数:10,代码来源:util.py
示例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')
开发者ID:ciju,项目名称:yql_hash,代码行数:17,代码来源:util.py
示例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')
开发者ID:BohanHsu,项目名称:developer,代码行数:22,代码来源:util.py
注:本文中的nltk.internals.slice_bounds函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论