]> gitweb.factorcode.org Git - factor.git/commitdiff
semantic-db: committing latest changes
authorAlex Chapman <chapman.alex@gmail.com>
Sun, 16 Mar 2008 01:41:13 +0000 (12:41 +1100)
committerAlex Chapman <chapman.alex@gmail.com>
Sun, 16 Mar 2008 01:41:13 +0000 (12:41 +1100)
extra/semantic-db/context/context.factor
extra/semantic-db/hierarchy/hierarchy.factor
extra/semantic-db/membership/membership.factor [new file with mode: 0644]
extra/semantic-db/relations/relations.factor
extra/semantic-db/semantic-db-tests.factor

index 777c481ebb2378543e299068b89091d21790ca66..9d2e175b5e455a863c75130730d14a6988727d73 100644 (file)
@@ -6,11 +6,5 @@ IN: semantic-db.context
 : create-context* ( context-name -- context-id ) create-node* ;
 : create-context ( context-name -- ) create-context* drop ;
 
-: context ( -- context-id )
-    \ context get ;
+SYMBOL: context
 
-: set-context ( context-id -- )
-    \ context set ;
-
-: with-context ( context-id quot -- )
-    >r \ context r> with-variable ;
index be0789ba5e07138426dd772ced4be1160782c451..f180ddb5df2e209eac2f052ba427cdc36151c139 100644 (file)
@@ -1,32 +1,31 @@
 ! Copyright (C) 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors db.tuples hashtables kernel new-slots
+USING: accessors db.tuples hashtables kernel namespaces new-slots
 semantic-db semantic-db.relations sequences sequences.deep ;
 IN: semantic-db.hierarchy
 
 TUPLE: tree id children ;
 C: <tree> tree
 
-: has-parent-relation ( -- relation-id )
-    "has parent" relation-id ;
+SYMBOL: has-parent-relation
 
 : parent-child* ( parent child -- arc-id )
-    has-parent-relation spin create-arc* ;
+    has-parent-relation get spin create-arc* ;
 
 : parent-child ( parent child -- )
     parent-child* drop ;
 
 : un-parent-child ( parent child -- )
-    has-parent-relation spin <arc> select-tuples [ id>> delete-arc ] each ;
+    has-parent-relation get spin <arc> select-tuples [ id>> delete-arc ] each ;
 
 : child-arcs ( node-id -- child-arcs )
-    has-parent-relation f rot <arc> select-tuples ;
+    has-parent-relation get f rot <arc> select-tuples ;
 
 : children ( node-id -- children )
     child-arcs [ subject>> ] map ;
 
 : parent-arcs ( node-id -- parent-arcs )
-    has-parent-relation swap f <arc> select-tuples ;
+    has-parent-relation get swap f <arc> select-tuples ;
 
 : parents ( node-id -- parents )
      parent-arcs [ object>> ] map ;
diff --git a/extra/semantic-db/membership/membership.factor b/extra/semantic-db/membership/membership.factor
new file mode 100644 (file)
index 0000000..c386922
--- /dev/null
@@ -0,0 +1,6 @@
+! Copyright (C) 2008 Alex Chapman
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors kernel new-slots semantic-db semantic-db.relations ;
+IN: semantic-db.membership
+
+
index 17c335c4aef7d7abb90b2601f878c1396cdc9a97..58003c9e9db2dc1910e636128ccad5c708f14e47 100644 (file)
@@ -23,4 +23,4 @@ IN: semantic-db.relations
     single-int-results ?first ;
 
 : relation-id ( relation-name -- relation-id )
