Help - Difference between revisions of "User Expressions"

From TTA Help System
 
(2 intermediate revisions by the same user not shown)
Line 144: Line 144:
  
 
== Text functions ==
 
== Text functions ==
 +
 +
The functions described here can be used to manipulate or characterize textual values. They are especially useful to calculating target column IDs.
 +
 +
''Note that none of these functions were available before version 0.2.0.''
 +
 +
<table class="default">
 +
  <tr class="default">
 +
    <th class="default">Name:</th>
 +
    <th class="default">Definition:</th>
 +
    <th class="default">Description:</th>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">To upper case</td>
 +
    <td class="default"><code>toUpperCase(''Textual'' text)</code></td>
 +
    <td class="default">Returns a text in upper case letters.<br><br>
 +
        Example: <code>toUpperCase(treeUserValue("someValue"))</code> would convert all textual values of a column to upper case.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">To lower case</td>
 +
    <td class="default"><code>toUpperCase(''Textual'' text)</code></td>
 +
    <td class="default">Returns a text in upper case letters.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Subsequence</td>
 +
    <td class="default"><code>subsequence(''Textual'' text, ''Numeric'' startIndex)</code></td>
 +
    <td class="default">Returns a suffix of a textual value starting at the specified position (inclusive). The index of the first character is 0.<br><br>
 +
        Example: <code>subsequence("ABC", 1)</code> would return "BC".</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default"></td>
 +
    <td class="default"><code>subsequence(''Textual'' text, ''Numeric'' startIndex, ''Numeric'' endIndex)</code></td>
 +
    <td class="default">Returns a part of a textual value ranging from <code>startIndex</code> (inclusive) to <code>endIndex</code> (exclusive). The index of the first character is 0.<br><br>
 +
        Example: <code>subsequence("ABCDEF", 1, 3)</code> would return "BC".</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Contains text</td>
 +
    <td class="default"><code>contains(''Textual'' text, ''Textual'' part)</code></td>
 +
    <td class="default">Returns a ''Boolean'' value indicating whether <code>part</code> is contained in <code>text</code>.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Starts with</td>
 +
    <td class="default"><code>startsWith(''Textual'' text, ''Textual'' prefix)</code></td>
 +
    <td class="default">Returns a ''Boolean'' value indicating whether <code>text</code> starts with <code>prefix</code>. (Both values may also be identical.)</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Ends with</td>
 +
    <td class="default"><code>endsWith(''Textual'' text, ''Textual'' suffix)</code></td>
 +
    <td class="default">Returns a ''Boolean'' value indicating whether <code>text</code> starts with <code>suffix</code>. (Both values may also be identical.)</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">First position of a text</td>
 +
    <td class="default"><code>firstIndexOf(''Textual'' text, ''Textual'' part)</code></td>
 +
    <td class="default">Returns the index of the first occurrence of <code>part</code> in <code>text</code> or -1 of it is not contained at all. The index of the first character is 0.<br><br>
 +
        Example: <code>firstIndexOf("ABC DBE DB", "BE")</code> would return 5.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default"></td>
 +
    <td class="default"><code>firstIndexOf(''Textual'' text, ''Textual'' part, ''Numeric'' startIndex)</code></td>
 +
    <td class="default">Returns the index of the first occurrence of <code>part</code> in <code>text</code> at or after <code>startIndex</code> or -1 of it is not contained at all.<br><br>
 +
        Example: <code>firstIndexOf("ABC DBE DB", "B", 4)</code> would return 5.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Last position of a text</td>
 +
    <td class="default"><code>lastIndexOf(''Textual'' text, ''Textual'' part)</code></td>
 +
    <td class="default">Returns the index of the last occurrence of <code>part</code> in <code>text</code> or -1 of it is not contained at all. The index of the first character is 0.<br><br>
 +
        Example: <code>lastIndexOf("ABC DBE DB", "D")</code> would return 8.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default"></td>
 +
    <td class="default"><code>lastIndexOf(''Textual'' text, ''Textual'' part, ''Numeric'' startIndex)</code></td>
 +
    <td class="default">Returns the index of the last occurrence of <code>part</code> in <code>text</code> at or before <code>startIndex</code> or -1 of it is not contained at all.<br><br>
 +
        Example: <code>firstIndexOf("ABC DBE DB", "D", 6)</code> would return 4.</td>
 +
  </tr>
 +
</table>
  
 
== General mathematical functions ==
 
== General mathematical functions ==
 +
 +
