# Split a scanned packet into documents

Split a stack of scanned pages into documents. `choose` says what kind each page is. `decide` marks where a new document starts.

*Three invoice pages and one notice.*

```
question="What kind of page is this?"
kinds=(
  invoice
  notice
)

cat <<'EOF' |
Invoice 7 for Northwind. Page 1 of 2.
Invoice 7 for Northwind. Page 2 of 2. Total due $1,200.
Invoice 8 for Contoso. Page 1 of 1. Total due $310.
Notice to all customers. Page 1 of 1. New terms from May 1.
EOF
thinkthen choose "$question" "${kinds[@]}" \
  --batch 1 \
  --lines \
  --raw
```

*Output*

```
invoice
invoice
invoice
notice
```

*exit 0: the run finished*

*awk pairs each page with the one before it. The two pages of Invoice 7 stay together. A new document starts at Invoice 8 and at the notice.*

```
question="Are the two sides from different documents?"

cat <<'EOF' |
Invoice 7 for Northwind. Page 1 of 2.
Invoice 7 for Northwind. Page 2 of 2. Total due $1,200.
Invoice 8 for Contoso. Page 1 of 1. Total due $310.
Notice to all customers. Page 1 of 1. New terms from May 1.
EOF
awk 'NR > 1 { print last " | " $0 } { last = $0 }' |
thinkthen decide "$question" --batch 1 --lines |
jq .value
```

*Output*

```
false
true
true
```

*exit 0*

## The functions it uses

- [choose](/functions/choose/): Pick one option from your list.

- [decide](/functions/decide/): Answer one yes or no question about the evidence.

On GitHub: [github.com/botassembly/thinkthen](https://github.com/botassembly/thinkthen)