-    context swap [ get-relation ] [ create-relation* ] ensure2 ;
+    context get swap [ get-relation ] [ create-relation* ] ensure2 ;
index 257133c67ff72e190978da421f0fdcb03053c3bf..fad2ea633207a9bbfbce4e444160980dbfe0b339 100644 (file)
@@ -24,16 +24,15 @@ delete-db
 
 test-db [
     init-semantic-db
-    "test content" create-context* [
-        [ 4 ] [ context ] unit-test
-        [ 5 ] [ context "is test content" create-relation* ] unit-test
-        [ 5 ] [ context "is test content" get-relation ] unit-test
-        [ 5 ] [ "is test content" relation-id ] unit-test
-        [ 7 ] [ "has parent" relation-id ] unit-test
-        [ 7 ] [ "has parent" relation-id ] unit-test
-        [ "has parent" ] [ "has parent" relation-id node-content ] unit-test
-        [ "test content" ] [ context node-content ] unit-test
-    ] with-context
+    "test content" create-context* context set
+    [ 4 ] [ context get ] unit-test
+    [ 5 ] [ context get "is test content" create-relation* ] unit-test
+    [ 5 ] [ context get "is test content" get-relation ] unit-test
+    [ 5 ] [ "is test content" relation-id ] unit-test
+    [ 7 ] [ "has parent" relation-id ] unit-test
+    [ 7 ] [ "has parent" relation-id ] unit-test
+    [ "has parent" ] [ "has parent" relation-id node-content ] unit-test
+    [ "test content" ] [ context get node-content ] unit-test
     ! type-type 1array [ "type" ensure-type ] unit-test
     ! [ { 1 2 3 } ] [ type-type select-nodes-of-type ] unit-test
     ! [ 1 ] [ type-type select-node-of-type ] unit-test
@@ -52,21 +51,21 @@ delete-db
 ! test hierarchy
 test-db [
     init-semantic-db
-    "family tree" create-context* [
-        "adam" create-node* "adam" set
-        "eve" create-node* "eve" set
-        "bob" create-node* "bob" set
-        "fran" create-node* "fran" set
-        "charlie" create-node* "charlie" set
-        "gertrude" create-node* "gertrude" set
-        [ t ] [ "adam" get "bob" get parent-child* integer? ] unit-test
-        { { "eve" "bob" } { "eve" "fran" } { "bob" "gertrude" } { "bob" "fran" } { "fran" "charlie" } } [ first2 [ get ] 2apply parent-child ] each
-        [ { "bob" "fran" } ] [ "eve" get children [ node-content ] map ] unit-test
-        [ { "adam" "eve" } ] [ "bob" get parents [ node-content ] map ] unit-test
-        [ "fran" { "charlie" } ] [ "fran" get get-node-hierarchy dup tree-id node-content swap tree-children [ tree-id node-content ] map ] unit-test
-        [ { "adam" "eve" } ] [ "charlie" get get-root-nodes [ node-content ] map natural-sort >array ] unit-test
-        [ { } ] [ "fran" get "charlie" get tuck un-parent-child parents [ node-content ] map ] unit-test
-    ] with-context
+    "family tree" create-context* context set
+    "has parent" relation-id has-parent-relation set
+    "adam" create-node* "adam" set
+    "eve" create-node* "eve" set
+    "bob" create-node* "bob" set
+    "fran" create-node* "fran" set
+    "charlie" create-node* "charlie" set
+    "gertrude" create-node* "gertrude" set
+    [ t ] [ "adam" get "bob" get parent-child* integer? ] unit-test
+    { { "eve" "bob" } { "eve" "fran" } { "bob" "gertrude" } { "bob" "fran" } { "fran" "charlie" } } [ first2 [ get ] 2apply parent-child ] each
+    [ { "bob" "fran" } ] [ "eve" get children [ node-content ] map ] unit-test
+    [ { "adam" "eve" } ] [ "bob" get parents [ node-content ] map ] unit-test
+    [ "fran" { "charlie" } ] [ "fran" get get-node-hierarchy dup tree-id node-content swap tree-children [ tree-id node-content ] map ] unit-test
+    [ { "adam" "eve" } ] [ "charlie" get get-root-nodes [ node-content ] map natural-sort >array ] unit-test
+    [ { } ] [ "fran" get "charlie" get tuck un-parent-child parents [ node-content ] map ] unit-test
 ] with-db
 
 delete-db