2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								! Copyright (C) 2008 Alex Chapman 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								! See http://factorcode.org/license.txt for BSD license. 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								USING:  accessors  arrays  combinators  combinators.cleave  combinators.lib 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-27 23:44:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								continuations db db.tuples db.types db.sqlite kernel math
							 
						 
					
						
							
								
									
										
										
										
											2008-06-25 04:25:08 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								math.parser namespaces parser lexer sets sequences sequences.deep
							 
						 
					
						
							
								
									
										
										
										
											2008-05-15 00:23:12 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								sequences.lib strings words destructors ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								IN:  semantic-db 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								TUPLE:  node  id  content  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								C:  <node>  node 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-06 07:54:16 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								node "node" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{
							 
						 
					
						
							
								
									
										
										
										
											2008-04-28 18:38:12 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { "id"  "id"  +db-assigned-id+ +autoincrement+ }
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    { "content"  "content"  TEXT }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} define-persistent
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-04-30 20:11:19 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  delete-node  (  node  --  )  delete-tuples ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  create-node  (  content  --  node  )  f  swap  <node> dup  insert-tuple ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  load-node  (  id  --  node  )  f  <node> select-tuple ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  node-content  (  node  --  content  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    dup  content>> [ nip  ] [ select-tuple content>> ] if*  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-06 07:54:16 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-04-08 19:22:12 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  node=  (  node  node  --  ?  )  [ id>> ] bi@  =  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								! TODO: get rid of arc id and write our own sql 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TUPLE:  arc  id  subject  object  relation  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  <arc>  (  subject  object  relation  --  arc  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-27 23:44:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    arc new  swap  >>relation swap  >>object swap  >>subject ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-06 07:54:16 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  <id-arc>  (  id  --  arc  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-13 16:06:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    arc new  swap  >>id ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-06 07:54:16 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-04-30 20:11:19 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  delete-arc  (  arc  --  )  delete-tuples ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-06 07:54:16 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  create-arc  (  subject  object  relation  --  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-06-27 03:17:19 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    [ id>> ] tri@  <arc> insert-tuple ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-06 07:54:16 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  nodes>arc  (  subject  object  relation  --  arc  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-06-27 03:17:19 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    [ [ id>> ] [ f  ] if*  ] tri@  <arc> ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  select-arcs  (  subject  object  relation  --  arcs  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    nodes>arc select-tuples ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  has-arc?  (  subject  object  relation  --  ?  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    select-arcs length  0  >  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  select-arc-subjects  (  subject  object  relation  --  subjects  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    select-arcs [ subject>> f  <node> ] map  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  select-arc-subject  (  subject  object  relation  --  subject  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    select-arcs ?first  [ subject>> f  <node> ] [ f  ] if*  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  select-subjects  (  object  relation  --  subjects  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-25 02:38:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    f  -rot  select-arc-subjects ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  select-subject  (  object  relation  --  subject  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    f  -rot  select-arc-subject ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  select-arc-objects  (  subject  object  relation  --  objects  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    select-arcs [ object>> f  <node> ] map  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  select-arc-object  (  subject  object  relation  --  object  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    select-arcs ?first  [ object>> f  <node> ] [ f  ] if*  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  select-objects  (  subject  relation  --  objects  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-25 02:38:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    f  swap  select-arc-objects ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  select-object  (  subject  relation  --  object  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    f  swap  select-arc-object ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  delete-arcs  (  subject  object  relation  --  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    select-arcs [ delete-arc ] each  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								arc "arc" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{
							 
						 
					
						
							
								
									
										
										
										
											2008-04-30 20:11:19 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { "id"  "id"  +db-assigned-id+ +autoincrement+ }
							 
						 
					
						
							
								
									
										
										
										
											2008-02-28 21:51:59 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { "relation"  "relation"  INTEGER +not-null+ }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { "subject"  "subject"  INTEGER +not-null+ }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { "object"  "object"  INTEGER +not-null+ }
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} define-persistent
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  create-bootstrap-nodes  (  --  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "semantic-db"  create-node drop
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "has-context"  create-node drop  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 20:37:51 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  semantic-db-context   T{ node f  1  "semantic-db"  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  has-context-relation  T{ node f  2  "has-context"  } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 20:37:51 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								:  create-bootstrap-arcs  (  --  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    has-context-relation semantic-db-context has-context-relation create-arc ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  init-semantic-db  (  --  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    node create-table arc create-table
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    create-bootstrap-nodes create-bootstrap-arcs ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-18 20:12:10 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								! db utilities 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  results  (  bindings  sql  --  array  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    f  f  <simple-statement> [ do-bound-query ] with-disposal ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 20:37:51 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  node-result  (  result  --  node  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    dup  first  string>number swap  second  <node> ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  ?1node-result  (  results  --  node  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ?first  [ node-result ] [ f  ] if*  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-10 20:44:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  node-results  (  results  --  nodes  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    [ node-result ] map  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-28 21:51:59 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  param  (  value  key  type  --  param  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-21 17:55:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    swapd  <sqlite-low-level-binding> ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 20:37:51 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-05-02 01:46:21 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  all-node-ids  (  --  seq  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    f  "select n.id from node n"  results [ first  string>number ] map  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  subjects-with-cor  (  content  object  relation  --  sql-results  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 22:41:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    [ id>> ] bi@
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ":relation"  INTEGER param ,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ":object"  INTEGER param ,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ":content"  TEXT param ,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] { } make
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "select n.id, n.content from node n, arc a where n.content = :content and n.id = a.subject and a.relation = :relation and a.object = :object"  results ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  objects-with-csr  (  content  subject  relation  --  sql-results  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 22:41:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    [ id>> ] bi@
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    [
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        ":relation"  INTEGER param ,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ":subject"  INTEGER param ,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ":content"  TEXT param ,
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ] { } make
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "select n.id, n.content from node n, arc a where n.content = :content and n.id = a.object and a.relation = :relation and a.subject = :subject"  results ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  (with-relation)  (  content  relation  --  bindings  sql  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    id>> [ ":relation"  INTEGER param , ":content"  TEXT param , ] { } make
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "select distinct n.id, n.content from node n, arc a where n.content = :content and a.relation = :relation"  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  subjects-with-relation  (  content  relation  --  sql-results  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    (with-relation) " and a.object = n.id"  append  results ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  objects-with-relation  (  content  relation  --  sql-results  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    (with-relation) " and a.subject = n.id"  append  results ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  (ultimate)  (  relation  b  a  --  sql-results  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "select distinct n.id, n.content from node n, arc a where a.relation = :relation and n.id = a."  % % " and n.id not in (select b."  % % " from arc b where b.relation = :relation)"  %
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] ""  make [ id>> ":relation"  INTEGER param 1array  ] dip  results ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  ultimate-objects  (  relation  --  sql-results  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "subject"  "object"  (ultimate) ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  ultimate-subjects  (  relation  --  sql-results  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "object"  "subject"  (ultimate) ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								! contexts: 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								!  - a node n is a context iff there exists a relation r such that r has context n 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  create-context  (  context-name  --  context  )  create-node ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  get-context  (  context-name  --  context/f  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    has-context-relation subjects-with-relation ?1node-result ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  ensure-context  (  context-name  --  context  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    dup  get-context [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        nip
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        create-context
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] if*  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								! relations: 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								!  - have a context in context 'semantic-db' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  create-relation  (  relation-name  context  --  relation  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    [ create-node dup  ] dip  has-context-relation create-arc ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  get-relation  (  relation-name  context  --  relation/f  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    has-context-relation subjects-with-cor ?1node-result ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  ensure-relation  (  relation-name  context  --  relation  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    2dup  get-relation [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        2nip
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        create-relation
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] if*  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-25 02:38:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TUPLE:  relation-definition  relate  id-word  unrelate  related?  subjects  objects  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								C:  <relation-definition>  relation-definition 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								<PRIVATE
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-06-28 03:36:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  default-word-name  (  relate-word-name  word-type  --  name>>  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-25 02:38:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { "relate"  [ ] }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { "id-word"  [ "-relation"  append  ] }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { "unrelate"  [ "!"  swap  append  ] }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { "related?"  [ "?"  append  ] }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { "subjects"  [ "-subjects"  append  ] }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { "objects"  [ "-objects"  append  ] }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } case  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-06-28 03:36:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  choose-word-name  (  relation-definition  given-word-name  word-type  --  name>>  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-25 02:38:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    over  string?  [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        drop  nip
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        nip  [ relate>> ] dip  default-word-name
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] if  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-06-28 03:36:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  (define-relation-word)  (  id-word  name>>  definition  --  id-word  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-25 02:38:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    >r create-in over  [ execute  ] curry  r> compose  define ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  define-relation-word  (  relation-definition  id-word  given-word-name  word-type  definition  --  relation-definition  id-word  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    >r >r [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        pick  swap  r> choose-word-name r> (define-relation-word)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        r> r> 2drop
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] if*   ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  define-relation-words  (  relation-definition  id-word  --  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    over  relate>> "relate"  [ create-arc ] define-relation-word
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    over  unrelate>> "unrelate"  [ delete-arcs ] define-relation-word
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    over  related?>> "related?"  [ has-arc? ] define-relation-word
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    over  subjects>> "subjects"  [ select-subjects ] define-relation-word
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    over  objects>> "objects"  [ select-objects ] define-relation-word
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    2drop  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  define-id-word  (  relation-definition  id-word  --  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-06-28 03:36:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    [ relate>> ] dip  tuck vocabulary>>
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    [ ensure-context ensure-relation ] 2curry  define ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-25 02:38:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  create-id-word  (  relation-definition  --  id-word  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    dup  id-word>> "id-word"  choose-word-name create-in ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								PRIVATE>
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  define-relation  (  relation-definition  --  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    dup  create-id-word 2dup  define-id-word define-relation-words ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  RELATION: 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-25 02:38:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    scan t  t  t  t  t  <relation-definition> define-relation ;  parsing
							 
						 
					
						
							
								
									
										
										
										
											2008-03-20 11:01:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								! hierarchy 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								TUPLE:  node-tree  node  children  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								C:  <node-tree>  node-tree 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  children  (  node  has-parent-relation  --  children  )  select-subjects ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  parents  (  node  has-parent-relation  --  parents  )  select-objects ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  get-node-tree  (  node  child-selector  --  node-tree  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    2dup  call  >r [ get-node-tree ] curry  r> swap  map  <node-tree> ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								! : get-node-tree ( node has-parent-relation -- node-tree ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								!     2dup children >r [ get-node-tree ] curry r> swap map <node-tree> ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  get-node-tree-s  (  node  has-parent-relation  --  tree  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    [ select-subjects ] curry  get-node-tree ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  get-node-tree-o  (  node  has-child-relation  --  tree  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    [ select-objects ] curry  get-node-tree ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  (get-node-chain)  (  node  next-selector  seq  --  seq  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    pick  [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        over  push  >r [ call  ] keep  r> (get-node-chain)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        2nip
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] if*  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								:  get-node-chain  (  node  next-selector  --  seq  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    V{ } clone  (get-node-chain) ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  get-node-chain-o  (  node  relation  --  seq  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    [ select-object ] curry  get-node-chain ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  get-node-chain-s  (  node  relation  --  seq  )
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    [ select-subject ] curry  get-node-chain ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  (get-root-nodes)  (  node  has-parent-relation  --  root-nodes/node  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    2dup  parents dup  empty?  [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        2drop
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        >r nip  [ (get-root-nodes) ] curry  r> swap  map
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] if  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-31 21:07:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								:  get-root-nodes  (  node  has-parent-relation  --  root-nodes  )
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 06:22:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    (get-root-nodes) flatten prune ;