評価

いくつかの組み込みタイプの C# によってサポートされる基本操作を解釈します。また、 Math クラスのように、いくつかの組み込みクラスの C# からのメソッドも解釈します。

コマンドの可用性: IBM RPA SaaS および IBM RPA オンプレミス

Description

いくつかの組み込みタイプの C# によってサポートされる基本操作を解釈します。また、 Math クラスのように、いくつかの組み込みクラスの C# からのメソッドも解釈します。 以下のリストは、サポートされる操作を定義しています。

  • 2 項算術演算
  • 比較演算
  • 2 項条件付き論理演算
  • 等価演算

以下のリストは、サポートされる C# タイプを定義しています。

名前 構文
ブール値 bool
Object object
Char char
10 進法 decimal
二重 double
シングル float
整数 int
UInt32 uint
IntPtr nint
UIntPtr nuint
Int64 long
UInt64 ulong
Int16 short
UInt16 ushort
DateTime DateTime
GUID Guid

操作で IBM RPA 変数を使用できます。 デフォルトでは、 IBM RPA は、式が基本算術演算子を使用する場合は Number 変数を C# 小数部に変換し、式が他の演算子を使用する場合は C# 倍精度に変換します。 IBM RPA 変数を、明示的な変換構文 ( (<c#_type>)${rpa_variable}とも呼ばれる) を使用して、サポートされる C# タイプに変換できます。 以下の式は、有効な evaluate 式でのキャストの例です。

Math.Round(${var1}, (int)${var2})

以下のリストは、キャストを許可する Math メソッドを定義しています。

  • BigMul
  • 倍数に切り上げ
  • Floor
  • 円形
  • 切り捨て

🛈 重要: Evaluate コマンドは計算ツールではありません。 計算機として使用する場合は、結果が正確でない可能性があることに注意してください。 コマンドがどのように評価されるかを理解するには、 を参照してください。 考えられる丸め誤差と数値精度の詳細については、 制限 を参照してください。

制限

  • コンピューターが数値を表す方法が原因で、丸め誤差が発生する可能性があります。 丸め誤差は、浮動小数点数で発生するエラーです。 このようなエラーを回避するには、 Math.Round() 操作を使用します。 数値を丸めると、実際の値よりも扱いやすい値が生成される可能性がありますが、精度が低下する可能性もあります。 例えば、 4.5 の 10 進値は 4 に丸められます。
  • 整数型には、以下の制限があります。
タイプ 最小整数値 最大整数値 整数精度
10 進法 -79,228,162,514,264,337,593,543,950,335 79,228,162,514,264,337,593,543,950,335 28 桁
二重 -9,007,199,254,740,992 9,007,199,254,740,992 15 桁
整数 -2,147,483,648 2,147,483,647 10 桁
UInt32 0 4,294,967,295 10 桁
IntPtr アーキテクチャーに依存するもの:
32 ビット: -2,147,483,648
64 ビット: -9,223,372,036,854,775,808
アーキテクチャーに依存するもの:
32 ビット: 2,147,483,647
64 ビット: 9,223,372,036,854,775,807
32 ビット: 10 桁の
64 ビット: 19 桁
UIntPtr 0 アーキテクチャーに依存するもの:
32 ビット: 4,294,967,295
64 ビット: 18,446,744,073,709,551,615
32 ビット: 10 桁の
64 ビット: 20 桁
Int64 -9,223,372,036,854,775,808 9,223,372,036,854,775,807 19 桁
UInt64 0 18,446,744,073,709,551,615 20 桁
Int16 -32,768 32,767 5 桁
UInt16 0 65,535 5 桁
  • 浮動小数点数型は、 IEEE 754 標準に従います。

スクリプト構文

evaluate --expression(String) (Numeric)=value

入力パラメーター

スクリプト Designer 必須 受け入れられるタイプ Description
expression Expression Required Text, Number, Money, Date Time, Date, Time Span, Boolean 数式論理式Spring 式、および 複合条件付きの式をサポートします。

また、 質問に回答 (answerQuestion) コマンドおよび ボットの質問と回答 (botAnswerQuestion) コマンドによって返される応答内の変数への参照も評価します。 変数への参照は、${variableName} パターンに続くテキストです。ここで、変数は、スクリプトでユーザーが定義した値に置き換えられます。

数式

プレーン・テキストで式を使用する場合 (例: "1.2 + 3.4")、コマンドは、認識時に数値タイプを考慮します。 数値に小数部がある場合は、倍精度と見なされます。 それ以外の場合は、整数と見なされます。

変数を持つ式 (例: "${firstNumber} + ${secondNumber}") を使用する場合、コマンドは操作に関して数値タイプを考慮します。 式に基本的な数学演算 (+-*/%) のみが含まれている場合、数値は小数部と見なされます。 それ以外の場合、数値は倍精度と見なされます。

