本文整理汇总了Python中BibleOrgSysGlobals.stripWordPunctuation方法的典型用法代码示例。如果您正苦于以下问题:Python BibleOrgSysGlobals.stripWordPunctuation方法的具体用法?Python BibleOrgSysGlobals.stripWordPunctuation怎么用?Python BibleOrgSysGlobals.stripWordPunctuation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BibleOrgSysGlobals
的用法示例。
在下文中一共展示了BibleOrgSysGlobals.stripWordPunctuation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: segmentizeLine
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import stripWordPunctuation [as 别名]
def segmentizeLine( line, segmentEndPunctuation='.?!;:' ):
"""
Break the line into segments (like sentences that should match across the translations)
and then break each segment into words.
If you want case folding, convert line to lowerCase before calling.
Set segmentEndPunctuation to None if you don't want the lines further divided.
Returns a list of lists of words.
"""
if BibleOrgSysGlobals.debugFlag:
if debuggingThisModule:
print( exp("segmentizeLine( {!r} )").format( line ) )
if segmentEndPunctuation:
for segmentEndChar in segmentEndPunctuation:
line = line.replace( segmentEndChar, 'SsSsSsS' )
line = line.replace('—',' ').replace('–',' ') # Treat em-dash and en-dash as word break characters
lineList = []
for segment in line.split( 'SsSsSsS' ):
segmentList = []
for rawWord in segment.split():
word = rawWord
for internalMarker in BibleOrgSysGlobals.internal_SFMs_to_remove: word = word.replace( internalMarker, '' )
word = BibleOrgSysGlobals.stripWordPunctuation( word )
if word and not word[0].isalnum():
#print( "not alnum", repr(rawWord), repr(word) )
if len(word) > 1:
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
print( "segmentizeLine: {} {}:{} ".format( self.BBB, C, V ) \
+ _("Have unexpected character starting word {!r}").format( word ) )
word = word[1:]
if word: # There's still some characters remaining after all that stripping
#print( "here", repr(rawWord), repr(word) )
if 1 or BibleOrgSysGlobals.verbosityLevel > 3: # why???
for k,char in enumerate(word):
if not char.isalnum() and (k==0 or k==len(word)-1 or char not in BibleOrgSysGlobals.MEDIAL_WORD_PUNCT_CHARS):
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
print( "segmentizeLine: {} {}:{} ".format( self.BBB, C, V ) + _("Have unexpected {!r} in word {!r}").format( char, word ) )
lcWord = word.lower()
isAReferenceOrNumber = True
for char in word:
if not char.isdigit() and char not in ':-,.': isAReferenceOrNumber = False; break
if not isAReferenceOrNumber:
segmentList.append( word )
#lDict['allWordCounts'][word] = 1 if word not in lDict['allWordCounts'] else lDict['allWordCounts'][word] + 1
#lDict['allCaseInsensitiveWordCounts'][lcWord] = 1 if lcWord not in lDict['allCaseInsensitiveWordCounts'] else lDict['allCaseInsensitiveWordCounts'][lcWord] + 1
lineList.append( segmentList )
#print( ' lineList', lineList )
return lineList