Advanced

Phrase queries from positions

A phrase is words that must be neighbours. Neighbours is a claim about positions, and the claim is only possible because the positions were kept.

What you will see

empty honest. The words are there and the order is not, which is the failure.

About 1 min of reading

Try It

Prove a neighbour claim

1

Write two positions

printf 'red 2\nfish 3\n' | awk '{print $2}' | awk 'NR==1{a=$1} NR==2{print $1-a}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
1. The difference is one, which is the phrase claim.
2

Write the near limit

printf 'near_max 5\n' > /tmp/k.txt; cat /tmp/k.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
near_max 5. The number is written, which is the rule.
3

Refuse a wrong order

printf 'fish 1 red 3\n' | awk '{d=$2-1} END{print (d==1) ? "phrase" : "empty honest"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
empty honest. The words are there and the order is not, which is the failure.

Data Flow

Positions to a phrase answer
1 The words narrow the documents first
↓
2 Each document positions are read
↓
3 A difference of one is the phrase
↓
4 A wider difference is a written number
Why this works
Why the positions are stored per document

The posting holds the positions of that document. Holding them per document is what keeps the list small enough to walk.

The failure of a phrase

The words are there and the order is not. The answer is empty, and the empty is honest because the positions were checked.

Examples

The difference is one

The next position minus this position. One is the claim, and the claim is the whole of a phrase.

Near is a wider claim

The difference is at most a number. The number is written, and a written number is a rule.

A phrase is checked after the words

The words narrow first. Narrowing first is cheaper, and cheaper is the reason for the order.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Word weight from the library
Previous Lesson
Word weight from the library
Next Lesson
Paging an answer that is long
Paging an answer that is long →