Search for Arguments at a Specific Position in Text

The position() function matches documents containing arguments at a specific position in text.

Syntax

position()

position([number], term_1, term_2…​)

The function position() has no required arguments. When called without arguments, optional named parameters should be specified, for example:

position(max_snt:=1) matches the first sentence of each text.

The first optional parameter number is used to specify the maximum position (in tokens) at which the argument can occur in text. By default, the function finds arguments at the first position in text. Punctuation marks are not taken into consideration when calculating position number.

The function accepts the following optional named parameters:

Parameter

Comments

scope:=line/sentence/paragraph/text/table_cell/table_name/table_row_name/table_column_name/heading/page

Specifies a position within a line/sentence/paragraph/text/heading/page.

mode:=forward/backward

Specifies a position from the beginning/end of the scope.

min_pos

Specifies the minimal position of the argument.

max_pos

Specifies the maximal position of the argument.

min_snt

Specifies the minimal sentence number.

max_snt

Specifies the maximal sentence number.

Note

  • By default, the parameters are set to the following values: scope:=text, mode:=forward.

  • The max_pos parameter is equivalent to the first optional argument number.

  • If both min_snt and min_pos parameters are specified, positions will be counted from the beginning of the indicated sentence. The same will occur if both max_snt and max_pos parameters are indicated.

  • If the sentence number is not specified, then the position is calculated from the beginning of the scope parameter.

  • If you need to count positions from the end of sentences, then you should specify negative values for min_pos and max_pos parameters.

  • If you need to count positions from the end of sentences, then you should specify negative values for min_pos and max_pos parameters.

Example

position(1, meeting, scope:=sentence) matches all occurrences of the word "meeting" at the first position in a sentence, e.g. "Meeting Confirmation - Monday, Dec. 11".

position(2, meeting, presentation) matches all occurrences of the words "meeting" or "presentation" if their position is equal to or less than 2 from the beginning of a document, e.g. "Presentation to Causey and AA", "Their presentation was interesting", "VEPCO meeting", "GE meeting on Friday".

position(1, meeting, scope:=sentence, mode:=backward) = position(meeting, scope:=sentence, mode:=backward, max_pos:=1) matches all occurrences of the word "meeting" if it is the last word in a sentence, e.g. "Internal training and awareness team meetings".

position(1, meeting, mode:=backward) = position(meeting, mode:=backward, max_pos:=1, scope:=text) matches all occurrences of the word "meeting" if it is the last word in a text.

position(2, meeting, scope:=sentence, mode:=backward) = position(meeting, scope:=sentence, mode:=backward, max_pos:=2) matches all occurrences of the word "meeting" if its position is equal to or less than 2 from the end of a document, e.g. "New Meeting Location", "German banker calls for special monetary meeting".

position(meeting, min_pos:=2, max_pos:=4, scope:=sentence) matches all occurrences of the word "meeting" if its position from the beginning of a sentence belongs to a closed range [2;4], e.g. "The meeting was hosted by the Partnership for New York City and Time Warner Inc.", "Is this meeting still on?", "VAR and Credit meeting on Wednesday".

position(meeting, min_pos:=3, max_pos:=3, scope:=sentence, mode:=backward) matches all occurrences of the word "meeting" at the third position from the end of a sentence, e.g. "I believe that the meeting was productive".

position(min_snt:=1, min_pos:=1, max_snt:=1, max_pos:=2, mode:=backward) matches the first two words of the last sentence.

position(min_snt:=1, min_pos:="-1") matches tokens starting from the last word of the first sentence.

position(max_pos:=1, scope:=line) matches the first word of each line.

position(scope:=page, max_pos:=1) matches the first word of each page.

position(scope:=page, sentence(), max_snt:=1, mode:=backward) matches the last sentence of the last page.

Task example: Find country names in upper case at the beginning of a document

The query expression position(case(upper, dictword(GeoAdministrative, "category=country")), min_pos:=1, max_pos:=4) matches documents in which country names in upper case occur at the first, second, third, or forth position from the beginning of a text. This may be useful for searching within newspaper articles.

pdl position 1