If you want winner takes all, we can do that too, just apply the desired filter/operator to the results. There are at least 3 approaches we can take:
- select the top matching result
- drop all the results below some threshold t using the drop-below[t] operator
- use exact matches (equal-input[pattern]), rather than the similar-input[pattern] operator
Here is the updated code:
pattern |node: 1> => |b> . |o> . |a>
matching-word |node: 1> => |boa>
pattern |node: 2> => |b> . |o> . |a> . |r>
matching-word |node: 2> => |boar>
pattern |node: 3> => |b> . |o> . |a> . |r> . |d>
matching-word |node: 3> => |board>
pattern |node: 4> => |b> . |o> . |a> . |t>
matching-word |node: 4> => |boat>
print | >
print |No filtering:>
sprint["input b: "] matching-word similar-input[pattern] ssplit |b>
sprint["input bo: "] matching-word similar-input[pattern] ssplit |bo>
sprint["input boa: "] matching-word similar-input[pattern] ssplit |boa>
sprint["input boar: "] matching-word similar-input[pattern] ssplit |boar>
sprint["input board: "] matching-word similar-input[pattern] ssplit |board>
sprint["input boat: "] matching-word similar-input[pattern] ssplit |boat>
print | >
print |Select top matching result:>
sprint["input b: "] select[1,1] matching-word similar-input[pattern] ssplit |b>
sprint["input bo: "] select[1,1] matching-word similar-input[pattern] ssplit |bo>
sprint["input boa: "] select[1,1] matching-word similar-input[pattern] ssplit |boa>
sprint["input boar: "] select[1,1] matching-word similar-input[pattern] ssplit |boar>
sprint["input board: "] select[1,1] matching-word similar-input[pattern] ssplit |board>
sprint["input boat: "] select[1,1] matching-word similar-input[pattern] ssplit |boat>
print | >
print |Drop below a threshold, eg t = 0.9:>
sprint["input b: "] drop-below[0.9] matching-word similar-input[pattern] ssplit |b>
sprint["input bo: "] drop-below[0.9] matching-word similar-input[pattern] ssplit |bo>
sprint["input boa: "] drop-below[0.9] matching-word similar-input[pattern] ssplit |boa>
sprint["input boar: "] drop-below[0.9] matching-word similar-input[pattern] ssplit |boar>
sprint["input board: "] drop-below[0.9] matching-word similar-input[pattern] ssplit |board>
sprint["input boat: "] drop-below[0.9] matching-word similar-input[pattern] ssplit |boat>
print | >
print |Only display exact matches:>
sprint["input b: "] matching-word equal-input[pattern] ssplit |b>
sprint["input bo: "] matching-word equal-input[pattern] ssplit |bo>
sprint["input boa: "] matching-word equal-input[pattern] ssplit |boa>
sprint["input boar: "] matching-word equal-input[pattern] ssplit |boar>
sprint["input board: "] matching-word equal-input[pattern] ssplit |board>
sprint["input boat: "] matching-word equal-input[pattern] ssplit |boat>
With the corresponding output:
No filtering:
input b: 0.333333|boa> + 0.250000|boar> + 0.250000|boat> + 0.200000|board>
input bo: 0.666667|boa> + 0.500000|boar> + 0.500000|boat> + 0.400000|board>
input boa: |boa> + 0.750000|boar> + 0.750000|boat> + 0.600000|board>
input boar: |boar> + 0.800000|board> + 0.750000|boa> + 0.750000|boat>
input board: |board> + 0.800000|boar> + 0.600000|boa> + 0.600000|boat>
input boat: |boat> + 0.750000|boa> + 0.750000|boar> + 0.600000|board>
Select top matching result:
input b: 0.333333|boa>
input bo: 0.666667|boa>
input boa: |boa>
input boar: |boar>
input board: |board>
input boat: |boat>
Drop below a threshold, eg t = 0.9:
input b: |>
input bo: |>
input boa: |boa>
input boar: |boar>
input board: |board>
input boat: |boat>
Only display exact matches:
input b: |>
input bo: |>
input boa: |boa>
input boar: |boar>
input board: |board>
input boat: |boat>
With the note that superpositions are by their nature sparse, and that includes being able to be “empty”. We represent empty superpositions using the so called empty ket |>. The empty ket has the property of being the identity element for ket/superposition addition, in the sense that if you add an “empty” superposition to another superposition that superposition remains unchanged (cf: 0 + a = a + 0 = a).
In the above example we see that if our filters are too strict we get the empty ket as a result. So in the example we need to keep providing input until we have enough information for our filters to return something other than the empty ket. And, we have the do-you-know operator that tells us if we have an empty ket or not.