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

27
LINES

< > BotCompany Repo | #1014164 // indexedSimpleWikipedia_magicMap - produces a "magic" map that loads on demand

JavaX fragment (include)

sbool indexedSimpleWikipedia_magicMap_debug;

srecord WikiPage(S title, S text) {}

static Map<S, WikiPage> indexedSimpleWikipedia_magicMap(final Map<S, IndexedWikiPage> map) {
  final File f = unpackSimpleWikipedia();
  Map<S, WikiPage> actualMap = new TreeMap<S, WikiPage>(caseInsensitiveComparator()) {
    public WikiPage get(O title) {
      IndexedWikiPage ip = map.get(title);
      if (ip == null) null;
      
      S xml = loadTextFilePart(f, ip.start, ip.start+ip.len);
      if (indexedSimpleWikipedia_magicMap_debug) {
        print("Loaded from " + ip.start + " to " + (ip.start+ip.len));
        printIndent(xml);
      }
      
      L<S> tok = htmlTok(xml);
      S realTitle = trim(htmldecode(join(contentsOfContainerTag(tok, "title"))));
      S text = trim(htmldecode(join(contentsOfContainerTag(tok, "text"))));
      ret WikiPage(realTitle, text);
    }
  };
  for (S title : keys(map))
    actualMap.put(title, null); // dummy entry to have key
  ret actualMap;
}

Author comment

Began life as a copy of #1014162

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014164
Snippet name: indexedSimpleWikipedia_magicMap - produces a "magic" map that loads on demand
Eternal ID of this version: #1014164/1
Text MD5: 84b937328cc8658adf16e49e820fb310
Author: stefan
Category: javax / a.i. / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-15 14:17:00
Source code size: 1012 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 263 / 293
Referenced in: [show references]