Exemple #1
0
    def create_summary(self, lecture_id: int, request_body: Dict) -> Dict:
        lecture: Dict[str, str] = self.lecture_service.get_lecture(lecture_id)
        if not lecture:
            return {}

        summary_name: str = request_body['name']
        ratio: float = float(request_body['ratio'])
        lecture_content: str = lecture['content']

        initial_sentences: List[str] = self.__process_content_sentences(
            lecture_content)
        if len(initial_sentences) == 0:
            raise RuntimeError(
                "No viable sentences found. Consider adding larger lectures.")
        sentences = self.bert_model.run_clusters(initial_sentences, ratio)
        result: str = ' '.join(sentences).strip()
        summary = Summarization(name=summary_name,
                                lecture=lecture_id,
                                ratio=ratio,
                                content=result)

        session = Engine.get_instance(self.use_memory).Session()
        session.add(summary)
        session.flush()
        session.commit()

        return {
            'id': summary.id,
            'name': summary.name,
            'ratio': summary.ratio,
            'content': summary.content,
            'lecture': summary.lecture
        }
Exemple #2
0
 def delete_lecture(self, l_id: int) -> Dict[str, int]:
     session = Engine.get_instance(self.memory_only).Session()
     lecture = session.query(Lecture).filter(Lecture.id == l_id).first()
     if lecture:
         session.delete(lecture)
         session.commit()
         return {'id': l_id}
     return {}
Exemple #3
0
 def create_lecture(self, request_body: Dict[str, str]) -> Dict[str, str]:
     session = Engine.get_instance(self.memory_only).Session()
     lecture = Lecture(name=request_body['name'],
                       course=request_body['course'],
                       content=request_body['content'])
     session.add(lecture)
     session.flush()
     session.commit()
     return {"id": lecture.id}
Exemple #4
0
 def delete_summary(self, summary_id: int) -> Dict[str, int]:
     session = Engine.get_instance(self.use_memory).Session()
     summary = session.query(Summarization).filter(
         Summarization.id == summary_id).first()
     if summary:
         session.delete(summary)
         session.commit()
         return {'id': summary_id}
     return {}
Exemple #5
0
 def get_lecture(self, l_id: int) -> Dict[str, str]:
     session = Engine.get_instance(self.memory_only).Session()
     query = session.query(Lecture).filter(Lecture.id == l_id)
     lecture: Lecture = query.first()
     if lecture:
         return {
             'id': lecture.id,
             'name': lecture.name,
             'course': lecture.course,
             'content': lecture.content
         }
     return {}
Exemple #6
0
 def get_summary(self, lecture_id: int, summary_id: int) -> Dict:
     session = Engine.get_instance(self.use_memory).Session()
     query = session.query(Summarization)\
         .filter(Summarization.lecture == lecture_id)\
         .filter(Summarization.id == summary_id)
     summary: Summarization = query.first()
     if summary:
         return {
             'id': summary.id,
             'name': summary.name,
             'ratio': summary.ratio,
             'content': summary.content,
             'lecture': summary.lecture
         }
     return {}
Exemple #7
0
    def get_lectures(self, course: str, name: str,
                     limit: int) -> List[Dict[str, str]]:
        session = Engine.get_instance(self.memory_only).Session()
        query = session.query(Lecture)
        if course:
            query = query.filter(Lecture.course == course)
        if name:
            query = query.filter(Lecture.name == name)

        limit = limit if limit else 10
        query = query.limit(limit)

        result = query.all()
        return [{
            'id': lecture.id,
            'name': lecture.name,
            'course': lecture.course,
            'content': lecture.content
        } for lecture in result]
Exemple #8
0
    def list_summaries(self, name: str, lecture: int,
                       limit: int) -> List[Dict]:
        session = Engine.get_instance(self.use_memory).Session()
        query = session.query(Summarization)
        if name:
            query = query.filter(Summarization.name == name)
        if lecture:
            query = query.filter(Summarization.lecture == lecture)

        limit = limit if limit else 10
        query = query.limit(limit)
        result = query.all()
        return [{
            'id': summary.id,
            'name': summary.name,
            'lecture': summary.lecture,
            'content': summary.content,
            'ratio': summary.ratio
        } for summary in result]