This repository has been archived on 2019-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
features-tree/phonetics-feature-tree.scm

104 lines
3.0 KiB
Scheme
Raw Normal View History

2019-07-16 17:33:09 +00:00
(define (declare-node node-text node-generation)
(string-append ;; "node"
(number->string node-generation)
"[label=\""
node-text
"\"];\n"))
2019-06-27 11:05:54 +00:00
2019-07-16 17:33:09 +00:00
(define (make-link previous-node current-node)
(string-append ;; "node"
(number->string previous-node)
" -- "
;; "node"
(number->string current-node)
";\n"))
2019-06-27 11:05:54 +00:00
2019-07-16 17:33:09 +00:00
(define (tree-to-dot-helper tree current-generation previous-generation)
;; Helper to ~tree-to-dot~ that translates a Scheme tree with any number of
;; children per node to a corresponding graphviz file that can be executed from
;; dot.
;; Arguments:
;; - tree :: tree to convert
;; - current-generation :: Generation number, incremented when changing from a node
;; to another node from the same generation, multiplied by 10 when going from
;; a node to one of its children.
;; - previous-generation :: Generation number from previous named node
(cond ((null? tree) "")
((atom? (car tree)) ;; '("text" () () ())
(string-append (declare-node (car tree) current-generation)
(make-link previous-generation current-generation)
(tree-to-dot-helper (cdr tree)
(+ 1 (* 10 current-generation))
current-generation)))
((list? (car tree)) ;; '(() () () ())
(string-append (tree-to-dot-helper (car tree) ;; child of current node
current-generation
previous-generation)
(tree-to-dot-helper (cdr tree) ;; sibling of current node
(+ 1 current-generation)
previous-generation)))))
2019-06-27 11:05:54 +00:00
2019-07-16 17:33:09 +00:00
(define (tree-to-dot tree)
;; Returns a graphvizs dot-compatible string representing a Scheme tree
(if (null? tree) ""
(string-append
"graph{node[shape=plaintext];graph[bgcolor=\"transparent\"];\n"
(declare-node (car tree) 0)
(tree-to-dot-helper (cdr tree) 1 0)
2019-06-27 11:05:54 +00:00
"}")))
(define vowel-tree
'("[vowel]"
("[back]"
("[tense]"
2019-07-16 17:33:09 +00:00
("[high]")
("{high}"))
2019-06-27 11:05:54 +00:00
("{tense}"
2019-07-16 17:33:09 +00:00
("[high]")
("{high}")))
2019-06-27 11:05:54 +00:00
("{back}"
("[tense]"
2019-07-16 17:33:09 +00:00
("[high]")
("{high}"))
2019-06-27 11:05:54 +00:00
("{tense}"
2019-07-16 17:33:09 +00:00
("[high]")
("{high}")))))
2019-06-27 11:05:54 +00:00
(define cons-tree
'("[cons]"
("[son]"
("[dor]"
2019-07-16 17:33:09 +00:00
("[high]")
("{high}"))
2019-06-27 11:05:54 +00:00
("{dor}"
2019-07-16 17:33:09 +00:00
("[cor]")
("{cor}")))
2019-06-27 11:05:54 +00:00
("{son}"
("[dor]"
("[voice]"
2019-07-16 17:33:09 +00:00
("[high]")
("{high}"))
2019-06-27 11:05:54 +00:00
("{voice}"
2019-07-16 17:33:09 +00:00
("[high]")
("{high}")))
2019-06-27 11:05:54 +00:00
("{dor}"
("[voice]"
2019-07-16 17:33:09 +00:00
("[cor]")
("{cor}"))
2019-06-27 11:05:54 +00:00
("{voice}"
2019-07-16 17:33:09 +00:00
("[cor]")
("{cor}"))))))
2019-06-27 11:05:54 +00:00
(define verbs
'("[verbs]"
("[réel]"
2019-07-16 17:33:09 +00:00
("[passé]")
("{passé}"))
("{réel}"
2019-07-16 17:33:09 +00:00
("[optatif]")
("{optatif}"
2019-07-16 17:33:09 +00:00
("[passé]")
("{passé}")))))
2019-07-16 17:33:09 +00:00
(display (tree-to-dot vowel-tree))