// A shop's reviews: the phrases customers use most, product names matched despite typos, and copy-pasted reviews caught.
//
//   quillo run ngrams.qwe      then open http://localhost:8080/reviews

use "ngrams.qwer"

let REVIEWS = [
    "Great coffee and friendly staff, the customer service was excellent.",
    "The customer service was slow but the coffee was great.",
    "Out of stock again! Third time the beans were out of stock.",
    "Great coffee and friendly staff, the customer service was excellent!!",
    "Lovely place. Great coffee, great cake, great customer service.",
    "Beans out of stock, customer service could not say when they return.",
]

route GET /reviews {
    let all = join(REVIEWS, " ")
    {
        bigrams: ngrams_words("the quick brown fox", 2)?,
        trigrams: slice(ngrams_chars("Coffee", 3)?, 0, 3),
        phrases: ngrams_top(all, 2, 3, true)?,
        long_phrases: ngrams_top(all, 3, 1, true)?,
        same_product: ngrams_similarity("Ethiopia Yirgacheffe 250g", "Ethiopia Yirgachefe 250 g", 3)?,
        other_product: ngrams_similarity("Ethiopia Yirgacheffe 250g", "Colombia Supremo 1kg", 3)?,
        copies: ngrams_near_duplicates(REVIEWS, 0.6)?,
    }
}
