From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price <moptop99@gmail.com> Subject: Re: fuzzy matching of parameters Date: Sat, 3 Dec 2016 12:06:14 -0500 Message-ID: <CAN_Dec-y1zBJnqEYaAS6LonOU9foLLjF4urdrxgOKfn0YAZ6xA@mail.gmail.com> References: <CAN_Dec8js7xhAbbb6qFPX92EieikkjaZuOS5TOK3M2ia5O50TA@mail.gmail.com> <m28trywi45.fsf@Johns-MacBook-Air.local> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1141cb547c84600542c412db Return-path: <emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org> Received: from eggs.gnu.org ([2001:4830:134:3::10]:52125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <moptop99@gmail.com>) id 1cDDlT-0003Ui-PK for emacs-orgmode@gnu.org; Sat, 03 Dec 2016 12:06:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <moptop99@gmail.com>) id 1cDDlS-0007pE-7b for emacs-orgmode@gnu.org; Sat, 03 Dec 2016 12:06:19 -0500 Received: from mail-io0-x231.google.com ([2607:f8b0:4001:c06::231]:35310) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <moptop99@gmail.com>) id 1cDDlR-0007oo-Qg for emacs-orgmode@gnu.org; Sat, 03 Dec 2016 12:06:18 -0500 Received: by mail-io0-x231.google.com with SMTP id a124so532893775ioe.2 for <emacs-orgmode@gnu.org>; Sat, 03 Dec 2016 09:06:15 -0800 (PST) In-Reply-To: <m28trywi45.fsf@Johns-MacBook-Air.local> List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>, <mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe> List-Archive: <http://lists.gnu.org/archive/html/emacs-orgmode/> List-Post: <mailto:emacs-orgmode@gnu.org> List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>, <mailto:emacs-orgmode-request@gnu.org?subject=subscribe> Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" <emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org> To: John Kitchin <jkitchin@andrew.cmu.edu> Cc: Org Mode <emacs-orgmode@gnu.org> --001a1141cb547c84600542c412db Content-Type: text/plain; charset=UTF-8 THanks, John, I'm sure you're right actually. So I've just written my matching function like this: (lambda (f) (string-match (concat "\\\(" fname "\\\)\\\([^[:alnum:]]\\\)*" lname) f)) and if that has a nil result: (lambda (f) (string-match (concat "\\\(" nname "\\\)\\\([^[:alnum:]]\\\)*" lname) f)) That seems to work pretty well so far. And as you suggest, I've written a simple function that calls read-file-name for org-attach-attach in the appropriate directory -- though it' s extremely simple, it makes manual attachment much quicker when my brain starts to get foggy from grading papers. On Fri, Dec 2, 2016 at 8:55 AM, John Kitchin <jkitchin@andrew.cmu.edu> wrote: > I would not do that if I were you. The fuzzy match might inadvertently > send feed back to the wrong student. I would fall back to some manual > attachment if you do not find an exact match, e.g. using helm or ivy to > select the files for attachment, perhaps sorted and matched using their > fuzzy algorithms. > > > > Matt Price writes: > > > 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) > > > -- > Professor John Kitchin > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu > --001a1141cb547c84600542c412db Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div><div>THanks, John, I'm sure you're right actu= ally. So I've just written my matching function like this:<br><br>(lamb= da (f) (string-match (concat "\\\(" fname "\\\)\\\([^[:alnum= :]]\\\)*" lname) f))<br><br></div>and if that has a nil result:<br><br= >(lambda (f) (string-match (concat "\\\(" nname "\\\)\\\([^[= :alnum:]]\\\)*" lname) f))<br><br></div>That seems to work pretty well= so far.=C2=A0 And as you suggest, I've written a simple function that = calls read-file-name for org-attach-attach in the appropriate directory -- = though it' s extremely simple, it makes manual attachment much quicker = when my brain starts to get foggy from grading papers. <br><div><div><div><= div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Fri, Dec 2, 201= 6 at 8:55 AM, John Kitchin <span dir=3D"ltr"><<a href=3D"mailto:jkitchin= @andrew.cmu.edu" target=3D"_blank">jkitchin@andrew.cmu.edu</a>></span> w= rote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e= x;border-left:1px solid rgb(204,204,204);padding-left:1ex">I would not do t= hat if I were you. The fuzzy match might inadvertently<br> send feed back to the wrong student. I would fall back to some manual<br> attachment if you do not find an exact match, e.g. using helm or ivy to<br> select the files for attachment, perhaps sorted and matched using their<br> fuzzy algorithms.<br> <div class=3D"gmail-HOEnZb"><div class=3D"gmail-h5"><br> <br> <br> Matt Price writes:<br> <br> > I have just done something I'm very excited about.=C2=A0 Given a d= irectory name<br> > (the variable ~assignment~ in this case) and a list of student info, s= earch<br> > through the directory for files whose names contain the student names,= and<br> > attach those to newly created subtrees.<br> ><br> > Before now, manually attaching those files has been a real pain, so it= 's<br> > great to have this automated! However, sometimes the name I have on fi= le<br> > doesn't quite match the submitted name. In particular, my Chinese = students<br> > usually have an English first name that we use in class, and a<br> > transliterated Chinese personal name that is used in official document= s<br> > (like my class list).=C2=A0 I would like to first try to match the who= le name,<br> > and if that fails, attempt some kind of "fuzzy" match of the= name. I'm not<br> > sure the best way to go about it.<br> ><br> > Any suggestions? Here is, I think, the relevant section of code (I can= post<br> > the wider context if that would be helpful). Thanks!<br> ><br> > Matt<br> ><br> > (mapcar (lambda (stu)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((name (car stu))<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(email (cdr stu))<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(insert (format "\n** %s" name)= )<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-todo 'todo)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-set-property "MAIL_TO" ema= il)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-set-property "MAIL_SUBJECT"= ;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(format "Comments on %s<br> > Assignment (%s)"<br> ><br> > (mwp-org-get-parent-headline) name ))<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; try to attach files, if possible<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(condition-case nil<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let* (( afiles (directory-= files<br> > assignment=C2=A0 nil name)))<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if afiles<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(dolis= t (f afiles)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(org-attach-attach (concat<br> > (file-name-directory (buffer-file-name)) assignment "/" f) )= )<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(message &quo= t;No files match name of %s"<br> > name)))<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(error (message "Unable to at= tach file<br> > belonging to student")))<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(save-excursion<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-mark-subtree)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-cycle nil))<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0)) students)<br> <br> <br> </div></div><span class=3D"gmail-HOEnZb"><font color=3D"#888888">--<br> Professor John Kitchin<br> Doherty Hall A207F<br> Department of Chemical Engineering<br> Carnegie Mellon University<br> Pittsburgh, PA 15213<br> <a href=3D"tel:412-268-7803" value=3D"+14122687803">412-268-7803</a><br> @johnkitchin<br> <a href=3D"http://kitchingroup.cheme.cmu.edu" rel=3D"noreferrer" target=3D"= _blank">http://kitchingroup.cheme.cmu.<wbr>edu</a><br> </font></span></blockquote></div><br></div></div></div></div></div> --001a1141cb547c84600542c412db--