<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#f9f9fa">
    <p>Projectje: met voiceherkenning een transcriptie van het Journaal
      maken, de zinnen vervolgens random verhaspelen en vervangen en mbv
      AI Text-to speech een alternatief journaal maken... Met
      teletekstnieuws is het wellicht makkelijker te implementeren. MMM,
      als ik de tijd er voor vind is het misschien een artistieke poging
      waard...</p>
    <p>RO<br>
    </p>
    <p><br>
    </p>
    <p><font color="#26a269">import random<br>
        import re<br>
        <br>
        def substitute_subject_object(sentence):<br>
            subjects = ["I", "You", "He", "She", "They", "We", "The
        cat", "The dog", "The bird", "The robot"]<br>
            objects = ["apple", "book", "car", "dog", "house", "pen",
        "table", "tree", "umbrella", "watch"]<br>
            <br>
            # Find the subject and object using regular expressions<br>
            match = re.match(r'(.+?)(\b(?:loves|likes)\b)(.+)',
        sentence)<br>
            if not match:<br>
                return sentence<br>
            <br>
            subject = match.group(1).strip()<br>
            verb = match.group(2).strip()<br>
            direct_object = match.group(3).strip()<br>
            <br>
            # Randomly substitute the subject and object<br>
            new_subject = random.choice(subjects)<br>
            new_object = random.choice(objects)<br>
            <br>
            # Build the new sentence<br>
            new_sentence = f"{new_subject} {verb} {new_object}."<br>
            return new_sentence<br>
        <br>
        # Example usage<br>
        sentence = "She likes dogs."<br>
        new_sentence = substitute_subject_object(sentence)<br>
        print("Original sentence:", sentence)<br>
        print("New sentence:", new_sentence)<br>
      </font></p>
    <p>--<br>
    </p>
    <p>Voorbeeld:</p>
    <p><br>
    </p>
    <p>reinold@fedora test]$ python directobject2.py<br>
      Original sentence: She likes dogs.<br>
      New sentence: The robot likes umbrella.<br>
      <br>
      Original sentence: She likes dogs.<br>
      New sentence: The robot likes pen.<br>
      <br>
      Original sentence: She likes dogs.<br>
      New sentence: He likes tree.<br>
      <br>
      Original sentence: She likes dogs.<br>
      New sentence: I likes book.<br>
      <br>
      Original sentence: She likes dogs.<br>
      New sentence: The cat likes house.<br>
    </p>
    <p>--<br>
    </p>
    <p><br>
    </p>
    <p>RO: improve this program with a large set of words of verbs,
      objects and subjects</p>
    <p>ChatGPT: Certainly!</p>
    <p><br>
    </p>
    <p><font color="#26a269">import random<br>
        import re<br>
      </font></p>
    <font color="#26a269"><br>
      def load_word_list(filename):<br>
          with open(filename, 'r') as file:<br>
              word_list = [word.strip() for word in file.readlines()]<br>
          return word_list<br>
      <br>
      def substitute_subject_verb_object(sentence, subject_list,
      verb_list, object_list):<br>
          # Find the subject, verb, and object using regular expressions<br>
          match = re.match(r'(.+?)\b(.*?)\b(.+)', sentence)<br>
          if not match:<br>
              return sentence<br>
          <br>
          subject = match.group(1).strip()<br>
          verb = match.group(2).strip()<br>
          direct_object = match.group(3).strip()<br>
          <br>
          # Randomly substitute the subject, verb, and object<br>
          new_subject = random.choice(subject_list)<br>
          new_verb = random.choice(verb_list)<br>
          new_object = random.choice(object_list)<br>
          <br>
          # Build the new sentence<br>
          new_sentence = f"{new_subject} {new_verb} {new_object}."<br>
          return new_sentence<br>
      <br>
      # Load subject, verb, and object word lists<br>
      subject_word_list = load_word_list('subject_words.txt')<br>
      verb_word_list = load_word_list('verb_words.txt')<br>
      object_word_list = load_word_list('object_words.txt')<br>
      <br>
      # Example usage<br>
      sentence = "She likes dogs."<br>
      new_sentence = substitute_subject_verb_object(sentence,
      subject_word_list, verb_word_list, object_word_list)<br>
      print("Original sentence:", sentence)<br>
      print("New sentence:", new_sentence)<br>
    </font><br>
  </body>
</html>