Money 型には特定のフォーマット規則があるため、値に関する二重キャスト (つまり、小数部を持たない値) が必要になる場合があります。

以下のリストは、サポートされるすべての .NET Math 関数を示しています。

操作 構文 Description
Abs Math.Abs(double, int) 倍精度浮動小数点数または整数の絶対値を返します。
Acos Math.Acos(double) コサインが指定された数値である角度を戻します。
Asin Math.Asin(double) 正弦が指定された数値である角度を戻します。
Atan Math.Atan(double) タンジェントが指定された数値である角度を戻します。
倍数に切り上げ Math.Ceiling(double) 指定された倍精度浮動小数点数以上の整数の最小値を返します。
Cos Math.Cos(double) 指定された角度のコサインを戻します。
Cosh Math.Cosh(double) 指定された角度の双曲線コサインを戻します。
Exp Math.Exp(double) 指定された累乗の数値を返します。
Floor Math.Floor(double) 指定された倍精度浮動小数点数以下の最大整数値を戻します。
IEEERemainder (EEERemainder) Math.IEEERemainder(double) 指定された数値を別の指定された数値で除算した結果の剰余を返します。
log Math.Log(double) 指定された数値の自然対数 (底 n) を戻します。
Log10 Math.Log10(double) 指定された数値の 10 を底とする対数を返します。
最大 Math.Max(double, int) 2 つの数値のうち大きい方を返します。 タイプは、Double または Integer のいずれかです。
最小 Math.Min(double, int) 2 つの数値のうち小さい方を返します。 タイプは、Double または Integer のいずれかです。
pow Math.Pow(double, double) 指定された数値の指定された累乗を返します。
円形 Math.Round(double) 浮動小数点値を最も近い整数値に丸め、中間点値を最も近い偶数に丸めます。
署名 Math.Sign(double, int) 倍精度浮動小数点数または整数の符号を示す整数を戻します。
Sin Math.Sin(double) 指定された角度のサインを返します。
Sinh Math.Sinh(double) 指定された角度の双曲線サインを返します。
Tan Math.Tan(double) 指定された角度のタンジェントを戻します。
Tanh Math.Tanh(double) 指定された角度の双曲線タンジェントを戻します。
切り捨て Math.Truncate(double) 指定された倍精度浮動小数点数の整数部分を計算します。

以下のリストは、キャストがサポートされているすべての .NET Math 関数を示しています。

操作 タイプ 構文 キャスト Description
BigMul Numeric Math.BigMul(int, int) Math.BigMul((int)${var1}, (int)${var2}) 2 つの整数の完全な積を生成します。
ラウンド (3) Numeric Math.Round(double, int) Math.Round(${var1}, (int)${var2}) 浮動小数点値を指定された小数桁数に丸め、中間点値を最も近い偶数に丸めます。
ラウンド (3) ¹ Money Math.Round(double, int) Math.Round((double)${var1}, ${var2}) 倍精度浮動小数点値を最も近い整数値に丸め、中間点値を最も近い偶数に丸めます。
上限 ¹ Money Math.Ceiling(double) Math.Ceiling((double)${var1}) 指定された倍精度浮動小数点数以上の整数の最小値を返します。
フロア ¹ Money Math.Floor(double) Math.Floor((double)${var1}) 指定された倍精度浮動小数点数以下の最大整数値を戻します。
切り捨て ¹ Money Math.Truncate(double) Math.Truncate((double)${var1}) 指定された倍精度浮動小数点数の整数部分を計算します。
ラウンド ¹ Money Math.Round(double) Math.Round((double)${var1}) 倍精度浮動小数点値を最も近い整数値に丸め、中間点値を最も近い偶数に丸めます。

¹ 変数に設定された値によって異なります。 予想される値が分からない場合は、キャストを行う方がより効果的です。

ストリング式

文字列式を使用する場合、変数は二重引用符で囲む必要があります。 例えば、"${testVariable}".EndsWith("${e}")。 操作の構文は、ライブラリー名の「ストリング」および「ストリング」でのみ機能します。

以下のリストは、ストリング式でサポートされるすべての操作を示しています。

