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

39
LINES

< > BotCompany Repo | #1005260 // Collect Words [works]

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

Libraryless. Click here for Pure Java version (5086L/33K/112K).

!752

concepts.

concept Language {
  S name;
}

concept Word {
  S text;
}

concept ProbablyInLanguage {
  new Ref<Word> word;
  new Ref<Language> language;
}

p {
  loadAndAutoSaveConcepts();
  print("Have " + n(countConcepts(Language), "languages")
    + ", " + n(countConcepts(Word), "words"));
  makeBot();
}

synchronized answer {
  if "add to * *" {
    S langName = toLowerCase($1), text = $2;
    if (!hasConcept(Language, langName))
      print("New language: " + langName);
    Language language = uniq(Language, langName);
    int newWords = countConcepts(ProbablyInLanguage);
    for (S word : codeTokens(javaTok(text)))
      uniq(ProbablyInLanguage, +language,
        word := uniq(Word, toLowerCase(word)));
    newWords = countConcepts(ProbablyInLanguage)-newWords;
    ret "Thanks. " + (newWords == 0 ? "I knew all these words already :)"
      : n(newWords, "new words") + " learned!");
  }
}

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: #1005260
Snippet name: Collect Words [works]
Eternal ID of this version: #1005260/1
Text MD5: b81d67bc3f1146cff4fa4398c1454168
Transpilation MD5: 1efec228e86e624eee609939d8bb1ea3
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-16 00:24:54
Source code size: 949 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 542 / 769
Referenced in: [show references]