Created
August 17, 2011 17:22
-
-
Save nagisa/1152069 to your computer and use it in GitHub Desktop.
Split by sentence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#settings | |
DESCRIPTION_LEN = 5 | |
DESCRIPTION_SPLITTER = r'(?<=[.?!。!?])\s+' | |
#Modelis | |
def get_description(self, splitter = re.compile(settings.DESCRIPTION_SPLITTER)): | |
if self.short_content: | |
return self.short_content | |
else: | |
return ' '.join(splitter.split(self.content, settings.DESCRIPTION_LEN)[:-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment