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

126
LINES

< > BotCompany Repo | #1030319 // PhraseCache docs

Document

PhraseCache is a simple language for matching user input.
  (see also https://PhraseCache.best)

A PhraseCache expression can consist of:


  ** just a WORD OR PHRASE, e.g.:
  
     school
     lunch time
    
   This will match when the phrase appears anywhere in the input, e.g.:
   
     Is it lunch time now?


  ** a QUOTED STRING, e.g.:
  
     "q&a"
     "\o/"
     
   These strings can contain any special character. They are
   matched exactly character-by-character, but are
   case-insensitive. The pattern does not match when it's part
   of a bigger word (e.g. the first example would not match
   the input "faq&answers").
   
   So the second line will match e.g. these inputs:
   
     That's cool \o/
     \O/
   
   You can even match quotes, like this:
   
     "\"hello\""
     
   This will only match a "hello" actually put in quotes by
   the user.

   
  ** "OR" combination (comma)
  
     fun, enjoying
     
   matches when any of the elements is present in input.
    
   So the example matches "this is fun" as well as
   "I am enjoying this".
   

  ** "AND" combination (plus)
  
     this + that
   
   requires all elements to be present in input (in any order).
   
   So the example matches "this and that" and "that or this",
   but not "this one" or "that one".
   
   "and" takes precedence over "or", so:
   
     the + solution, a + resolution
     
   is the same as:
   
     (the + solution), (a + resolution)
     
   (See "bracketing" below.)
  
  
  ** NEGATION (exclamation mark in front)
  
     great + !not
  
   matches "this is great", but not "this is not that great".

    
  ** match START OF LINE only (with ^)
  
     ^hello bot
    
   will match "hello bot friend", but not "oh hello bot".

  
  ** match END OF LINE only (with $)
  
     please do this$
     
   will match "now please do this", but not "please do this now".
   
   Start of line and end of line can be combined like this:
   
     ^ok!$
     
   matches just "ok" and nothing else. (See "typo" section
   below.)
   

  -BRACKETING (grouping)
  
     (quick, fast) + (solution, resolution)
    
   will match "we need a fast solution" as well as "the
   resolution should be quick".
   

  ** DISALLOW TYPOS with exclamation mark, e.g.:
  
     hi!
     
   By default, PhraseCache has a crude typo detection system
   that allows one typo (1 character added, removed or inserted
   per input row). It's a cool feature, but arguably could see
   some improvement. For naive patterns, it sometimes fails
   badly, e.g. input "I" will also match the pattern "hi".
   
   To circumvent this, add an exclamation mark AFTER the phrase
   in question. (Not before the phrase as that would mean
   negation.)
  

Advanced features (not really used currently):

  -add a weight to a sub-pattern:
  
    (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: 212 / 104
Version history: 9 change(s)
Referenced in: