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

74
LINES

< > BotCompany Repo | #1019714 // Definitions [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (16469L/89K).

!7

concept Definition {
  S word, definition;
  
  sS _fieldOrder = "word definition";
}

cmodule Definitions > DynCRUD<Definition> {
  start {
    dbIndexingCI(Definition, 'word, Definition, 'definition);
  }
  
  afterVisualize {
    replaceComponent(crud.tableSearcher.tfInput, func(JComponent c) -> JComponent {
      centerAndEastWithMargin(c, jbutton("Define...", rThread {
        define(searchTerm())
      }))
    });
    onEnter(crud.tableSearcher.tfInput, rThread { define(searchTerm()) });
  }
  
  void define(fS term) enter {
    final JTextField tfWord = jtextfield(or2(term, dm_topInput())), tfDefinition = jtextfield();
    showFormTitled("Add Definition",
      "Word/Phrase:", tfWord,
      "Definition:", tfDefinition,
      rThread {
        S word = gtt(tfWord), definition = gtt(tfDefinition);
        uniq_sync(Definition, +word, +definition);
      });
    focus(nempty(term) ? tfDefinition : tfWord);
  }

  enhanceFrame {
    internalFrameTitleMenuItem(f, "Import Text...", r {
      inputMultiLineText("Definitions (Format: a - b)", "Ice cream - something to eat", voidfunc(S s) {
        importText(s)
      });
    });
  }
  
  // API
  
  LS getDefinitions(S word) {
    ret collect('definition, conceptsWhereIC(Definition, +word));
  }
  
  LS getReverseDefinitions(S definition) {
    ret collect('word, conceptsWhereIC(Definition, +definition));
  }
  
  Map<S, LS> getDefinitionsMap() {
    ret main.<S> ciMultiMapFromKeyAndValueField(list(Definition), 'word, 'definition).data;
  }

  void importText(S text) {
    for (S s : tlft(text)) {
      LS l = tok_splitAtFirstSpacedDash(s);
      if (l(l) == 5)
        uniq_sync(Definition, word := l.get(1), definition := l.get(3));
    }
  }
  
  S exportAsText() {
    ret lines(map(list(Definition), func(Definition d) -> S {
      d.word + " - " + d.definition
    }));
  }
  
  void addDefinition(S word, S definition) {
    uniq_sync(Definition, +word, +definition);
  }
}

Author comment

Began life as a copy of #1019484

download  show line numbers  debug dex  old transpilations   

Travelled to 12 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1019714
Snippet name: Definitions [Dyn Module]
Eternal ID of this version: #1019714/26
Text MD5: 3c06c6289232ca26e2418d55d9ec6f7a
Transpilation MD5: 4b7ebf6ab94c9f2559da44abac28da48
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-22 21:27:15
Source code size: 2033 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 320 / 12509
Version history: 25 change(s)
Referenced in: [show references]