Skip to content

Instantly share code, notes, and snippets.

@nagisa
Created August 17, 2011 17:22
Show Gist options
  • Save nagisa/1152069 to your computer and use it in GitHub Desktop.
Save nagisa/1152069 to your computer and use it in GitHub Desktop.
Split by sentence
#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