操作 構文 Description
比較 String.Compare(string, string) 指定された 2 つのストリング・オブジェクトを比較し、ソート順での相対位置を示す整数を返します。
CompareOrdinal String.CompareOrdinal(string, string) 各ストリング内の対応する Char オブジェクトの数値を評価することにより、指定された 2 つの String オブジェクトを比較します。
CompareTo "${value}".CompareTo(string) このインスタンスを、指定されたストリング・オブジェクトと比較し、このインスタンスが、指定されたストリングと同じソート順の前、後、または同じ位置にあるかどうかを示します。
次を含む "${value}".Contains(string) 指定されたサブストリングがこのストリング内にあるかどうかを示す値を戻します。
EndsWith "${value}".EndsWith(string) このストリング・インスタンスの終わりが、指定されたストリングと一致するかどうかを判別します。
等しい "${value}".Equals(string) 指定された 2 つのストリング・オブジェクトの値が同じかどうかを判別します。
IndexOf "${value}".IndexOf(string) このインスタンス内の指定されたストリングの最初のオカレンスのゼロ・ベースの索引を報告します。
IsNormalized "${value}".IsNormalized() このストリングが Unicode 正規化形式 C であるかどうかを示します。
LastIndex "${value}".LastIndexOf(string, int) このインスタンス内の指定されたストリングの最後のオカレンスの、ゼロ・ベースの索引位置を報告します。
StartsWith "${value}".StartsWith(string) このストリング・インスタンスの先頭が指定されたストリングと一致するかどうかを判別します。
IsNullOrWhiteスペース String.IsNullOrWhiteSpace(string) 指定されたストリングがヌルであるか、空であるか、または空白文字のみで構成されているかを示します。
IsNullOrEmpty String.IsNullOrEmpty(string) 指定されたストリングが null であるか、空ストリングであるかを示します。

ブール式と複合条件

サポートされる演算子を使用して、 math または string ライブラリーなどの他のライブラリーからの操作で複合条件を形成することができます。

以下のリストは、ブール式および複合条件でサポートされるすべての演算子を示しています。

オペレーター 構文 Description
AND && 両方のオペランドが trueの場合、 true を戻します。
等しい == それらのオペランドの厳密な等価性または不等価性を比較します。
より大きい > あるオペランドが別のオペランドより大きい場合に比較します。
< あるオペランドが別のオペランドより小さい場合に比較します。
以上 >= 1 つのオペランドが別のオペランド以上であるかどうかを比較します。
以下 <= 1 つのオペランドが別のオペランド以下であるかどうかを比較します。
否定 ! oposite 値を決定します。
等しくない != オペランドの値が同じでない場合は true を返し、それ以外の場合は falseを返します。
OR || オペランドのいずれかが trueの場合は、 true を返します。
XOR ^ オペランドが opposites の場合は true を返し、それ以外の場合は falseを返します。

その他の式

このコマンドは、 DateTime 値と TimeSpan 値も評価します。 変数は二重引用符で囲む必要があり、 Booleans および Numbersを返す式でのみ機能します。 コマンドがこれらのライブラリーを処理する方法の例については、 例 4 を参照してください。

Fuzzy 変数もサポートされます。 このコマンドを使用して、ファジー操作後に Fuzzy 型変数を Numeric 型に変換できます。

出力パラメーター

スクリプト Designer 受け入れられるタイプ Description
value 結果 Number, Text, Boolean 出力がストリングの場合、計算された式の結果を返します。コマンドは変数置換を行います。 それ以外の場合は、式を評価して、目的の出力に構文解析しようとします。

例 1: 数値変数 evaluatedExpression は、「10 * (5 + 5)」の結果を保管するために定義され、 Log Message コマンドを使用して IBM RPA Studio コンソールに表示されます。

defVar --name evaluatedExpression --type Numeric
// Evaluates the mathematical expression set.
evaluate --expression "10*(5+5)" evaluatedExpression=value
// Prints the result of the expression.
logMessage --message "${evaluatedExpression}" --type "Info"

例 2: 数値変数 evaluatedExpression は、「${numberExpression1} * ${numberExpression2}」の結果を保管するために定義されます。 前の例とは異なり、数値を持つ変数が使用されます。

defVar --name evaluatedExpression --type Numeric
defVar --name numberForCalculation1 --type Numeric --value 10
defVar --name numberForCalculation2 --type Numeric --value 5
// Evaluates the mathematical expression set.
evaluate --expression "${numberForCalculation1} * ${numberForCalculation2}" evaluatedExpression=value
// Prints the result of the expression.
logMessage --message "${evaluatedExpression}" --type "Info"

例 3: この例では、 String 型の 2 つの変数が設定され、コマンドはこれらの変数を持つ式を評価します。

defVar --name evaluatedExpression --type Text
defVar --name firstString --type Test --value a
defVar --name secondString --type Text --value b
// Evaluates the string expression set.
evaluate --expression "${firstString} ${secondString}" evaluatedExpression=value
// Prints the result of the expression.
logMessage --message "${evaluatedExpression}" --type "Info"

例 4: この例では、 DateDateTime 、および TimeSpan の各タイプの 1 つの変数が設定され、コマンドは各変数を個別に評価し、その結果を出力します。

