OK. I gave it some thought, and here is one way to construct a basic graph from some text using the SDB. Basically I built a simple parser. The structure is as follows:
- map layer
- equality layer
- merge layer
- less than layer
- cast layer
- learn layer
In particular, putting it all together we invoke it using:
(yeah, once you have defined your operators, operator sequences can be quite clean!)
our |result> => learn-layer sdrop cast-layer less-than-layer^2 merge-layer equality-layer map ssplit[" "] the |sentence>
Now for a brief discussion of the details of this algo:
First, map-layer, maps words to tagged/typed kets (otherwise known as parts-of-speech).
eg:
map |frog> => |noun: frog>
map |green> => |colour: green>
map |seven> => |number: seven>
The code does this by defining a bunch of lists, and then prepending the relevant type to objects in that list. Note, this toy code does not handle the case where a word has more than one type. I’m not sure the cleanest way to handle that problem! And in the real world, that is almost always the case.
Next, the equality-layer, merges objects with the same type:
(If more than two in a row, merge them all together)
|A: alpha> . |A: beta> maps to |A: alpha beta>
eg:
|proper-noun: Fred> . |proper-noun: Smith> maps to |proper-noun: Fred Smith>
Next, the merge-layer:
|noun> . |of> . |noun> maps to |noun>
|number> . |and> . |number> maps to |number>
|colour> . |and> . |colour> maps to |colour>
eg:
|colour: red> . |and: and> . |colour: green> maps to |colour: red and green>
Next, the less-than layer:
(see the appendix where we define the relations for types)
If A < B then:
|A: alpha> . |B: beta> maps to |B: beta>
and we learn: A |beta> +=> |alpha>
eg:
|colour: green> . |noun: apple> maps to |noun: apple>
and we learn: colour |apple> +=> |green>
Next, the cast-layer:
|noun> . |comma> . |noun> maps to |protolist>
|protolist> . |comma> . |noun> maps to |protolist>
|protolist> . |and> . |noun> maps to |protolist>
|noun> . |verb> . |noun> maps to |NVN>
Finally, the learn-layer, using some if-then machines:
If we see the pattern: |*> . |is> . |*>
then learn: is |alpha> +=> |gamma>
If we see the pattern |*> . |was> . |*>
then learn: was |alpha> +=> |gamma>
If we see the pattern |proper-noun> . |comma> . |proper-noun>
then learn: where |alpha> +=> |gamma>
And so on for other patterns of interest.
With this basic parser in place, we have results such as:
the |sentence> => |The capital city of Western Australia is Perth #EOS#>
produces:
pre|capital city of Western Australia> => |The>
is|capital city of Western Australia> => |Perth>
And given this sentence:
the |sentence> => |Sydney comma New South Wales #EOS#>
produces:
map|Sydney> => |proper-noun: Sydney>
where|Sydney> => |New South Wales>
And finally, given this sentence:
the |sentence> => |The example listy is one thousand two hundred and thirty two red and blue green fish comma thirty three sharks comma eel and turtle #EOS#>
produces:
map |listy> => |noun: listy>
adj |listy> => |example>
pre |listy> => |The>
is |listy> => |fish comma sharks comma eel and turtle>
map |fish> => |noun: fish>
colour |fish> => |red and blue green>
number |fish> => |one thousand two hundred and thirty two>
map|sharks> => |noun: sharks>
number |sharks> => |thirty three>
Anyway, just a quick taste of an idea.
Appendix: Here are our grammar rules, just add more as needed:
relation-1 |noun __ noun> => |equal>
relation-1 |proper-noun __ proper-noun> => |equal>
relation-1 |adj __ adj> => |equal>
relation-1 |number __ number> => |equal>
relation-1 |colour __ colour> => |equal>
relation-2 |adj __ noun> => |less than>
relation-2 |pre __ noun> => |less than>
relation-2 |number __ noun> => |less than>
relation-2 |colour __ noun> => |less than>
relation-2 |title __ proper-noun> => |less than>
type-1 |number __ and __ number> => |number>
type-1 |colour __ and __ colour> => |colour>
type-1 |noun __ of __ noun> => |noun>
type-1 |noun __ of __ proper-noun> => |noun>
type-2 |noun __ comma __ noun> => |protolist>
type-2 |protolist __ comma __ noun> => |protolist>
type-2 |protolist __ and __ noun> => |protolist>
type-2 |noun __ verb __ noun> => |NVN>
And here are our if-then machines:
(again, define more as required)
template |node: 1: 1> => |*> . |is> . |*>
then |node: 1: *> #=>
is sselect[1,1] the |values> +=> sselect[-1,-1] the |values>
template |node: 2: 1> => |*> . |was> . |*>
then |node: 2: *> #=>
was sselect[1,1] the |values> +=> sselect[-1,-1] the |values>
template |node: 3: 1> => |proper-noun> . |comma> . |proper-noun>
then |node: 3: *> #=>
where sselect[1,1] the |values> +=> sselect[-1,-1] the |values>