Libraryless. Click here for Pure Java version (1569L/11K/36K).
!7 sclass WikiResult { S rawPage, firstPart; S firstSentence() { L<S> lines = toLines(firstPart); ret get(lines, indexOfNotStartingWith(lines, "[[")); } } WikiResult > Redirect { S toWord; } p { testWord("fun"); testWord("recreation"); } svoid testWord(S word) { print("= " + word + " ="); WikiResult result = querySimpleWikipedia(word); print(result.rawPage); print(); if (result >> Redirect) print("Redirect to: " + quote(result/Redirect.toWord)); else print("First sentence:\n" + indent(dropContainerTags(result.firstSentence()))); print(); } static WikiResult querySimpleWikipedia(S word) { S raw = loadPageSilently("https://simple.wikipedia.org/wiki/" + urlencode(word) + "?action=raw"), rawPage = raw; // check for redirect S p = "#REDIRECT [["; if (startsWith(raw, p) && endsWith(raw, "]]")) ret nu(Redirect, +rawPage, toWord := dropPrefix(p, dropSuffix("]]", raw))); L<S> lines = toLines(raw); int n = smartIndexOfStartsWith(lines, "=="); S firstPart = joinLines(subList(lines, 0, n)); print("First part:\n" + indent(firstPart)); ret nu(WikiResult, +rawPage, +firstPart); }
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, nbgitpuheiab, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xinetxnxrdbb
No comments. add comment
Snippet ID: | #1007924 |
Snippet name: | Test querying Simple Wikipedia [WORKS] |
Eternal ID of this version: | #1007924/21 |
Text MD5: | a913bd3175f93c3b8f18e10c27d04a90 |
Transpilation MD5: | 2ef74f3b24b6c58cdb1bdffc95142503 |
Author: | stefan |
Category: | javax / a.i. / networking |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-04-18 17:04:26 |
Source code size: | 1223 bytes / 48 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 671 / 1328 |
Version history: | 20 change(s) |
Referenced in: | #1007510 - Intelligence Machine [no longer live] #1008005 - Intelligence Machine [LIVE at ai1.lol/wiki] backup |