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).

!752

p {
  typeWriterConsole();
  L<S> paragraphs = rawTextFromODT(userHome("Documents/super-state.odt"));
  printNumberedParagraphs(paragraphs);
  L<S> structures = map(paragraphs, "structureNoQuote");
  MultiSet<S> ms = asMultiSet(structures);
  new L<S> unique;
  for (S s : ms.lowestFirst()) {
    int n = ms.get(s);
    unique.add(n == 1 ? s : "[" + n + "]\n" + s);
  }
  printAsciiHeading("UNIQUE STRUCTURES");
  printNumberedParagraphs(unique);
  print("\n" + nl(unique, "unique structure")
    + " out of " + nl(paragraphs, "paragraph"));
  editText(getPrintLog());
}

static L<S> structure_pre(S s) {
  s = normalizeQuotes(s);
  s = replaceLineBreaksWith(s, " # ");
  ret replaceAll(codeTokens(nlTok(s)), "#", "\n");
}

// probably not so useful, keeps everything in place except white space
static S structure0(S s) {
  ret join(" ", structure_pre(s));
}

// replaces all quoted stuff with "*"
static S structureNoQuote(S s) {
  L<S> tok = structure_pre(s);
  tok = map(tok, func(S t) { isQuoted(t) ? "*" : t });
  ret join(" ", tok).replaceAll(" ?\n ?", "\n");
}

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: 479 / 550
Referenced in: [show references]