Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vishwac/lg samples #1405

Merged
merged 2 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions experimental/common-expression-language/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Common Expression Language ***_[PREVIEW]_***

Bots, like any other application, require use of expressions to evaluate outcome of a condition based on runtime information available in memory or to the dialog or the language generation system.

Common expression language was put together to address this core need as well as to rationalize and snap to a common expression language that will be used across Bot Builder SDK and other conversational AI components that need an expression language.

See [here](./api-reference.md) for API reference.

***_An expression is a sequence that can contain one or more [operators](#Operators), [variables](#Variables), [explicit values](#Explicit-values), [pre-built functions](./prebuilt-functions.md) or [Language Generation templates](../fileformats/lg/README.md#Template)._***

## Operators

| Operator | Functionality | Prebuilt function equivalent |
|-----------|-------------------------------------------------------------------------------------------|-----------------------------------|
|+ |Arithmetic operator – addition. E.g. A + B |[add][1] |
|- |Arithmetic operator – subtraction. E.g. A – B |[sub][2] |
|* |Arithmetic operator – multiplication. E.g. A * B |[mul][3] |
|/ |Arithmetic operator – division. E.g. A / B |[div][4] |
|^ |Arithmetic operator – exponentiation. E.g. A ^ B |[exp][5] |
|% |Arithmetic operator – modulus. E.g. A % B |[mod][6] |
|== |Comparison operator – equals. E.g. A == B |[equals][7] |
|!= |Comparison operator – Not equals. E.g. A != B |[not][8]([equals][7]()) |
|> |Comparison operator – Greater than. A > B |[greater][9] |
|< |Comparison operator – Less than. A < B |[less][10] |
|>= |Comparison operator – Greater than or equal. A >= B |[greaterOrEquals][11] |
|<= |Comparison operator – Less than or equal. A <= B |[lessOrEquals][12] |
|& |Concatenation operator. Operands will always be cast to string – E.g. A & B |N/A |
|&& |Logical operator – AND. E.g. exp1 && exp2 |[and][13] |
|\|\| |Logical operator – OR. E.g. exp1 \|\| exp2 |[or][14] |
|! |Logical operator – NOT. E.g. !exp1 |[Not][8] |
|' |Used to wrap a string literal. E.g. 'myValue' |N/A |
|" |Used to wrap a string literal. E.g. "myValue" |N/A |
|[] |Used to denote a Template. E.g. [MyTemplate]. |N/A |
|[] |Used to refer to an item in a list by its index. E.g. A[3] |N/A |
|{} |Used to denote an expression. E.g. {A == B}. |N/A |
|{} |Used to denote a variable in template expansion. E.g. {myVariable} |N/A |
|() |Enforces precedence order and groups sub expressions into larger expressions. E.g. (A+B)*C |N/A |
|. |Property selector. E.g. myObject.Property1 |N/A |
|@{} |Used to denote parts of a multi-line value that requires evaluation |N/A |
|\ |Escape character for templates, expressions. |N/A |
|@entityName|Short hand notation that expands to turn.entities.entityName |N/A |
|$propertyName|Short hand notation that expands to dialog.result.property |N/A |
|#intentName|Short hand notation that expands to turn.intents.intentName |N/A |

## Variables
Variables are always referenced by their name. E.g. {myVariable}
Variables can be complex objects. In which case they are referenced either using the property selector operator e.g. myParent.myVariable or using the item index selection operator. E.g. myParent.myList[0]. or using the [parameters](TODO) function.

## Explicit values
Explicit values are enclosed in single quotes 'myExplicitValut' or double quotes - "myExplicitValue".

## Pre-built functions
See [Here](./prebuilt-functions.md) for a complete list of prebuilt functions supported by the common expression language library.

## Packages
Packages for C# are available under the [BotBuidler MyGet feed][15]

[1]:prebuilt-functions.md#add
[2]:prebuilt-functions.md#sub
[3]:prebuilt-functions.md#mul
[4]:prebuilt-functions.md#div
[5]:prebuilt-functions.md#exp
[6]:prebuilt-functions.md#mod
[7]:prebuilt-functions.md#equals
[8]:prebuilt-functions.md#not
[9]:prebuilt-functions.md#greater
[10]:prebuilt-functions.md#less
[11]:prebuilt-functions.md#greaterOrEquals
[12]:prebuilt-functions.md#essOrEquals
[13]:prebuilt-functions.md#and
[14]:prebuilt-functions.md#or
[15]:https://botbuilder.myget.org/feed/botbuilder-declarative/package/nuget/Microsoft.Bot.Builder.Expressions
74 changes: 74 additions & 0 deletions experimental/common-expression-language/api-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# API reference for Expression

For Nuget packages, see [this MyGet feed][1]

### ExpressionEngine Class

#### Constructors
```C#
/// <summary>
/// Constructor
/// </summary>
/// <param name="lookup">If present delegate to lookup evaluation information from type string.</param>
public ExpressionEngine(EvaluatorLookup lookup = null)
```
#### Methods
```C#
/// <summary>
/// Parse the input into an expression.
/// </summary>
/// <param name="expression">Expression to parse.</param>
/// <returns>Expresion tree.</returns>
public Expression Parse(string expression)
```

### Expression Class

#### Fields
```C#
/// <summary>
/// Type of expression.
/// </summary>
public string Type { get; }

/// <summary>
/// Evaluator of this expression
/// </summary>
public ExpressionEvaluator Evaluator { get; }

/// <summary>
/// Children expressions.
/// </summary>
public Expression[] Children { get; set; }

/// <summary>
/// Expected result of evaluating expression.
/// </summary>
public ReturnType ReturnType => Evaluator.ReturnType;
```

#### Contructor
```C#
/// <summary>
/// Expression constructor.
/// </summary>
/// <param name="type">Type of expression from <see cref="ExpressionType"/>.</param>
/// <param name="evaluator">Information about how to validate and evaluate expression.</param>
/// <param name="children">Child expressions.</param>
public Expression(string type, ExpressionEvaluator evaluator = null, params Expression[] children)
```

#### Methods

```C#
/// <summary>
/// Evaluate the expression.
/// </summary>
/// <param name="state">
/// Global state to evaluate accessor expressions against. Can be <see cref="IDictionary{String}{Object}"/>, <see cref="IDictionary"/> otherwise reflection is used to access property and then indexer.
/// </param>
/// <returns>Computed value and an error string. If the string is non-null, then there was an evaluation error.</returns>
public (object value, string error) TryEvaluate(object state)
```

[1]:https://botbuilder.myget.org/feed/botbuilder-declarative/package/nuget/Microsoft.Bot.Builder.Expressions
Loading