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

31
LINES

< > BotCompany Repo | #1028082 // mmo2_scoredMatch [dev.]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4010L/24K).

1  
// usually returns value from 0 to 1 (possibly higher values too depending on pattern)
2  
static double mmo2_scoredMatch(MMOPattern pattern, S s) {
3  
  ret mmo2_scoredMatch(pattern, s, false, false);
4  
}
5  
6  
static double mmo2_scoredMatch(MMOPattern pattern, S s, bool startOfLine, bool endOfLine) {
7  
  ifdef mmo2_scoredMatch_debug
8  
    printFunctionCall mmo2_scoredMatch(pattern, s, startOfLine, endOfLine);
9  
  endifdef
10  
  if (pattern == null) ret 0;
11  
  S s2 = trim(s);
12  
  if (pattern cast MMOPattern.StartOfLine)
13  
    ret mmo2_scoredMatch(pattern.p, s2, true, endOfLine);
14  
  if (pattern cast MMOPattern.EndOfLine)
15  
    ret mmo2_scoredMatch(pattern.p, s2, startOfLine, true);
16  
  if (pattern cast MMOPattern.Phrase)
17  
    ret mmo2_match(pattern, s, startOfLine, endOfLine) ? 1 : 0;
18  
  if (pattern cast MMOPattern.And)
19  
    ret doubleProduct(map(pattern.l, pat -> mmo2_scoredMatch(pat, s2, startOfLine, endOfLine)));
20  
  if (pattern cast MMOPattern.Or)
21  
    ret doubleMax(map(pattern.l, pat -> mmo2_scoredMatch(pat, s2, startOfLine, endOfLine)));
22  
  if (pattern cast MMOPattern.Not)
23  
    ret invertZeroToOne(mmo2_scoredMatch(pattern.p, s2, startOfLine, endOfLine));
24  
  if (pattern cast MMOPattern.Weighted)
25  
    ret mmo2_scoredMatch(pattern.p, s2, startOfLine, endOfLine)*pattern.weight;
26  
  fail("what. " + pattern);
27  
}
28  
29  
static double mmo2_scoredMatch(S pattern, S s) {
30  
  ret mmo2_scoredMatch(mmo2_parsePattern(pattern), s);
31  
}

Author comment

Began life as a copy of #1028074

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: #1028082
Snippet name: mmo2_scoredMatch [dev.]
Eternal ID of this version: #1028082/7
Text MD5: e130182ee13ef4895e21c333edc02596
Transpilation MD5: f78f69ed78ecf3f83e01a29b22e3b3a6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-05-17 15:53:28
Source code size: 1422 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 192 / 283
Version history: 6 change(s)
Referenced in: [show references]