|
@@ -20,97 +20,53 @@
|
|
|
(if (string= (:/gender person) "M") "blue" "pink"))))
|
|
|
|
|
|
;;; Generate edges between people
|
|
|
-;; (defun generate-person-edges (person-id)
|
|
|
-;; (let ((birth (first (select :births (where (equal :/person person-id))))))
|
|
|
-;; (if (or (= 0 (:/father birth))
|
|
|
-;; (= 0 (:/mother birth)))
|
|
|
-;; (if (= 0 (:/mother birth))
|
|
|
-;; (format nil "person_~a -> person_~a;" (:/father birth) person-id)
|
|
|
-;; (if (= 0 (:/father birth))
|
|
|
-;; (format nil "person_~a -> person_~a;" (:/mother birth) person-id)
|
|
|
-;; ""))
|
|
|
-;; (let ((marriage
|
|
|
-;; (first (select :marriages
|
|
|
-;; (where (and (equal :/wife (:/mother birth))
|
|
|
-;; (equal :/husband (:/father birth))))))))
|
|
|
-;; (if (not (null marriage))
|
|
|
-;; (format nil "marriage_~a -> person_~a;"
|
|
|
-;; (:/marriage-id marriage)
|
|
|
-;; person-id)
|
|
|
-;; (format nil "{person_~a, person_~a} -> person_~a"
|
|
|
-;; (:/mother birth)
|
|
|
-;; (:/father birth)
|
|
|
-;; person-id))))))
|
|
|
-
|
|
|
(defun generate-person-edges (person-id)
|
|
|
- (let* ((birth
|
|
|
- (first (select :births (where (equal :/person person-id)))))
|
|
|
+ (let* ((birth (get-birth person-id))
|
|
|
(mother (:/mother birth))
|
|
|
- (father (:/father birth))
|
|
|
- (marriage
|
|
|
- (first (select :marriages
|
|
|
- (where (and (equal :/wife mother)
|
|
|
- (equal :/husband father)))))))
|
|
|
+ (father (:/father birth)))
|
|
|
(cond
|
|
|
- ((= 0 (:/father birth))
|
|
|
- )
|
|
|
- ((= 0 (:/mother birth))
|
|
|
+ ((and (= 0 father)
|
|
|
+ (= 0 mother))
|
|
|
+ "")
|
|
|
+ ((= 0 father)
|
|
|
+ (format nil "person_~a -> person_~a;" mother person-id))
|
|
|
+ ((= 0 mother)
|
|
|
(format nil "person_~a -> person_~a;" father person-id))
|
|
|
- ((null marriage)
|
|
|
- (format nil "{person_~a, person_~a} -> person_~a;"
|
|
|
- mother
|
|
|
- father
|
|
|
- person-id))
|
|
|
(t
|
|
|
- (format nil "marriage_~a -> person_~a;"
|
|
|
- (:/marriage-id marriage)
|
|
|
- person-id)))))
|
|
|
+ (let ((marriage (get-marriage father mother)))
|
|
|
+ (if (null marriage)
|
|
|
+ (format nil "{person_~a, person_~a} -> person_~a;"
|
|
|
+ mother
|
|
|
+ father
|
|
|
+ person-id)
|
|
|
+ (format nil "marriage_~a -> person_~a;"
|
|
|
+ (:/marriage-id marriage)
|
|
|
+ person-id)))))))
|
|
|
|
|
|
-(defun generate-person-edges (person-id)
|
|
|
- (flet ((unlisted-father (birth-record)
|
|
|
- (= 0 (:/father birth-record)))
|
|
|
- (unlisted-mother (birth-record)
|
|
|
- (= 0 (:/mother birth-record)))
|
|
|
- (parent-married-status (birth-record)
|
|
|
- (let* ((mother (:/mother birth-record))
|
|
|
- (father (:/father birth-record))
|
|
|
- (records (select :marriages))
|
|
|
- (record (first
|
|
|
- (remove-if (lambda (record)
|
|
|
- (not (= (:/wife record) mother)))
|
|
|
- (remove-if (lambda (record)
|
|
|
- (not (= (:/husband record) father)))
|
|
|
- records)))))
|
|
|
- (values (not (null record)) (:/marriage-id record)))))
|
|
|
- (let ((birth (first (select :births
|
|
|
- (where (equal :/birth-person person-id))))))
|
|
|
- (cond
|
|
|
- ((unlisted-father birth)
|
|
|
- (format nil "person_~a -> person_~a;" (:/mother birth) person-id))
|
|
|
- ((unlisted-mother birth)
|
|
|
- (format nil "person_~a -> person_~a;" (:/father birth) person-id))
|
|
|
- ((parent-married-status birth)
|
|
|
- (multiple-value-bind (bool id)
|
|
|
- (parent-married-status birth)
|
|
|
- (declare (ignore bool))
|
|
|
- (format nil "marriage_~a -> person_~a;"
|
|
|
- id
|
|
|
- person-id)))
|
|
|
- ((not (parent-married-status birth))
|
|
|
- (format nil "{person_~a, person_~a} -> person_~a;"
|
|
|
- (:/mother birth)
|
|
|
- (:/father birth)
|
|
|
- person-id))))))
|
|
|
;;; Generate nodes for weddings
|
|
|
+;; (defun generate-marriage-node (marriage-id)
|
|
|
+;; (let ((marriage (first (select :marriages (where (equal :/marriage-id
|
|
|
+;; marriage-id)))))
|
|
|
+;; (divorce (first (select :divorces (where (equal :/marriage marriage-id))))))
|
|
|
+;; (format nil "marriage_~a [label = \"Married ~a — ~a\", shape = invtrapezium];"
|
|
|
+;; marriage-id
|
|
|
+;; (:/wedding-date marriage)
|
|
|
+;; (if (not (null divorce))
|
|
|
+;; (if (string= "0" (:/end-date marriage))
|
|
|
+;; "Present"
|
|
|
+;; (:/end-date marriage))
|
|
|
+;; (format nil "Div. ~a" (:/divorce-date divorce))))))
|
|
|
+
|
|
|
(defun generate-marriage-node (marriage-id)
|
|
|
- (let ((marriage (first (select :marriages (where (equal :/marriage-id
|
|
|
- marriage-id)))))
|
|
|
- (divorce (first (select :divorces (where (equal :/marriage marriage-id))))))
|
|
|
- (format nil "marriage_~a [label = \"Married ~a — ~a\", shape = invtrapeseum];"
|
|
|
+ (let* ((marriage (get-marriage-id marriage-id))
|
|
|
+ (start-date (:/wedding-date marriage))
|
|
|
+ (end-date (:/end-date marriage))
|
|
|
+ (divorce (get-divorce marriage-id)))
|
|
|
+ (format nil "marriage_~a [label = \"Married ~a — ~a\", shape = invtrapezium];"
|
|
|
marriage-id
|
|
|
- (:/wedding-date marriage)
|
|
|
- (if (not (null divorce))
|
|
|
- (if (string= "0" (:/end-date marriage))
|
|
|
+ start-date
|
|
|
+ (if (null divorce)
|
|
|
+ (if (string= "0" end-date)
|
|
|
"Present"
|
|
|
(:/end-date marriage))
|
|
|
(format nil "Div. ~a" (:/divorce-date divorce))))))
|
|
@@ -126,5 +82,30 @@
|
|
|
wife-id
|
|
|
marriage-id)))
|
|
|
|
|
|
-;; (defun generate-graph ()
|
|
|
-;; ())
|
|
|
+;;; Generate Family Tree
|
|
|
+(defun generate-graph (file-name)
|
|
|
+ (let ((people (iter (for i from 1 to (length (select :people)))
|
|
|
+ (collect (generate-person-node i))))
|
|
|
+ (birth-edges (remove-if (lambda (edge)
|
|
|
+ (string= edge ""))
|
|
|
+ (iter (for i from 1 to (length (select :people)))
|
|
|
+ (collect (generate-person-edges i)))))
|
|
|
+ (weddings (iter (for i from 1 to (length (select :marriages)))
|
|
|
+ (collect (generate-marriage-node i))))
|
|
|
+ (wedding-edges (iter (for i from 1 to (length (select :marriages)))
|
|
|
+ (collect (generate-marriage-edges i)))))
|
|
|
+ (with-open-file (out file-name
|
|
|
+ :direction :output
|
|
|
+ :if-exists :overwrite
|
|
|
+ :if-does-not-exist :create)
|
|
|
+ (format out
|
|
|
+ "digraph {
|
|
|
+~{ ~a~%~}
|
|
|
+~{ ~a~%~}
|
|
|
+~{ ~a~%~}
|
|
|
+~{ ~a~%~}
|
|
|
+}"
|
|
|
+ people
|
|
|
+ weddings
|
|
|
+ wedding-edges
|
|
|
+ birth-edges))))
|