Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

77
LINES

< > BotCompany Repo | #1023783 // "My Day" v5 [abandoned], trying all words as power words. OK it doesn't work like that

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (5205L/27K).

!7

// Text + questions from https://lingua.com/english/reading/my-day/

cmodule MyDay > DynPrintLog {
  transient ReadingComprehensionTest test;
  switchable S text = [[
    
    Text
    ----
    
    First, I wake up. Then, I get dressed. I walk to school. I do not ride a bike. I do not ride the bus. I like to go to school. It rains. I do not like rain. I eat lunch. I eat a sandwich and an apple.
    
    I play outside. I like to play. I read a book. I like to read books. I walk home. I do not like walking home. My mother cooks soup for dinner. The soup is hot. Then, I go to bed. I do not like to go bed.
    
    
    Question 1:
    What happens first?
    1 Get dressed 2 Wake up
    3 Eat lunch 4 Walk to school
    
    Question 2:
    What do I like?
    1 Books 2 Rain
    3 Walking home  4 Going to bed
    
    Question 3:
    How do I go to school?
    1 I ride a bike.  2 I walk.
    3 I ride the bus. 4 I drive a car.
    
    Question 4:
    What do I eat for dinner?
    1 Sandwich  2 Pie
    3 Soup  4 Apple
    
    Question 5:
    What do I not like?
    1 Going to school 2 Going to bed
    3 Playing 4 Soup
    
  ]];
  
  transient LS regexps;

  start-thread {
    test = ai_parseReadingComprehensionTest_v1(text);
    regexps = map wordRegexp(wordSet(text));
    pnl(map_curry renderLineWithMatchingRegexpsIC(regexps, test.sentences)); // to see if the regexps work
    
    for (ReadingComprehensionTest.Question q : test.questions) {
      print_nlBefore(q.question);
      LS matchedInQ = matchingRegexpsIC(regexps, q.question);
      if (empty(matchedInQ)) matchedInQ = ll(""); // match all
      bool firstType = containsWord(q.question, "first");
      
      new Best<S> best;
      for (S answer : q.answers) {
        LS regexps2 = ll(quoteRegexp(dropPunctuation(answer))); // treat the whole answer as a regexp
        LS regexps2b = matchingRegexpsIC(regexps, answer); // find the regexps that match the answer
        double score = 0;
        if (firstType) { // mode 1: find what appears first in text
          int idx = indexOfEntryContainingAllRegexpsIC(regexps2, test.sentences);
          if (idx < 0)
            idx = indexOfEntryContainingAllRegexpsIC(regexps2b, test.sentences); // try the second set of regexps
          if (idx >= 0) score = -idx; else continue;
        } else { // mode 2: find sentence in text that matches question + answer best
          score = ai_regexpMixScoreIC(regexps2, matchedInQ, test.sentences, quote(answer));
          if (score == 0)
            score = ai_regexpMixScoreIC(regexps2b, matchedInQ, test.sentences, quote(answer)); // try second set of regexps here too
        }
        best.put(answer, score);
      }
      print(">> " + or(best!, "?")); // print answer
    }
  }
}

Author comment

Began life as a copy of #1023742

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023783
Snippet name: "My Day" v5 [abandoned], trying all words as power words. OK it doesn't work like that
Eternal ID of this version: #1023783/6
Text MD5: 0b2caf10c080bda84d2297568142cec6
Transpilation MD5: df796e486eb01dc35edc101ad165b529
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-09 01:31:39
Source code size: 2849 bytes / 77 lines
Pitched / IR pitched: No / No
Views / Downloads: 185 / 296
Version history: 5 change(s)
Referenced in: [show references]