tf:containsAdjacentText

Search word tokens in order within some distance.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

tf:containsAdjacentText(node $input, integer $distance, token+ $word) => boolean

Description

The function tf:containsAdjacentText is specific to Tamino. It searches a node for a sequence of one or more word tokens within a specified proximity distance and in token order. If the argument $node evaluates to the empty sequence, false is returned.

The $distance argument determines how far apart the matched word tokens in the node may be. The distance is evaluated as the maximum number of unmatched tokens between the first matched word token and the last matched word token. The function returns true, if $distance is larger than this computed distance. For example, a value of "1" means they must follow immediately after one another, a value of 2 allows a gap of one word in between etc.

With tf:containsAdjacentText you can perform search operations including the use of a wildcard character. The section Pattern Matching in the XQuery 4 User Guide explains this in detail.

Arguments

$input

node to be searched

$distance

integer value denoting proximity distance

$word

a word token

Examples

  • Retrieve all patients who are responding to current treatment:

    for $a in input()/patient
    where tf:containsAdjacentText($a/remarks, 3, "patient", "to", "treatment")
    return $a/name

    This query returns all the names of all patients for which tf:containsAdjacentText returns true. This is the case for all remarks nodes in which the word tokens "patient", "to" and "treatment" follow after one another in a distance of a most three word tokens, i.e., there may be no more than two word tokens in-between. Given the sample data, Bloggs is the only patient.

    Since tf:containsAdjacentText takes the order of the word tokens into account, swapping the tokens would yield an empty result set:

    for $a in input()/patient
    where tf:containsAdjacentText($a/remarks, 3, "treatment", "patient", "to")
    return $a/name
  • Retrieve all remarks in which the word "treatment" occurs:

    for $a in input()/patient
    where tf:containsAdjacentText($a/remarks, 1000, "treatment")
    return $a/name

    This is the trivial case of searching only one word token. If the word token is present in the node, the result is true regardless of the specified distance. You can express this equivalently using the function containsText:

    for $a in input()/patient
    where tf:containsText($a/remarks, "treatment")
    return $a/name