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

126
LINES

< > BotCompany Repo | #1030319 // PhraseCache docs

Document

1  
PhraseCache is a simple language for matching user input.
2  
  (see also https://PhraseCache.best)
3  
4  
A PhraseCache expression can consist of:
5  
6  
7  
  ** just a WORD OR PHRASE, e.g.:
8  
  
9  
     school
10  
     lunch time
11  
    
12  
   This will match when the phrase appears anywhere in the input, e.g.:
13  
   
14  
     Is it lunch time now?
15  
16  
17  
  ** a QUOTED STRING, e.g.:
18  
  
19  
     "q&a"
20  
     "\o/"
21  
     
22  
   These strings can contain any special character. They are
23  
   matched exactly character-by-character, but are
24  
   case-insensitive. The pattern does not match when it's part
25  
   of a bigger word (e.g. the first example would not match
26  
   the input "faq&answers").
27  
   
28  
   So the second line will match e.g. these inputs:
29  
   
30  
     That's cool \o/
31  
     \O/
32  
   
33  
   You can even match quotes, like this:
34  
   
35  
     "\"hello\""
36  
     
37  
   This will only match a "hello" actually put in quotes by
38  
   the user.
39  
40  
   
41  
  ** "OR" combination (comma)
42  
  
43  
     fun, enjoying
44  
     
45  
   matches when any of the elements is present in input.
46  
    
47  
   So the example matches "this is fun" as well as
48  
   "I am enjoying this".
49  
   
50  
51  
  ** "AND" combination (plus)
52  
  
53  
     this + that
54  
   
55  
   requires all elements to be present in input (in any order).
56  
   
57  
   So the example matches "this and that" and "that or this",
58  
   but not "this one" or "that one".
59  
   
60  
   "and" takes precedence over "or", so:
61  
   
62  
     the + solution, a + resolution
63  
     
64  
   is the same as:
65  
   
66  
     (the + solution), (a + resolution)
67  
     
68  
   (See "bracketing" below.)
69  
  
70  
  
71  
  ** NEGATION (exclamation mark in front)
72  
  
73  
     great + !not
74  
  
75  
   matches "this is great", but not "this is not that great".
76  
77  
    
78  
  ** match START OF LINE only (with ^)
79  
  
80  
     ^hello bot
81  
    
82  
   will match "hello bot friend", but not "oh hello bot".
83  
84  
  
85  
  ** match END OF LINE only (with $)
86  
  
87  
     please do this$
88  
     
89  
   will match "now please do this", but not "please do this now".
90  
   
91  
   Start of line and end of line can be combined like this:
92  
   
93  
     ^ok!$
94  
     
95  
   matches just "ok" and nothing else. (See "typo" section
96  
   below.)
97  
   
98  
99  
  -BRACKETING (grouping)
100  
  
101  
     (quick, fast) + (solution, resolution)
102  
    
103  
   will match "we need a fast solution" as well as "the
104  
   resolution should be quick".
105  
   
106  
107  
  ** DISALLOW TYPOS with exclamation mark, e.g.:
108  
  
109  
     hi!
110  
     
111  
   By default, PhraseCache has a crude typo detection system
112  
   that allows one typo (1 character added, removed or inserted
113  
   per input row). It's a cool feature, but arguably could see
114  
   some improvement. For naive patterns, it sometimes fails
115  
   badly, e.g. input "I" will also match the pattern "hi".
116  
   
117  
   To circumvent this, add an exclamation mark AFTER the phrase
118  
   in question. (Not before the phrase as that would mean
119  
   negation.)
120  
  
121  
122  
Advanced features (not really used currently):
123  
124  
  -add a weight to a sub-pattern:
125  
  
126  
    (foo, bar)*0.5 

download  show line numbers   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030319
Snippet name: PhraseCache docs
Eternal ID of this version: #1030319/10
Text MD5: d2896173088cb3a7e577b1b0d62155aa
Author: stefan
Category: PhraseCache
Type: Document
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-12-02 16:52:48
Source code size: 2966 bytes / 126 lines
Pitched / IR pitched: No / No
Views / Downloads: 213 / 104
Version history: 9 change(s)
Referenced in: [show references]