Python - Deciphering Line from SiriServer Plugin - python

I'm currently learning how to program plugins for SiriServer, in hope to create a bit of home automation using my phone. I'm trying to figure out how to program the text coverted speech to match and run the plugin.
I've learnt how to to short phrases, like this for example.:
#register("en-US", ".*Start.*XBMC.*")
Though if I'm understanding it's searching at random for the two words. If I were to say XBMC Start, it would probably work as well, but when I start working with wolframalpha, I need to be a bit more specific.
For example, speech to text saying "What's the weather like in Toronto?", somehow connects to this:
#register("en-US", "(what( is|'s) the )?weather( like)? in (?P<location>[\w ]+?)$")
What would all the extra symbols in that line mean that could connect these two together? I've tried messing around with a couple ideas but nothing seems to work the way I want it to. Any help is appreciated, thanks!

I will break down the example you provided so hopefully that is a good start, but searching for python regex would provide more thorough information.
The parentheses set the enclosed items to be seen as the result, not the individual items by the remaining expression. The pipes mean "or", the question marks mean this portion may or may not be present, and the group for location is a regex which sets the variable "location" as the input provided at this point in the input. The $ at the end means that this will complete the sentence. .* means anything at this place in the input is acceptable, but should also be ignored. Hopefully that helps.

Related

Is there anyway to recognize just one word without using speech to text api in python

I need to turn on something when the user says a given word, Let's say the word is "Hello", So whenever the user says "Hello" I need to turn on something, I only need to recognize this word, And I don't want to use a whole speech to text API to identify just one word. I have tried a few things using frequencies and didn't work. Any help will be really appreciated. Thank you.
I think what you want to do is wake word detection or keyword spotting. In wake word detection, the goal is to trigger the output when a specified word is heard in input.
There are several good libraries to do this. For example check these ones:
https://github.com/Picovoice/porcupine (it requires access key from their website)
https://github.com/MycroftAI/mycroft-precise (It looks like its free)

How to check for blank lines after a string in python?

I am a bit new to python but Im working on a project with rflint and want to make a rule that will basically "check" if there are any blank lines after a sentence, and then I could issue some commands based on if it meets that check or not.
I had a few ideas but got stumped pretty quick, but imagine there is probably a nice function for this in python.

How to correct badly written emails?

I am trying to correct badly written emails contained in a list, by searching differences in the most common domains. E.g: hotmal.com to hotmail.com.
The thing is, there are tons of variations to one single domain. It would be extremly helpful if someone knew of an algorithm in python that can work as an autocorrect for email domains. Or if this is too complex of a problem for a few lines of code.
Check Levenshtein distance starting at https://en.wikipedia.org/wiki/Levenshtein_distance
It is commonly used for auto-correct
What if...you search for keywords in the domain. Like for hotmail.com, you can search for hot, or something similar. Also, like the #user10817019 wrote, you can combine it with searching for the first and last letters of the domain.
Write a small script in your preferred language that takes domains that start with h and end with l, and replace the entire string with hotmail so it fixes everything in between. Search for mai if they forgot the L. I had to do this the other day in vb.net so check my lists twice and correct bad data.

Sending multiple python lines with ConqueTerm

I'm using vim with ConqueTerm and ipython (--pylab if it matters) on Ubuntu 14.04. When I select multiple lines and send them using F9, everything pastes in the same line, as in this question. I could try remapping as the poster did for that question, but I don't have this issue with matlab on the same machine or with ConqueTerm+ipython on mac. Is there a way to fix this so I can continue using F9? Thanks!
The solution
It was my first experience using vimscript, but I was able to modify the plugin so it can send the selected lines properly.
I changed the send_selected function in the conque.vim(or another mirror)\autoload\conque_term.vim to this: https://gist.github.com/freencis/28e351e3bb267a8522e1dff53436fb8d
The function name is the same, just go there and replace it.
What I did
I will skip the "explaing what was wrong" part, mostly because I didn't fully grasp the original implementation.
So, after searching a bit on the internet about how I could access the file's text from a plugin, I ended up finding a way to get the text from specific lines from the file: using the getline function. Luckly there were already a Conque's function to send the line to the terminal and execute it (used by the 's send_file), so I just used it.
Then It was just a matter of knowing which lines were selected and get those. Which led me to the line function, which returns the line number in a different ways. One of these was by marker, in this case the '<, '> markers from the visual selection. Unfortunately I also don't know how to explain these, but calling line("'<") and line("'>") returned me the selection's start and end lines respectively.
And that was the vimscript programming part, the :help is really a life saver. The traditional programming was just looping through the line numbers, getting the text from those and sending them to the terminal.
Notes
It was my first ever experience with vimscript (I've only been using vim for a month), so I'm sure it might not the proper way to do it, plus I replaced a functionality, so I'm just sharing it as a quick hack. Any feedback is appreciated.
Props to http://learnvimscriptthehardway.stevelosh.com/, it helped me a lot with the language, I never expected it to be that accessible
And sorry for any bad English. peace

Python - Detect (spammy) URLS in string

So, I've been doing some research for a while now and I could't find anything about detecting a URL in a string. The problem is that most results are about detecting whether a string IS a URL, and not if it contains a URL. The 2 results that look best to me are
Regex to find urls in string in Python
and
Detecting a (naughty or nice) URL or link in a text string
but the first requires http://, which is not something spammers would use (:P) and the second one isn't in regex - and my limited knowledge does not know how to translate any of these. Something I have considered doing is using something dull like
spamlist = [".com",".co.uk","etc"]
for word in string:
if word in spamlist:
Do().stuff()
But that would honestly do more bad than good, and I am 100% sure there is a better way using regex or anything!
So if anyone knows anything that could help me I'd be very grateful! I've only been doing python for 1-2 months and not very intensively during this period but I feel like I'm making great progress and this one thing is all that's in the way, really.
EDIT: Sorry for not specifying earlier, I am looking to use this locally, not website (apache) based or anything similar. More trying to clean out any links from files I've got hanging around.
As I said in the comments,
Detecting a (naughty or nice) URL or link in a text string 's solution is a regex and you should probably make it a raw string or escape backslashes in it when using it in Python
You really shouldn't reinvent the square wheel here, especially since spam filtering is an arms race domain (couldn't remember the exact English phrase for this)

Categories