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

37
LINES

< > BotCompany Repo | #1005104 // Find similar structures

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 1314K of libraries. Click here for Pure Java version (4489L/32K/108K).

1  
!752
2  
3  
p {
4  
  typeWriterConsole();
5  
  L<S> paragraphs = rawTextFromODT(userHome("Documents/super-state.odt"));
6  
  printNumberedParagraphs(paragraphs);
7  
  L<S> structures = map(paragraphs, "structureNoQuote");
8  
  MultiSet<S> ms = asMultiSet(structures);
9  
  new L<S> unique;
10  
  for (S s : ms.lowestFirst()) {
11  
    int n = ms.get(s);
12  
    unique.add(n == 1 ? s : "[" + n + "]\n" + s);
13  
  }
14  
  printAsciiHeading("UNIQUE STRUCTURES");
15  
  printNumberedParagraphs(unique);
16  
  print("\n" + nl(unique, "unique structure")
17  
    + " out of " + nl(paragraphs, "paragraph"));
18  
  editText(getPrintLog());
19  
}
20  
21  
static L<S> structure_pre(S s) {
22  
  s = normalizeQuotes(s);
23  
  s = replaceLineBreaksWith(s, " # ");
24  
  ret replaceAll(codeTokens(nlTok(s)), "#", "\n");
25  
}
26  
27  
// probably not so useful, keeps everything in place except white space
28  
static S structure0(S s) {
29  
  ret join(" ", structure_pre(s));
30  
}
31  
32  
// replaces all quoted stuff with "*"
33  
static S structureNoQuote(S s) {
34  
  L<S> tok = structure_pre(s);
35  
  tok = map(tok, func(S t) { isQuoted(t) ? "*" : t });
36  
  ret join(" ", tok).replaceAll(" ?\n ?", "\n");
37  
}

Author comment

Began life as a copy of #1005102

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005104
Snippet name: Find similar structures
Eternal ID of this version: #1005104/1
Text MD5: 54cfe330b9ee843b9fe0f65be340554e
Transpilation MD5: b1c2e6f478b96c63254f67085488f6cc
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-10-16 18:48:50
Source code size: 1112 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 483 / 554
Referenced in: [show references]