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

76
LINES

< > BotCompany Repo | #1023737 // "My Day" [v2, parse into fields]

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

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

1  
!7
2  
3  
// Text + questions from https://lingua.com/english/reading/my-day/
4  
5  
cmodule MyDay > DynPrintLog {
6  
  transient new L<Question> questions;
7  
  transient S text;
8  
  transient LS textSentences;
9  
  
10  
  sclass Question {
11  
    S question;
12  
    LS answers; // 1 to 4
13  
  }
14  
  
15  
  start-thread {
16  
    LS paragraphs = pnlStruct(paragraphsTokC([[
17  
    
18  
      Text
19  
      ----
20  
      
21  
      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.
22  
      
23  
      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.
24  
      
25  
      
26  
      Question 1:
27  
      What happens first?
28  
      1 Get dressed	2 Wake up
29  
      3 Eat lunch	4 Walk to school
30  
      
31  
      Question 2:
32  
      What do I like?
33  
      1 Books	2 Rain
34  
      3 Walking home	4 Going to bed
35  
      
36  
      Question 3:
37  
      How do I go to school?
38  
      1 I ride a bike.	2 I walk.
39  
      3 I ride the bus.	4 I drive a car.
40  
      
41  
      Question 4:
42  
      What do I eat for dinner?
43  
      1 Sandwich	2 Pie
44  
      3 Soup	4 Apple
45  
      
46  
      Question 5:
47  
      What do I not like?
48  
      1 Going to school	2 Going to bed
49  
      3 Playing	4 Soup
50  
      
51  
    ]]));
52  
    
53  
    L<Bool> isQ = print(map(rcurry_swic("Question"), paragraphs));
54  
    int idx = print(falsesFollowedByTrues_changeIndex_assertNotNull(isQ));
55  
    LS textPart = takeFirst(paragraphs, idx);
56  
    LS questionsPart = sublist(paragraphs, idx);
57  
    assertTrue(isPreciseMultiDashesHeading(first(textPart)));
58  
    text = joinWithEmptyLines(dropFirst(textPart));
59  
    textSentences = pnl(sentences(text));
60  
    
61  
    for (S s : questionsPart) {
62  
      LS lines = tlft(s);
63  
      assertEquals(4, l(lines));
64  
      assertStartsWith(first(lines), "Question ");
65  
      S q = second(lines);
66  
      LS answersOnLine = regexpGroups("^1(.+)2(.+)$", third(lines));
67  
      assertNempty(answersOnLine);
68  
      LS answersOnLine2 = regexpGroups("^3(.+)4(.+)$", last(lines));
69  
      assertNempty(answersOnLine2);
70  
      LS answers = trimAll(concatLists(answersOnLine, answersOnLine2));
71  
      add(questions, nu Question(question := q, +answers));
72  
      print(q);
73  
      printStruct(answers);
74  
    }
75  
  }
76  
}

Author comment

Began life as a copy of #1023735

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: #1023737
Snippet name: "My Day" [v2, parse into fields]
Eternal ID of this version: #1023737/1
Text MD5: 0ac399a6a69ddd819e22fdbcaa0e81f5
Transpilation MD5: 5b9c15a73cd8fe434a405b7f5f981b4f
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-07 21:57:53
Source code size: 2415 bytes / 76 lines
Pitched / IR pitched: No / No
Views / Downloads: 229 / 22577
Referenced in: [show references]