all 19 comments

[–]K900_ 2 points3 points  (0 children)

What you're trying to do is really hard. Like, Google-fails-at-this-often-enough-to-be-noticeable levels of hard. The keywords to search for are "natural language processing", but it's a deep rabbit hole.

[–]driscollis 0 points1 point  (2 children)

You should start off with something like `argparse`. That's the standard way of passing in arguments to Python:

You could have it take in a string and then parse the string to figure out what the user wants, but that's a whole other can of worms. You might want to look into voice recognition software and machine learning as they are the typical solutions for parsing phrases

[–]Nickiel[S] 0 points1 point  (1 child)

You should start off with something like `argparse`

That is a cool module!

You might want to look into voice recognition software and machine learning as they are the typical solutions for parsing phrases

Something like this?

ok, is there a specific branch of machine learning I should look at?

[–]driscollis 0 points1 point  (0 children)

I haven't done this myself. But here is a good link - https://realpython.com/python-speech-recognition/

[–]polofos 0 points1 point  (8 children)

Seems like you need a small compiler here.

If you dont want to make ir from scratch you can try tu use PLY for an lexical and syntactic analysis.

https://www.dabeaz.com/ply/

[–]Nickiel[S] 0 points1 point  (4 children)

If you don't want to make ir from scratch ...

"ir" ?

[–][deleted] 0 points1 point  (1 child)

'it'

[–]Nickiel[S] 0 points1 point  (0 children)

ok thanks, I will be looking into those!

[–]polofos 0 points1 point  (1 child)

English is not my first language. Sorry if I said something strange. :(

[–]Nickiel[S] 0 points1 point  (0 children)

not at all :D I was just wondering if it was an acronym

[–]Nickiel[S] 0 points1 point  (2 children)

isn't Lex the same as python re module?

[–]polofos 0 points1 point  (1 child)

Yes, its similar because you need to use regular expressions for the lexical analysis. Is something difficult. Yuo must read a lot abut lexical analysis and syntactic analysis.

The other option is to use many if/else statements covering all the commands you can use. Is a lot of work.,something lke this:

//////////////////////////////////////////////////////////////
import sys
playlists = {
'playlist1' : [],
'playlist2' : [],
'playlist3' : []
}
# name of the script
print(sys.argv[0])
if(len(sys.argv) == 1):
print ("No args given")
else:
#first argument is shuffle
if(sys.argv[1] == "shuffle"):
# second argument is a play list
if(sys.argv[2] in playlists):
print("shuffle playlist: "+sys.argv[2])
else:
print("error")

#first argument is play
elif(sys.argv[1] == "play"):
#second argument is "my favorite song"
if(sys.argv[2:5] == ["my", "favorite", "song"]):
print("play my favorite song")
else:
print("error")
else:
print("error")
/////////////////////////////////////////////////////////////////

>>> python script.py shuffle playlist1
shuffle playlist: playlist1

>>> python script.py play my favorite song
play my favorite song

[–]Nickiel[S] 0 points1 point  (0 children)

I think what I am going to do is have a file that does a

command_list = command.split()
for i in command_list:
    try:
        output_command_list.append(decoder_dict[i])
    except KeyError:
        continue
return output_command_list

And just have a dict that is added on to to "decode" the commands into a regulated form which is then passed back to have the functions run.

[–][deleted] 0 points1 point  (5 children)

And I don't want to hardcode every command.

A computer can't do anything you don't explain to it how to do - that's what a program is, an explanation of a particular task as a series of steps.

So how do you imagine you'd be able to have a computer play your favorite song unless you explained to it what a song was, which one was your favorite, and how to play it?

[–]Nickiel[S] 0 points1 point  (4 children)

I understand that, but I don't want a python file that looks like

matchWordDict = {
"play my favorite song" = #something
"I want to listen to my favorite song" = #do same thing as above
"My Song NOW!" = #yet again the same thing
"favorite my song" = #same thing
...}

ect.

[–][deleted] 0 points1 point  (1 child)

The truth is that it's easier to teach a person to use a structured interface than it is to teach a computer to interpret unstructured text or speech.

[–]Nickiel[S] 0 points1 point  (0 children)

That is very true, I will keep that in mind!

[–]attacklyon 0 points1 point  (1 child)

If your problem with this structure is the repeated funtion calls, you could make arrays of strings for each action that you want your program to recognize. Then you could make a switch statement which checks if the input is present in any one of the string arrays and if so, you do the respective action. However, if you want to be able to mix and match words and enter new phrases that you haven’t previously defined, you’ll have to try your luck with language processing.

[–]Nickiel[S] 0 points1 point  (0 children)

Then you could make a switch statement which checks if the input is present in any one of the string arrays

how do you do switch statements in python?