But I have to say I'm not as displeased with the look and feel of the string version as I had thought I would be, so I think this is the version I'll extend.
Standard disclaimers: as-is, no warranty or implied fitness, use at your own risk.
open System.Collections.Generic
type Rel () =
let store =
new Dictionary<string,Dictionary<string,HashSet<string>>>()
member private this.TryAdd
((n0,l,n1):string*string*string) =
let d =
match store.TryGetValue n0 with
| (true,d0) -> d0
| (false,_) ->
let d0 = new Dictionary<string,HashSet<string>>()
store.Add(n0,d0)
d0
let h =
match d.TryGetValue l with
| (true,h0) -> h0
| (false,_) ->
let h0 = new HashSet<string>()
d.Add(l,h0)
h0
h.Add n1 |> ignore
static member (+=)
((r:Rel),((nln):string*string*string)) =
r.TryAdd nln
r
let r = Rel()
r += ("mammal","isA","animal") |> ignore
r += ("dog","isA","mammal") |> ignore
r += ("spot","isA","dog") += ("spot","isA","pet") |> ignore
No comments:
Post a Comment