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

32
LINES

< > BotCompany Repo | #1026395 // ELE: Apply Recognition Replacements [dev.]

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

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

1  
!7
2  
3  
srecord Replacement(S in, S out) {
4  
  // in = heard phrase, out = said phrase
5  
}
6  
7  
cmodule ELEApplyRecognitionReplacements > ELESuggester {
8  
  void process_impl(S input) {
9  
    L<Replacement> 
l = getReplacements();
10  
    SS map = ciMapFromKeyAndValueField('in, 'out, l);
11  
    FullPhraseCache phraseCache = makeFullPhraseCache(map(l, r -> r.in));
12  
    LS tok = javaTokNPunct(input);
13  
    L<IntRange> ranges = fullPhraseCache_tokenRanges(phraseCache, tok);
14  
    if (empty(ranges)) ret;
15  
    print("Found replaceable phrases: " + getJoinedTokenRangesWithoutN(tok, ranges));
16  
    tok = cloneList(tok);
17  
    for (IntRange r : ranges) {
18  
      S in = joinSubList(tok, r);
19  
      S replaced = map.get(in);
20  
      if (replaced == null) continue with print("punctuation problem with " + quote(in));
21  
      replaceTokens(tok, r.start, r.end, replaced);
22  
    }
23  
    S s = join(tok);
24  
    print("All replacements applied: " + s);
25  
    showSuggestions(input, ll(s));
26  
  }
27  
  
28  
  L<Replacement> getReplacements() {
29  
    L l = dm_getConcepts(dm_require("#1026379/ELERecognitionReplacements"));
30  
    ret shallowCloneListToClass Replacement(l);
31  
  }
32  
}

Author comment

Began life as a copy of #1026379

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026395
Snippet name: ELE: Apply Recognition Replacements [dev.]
Eternal ID of this version: #1026395/9
Text MD5: 4e3de1d1bbb600bb3568013a5f797ec6
Transpilation MD5: 9c14e71ae8ac0d80f4c5c1b20915ffdd
Author: stefan
Category: javax / speech recognition
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-22 14:57:36
Source code size: 1141 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 145 / 421
Version history: 8 change(s)
Referenced in: [show references]