|
| 1 | +import random |
| 2 | +import re |
| 3 | + |
| 4 | +def generate_questions(note): |
| 5 | + # Split the note into paragraphs |
| 6 | + paragraphs = note.split('\n\n') |
| 7 | + |
| 8 | + # Generate questions from the paragraphs |
| 9 | + questions = [] |
| 10 | + for paragraph in paragraphs: |
| 11 | + # Split the paragraph into sentences |
| 12 | + sentences = re.split(r'(?<=[.!?])\s+', paragraph.strip()) |
| 13 | + |
| 14 | + # Generate questions based on sentence structure |
| 15 | + for i in range(len(sentences)): |
| 16 | + sentence = sentences[i].strip() |
| 17 | + if sentence: |
| 18 | + if i == 0: |
| 19 | + # Start with a general question about the paragraph |
| 20 | + question = "What is the main topic of this paragraph?" |
| 21 | + elif i == len(sentences) - 1: |
| 22 | + # End with a reflection or summary question |
| 23 | + question = "What are the key takeaways from this paragraph?" |
| 24 | + else: |
| 25 | + # Generate a random question related to the content of the sentence |
| 26 | + question = generate_random_question(sentence) |
| 27 | + |
| 28 | + questions.append(question) |
| 29 | + |
| 30 | + # Shuffle the order of the questions |
| 31 | + random.shuffle(questions) |
| 32 | + |
| 33 | + return questions |
| 34 | + |
| 35 | +def generate_random_question(sentence): |
| 36 | + # Implement your logic to generate a random question based on the content of the sentence |
| 37 | + # Here's a simple example that generates a generic question |
| 38 | + return "What can you infer from the statement: '" + sentence + "'?" |
| 39 | + |
| 40 | +# Example usage |
| 41 | +note = """ |
| 42 | +Chapter 1: Introduction to Biology |
| 43 | +
|
| 44 | +Biology is the study of living organisms. It encompasses various aspects such as the structure, function, growth, origin, evolution, and distribution of organisms. |
| 45 | +
|
| 46 | +Cell Theory states that all living organisms are composed of cells, which are the basic structural and functional units of life. |
| 47 | +
|
| 48 | +DNA, or deoxyribonucleic acid, carries the genetic information of an organism and is responsible for transmitting hereditary traits. |
| 49 | +
|
| 50 | +""" |
| 51 | + |
| 52 | +questions = generate_questions(note) |
| 53 | +for question in questions: |
| 54 | + print(question) |
0 commit comments