comparison implementations/tabcode/ecolm.lisp @ 183:5b2d0e5a99f1

More tabcode, plus fixes for gsharp key-sigs and some new restart symbols in amuse darcs-hash:20080721130227-40ec0-858017ddbc42513731d0119e704926768906dbc6.gz
author d.lewis <d.lewis@gold.ac.uk>
date Mon, 21 Jul 2008 14:02:27 +0100
parents 1a2b876b5587
children
comparison
equal deleted inserted replaced
182:470e83242576 183:5b2d0e5a99f1
1 (in-package #:amuse-tabcode) 1 (in-package #:amuse-ecolm)
2 2
3 (defun get-ecolm-connection () 3 (defun get-ecolm-connection ()
4 (clsql:connect (list "127.0.0.1" "ecolm" "basicuser" "basicuser" "29183") 4 (clsql:connect (list "127.0.0.1" "ecolm" "basicuser" "basicuser" "29183")
5 :if-exists :old :database-type :mysql)) 5 :if-exists :old :database-type :mysql))
6 6
9 (edition-text-id :initarg :ed-id :accessor %edition-text-id) 9 (edition-text-id :initarg :ed-id :accessor %edition-text-id)
10 (piece-id :initarg :p-id :accessor piece-id) 10 (piece-id :initarg :p-id :accessor piece-id)
11 (tabcode :initarg :code :accessor %tabcode))) 11 (tabcode :initarg :code :accessor %tabcode)))
12 12
13 (defclass ecolm-search () 13 (defclass ecolm-search ()
14 ((piece-title :initarg :p-title :reader piece-title) 14 ((piece-title :initarg :piece :reader piece-title)
15 (source-title :initarg :s-title :reader source-title))) 15 (source-title :initarg :source :reader source-title)
16 (cluster-name :initarg :cluster :reader cluster-name)))
16 17
17 (defun edition-text-id (ecolm-id) 18 (defun edition-text-id (ecolm-id)
18 (unless (or (slot-boundp ecolm-id 'edition-text-id) 19 (unless (or (slot-boundp ecolm-id 'edition-text-id)
19 (slot-boundp ecolm-id 'edition-id)) 20 (slot-boundp ecolm-id 'edition-id))
20 (get-best-edition ecolm-id)) 21 (get-best-edition ecolm-id))
49 (%tabcode identifier) 50 (%tabcode identifier)
50 (when (edition-text-id identifier) 51 (when (edition-text-id identifier)
51 (%tabcode identifier)))) 52 (%tabcode identifier))))
52 53
53 (defmethod get-composition ((identifier ecolm-identifier)) 54 (defmethod get-composition ((identifier ecolm-identifier))
54 (get-composition-from-tabwords 55 (amuse-tabcode::get-composition-from-tabwords
55 (tabcode::parse-tabcode-string (tabcode identifier)))) 56 (tabcode::parse-tabcode-string (tabcode identifier))))
57
58 (defun make-ecolm-search (&key (piece-title nil) (source-title nil) (cluster-name nil))
59 (make-instance 'ecolm-search
60 :piece piece-title
61 :source source-title
62 :cluster cluster-name))
63
64 (defun ecolm-search (&key (piece-title nil) (source-title nil) (cluster-name nil))
65 (get-ecolm-search-results (make-ecolm-search :piece-title piece-title
66 :source-title source-title
67 :cluster-name cluster-name)))
68
69 (defun get-ecolm-search-results (ecolm-search)
70 (let ((prefixes '("SELECT DISTINCT p.`Piece ID` FROM Pieces p"))
71 (where-clauses '("WHERE 1"))
72 (results)
73 (query-string "") (sourcep))
74 (when (and (slot-boundp ecolm-search 'piece-title)
75 (piece-title ecolm-search))
76 (push " LEFT JOIN Piece_Names pn USING (`Piece ID`) "
77 prefixes)
78 (push (format nil " AND (`Piece Title` LIKE '~D' OR `PieceName Alias` LIKE '~D') "
79 (piece-title ecolm-search) (piece-title ecolm-search))
80 where-clauses))
81 (when (and (slot-boundp ecolm-search 'source-title)
82 (source-title ecolm-search))
83 (setf sourcep t)
84 (push " LEFT JOIN Sources s ON p.`Source ID`=s.`Source ID`
85 LEFT JOIN Source_Names sn ON s.`Source ID`=sn.`Source ID` "
86 prefixes)
87 (push (format nil " AND (`Source Title` LIKE '~D' OR `SourceName Alias` LIKE '~D') "
88 (source-title ecolm-search) (source-title ecolm-search))
89 where-clauses))
90 (when (and (slot-boundp ecolm-search 'cluster-name)
91 (cluster-name ecolm-search))
92 (push (if sourcep
93 " LEFT JOIN Cluster_Pieces cp ON p.`Piece ID`=cp.`Piece ID`
94 LEFT JOIN Clusters c1 ON cp.`Cluster ID`=c1.`Cluster ID`
95 LEFT JOIN Cluster_Sources cs on s.`Source ID`=cs.`Source ID`
96 LEFT JOIN Clusters c2 ON cs.`Cluster ID`=c2.`Cluster ID` "
97 " LEFT JOIN Cluster_Pieces cp ON p.`Piece ID`=cp.`Piece ID`
98 LEFT JOIN Clusters c1 ON cp.`Cluster ID`=c1.`Cluster ID` ")
99 prefixes)
100 (push (format nil " AND (c1.`Cluster Name` LIKE '~D'~D)"
101 (cluster-name ecolm-search)
102 (if sourcep
103 (format nil "OR c2.`Cluster Name` LIKE '~D'"
104 (cluster-name ecolm-search))
105 ""))
106
107 where-clauses))
108 (setf query-string (concatenate 'string
109 (apply #'concatenate
110 'string (reverse prefixes))
111 (apply #'concatenate
112 'string (reverse where-clauses)))
113 results (clsql:query query-string))
114 (remove-if-not #'edition-text-id (mapcar #'(lambda (x) (make-instance 'ecolm-identifier :p-id x)) results))))
115