Skip to content

Commit

Permalink
Merge pull request #42 from TUK-DP/fix/39
Browse files Browse the repository at this point in the history
[fix] 퀴즈를 만들 수 없는 경우 일기만 저장하도록 구조 수정
  • Loading branch information
Leewonchan14 authored Mar 7, 2024
2 parents 2821c0a + 2bd1234 commit f30e5a6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
30 changes: 14 additions & 16 deletions diary/textrank.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,20 @@ def __init__(self, content):
# 명사 추출
nouns = SentenceTokenizer.get_nouns(self.sentences)

# 가중치 그래프 객체 생성
matrix = GraphMatrix(nouns)
# 문장별 가중치 그래프 [문장수, 문장수], {index: 문장} 사전
# sent_graph, sent_vocab = matrix.get_sent_graph_vocab()
# 단어별 가중치 그래프 [단어수, 단어수], {index: 단어} 사전
words_graph, word_vocab = matrix.get_words_graph_vocab()

# (문장, index, 가중치) 리스트 생성
# sent_rank = [(sent_vocab[index], index, weight) for index, weight in (Rank.get_ranks(sent_graph).items())]
# weight 기준으로 정렬
# self.sorted_sent_rank = sorted(sent_rank, key=lambda k: k[2], reverse=True)

# (단어, index, 가중치) 리스트 생성
word_rank_idx = [(word_vocab[index], index, weight) for index, weight in Rank.get_ranks(words_graph).items()]
# weight 기준으로 정렬
self.sorted_word_rank = sorted(word_rank_idx, key=lambda k: k[2], reverse=True)
if nouns:
# 가중치 그래프 객체 생성
matrix = GraphMatrix(nouns)
# 문장별 가중치 그래프 [문장수, 문장수], {index: 문장} 사전
# sent_graph, sent_vocab = matrix.get_sent_graph_vocab()
# 단어별 가중치 그래프 [단어수, 단어수], {index: 단어} 사전
words_graph, word_vocab = matrix.get_words_graph_vocab()

# (단어, index, 가중치) 리스트 생성
word_rank_idx = [(word_vocab[index], index, weight) for index, weight in Rank.get_ranks(words_graph).items()]
# weight 기준으로 정렬
self.sorted_word_rank = sorted(word_rank_idx, key=lambda k: k[2], reverse=True)
else:
self.sorted_word_rank = []

# sent_size 개의 문장 요약
# def summarize(self, sent_size=3):
Expand Down
24 changes: 18 additions & 6 deletions diary/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ def post(self, request):
# Diary 객체 생성
newDiary = Diary.objects.create(user=findUser, title=request.get('title'))

sentence = request.get('content')

content = request.get('content')
# Sentences 객체 생성
newSentence = Sentences.objects.create(sentence=sentence, diary=newDiary)
newSentence = Sentences.objects.create(sentence=content, diary=newDiary)

# 키워드 추출
memory = TextRank(content=sentence)
memory = TextRank(content=content)

if memory is None:
return ApiResponse.on_success(
result=SentenceSimpleSerializer(newSentence).data,
response_status=status.HTTP_201_CREATED
)

# 키워드 추출 후 가중치가 높은 키워드 5개로 퀴즈 생성
question, keyword = make_quiz(memory, keyword_size=5)

Expand Down Expand Up @@ -71,13 +77,19 @@ def post(self, request):
for sentence in sentences:
sentence.keywords.all().delete()
sentence.delete()

# Sentence 객체 생성

content = request.get('content')
newSentence = Sentences.objects.create(sentence=content, diary=findDiary)

# 키워드 추출
memory = TextRank(content=content)

if memory is None:
return ApiResponse.on_success(
result=SentenceSimpleSerializer(sentence).data,
response_status=status.HTTP_201_CREATED
)

# 키워드 추출 후 가중치가 높은 키워드 5개로 퀴즈 생성
question, keyword = make_quiz(memory, keyword_size=5)

Expand Down

0 comments on commit f30e5a6

Please sign in to comment.