emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* fuzzy matching of parameters
@ 2016-12-02  2:11 Matt Price
  2016-12-02  3:01 ` Charles C. Berry
  2016-12-02 13:55 ` John Kitchin
  0 siblings, 2 replies; 4+ messages in thread
From: Matt Price @ 2016-12-02  2:11 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 2242 bytes --]

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)

[-- Attachment #2: Type: text/html, Size: 3246 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fuzzy matching of parameters
  2016-12-02  2:11 fuzzy matching of parameters Matt Price
@ 2016-12-02  3:01 ` Charles C. Berry
  2016-12-02 13:55 ` John Kitchin
  1 sibling, 0 replies; 4+ messages in thread
From: Charles C. Berry @ 2016-12-02  3:01 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

On Thu, 1 Dec 2016, Matt Price wrote:

> 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.

A Google Scholar search on 'personal name matching' will point you to the 
literature on this subject.

You might get lucky and find something in a scripting language that Babel 
supports that you can piggyback onto.

HTH,

Chuck

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fuzzy matching of parameters
  2016-12-02  2:11 fuzzy matching of parameters Matt Price
  2016-12-02  3:01 ` Charles C. Berry
@ 2016-12-02 13:55 ` John Kitchin
  2016-12-03 17:06   ` Matt Price
  1 sibling, 1 reply; 4+ messages in thread
From: John Kitchin @ 2016-12-02 13:55 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fuzzy matching of parameters
  2016-12-02 13:55 ` John Kitchin
@ 2016-12-03 17:06   ` Matt Price
  0 siblings, 0 replies; 4+ messages in thread
From: Matt Price @ 2016-12-03 17:06 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 3673 bytes --]

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
>

[-- Attachment #2: Type: text/html, Size: 5171 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-03 17:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-02  2:11 fuzzy matching of parameters Matt Price
2016-12-02  3:01 ` Charles C. Berry
2016-12-02 13:55 ` John Kitchin
2016-12-03 17:06   ` Matt Price

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).