factor/extra/semantic-db/hierarchy/hierarchy.factor

28 lines
749 B
Factor
Raw Normal View History

2008-02-18 20:12:10 -05:00
! Copyright (C) 2008 Alex Chapman
! See http://factorcode.org/license.txt for BSD license.
2008-02-21 04:44:15 -05:00
USING: accessors kernel new-slots semantic-db semantic-db.context sequences ;
2008-02-18 20:12:10 -05:00
IN: semantic-db.hierarchy
2008-02-21 04:44:15 -05:00
TUPLE: tree id children ;
C: <tree> tree
2008-02-18 20:12:10 -05:00
2008-02-21 04:44:15 -05:00
: hierarchy-context ( -- context-id )
"hierarchy" ensure-context ;
: has-parent-relation ( -- relation-id )
! find an arc with:
! type = relation (in semantic-db context)
! context = hierarchy
! name = "has parent"
;
: find-children ( node-id -- children )
! find arcs with:
! relation = has-parent-relation
! object = node-id
! then load the subjects either as nodes or subtrees
;
: get-node-hierarchy ( node-id -- tree )
dup find-children <tree> ;