26 lines
797 B
Python
26 lines
797 B
Python
from app.repositories import NERSRLRepository
|
|
import re
|
|
|
|
|
|
class QuestionGenerationService:
|
|
|
|
def __init__(self, ner_srl_repository: NERSRLRepository):
|
|
self._ner_srl_repository = ner_srl_repository
|
|
|
|
def createQuizAutomate(self, sentence: str):
|
|
# Gunakan regex untuk split hanya pada titik yang diikuti spasi atau akhir kalimat,
|
|
# dan bukan bagian dari angka (contoh: 19.00 tidak dipisah)
|
|
split_pattern = r"\.(?=\s|$)(?!\d)"
|
|
|
|
# Pisahkan kalimat menggunakan regex
|
|
sentences = [s.strip() for s in re.split(split_pattern, sentence) if s.strip()]
|
|
|
|
results = []
|
|
for s in sentences:
|
|
result = self._ner_srl_repository.predict_sentence(s)
|
|
results.append(result)
|
|
|
|
|
|
|
|
return results
|