Jump to content

Perl Phrase Dictionary workflow - Help wanted


Recommended Posts

Hi,

I am trying to make a hotkey triggered workflow that will match and substitute parts of the selected text with phrases in a custom dictionary. This dictionary would in the best of worlds be stored in as a sheet in Google Docs but could also be a locally stored CSV or whatever is best.

 

I reckon making a simple perl script is the way forward, but I thought I would ask here before trying a perl forum.

 

I found this promising Dictionary implementation at PerlMonks but it baffles my noobish skills.

I imagine the code would have to be saved as a .pm file in the workflow folder and declared (use?) in the script (filter?). The lookup and substitute functions could then be used with the input query and the return pasted.

I have tried to make a mockup of this workflow but I really have not much of an idea about bridging perl script and alfred, I will keep working on it and read up on workflow practices but thought I might ask for some pointers from here and maybe find out if I'm on the right track?

 
---
 

Sidenote: As a working solution I have been using a hack of the "save a sequence of regexs" functionality in Matthew Lancellottis excellent RegEx Workflow. The final dictionary would have a couple of hundred substitution pairs but for testing the regex solution I compiled the following pairs.

elsif( $c =~ /^mal$/ ){
   $q =~ s/Sign./Signed/gi;
   $q =~ s/Olie på lærred./Oil on canvas./gi;
   $q =~ s/Lysmål /Visible size /gi;
   $q =~ s/Bladstørrelse /Sheet size /gi;
} 

It would be much more convenient if the workflow would compile theses expressions from a simple set of values. Also, this workflow uses the clipboard text and not the selection as input.

Sadly my programming skills are not up to the task of modding the RegEx workflow further and that might be a bit of an inelegant overkill.

 

 

Please let me have any input you might be able to give.

Link to post
  • 4 weeks later...

OK, thanks.

This is very helpful, I was wondering about the lack of response from the wonderful community.

I am no good in any language, excepting maybe applescript.

I will try to learn a bit and rethink.

What are your thoughts about whether to look at Ruby or Python with regards to specific and general usefulness?

Link to post

I'm going to invoke the power of Cunningham's Law a wee bit to get someone who knows Ruby well to answer your question, too…
 
Absolutely Python. No question. It's much more readable than Ruby and has a much better community.
 
When it comes to Alfred workflows in particular, my Alfred-Workflow library for Python is streets ahead of the Ruby competition in terms of how much of the grunt work it can take off your hands.
 
There are awesome tutorials available for Python:

And my own tutorial for writing workflows in Python with Alfred-Workflow.

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...