<table class="default">
 +
  <tr class="default">
 +
    <th class="default">Name:</th>
 +
    <th class="default">Definition:</th>
 +
    <th class="default">Description:</th>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Sine</td>
 +
    <td class="default"><code>sin(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the sine of the passed numeric value.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Cosine</td>
 +
    <td class="default"><code>cos(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the cosine of the passed numeric value.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Tangent</td>
 +
    <td class="default"><code>tan(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the tangent of the passed numeric value.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Inverse sine</td>
 +
    <td class="default"><code>asin(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the inverse sine of the passed numeric value.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Inverse cosine</td>
 +
    <td class="default"><code>acos(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the inverse cosine of the passed numeric value.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Inverse tangent</td>
 +
    <td class="default"><code>atan(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the inverse tangent of the passed numeric value.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Inverse tangent</td>
 +
    <td class="default"><code>atan2(''Numeric'' x, ''Numeric'' y)</code></td>
 +
    <td class="default">Calculates the inverse tangent (or arcus tangent) of y / x given adjacent and x. The result is between -&pi; and &pi;</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Hyperbolic sine</td>
 +
    <td class="default"><code>sinh(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the hyperbolic sine of the given angle.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Hyperbolic cosine</td>
 +
    <td class="default"><code>cosh(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the hyperbolic cosine of the given angle.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Hyperbolic tangent</td>
 +
    <td class="default"><code>tanh(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the hyperbolic tangent of the given angle.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Inverse hyperbolic sine</td>
 +
    <td class="default"><code>asinh(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the inverse hyperbolic sine of the given angle.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Inverse hyperbolic cosine</td>
 +
    <td class="default"><code>acosh(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the inverse hyperbolic cosine of the given angle.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Inverse hyperbolic tangent</td>
 +
    <td class="default"><code>atanh(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the inverse hyperbolic tangent of the given angle.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Natural logarithm</td>
 +
    <td class="default"><code>ln(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the natural logarithm of the passed numeric value.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Logarithm to the base 10</td>
 +
    <td class="default"><code>log(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the logarithm to the base 10 of the passed numeric value.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Exponential function</td>
 +
    <td class="default"><code>exp(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the exponential function to the base ''e''. It is the inverse function of the natural logarithm (<code>ln</code>).</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Magnitude</td>
 +
    <td class="default"><code>abs(''Numeric'' x)</code></td>
 +
    <td class="default">Returns the absolute value of the passed numeric parameter.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Random number</td>
 +
    <td class="default"><code>rand(''Numeric'' x)</code></td>
 +
    <td class="default">Returns a random number between 0 and 1.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Square Root</td>
 +
    <td class="default"><code>sqrt(''Numeric'' x)</code></td>
 +
    <td class="default">Calculates the square root of the passed numeric parameter.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Alternative</td>
 +
    <td class="default"><code>if(''Boolean'' condition, ''Numeric or textual'' trueValue, ''Numeric or textual'' falseValue)</code></td>
 +
    <td class="default">Returns the second parameter if the condition is true or the third if not.</td>
 +
  </tr>
 +
  <tr class="default">
 +
    <td class="default">Number to text</td>
 +
    <td class="default"><code>str(''Numeric or textual'' x)</code></td>
 +
    <td class="default">Returns a textual representation of the passed parameter.</td>
 +
  </tr>
 +
</table>
  
 
== General constants ==
 
== General constants ==
 +
 +
* Euler's number: <code>e</code>
 +
* &pi;: <code>pi</code>

Latest revision as of 15:05, 7 October 2020

In Topological Tree Analyszer user-defined expressions are used to calculate the actual data (e.g., distances between trees) from basic topological values. A set of functions is available to formulate such expressions and to access the basic values. An unlimited number of user expressions can be defined and will be written to a results table at the end of an analysis. It is also possible to reference results from one user expression from another one and reuse the result there.

Functions to access basic topological values

Functions to access results of other expressions

Operators

The following list contains all valid operators. Each operator binds as strong or more than all operators listed below. The right columns indicate which types the operands need to have.

Name: Operator: Numeric: Textual: Boolean: Example:
Power ^ YesSymbol.png NoSymbol.png NoSymbol.png 10^-2 (= 0.02)
Unary plus + YesSymbol.png NoSymbol.png NoSymbol.png +4
Unary minus - YesSymbol.png NoSymbol.png NoSymbol.png -4
Modulo % YesSymbol.png NoSymbol.png NoSymbol.png 10 % 4 (= 2)
Division / YesSymbol.png NoSymbol.png NoSymbol.png treeUserValue("someValue") / 2
Multiplication * YesSymbol.png NoSymbol.png NoSymbol.png treeUserValue("someValue") * 100
Addition + YesSymbol.png YesSymbol.png NoSymbol.png
treeUserValue("someValue") + 10
"Two " + "words"
Less or equal <= YesSymbol.png NoSymbol.png NoSymbol.png if(treeUserValue("someValue") <= 100, treeUserValue("someValue"), 100)
Greater or equal >= YesSymbol.png NoSymbol.png NoSymbol.png if(treeUserValue("someValue") <= 100, "A", "B")
Less then < YesSymbol.png NoSymbol.png NoSymbol.png if(treeUserValue("someValue") < 100, treeUserValue("someValue"), 100)
Greater then > YesSymbol.png NoSymbol.png NoSymbol.png if(treeUserValue("someValue") < 100, "A", "B")
Equal = YesSymbol.png YesSymbol.png NoSymbol.png if(treeUserValue("value1") = 100, treeUserValue("value2"), treeUserValue("value3"))
Not equal != YesSymbol.png YesSymbol.png NoSymbol.png if(treeUserValue("value1") != "empty", treeUserValue("value2"), 0)
And && NoSymbol.png NoSymbol.png YesSymbol.png if(treeUserValue("value1") < 100 && treeUserValue("value1") > 50, treeUserValue("value2"), "")
Or || NoSymbol.png NoSymbol.png YesSymbol.png if(treeUserValue("value1") < 100 || treeUserValue("value2") < 100, treeUserValue("value3"), "undefined")

Text functions

The functions described here can be used to manipulate or characterize textual values. They are especially useful to calculating target column IDs.

Note that none of these functions were available before version 0.2.0.

Name: Definition: Description:
To upper case toUpperCase(Textual text) Returns a text in upper case letters.

Example: toUpperCase(treeUserValue("someValue")) would convert all textual values of a column to upper case.
To lower case toUpperCase(Textual text) Returns a text in upper case letters.
Subsequence subsequence(Textual text, Numeric startIndex) Returns a suffix of a textual value starting at the specified position (inclusive). The index of the first character is 0.

Example: subsequence("ABC", 1) would return "BC".
subsequence(Textual text, Numeric startIndex, Numeric endIndex) Returns a part of a textual value ranging from startIndex (inclusive) to endIndex (exclusive). The index of the first character is 0.

Example: subsequence("ABCDEF", 1, 3) would return "BC".
Contains text contains(Textual text, Textual part) Returns a Boolean value indicating whether part is contained in text.
Starts with startsWith(Textual text, Textual prefix) Returns a Boolean value indicating whether text starts with prefix. (Both values may also be identical.)
Ends with endsWith(Textual text, Textual suffix) Returns a Boolean value indicating whether text starts with suffix. (Both values may also be identical.)
First position of a text firstIndexOf(Textual text, Textual part) Returns the index of the first occurrence of part in text or -1 of it is not contained at all. The index of the first character is 0.

Example: firstIndexOf("ABC DBE DB", "BE") would return 5.
firstIndexOf(Textual text, Textual part, Numeric startIndex) Returns the index of the first occurrence of part in text at or after startIndex or -1 of it is not contained at all.

Example: firstIndexOf("ABC DBE DB", "B", 4) would return 5.
Last position of a text lastIndexOf(Textual text, Textual part) Returns the index of the last occurrence of part in text or -1 of it is not contained at all. The index of the first character is 0.

Example: lastIndexOf("ABC DBE DB", "D") would return 8.
lastIndexOf(Textual text, Textual part, Numeric startIndex) Returns the index of the last occurrence of part in text at or before startIndex or -1 of it is not contained at all.

Example: firstIndexOf("ABC DBE DB", "D", 6) would return 4.

General mathematical functions

Name: Definition: Description:
Sine sin(Numeric x) Calculates the sine of the passed numeric value.
Cosine cos(Numeric x) Calculates the cosine of the passed numeric value.
Tangent tan(Numeric x) Calculates the tangent of the passed numeric value.
Inverse sine asin(Numeric x) Calculates the inverse sine of the passed numeric value.
Inverse cosine acos(Numeric x) Calculates the inverse cosine of the passed numeric value.
Inverse tangent atan(Numeric x) Calculates the inverse tangent of the passed numeric value.
Inverse tangent atan2(Numeric x, Numeric y) Calculates the inverse tangent (or arcus tangent) of y / x given adjacent and x. The result is between -π and π
Hyperbolic sine sinh(Numeric x) Calculates the hyperbolic sine of the given angle.
Hyperbolic cosine cosh(Numeric x) Calculates the hyperbolic cosine of the given angle.
Hyperbolic tangent tanh(Numeric x) Calculates the hyperbolic tangent of the given angle.
Inverse hyperbolic sine asinh(Numeric x) Calculates the inverse hyperbolic sine of the given angle.
Inverse hyperbolic cosine acosh(Numeric x) Calculates the inverse hyperbolic cosine of the given angle.
Inverse hyperbolic tangent atanh(Numeric x) Calculates the inverse hyperbolic tangent of the given angle.
Natural logarithm ln(Numeric x) Calculates the natural logarithm of the passed numeric value.
Logarithm to the base 10 log(Numeric x) Calculates the logarithm to the base 10 of the passed numeric value.
Exponential function exp(Numeric x) Calculates the exponential function to the base e. It is the inverse function of the natural logarithm (ln).
Magnitude abs(Numeric x) Returns the absolute value of the passed numeric parameter.
Random number rand(Numeric x) Returns a random number between 0 and 1.
Square Root sqrt(Numeric x) Calculates the square root of the passed numeric parameter.
Alternative if(Boolean condition, Numeric or textual trueValue, Numeric or textual falseValue) Returns the second parameter if the condition is true or the third if not.
Number to text str(Numeric or textual x) Returns a textual representation of the passed parameter.

General constants

  • Euler's number: e
  • π: pi