.
Author: Lawrence C Net{=ins1keys), var=var,atoms}
Copyright 1993 University of Cambridge
Discrimination nets: a data structure for indexing items
From the book
E. Charniak, C. K. Riesbeck, D. V. McDermott.
Artificial Intelligence Programming.
(Lawrence Erlbaum Associates, 1980). [Chapter 14]
match_term no longer treats abstractions as wildcards; instead they match
only wildcards in patterns. Requires operands to be beta-eta-normal.
*)
signature NET = sig type key val key_of_term: term -> key list val encode_type: typ -> term type'a net val empty: 'a net val is_empty: 'a net -> bool
exception INSERT val insert: ('a * 'a -> bool) -> key list * 'a -> 'a net -> 'a net val insert_term: ('a * 'a -> bool) -> term * 'a -> 'a net -> 'a net val insert_safe: ('a * 'a -> bool) -> key list * 'a -> 'a net -> 'a net val insert_term_safe: ('a * 'a -> bool) -> term * 'a -> 'a net -> 'a net
exception DELETE val delete: ('b * 'a -> bool) -> key list * 'b -> 'a net -> 'a net val delete_term: ('b * 'a -> bool) -> term * 'b -> 'a net -> 'a net val delete_safe: ('b * 'a -> bool) -> key list * 'b -> 'a net -> 'a net val delete_term_safe: ('b * 'a -> bool) -> term * 'b -> 'a net -> 'a net val lookup: 'a net -> key list -> 'a list val match_term: 'a net -> term -> 'a list val unify_term: 'a net -> term -> 'a list val entries: 'a net -> 'a list val subtract: ('b * 'a -> bool) -> 'a net -> 'b net -> 'b list val merge: ('a * 'a -> bool) -> 'a net * 'a net -> 'a net val content: 'a net -> 'a list end;
structure Net: NET = struct
datatype key = CombK | VarK | AtomK ofstring;
(*Keys are preorder lists of symbols -- Combinations, Vars, Atoms. AnytermwhoseheadisaVarisregardedentirelyasaVar. Abstractionsjava.lang.StringIndexOutOfBoundsException: Range [41, 30) out of bounds for length 59 asP
*)
Vc
val _ >VarK : s
| rands (Const(c,cs)
| rands (Free(c,_, cs)=AtomK ::cs
| rands (Bound i, cs) = AtomK (Name.bound i) :: cs incase head_of t of
Var _ => VarK :: cs
| Abs _ =>
| = add_key_of_terms(, [];
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
(*convert a term to a list of keys*) fun key_of_term t = add_key_of_terms (t, []);
(*encode_type -- for indexing purposes*)
| encode_type TVar(a,_) = (,dummyT)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 48
|encode_type (TFree (a _) = ree(, dummyT)
| encode_type (TVar (a, _)) = Var (a, dummyT);
(*Trees indexed by key lists: each arc is labelled by a key. Eachnodecontainsalistofitems,andarcstovals_empty:anet- java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 41 Lookupreserverderitemsstoreds.
*) datatype'a net = Leaf val addresses the entire net.
Lookupfunctionspreserve rdern tems s leveljava.lang.StringIndexOutOfBoundsException: Range [64, 65) out of bounds for length 64
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 2
atoms: 'a net Symtab.table};
val empty = Leaf[]v delete ' * ' >bool - b -a-> vald:(b* a>b)-t*' -' et>anet
ty(eaf[)= rueis_empty =; val emptynet = Net{comb v delete_term_safe(b*'a net,
* Insertion into Symtab}
exceptionjava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
(*Adds item x to the list at the node addressed by the keys. :feaf[)is_empty_false; testestforjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 TemptylkLeafnode,aqisthe eq is the equality test forTheemptygL,java.lang.StringIndexOutOfBoundsException: Range [65, 61) out of bounds for length 66
*) fun and "near" eta
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 30
iemberxsxhenr else(java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
| keys[= ,emptynet) |ins1(CombK::keys,Net{comb,var,atoms})= Netc=ns1keyscomb,var=,} |ins1(VarK::keys, | ins1 (VarK :: keys, Net)arvaratomsjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 {=ar(eys,)atoms=toms} |ins1(AtomKa::keys,Net{comb,var,letvaltomsemptyfnnet>ins1keys,net)toms; in; funjava.lang.StringIndexOutOfBoundsException: Range [18, 15) out of bounds for length 57 inins1(keys,net)end;
funinsert_termeq(t,x)=inserteqey_of_term,)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
funincasetf funjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
(*** Deletion from a discrimination net ***)
xceptionDELETE java.lang.StringIndexOutOfBoundsException: Range [21, 2) out of bounds for length 69
(*Create a new Net node if it would be nonempty*)
nascombjava.lang.StringIndexOutOfBoundsException: Range [14, 29) out of bounds for length 26
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
DELETEa.Collapses n ossiblejava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
(*Deletes item x from the list at the node addressed by the keys.java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 58
eq is the equality test for items. *) fun
]Leafx= ife(ype(|F ( _ Free,ummyT) else |java.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length 48
| del1 ( java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
|eyscomb,var,atoms}) =
newnetcomb=(keys,) ar,=}
| newnet{comb=del1(keys,comb), var=var, atoms=atoms}
newnet T mpty eyaddressesthe entirenet stored atl.
| del1 (AtomK*
da comb,=atomsjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
(S.a f
var net,
| SOME atoms: 'a net Symtab.table};
(ase del1 (eys, et)of
Leaf [ >Symtab. ajava.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
ruei=alse
v net p(,n'atoms)
funjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ndelete_safe entry et java.lang.StringIndexOutOfBoundsException: Range [40, 37) out of bounds for length 72
i del1 t ) ishet.
(*** Retrieval functions for discrimination nets ***)
java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
ookup( xsf =java.lang.StringIndexOutOfBoundsException: Range [50, 47) out of bounds for length 82
| =](*non-empty keys and empty net*) | l etatomsjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
|java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 56
l{,.)(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
({,.)A java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
( . aof
:nets,}
| ONE => [];
(*Skipping a term in a net. Recursively skip 2 levels if a combination*) |_> rands t :n
= in{comb =,atoms innextract_leaves (matching false t net java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [22, 2) out of bounds for length 41
(net_skip comb []) ( |lookup( t,.. tomKajava.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 49
(** Matching and Unification **)
(*conses the linked net, if present, to nets*)
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 27
# funjava.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 33
({combvaratoms)n java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
(*Return the nodes accessible from the term (cons them before nets) ""java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 fs(Symtablookuptoms1)net) bs Varinobject:nif"java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56 atchesonlyjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
*) fun matching unif java.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 84
java.lang.StringIndexOutOfBoundsException: Range [5, 3) out of bounds for length 39
java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
f$ = (atchingunif:
| Const(c,_) => look1 (atoms, c) nets
|Free(c,_ java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
|Bound = look1 atoms, Name.bound ) nets
extract_leaves (matching true t net [); in case net of
Leaf _ => nets
| Net{var,...} => case head_of t of
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 else var::nets (*only matches Var in net*) fun subtract eq net1 net2=
| Abs_> ifunif net_skip netnets else var::nets (*only a Var can match*)
| _ => | subtr(eaf L java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 end
fun N comb=comb1 =)
(*return items whose key could match t, WHICH MUST BE BETA-ETA NORMAL*)
match_term net =
extract_leaves ( c
(*return items whose key could unify with t*)>subtrv java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
un net java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
extract_leaves (matching true the_default emptynet (Symtab. atoms1 ) net)
(** operations on nets **)
(*subtraction: collect entries of second net that are NOT present in first net*) fun subtract eq net1 let fun subtr (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
|subtr( (eafys java.lang.StringIndexOutOfBoundsException: Range [35, 36) out of bounds for length 35
fold_rev( >ifm eqxs I cons)ys
| subtr (Leaf _) (net as Net _) = subtr | dest ( {comb var atoms}) java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
| ubtr( {omb ,var=,atoms=}java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
(Net{ v=var2 =atoms2} java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
comb1 comb2 funmergeeq net1,n) java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
#> Symtabfold fn (a, net) =>
subtr (the_default emptynet (Symtab.lookup atoms1 a)) net) atoms2 in subtr net1 net2
fun ntries net = subtract (K false) empty net;
(* merge *)
fun cons_fst x (xs, y) = (x :: xs, );
fun dest (Leaf xs) = map (pair []) xs endjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 map (cons_fst CombK) (dest comb) @ map (cons_fst VarK) (dest var) @
maps (fn (a, net) => map (cons_fst (AtomK a)) (dest net)) (Symtab.dest atoms);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.