| | |
| | | """ |
| | | if not entity_names: |
| | | return "" |
| | | _entities = self.session.query(TEntity).where(TEntity.name.in_(entity_names)).all() |
| | | _entitie_ids = [entity.id for entity in _entities] |
| | | links = self.session.query(TParagraphEntityLink).where(TParagraphEntityLink.entity_id.in_(_entitie_ids)).all() |
| | | _paragraphs = [link.paragraph for link in links] |
| | | |
| | | return '\n'.join([entity.name for entity in self.get_all_entities() if entity.name in entity_names]) |
| | | return '\n'.join([self.get_paragraph_full_text(p) for p in _paragraphs]) |
| | | |
| | | def get_paragraph_full_text(self, p: TParagraph): |
| | | result = p.text if p.title_level == 0 else p.title_num + ' ' + p.text |
| | | return result + '\n' + '\n'.join([self.get_paragraph_full_text(p) for p in p.children]) |
| | | |
| | | def commit(self): |
| | | self.session.commit() |
| | |
| | | doc_dbh = DocDbHelper() |
| | | |
| | | # if __name__ == '__main__': |
| | | # text = doc_dbh.get_text_with_entities(['遥控包格式']) |
| | | # print(text) |
| | | # doc_db = DocDbHelper() |
| | | # # doc_db.insert_entities() |
| | | # doc = doc_db.add_doc(DocInfo(file='aaa', file_name='test')) |