From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: fuzzy matching of parameters Date: Thu, 1 Dec 2016 21:11:19 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=94eb2c05f6bc312a680542a374ad Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCdJq-00080s-H4 for emacs-orgmode@gnu.org; Thu, 01 Dec 2016 21:11:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCdJp-0004nW-7v for emacs-orgmode@gnu.org; Thu, 01 Dec 2016 21:11:22 -0500 Received: from mail-io0-x22d.google.com ([2607:f8b0:4001:c06::22d]:34962) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cCdJp-0004n3-0h for emacs-orgmode@gnu.org; Thu, 01 Dec 2016 21:11:21 -0500 Received: by mail-io0-x22d.google.com with SMTP id a124so458467797ioe.2 for ; Thu, 01 Dec 2016 18:11:21 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Org Mode --94eb2c05f6bc312a680542a374ad Content-Type: text/plain; charset=UTF-8 I have just done something I'm very excited about. Given a directory name (the variable ~assignment~ in this case) and a list of student info, search through the directory for files whose names contain the student names, and attach those to newly created subtrees. Before now, manually attaching those files has been a real pain, so it's great to have this automated! However, sometimes the name I have on file doesn't quite match the submitted name. In particular, my Chinese students usually have an English first name that we use in class, and a transliterated Chinese personal name that is used in official documents (like my class list). I would like to first try to match the whole name, and if that fails, attempt some kind of "fuzzy" match of the name. I'm not sure the best way to go about it. Any suggestions? Here is, I think, the relevant section of code (I can post the wider context if that would be helpful). Thanks! Matt (mapcar (lambda (stu) (let ((name (car stu)) (email (cdr stu)) ) (insert (format "\n** %s" name)) (org-todo 'todo) (org-set-property "MAIL_TO" email) (org-set-property "MAIL_SUBJECT" (format "Comments on %s Assignment (%s)" (mwp-org-get-parent-headline) name )) ;; try to attach files, if possible (condition-case nil (let* (( afiles (directory-files assignment nil name))) (if afiles (dolist (f afiles) (org-attach-attach (concat (file-name-directory (buffer-file-name)) assignment "/" f) )) (message "No files match name of %s" name))) (error (message "Unable to attach file belonging to student"))) (save-excursion (org-mark-subtree) (org-cycle nil)) )) students) --94eb2c05f6bc312a680542a374ad Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: base64 PGRpdiBkaXI9Imx0ciI+PGRpdj48ZGl2PjxkaXY+SSBoYXZlIGp1c3QgZG9uZSBzb21ldGhpbmcg SSYjMzk7bSB2ZXJ5IGV4Y2l0ZWQgYWJvdXQuwqAgR2l2ZW4gYSBkaXJlY3RvcnkgbmFtZSAodGhl IHZhcmlhYmxlIH5hc3NpZ25tZW50fiBpbiB0aGlzIGNhc2UpIGFuZCBhIGxpc3Qgb2Ygc3R1ZGVu dCBpbmZvLCBzZWFyY2ggdGhyb3VnaCB0aGUgZGlyZWN0b3J5IGZvciBmaWxlcyB3aG9zZSBuYW1l cyBjb250YWluIHRoZSBzdHVkZW50IG5hbWVzLCBhbmQgYXR0YWNoIHRob3NlIHRvIG5ld2x5IGNy ZWF0ZWQgc3VidHJlZXMuwqAgPGJyPjxicj48L2Rpdj5CZWZvcmUgbm93LCBtYW51YWxseSBhdHRh Y2hpbmcgdGhvc2UgZmlsZXMgaGFzIGJlZW4gYSByZWFsIHBhaW4sIHNvIGl0JiMzOTtzIGdyZWF0 IHRvIGhhdmUgdGhpcyBhdXRvbWF0ZWQhIEhvd2V2ZXIsIHNvbWV0aW1lcyB0aGUgbmFtZSBJIGhh dmUgb24gZmlsZSBkb2VzbiYjMzk7dCBxdWl0ZSBtYXRjaCB0aGUgc3VibWl0dGVkIG5hbWUuIElu IHBhcnRpY3VsYXIsIG15IENo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