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

101
LINES

< > BotCompany Repo | #1023755 // "My name is John" [second reading comprehension test, dev.]

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

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

1  
!7
2  
3  
// Text + questions from https://lingua.com/english/reading/john/
4  
5  
cmodule John > DynPrintLog {
6  
  transient ReadingComprehensionTest test;
7  
  switchable S text = [[
8  
    
9  
    Hi! Nice to meet you! My name is John Smith. I am 19 and a student in college. I go to college in New York. My favorite courses are Geometry, French, and History. English is my hardest course. My professors are very friendly and smart. It’s my second year in college now. I love it!
10  
    
11  
    I live in a big house on Ivy Street. It’s near the college campus. I share the house with three other students. Their names are Bill, Tony, and Paul. We help each other with homework. On the weekend, we play football together.
12  
    
13  
    I have a younger brother. He just started high school. He is 14 and lives with my parents. They live on Mulberry Street in Boston. Sometimes they visit me in New York. I am happy when they visit. My Mom always brings me sweets and candy when they come. I really miss them, too!    
14  
    
15  
    Question 1:
16  
    Where does John Smith go to college?
17  
    1 Berlin    2 Boston
18  
    3 New York  4 Paris
19  
    
20  
    Question 2:
21  
    What is John Smith’s hardest course?
22  
    1 Art   2 English
23  
    3 Math  4 French
24  
    
25  
    Question 3:
26  
    Who shares a house with John Smith?
27  
    1 Anna, Margaret, and Tanya 2 Bill, John, and Tom
28  
    3 Frank, Tony, and Mike     4 Bill, Tony, and Paul
29  
    
30  
    Question 4:
31  
    How old is John Smith’s younger brother?
32  
    1 fourteen  2 eleven
33  
    3 seven     4 thirteen
34  
    
35  
    Question 5:
36  
    What does John Smith’s Mom bring him when they visit?
37  
    1 Candy and ice cream 2 Fruits and vegetables
38  
    3 Sweets and candy    4 Flowers and coffee
39  
40  
  ]];
41  
  
42  
  sS rules = [[
43  
    *person is 19 and a student in college
44  
      => person is 19
45  
      +  person is {a student in college}
46  
    
47  
    a student in college => a student
48  
    
49  
    a student in college => in college
50  
    
51  
    *person goes to college in *{New York}
52  
       => person goes to {college x}
53  
       +  {college x} is in {New York}
54  
       
55  
    *person is 14 and living with *y
56  
      => *person is 14
57  
      +  *person is living with *y
58  
      
59  
    *person is 19 => person is {19 years old}
60  
       
61  
    how old is *person? + person is {5 years old} => person is 5 years old
62  
  ]];
63  
  
64  
  start-thread {
65  
    test = ai_parseReadingComprehensionTest_v1(text);
66  
    pnl(test.sentences);
67  
    
68  
    // find out speaker's name
69  
    S name = assertNempty(print("Name", firstMatchesX_rest("My name is ...", test.sentences)));
70  
71  
    LS sentences = map_curry switcheroo_iToName(curly(name), test.sentences);
72  
    print("languages: " + ai_languages());
73  
    print("test: " + switcheroo_iToName(name, "i am dumb"));
74  
    pnl(sentences);
75  
    
76  
    L<WordTokReplacer> parsedRules = ai_parseStarVarsRules_v2(rules);
77  
    pnlStruct_nlBefore(parsedRules);
78  
    
79  
    //pnl_nlBefore(applyWordTokRules(parsedRules, sentences, seen := sentences));
80  
    
81  
    sentences = map ai_groupGeneralPhrases(sentences);
82  
    
83  
    print();
84  
    for (S s : sentences)
85  
      for (S x : applyWordTokRules(parsedRules, s))
86  
        print(s + " => " + x);
87  
        
88  
    for (ReadingComprehensionTest.Question q : test.questions) {
89  
      S question = q.question;
90  
      
91  
      Pair<Collection<Attractor>, Set<S>> p = applyAttractors_getRuleAndStringEmits(parsedRules, ai_groupGeneralPhrases(question));
92  
      for unnull (Attractor a : p.a) {
93  
        print("New attractor: " + question + " => " + a);
94  
        for (S out : applyAttractors(ll(a), sentences))
95  
          print("  => " + out);
96  
      }
97  
      for unnull (S s : p.b)
98  
        print(question + " => " + s);
99  
    }
100  
  }
101  
}

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: #1023755
Snippet name: "My name is John" [second reading comprehension test, dev.]
Eternal ID of this version: #1023755/30
Text MD5: 5fde1f0ced7197c7f934ab2787d2712f
Transpilation MD5: e1dcec64e64ecd9f781457e28f246912
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-09 00:05:11
Source code size: 3701 bytes / 101 lines
Pitched / IR pitched: No / No
Views / Downloads: 483 / 1300
Version history: 29 change(s)
Referenced in: [show references]