Documentation ¶
Index ¶
- Variables
- func HasAllWords(env envs.Environment, text types.XText, test types.XText) types.XValue
- func HasAnyWord(env envs.Environment, text types.XText, test types.XText) types.XValue
- func HasBeginning(env envs.Environment, text types.XText, beginning types.XText) types.XValue
- func HasCategory(env envs.Environment, resultObj *types.XObject, categories ...types.XText) types.XValue
- func HasDate(env envs.Environment, text types.XText) types.XValue
- func HasDateEQ(env envs.Environment, text types.XText, date types.XDateTime) types.XValue
- func HasDateGT(env envs.Environment, text types.XText, date types.XDateTime) types.XValue
- func HasDateLT(env envs.Environment, text types.XText, date types.XDateTime) types.XValue
- func HasDistrict(env envs.Environment, args ...types.XValue) types.XValue
- func HasEmail(env envs.Environment, text types.XText) types.XValue
- func HasError(env envs.Environment, value types.XValue) types.XValue
- func HasGroup(env envs.Environment, args ...types.XValue) types.XValue
- func HasIntent(env envs.Environment, result *types.XObject, name types.XText, ...) types.XValue
- func HasNumber(env envs.Environment, text types.XText) types.XValue
- func HasNumberBetween(env envs.Environment, arg1 types.XValue, arg2 types.XValue, arg3 types.XValue) types.XValue
- func HasNumberEQ(env envs.Environment, text types.XText, num types.XNumber) types.XValue
- func HasNumberGT(env envs.Environment, text types.XText, num types.XNumber) types.XValue
- func HasNumberGTE(env envs.Environment, text types.XText, num types.XNumber) types.XValue
- func HasNumberLT(env envs.Environment, text types.XText, num types.XNumber) types.XValue
- func HasNumberLTE(env envs.Environment, text types.XText, num types.XNumber) types.XValue
- func HasOnlyPhrase(env envs.Environment, text types.XText, test types.XText) types.XValue
- func HasOnlyText(env envs.Environment, text1 types.XText, text2 types.XText) types.XValue
- func HasPattern(env envs.Environment, text types.XText, pattern types.XText) types.XValue
- func HasPhone(env envs.Environment, text types.XText, args ...types.XValue) types.XValue
- func HasPhrase(env envs.Environment, text types.XText, test types.XText) types.XValue
- func HasState(env envs.Environment, text types.XText) types.XValue
- func HasText(env envs.Environment, text types.XText) types.XValue
- func HasTime(env envs.Environment, text types.XText) types.XValue
- func HasTopIntent(env envs.Environment, result *types.XObject, name types.XText, ...) types.XValue
- func HasValue(env envs.Environment, value types.XValue) types.XValue
- func HasWard(env envs.Environment, args ...types.XValue) types.XValue
- func NewTrueResult(match types.XValue) *types.XObject
- func NewTrueResultWithExtra(match types.XValue, extra *types.XObject) *types.XObject
- func ParseDecimalFuzzy(val string, format *envs.NumberFormat) (decimal.Decimal, error)
- func RegisterXTest(name string, function types.XFunction)
Constants ¶
This section is empty.
Variables ¶
var FalseResult = types.NewXObject(map[string]types.XValue{ "__default__": types.XBooleanFalse, "match": types.XTextEmpty, })
FalseResult is a false result
var XTESTS = map[string]types.XFunction{ "has_error": functions.OneArgFunction(HasError), "has_value": functions.OneArgFunction(HasValue), "has_only_text": functions.TwoTextFunction(HasOnlyText), "has_phrase": functions.TwoTextFunction(HasPhrase), "has_only_phrase": functions.TwoTextFunction(HasOnlyPhrase), "has_any_word": functions.TwoTextFunction(HasAnyWord), "has_all_words": functions.TwoTextFunction(HasAllWords), "has_beginning": functions.TwoTextFunction(HasBeginning), "has_text": functions.OneTextFunction(HasText), "has_pattern": functions.TwoTextFunction(HasPattern), "has_number": functions.OneTextFunction(HasNumber), "has_number_between": functions.ThreeArgFunction(HasNumberBetween), "has_number_lt": functions.TextAndNumberFunction(HasNumberLT), "has_number_lte": functions.TextAndNumberFunction(HasNumberLTE), "has_number_eq": functions.TextAndNumberFunction(HasNumberEQ), "has_number_gte": functions.TextAndNumberFunction(HasNumberGTE), "has_number_gt": functions.TextAndNumberFunction(HasNumberGT), "has_date": functions.OneTextFunction(HasDate), "has_date_lt": functions.TextAndDateFunction(HasDateLT), "has_date_eq": functions.TextAndDateFunction(HasDateEQ), "has_date_gt": functions.TextAndDateFunction(HasDateGT), "has_time": functions.OneTextFunction(HasTime), "has_phone": functions.InitialTextFunction(0, 1, HasPhone), "has_email": functions.OneTextFunction(HasEmail), "has_group": functions.MinAndMaxArgsCheck(2, 3, HasGroup), "has_category": functions.ObjectAndTextsFunction(HasCategory), "has_intent": functions.ObjectTextAndNumberFunction(HasIntent), "has_top_intent": functions.ObjectTextAndNumberFunction(HasTopIntent), "has_state": functions.OneTextFunction(HasState), "has_district": functions.MinAndMaxArgsCheck(1, 2, HasDistrict), "has_ward": HasWard, }
XTESTS is our mapping of the excellent test names to their actual functions
Functions ¶
func HasAllWords ¶
HasAllWords tests whether all the `words` are contained in `text`
The words can be in any order and may appear more than once.
@(has_all_words("the quick brown FOX", "the fox")) -> true @(has_all_words("the quick brown FOX", "the fox").match) -> the FOX @(has_all_words("the quick brown fox", "red fox")) -> false
@test has_all_words(text, words)
func HasAnyWord ¶
HasAnyWord tests whether any of the `words` are contained in the `text`
Only one of the words needs to match and it may appear more than once.
@(has_any_word("The Quick Brown Fox", "fox quick")) -> true @(has_any_word("The Quick Brown Fox", "fox quick").match) -> Quick Fox @(has_any_word("The Quick Brown Fox", "red fox").match) -> Fox
@test has_any_word(text, words)
func HasBeginning ¶
HasBeginning tests whether `text` starts with `beginning`
Both text values are trimmed of surrounding whitespace, but otherwise matching is strict without any tokenization.
@(has_beginning("The Quick Brown", "the quick")) -> true @(has_beginning("The Quick Brown", "the quick").match) -> The Quick @(has_beginning("The Quick Brown", "the quick")) -> false @(has_beginning("The Quick Brown", "quick brown")) -> false
@test has_beginning(text, beginning)
func HasCategory ¶ added in v0.51.0
func HasCategory(env envs.Environment, resultObj *types.XObject, categories ...types.XText) types.XValue
HasCategory tests whether the category of a result on of the passed in `categories`
@(has_category(results.webhook, "Success", "Failure")) -> true @(has_category(results.webhook, "Success", "Failure").match) -> Success @(has_category(results.webhook, "Failure")) -> false
@test has_category(result, categories...)
func HasDate ¶
HasDate tests whether `text` contains a date formatted according to our environment
@(has_date("the date is 15/01/2017")) -> true @(has_date("the date is 15/01/2017").match) -> 2017-01-15T13:24:30.123456-05:00 @(has_date("there is no date here, just a year 2017")) -> false
@test has_date(text)
func HasDateEQ ¶
HasDateEQ tests whether `text` a date equal to `date`
@(has_date_eq("the date is 15/01/2017", "2017-01-15")) -> true @(has_date_eq("the date is 15/01/2017", "2017-01-15").match) -> 2017-01-15T13:24:30.123456-05:00 @(has_date_eq("the date is 15/01/2017 15:00", "2017-01-15").match) -> 2017-01-15T15:00:00.000000-05:00 @(has_date_eq("there is no date here, just a year 2017", "2017-06-01")) -> false @(has_date_eq("there is no date here, just a year 2017", "not date")) -> ERROR
@test has_date_eq(text, date)
func HasDateGT ¶
HasDateGT tests whether `text` a date after the date `min`
@(has_date_gt("the date is 15/01/2017", "2017-01-01")) -> true @(has_date_gt("the date is 15/01/2017", "2017-01-01").match) -> 2017-01-15T13:24:30.123456-05:00 @(has_date_gt("the date is 15/01/2017", "2017-03-15")) -> false @(has_date_gt("there is no date here, just a year 2017", "2017-06-01")) -> false @(has_date_gt("there is no date here, just a year 2017", "not date")) -> ERROR
@test has_date_gt(text, min)
func HasDateLT ¶
HasDateLT tests whether `text` contains a date before the date `max`
@(has_date_lt("the date is 15/01/2017", "2017-06-01")) -> true @(has_date_lt("the date is 15/01/2017", "2017-06-01").match) -> 2017-01-15T13:24:30.123456-05:00 @(has_date_lt("there is no date here, just a year 2017", "2017-06-01")) -> false @(has_date_lt("there is no date here, just a year 2017", "not date")) -> ERROR
@test has_date_lt(text, max)
func HasDistrict ¶
HasDistrict tests whether a district name is contained in the `text`. If `state` is also provided then the returned district must be within that state.
@(has_district("Gasabo", "Kigali").match) -> Rwanda > Kigali City > Gasabo @(has_district("I live in Gasabo", "Kigali").match) -> Rwanda > Kigali City > Gasabo @(has_district("Gasabo", "Boston")) -> false @(has_district("Gasabo").match) -> Rwanda > Kigali City > Gasabo
@test has_district(text, state)
func HasEmail ¶
HasEmail tests whether an email is contained in `text`
@(has_email("my email is foo1@bar.com, please respond")) -> true @(has_email("my email is foo1@bar.com, please respond").match) -> foo1@bar.com @(has_email("my email is <foo@bar2.com>").match) -> foo@bar2.com @(has_email("i'm not sharing my email")) -> false
@test has_email(text)
func HasError ¶ added in v0.33.9
HasError returns whether `value` is an error
@(has_error(datetime("foo"))) -> true @(has_error(datetime("foo")).match) -> error calling DATETIME: unable to convert "foo" to a datetime @(has_error(run.not.existing).match) -> object has no property 'not' @(has_error(contact.fields.unset).match) -> object has no property 'unset' @(has_error("hello")) -> false
@test has_error(value)
func HasGroup ¶
HasGroup returns whether the `contact` is part of group with the passed in UUID
@(has_group(contact.groups, "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d").match) -> {name: Testers, uuid: b7cf0d83-f1c9-411c-96fd-c511a4cfa86d} @(has_group(array(), "97fe7029-3a15-4005-b0c7-277b884fc1d5")) -> false
@test has_group(contact, group_uuid)
func HasIntent ¶ added in v0.51.0
func HasIntent(env envs.Environment, result *types.XObject, name types.XText, confidence types.XNumber) types.XValue
HasIntent tests whether any intent in a classification result has `name` and minimum `confidence`
@(has_intent(results.intent, "book_flight", 0.5)) -> true @(has_intent(results.intent, "book_hotel", 0.2)) -> true
@test has_intent(result, name, confidence)
func HasNumber ¶
HasNumber tests whether `text` contains a number
@(has_number("the number is 42")) -> true @(has_number("the number is 42").match) -> 42 @(has_number("the number is forty two")) -> false
@test has_number(text)
func HasNumberBetween ¶
func HasNumberBetween(env envs.Environment, arg1 types.XValue, arg2 types.XValue, arg3 types.XValue) types.XValue
HasNumberBetween tests whether `text` contains a number between `min` and `max` inclusive
@(has_number_between("the number is 42", 40, 44)) -> true @(has_number_between("the number is 42", 40, 44).match) -> 42 @(has_number_between("the number is 42", 50, 60)) -> false @(has_number_between("the number is not there", 50, 60)) -> false @(has_number_between("the number is not there", "foo", 60)) -> ERROR
@test has_number_between(text, min, max)
func HasNumberEQ ¶
HasNumberEQ tests whether `text` contains a number equal to the `value`
@(has_number_eq("the number is 42", 42)) -> true @(has_number_eq("the number is 42", 42).match) -> 42 @(has_number_eq("the number is 42", 40)) -> false @(has_number_eq("the number is not there", 40)) -> false @(has_number_eq("the number is not there", "foo")) -> ERROR
@test has_number_eq(text, value)
func HasNumberGT ¶
HasNumberGT tests whether `text` contains a number greater than `min`
@(has_number_gt("the number is 42", 40)) -> true @(has_number_gt("the number is 42", 40).match) -> 42 @(has_number_gt("the number is 42", 42)) -> false @(has_number_gt("the number is not there", 40)) -> false @(has_number_gt("the number is not there", "foo")) -> ERROR
@test has_number_gt(text, min)
func HasNumberGTE ¶
HasNumberGTE tests whether `text` contains a number greater than or equal to `min`
@(has_number_gte("the number is 42", 42)) -> true @(has_number_gte("the number is 42", 42).match) -> 42 @(has_number_gte("the number is 42", 45)) -> false @(has_number_gte("the number is not there", 40)) -> false @(has_number_gte("the number is not there", "foo")) -> ERROR
@test has_number_gte(text, min)
func HasNumberLT ¶
HasNumberLT tests whether `text` contains a number less than `max`
@(has_number_lt("the number is 42", 44)) -> true @(has_number_lt("the number is 42", 44).match) -> 42 @(has_number_lt("the number is 42", 40)) -> false @(has_number_lt("the number is not there", 40)) -> false @(has_number_lt("the number is not there", "foo")) -> ERROR
@test has_number_lt(text, max)
func HasNumberLTE ¶
HasNumberLTE tests whether `text` contains a number less than or equal to `max`
@(has_number_lte("the number is 42", 42)) -> true @(has_number_lte("the number is 42", 42).match) -> 42 @(has_number_lte("the number is 42", 40)) -> false @(has_number_lte("the number is not there", 40)) -> false @(has_number_lte("the number is not there", "foo")) -> ERROR
@test has_number_lte(text, max)
func HasOnlyPhrase ¶
HasOnlyPhrase tests whether the `text` contains only `phrase`
The phrase must be the only text in the text to match
@(has_only_phrase("Quick Brown", "quick brown")) -> true @(has_only_phrase("Quick Brown", "quick brown").match) -> Quick Brown @(has_only_phrase("The Quick Brown Fox", "quick brown")) -> false @(has_only_phrase("the Quick Brown fox", "")) -> false @(has_only_phrase("", "").match) -> @(has_only_phrase("The Quick Brown Fox", "red fox")) -> false
@test has_only_phrase(text, phrase)
func HasOnlyText ¶ added in v0.35.0
HasOnlyText returns whether two text values are equal (case sensitive). In the case that they are, it will return the text as the match.
@(has_only_text("foo", "foo")) -> true @(has_only_text("foo", "foo").match) -> foo @(has_only_text("foo", "FOO")) -> false @(has_only_text("foo", "bar")) -> false @(has_only_text("foo", " foo ")) -> false @(has_only_text(run.status, "completed").match) -> completed @(has_only_text(results.webhook.category, "Success").match) -> Success @(has_only_text(results.webhook.category, "Failure")) -> false
@test has_only_text(text1, text2)
func HasPattern ¶
HasPattern tests whether `text` matches the regex `pattern`
Both text values are trimmed of surrounding whitespace and matching is case-insensitive.
@(has_pattern("Buy cheese please", "buy (\w+)")) -> true @(has_pattern("Buy cheese please", "buy (\w+)").match) -> Buy cheese @(has_pattern("Buy cheese please", "buy (\w+)").extra) -> {0: Buy cheese, 1: cheese} @(has_pattern("Sell cheese please", "buy (\w+)")) -> false
@test has_pattern(text, pattern)
func HasPhone ¶
HasPhone tests whether `text` contains a phone number. The optional `country_code` argument specifies the country to use for parsing.
@(has_phone("my number is +12067799294 thanks")) -> true @(has_phone("my number is +12067799294").match) -> +12067799294 @(has_phone("my number is 2067799294", "US").match) -> +12067799294 @(has_phone("my number is 206 779 9294", "US").match) -> +12067799294 @(has_phone("my number is none of your business", "US")) -> false
@test has_phone(text, country_code)
func HasPhrase ¶
HasPhrase tests whether `phrase` is contained in `text`
The words in the test phrase must appear in the same order with no other words in between.
@(has_phrase("the quick brown fox", "brown fox")) -> true @(has_phrase("the quick brown fox", "brown fox").match) -> brown fox @(has_phrase("the Quick Brown fox", "quick fox")) -> false @(has_phrase("the Quick Brown fox", "").match) ->
@test has_phrase(text, phrase)
func HasState ¶
HasState tests whether a state name is contained in the `text`
@(has_state("Kigali").match) -> Rwanda > Kigali City @(has_state("¡Kigali!").match) -> Rwanda > Kigali City @(has_state("I live in Kigali").match) -> Rwanda > Kigali City @(has_state("Boston")) -> false
@test has_state(text)
func HasText ¶
HasText tests whether there the text has any characters in it
@(has_text("quick brown")) -> true @(has_text("quick brown").match) -> quick brown @(has_text("")) -> false @(has_text(" \n")) -> false @(has_text(123).match) -> 123 @(has_text(contact.fields.not_set)) -> false
@test has_text(text)
func HasTime ¶
HasTime tests whether `text` contains a time.
@(has_time("the time is 10:30")) -> true @(has_time("the time is 10:30").match) -> 10:30:00.000000 @(has_time("the time is 10 PM").match) -> 22:00:00.000000 @(has_time("the time is 10:30:45").match) -> 10:30:45.000000 @(has_time("there is no time here, just the number 25")) -> false
@test has_time(text)
func HasTopIntent ¶ added in v0.51.0
func HasTopIntent(env envs.Environment, result *types.XObject, name types.XText, confidence types.XNumber) types.XValue
HasTopIntent tests whether the top intent in a classification result has `name` and minimum `confidence`
@(has_top_intent(results.intent, "book_flight", 0.5)) -> true @(has_top_intent(results.intent, "book_hotel", 0.5)) -> false
@test has_top_intent(result, name, confidence)
func HasValue ¶
HasValue returns whether `value` is non-nil and not an error
Note that `contact.fields` and `run.results` are considered dynamic, so it is not an error to try to retrieve a value from fields or results which don't exist, rather these return an empty value.
@(has_value("hello")) -> true @(has_value("hello").match) -> hello @(has_value(datetime("foo"))) -> false @(has_value(not.existing)) -> false @(has_value(contact.fields.unset)) -> false @(has_value("")) -> false
@test has_value(value)
func HasWard ¶
HasWard tests whether a ward name is contained in the `text`
@(has_ward("Gisozi", "Gasabo", "Kigali").match) -> Rwanda > Kigali City > Gasabo > Gisozi @(has_ward("I live in Gisozi", "Gasabo", "Kigali").match) -> Rwanda > Kigali City > Gasabo > Gisozi @(has_ward("Gisozi", "Gasabo", "Brooklyn")) -> false @(has_ward("Gisozi", "Brooklyn", "Kigali")) -> false @(has_ward("Brooklyn", "Gasabo", "Kigali")) -> false @(has_ward("Gasabo")) -> false @(has_ward("Gisozi").match) -> Rwanda > Kigali City > Gasabo > Gisozi
@test has_ward(text, district, state)
func NewTrueResult ¶
NewTrueResult creates a new true result with a match
func NewTrueResultWithExtra ¶
NewTrueResultWithExtra creates a new true result with a match and extra
func ParseDecimalFuzzy ¶
ParseDecimalFuzzy parses a decimal from a string
func RegisterXTest ¶
RegisterXTest registers a new router test (and Excellent function)
Types ¶
This section is empty.