defVar --name result --type Numeric
defVar --name d --type Date --value "2022-08-01"
defVar --name dt --type DateTime --value "2022-08-01 03:00:00"
defVar --name t --type TimeSpan --value "05:40:32"
// Evaluates the expression set with the variable of type DateTime.
evaluate --expression "DateTime.Parse(\"${dt}\").Hour" result=value
// Prints the result of the expression.
logMessage --message "Hour from \"${dt}\": ${result}" --type "Info"
// Evaluates the expression set with the variable of type Date.
evaluate --expression "DateTime.Parse(\"${d}\").Month" result=value
// Prints the result of the expression.
logMessage --message "Month from \"${d}\": ${result}" --type "Info"
// Evaluates the expression set with the variable of type TimeSpan.
evaluate --expression "TimeSpan.Parse(\"${t}\").Minutes" result=value
// Prints the result of the expression.
logMessage --message "Minutes from \"${t}\": ${result}" --type "Info"

例 5: この例では、2 つの式が設定され、 AND 演算子を介して結合されます。 このコマンドは、オペラドールに従って式を評価します。

defVar --name evaluatedExpression --type Text
defVar --name firstString --type Test --value a
defVar --name secondString --type Text --value b
defVar --name firstNumber --type Numeric --value 1
defVar --name secondNumbert --type Numeric --value 2
// Evaluates the string expression set.
evaluate --expression "${firstString}".StartsWith("${secondString}") && ${firstNumber} > Math.Min(${firstNumber},${secondNumber}))" evaluatedExpression=value
// Prints the result of the expression.
logMessage --message "${evaluatedExpression}" --type "Info"

例 6: この例では、コマンドは 2 つの式を評価します。 最初の式は、丸めエラーの原因となる Math.Round() を使用しません。一方、2 番目の式は Math.Round() メソッドを使用します。これにより、処理しやすい数値が生成されます。

defVar --name number1 --type Numeric --value 11
defVar --name number2 --type Numeric --value 2
defVar --name expressionResult --type Numeric
evaluate --expression "${number1}/${number2}" expressionResult=value
logMessage --message " Result of the expression without rounding: ${expressionResult}" --type "Info"
evaluate --expression "Math.Round(${number1}/${number2})" expressionResult=value
logMessage --message " Result of the expression without rounding: ${expressionResult}" --type "Info"

例 7: この例では、ファジー操作の後、このコマンドを使用して tip 変数の数値を取得します。

defVar --name low --type FuzzySet
defVar --name medium --type FuzzySet
defVar --name good --type FuzzySet
defVar --name serviceQuality --type Fuzzy
defVar --name foodQuality --type Fuzzy
defVar --name littleTip --type FuzzySet
defVar --name reasonableTip --type FuzzySet
defVar --name generousTip --type FuzzySet
defVar --name tip --type Fuzzy
defVar --name tipValue --type Numeric
beginFuzzy --intervals 1000
	fuzzySet --function "Trapezoidal" --shape "Number" --edge "Right" --m1 0 --m2 5 low=value
	fuzzySet --function "Trapezoidal" --shape "Triangular" --m1 3 --m2 5 --m3 7 medium=value
	fuzzySet --function "Trapezoidal" --shape "Number" --edge "Left" --m1 5 --m2 10 good=value
	fuzzyVariable --left 0 --right 10 --labels "${low} ${medium} ${good}" serviceQuality=value
	fuzzyVariable --left 0 --right 10 --labels "${low} ${medium} ${good}" foodQuality=value
	fuzzySet --function "Trapezoidal" --shape "Number" --edge "Right" --m1 0 --m2 12.5 littleTip=value
	fuzzySet --function "Trapezoidal" --shape "Triangular" --m1 6.25 --m2 12.5 --m3 18.75 reasonableTip=value
	fuzzySet --function "Trapezoidal" --shape "Number" --edge "Left" --m1 12.5 --m2 25 generousTip=value
	fuzzyVariable --left 0 --right 25 --labels "${littleTip} ${reasonableTip} ${generousTip}" tip=value
	
	//The food was rancid or the service was poor.
	fuzzyRule --name "Terrible food or service" --condition "${foodQuality} IS ${low} OR ${serviceQuality} IS ${low}" --variable ${tip} --set ${littleTip}
	
	//The service was reasonable.
	fuzzyRule --name "Average service" --condition "${serviceQuality} IS ${medium}" --variable ${tip} --set ${reasonableTip}
	
	//The food was delicious or the service was good.
	fuzzyRule --name "Great Food or Service" --condition "${foodQuality} IS ${good} OR ${serviceQuality} IS ${good}" --variable ${tip} --set ${generousTip}
endFuzzy
evaluate --expression "${tip}" tipValue=value