<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def recreate_grams(self):
 """Re-create grams for database. In normal situations, you never need to call this method. But after migrate DB, this method is useful. :param session: DB session :type session: :class:`sqlalchemt.orm.Session` """


        session = self.Session()

        for document in session.query(Document).all():
            logger.info(document.text)
            grams = self._get_grams(session, document.text, make=True)
            document.grams = list(grams)

        broken_links = session.query(Gram) \
            .filter(~Gram.documents.any()).all()
        for gram in broken_links:
            session.delete(gram)

        session.commit()