def add_document(title, body, user=None): regex = r"[^a-zA-Z\s\.-]" title = re.sub(regex, "", title.strip()) slug = str(uuid.uuid4())[:8] document = Document(title=title, body=body, slug=slug, user=user) db.session.add(document) phrase_texts = TextBlob(body).noun_phrases app.logger.info(phrase_texts) Phrase.add_multiple(phrase_texts, user, document) db.session.commit() return document
def add_cluster(title, body, user=None): regex = r"[^a-zA-Z\s\.-]" title = re.sub(regex, "", title.strip()) slug = str(uuid.uuid4())[:8] cluster = Cluster(title=title, body=body, slug=slug) db.session.add(cluster) phrase_texts = TextBlob(body).noun_phrases app.logger.info(phrase_texts) Phrase.add_multiple(phrase_texts, user, cluster) db.session.commit() return cluster