Function / API design when porting Perl to Python code [on hold]











up vote
0
down vote

favorite












In Perl there are two functions that users interacts in shell



perl train-truecaser.perl --model outputmodelfile --corpus inputfile1


perl truecaser.perl --model outputmodelfile < inputfile2 > outputfile2


from:




  • https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/train-truecaser.perl

  • https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/truecase.perl


In Python, if the two functions are going to be an object, it's a little hard to conceive how the user should interact with the function with and without shell interaction.



Assuming that there are two methods in the Truecaser() object in Python





  • train() that does what train-truecaser.perl do


  • truecase() that does what truecaser.perl do


Proposal 1



We could simply follow the perl style functions:



# Initialize an object.
tc = Truecaser()

# Train the model.
tc.train(inputfile1, save_to=outputmodelfile)

# Use the Truecase model from outputmodelfile
outputfile2 = tc.truecase(inputfile2, model=outputmodelfile)


In that case the train(...) returns nothing.
And truecase outputs the outputfile2



Proposal 2



But what if we make it less function and connect the models output without output-ing it to a file, e.g.



# Initialize the object.
tc = Truecaser()

# Still allow output-ing model to file
model = tc.train(inputfile1, save_to=outputmodelfile)

# Apply the truecase
outputfile2 = tc.truecase(inputfile2, model=model)


In that case, possible model has to be loaded as a specific object instead of a file or on top of loading a file.



Proposal 3



We can also implicitly load/override the model when train() is called, e.g.



# Initialize the object.
tc = Truecaser()

# Still allow output-ing model to file
# But the output model is saved to tc.model variable.
tc.train(inputfile1, save_to=outputmodelfile)

# Implicitly calls the tc.model saves from the previous tc.train()
outputfile2 = tc.truecase(inputfile2)




I'm not sure which proposal for the Python interface is more Pythonic or more intuitive to users. Esp. when Perl interface focused on shell interactions while the goal of the Python interface is to encapsulate both the train() and truecase() methods in a single object.



Which is a preferred interface for the Python object + functions?



Are there examples of similar functions in other Python library?










share|improve this question















put on hold as unclear what you're asking by 200_success, Ludisposed, Graipher, Zeta, Nic Hartley 35 mins ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 1




    I don't understand this question, and I think if is because it lacks contextual information about train() and truecase().
    – 200_success
    13 hours ago















up vote
0
down vote

favorite












In Perl there are two functions that users interacts in shell



perl train-truecaser.perl --model outputmodelfile --corpus inputfile1


perl truecaser.perl --model outputmodelfile < inputfile2 > outputfile2


from:




  • https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/train-truecaser.perl

  • https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/truecase.perl


In Python, if the two functions are going to be an object, it's a little hard to conceive how the user should interact with the function with and without shell interaction.



Assuming that there are two methods in the Truecaser() object in Python





  • train() that does what train-truecaser.perl do


  • truecase() that does what truecaser.perl do


Proposal 1



We could simply follow the perl style functions:



# Initialize an object.
tc = Truecaser()

# Train the model.
tc.train(inputfile1, save_to=outputmodelfile)

# Use the Truecase model from outputmodelfile
outputfile2 = tc.truecase(inputfile2, model=outputmodelfile)


In that case the train(...) returns nothing.
And truecase outputs the outputfile2



Proposal 2



But what if we make it less function and connect the models output without output-ing it to a file, e.g.



# Initialize the object.
tc = Truecaser()

# Still allow output-ing model to file
model = tc.train(inputfile1, save_to=outputmodelfile)

# Apply the truecase
outputfile2 = tc.truecase(inputfile2, model=model)


In that case, possible model has to be loaded as a specific object instead of a file or on top of loading a file.



Proposal 3



We can also implicitly load/override the model when train() is called, e.g.



# Initialize the object.
tc = Truecaser()

# Still allow output-ing model to file
# But the output model is saved to tc.model variable.
tc.train(inputfile1, save_to=outputmodelfile)

# Implicitly calls the tc.model saves from the previous tc.train()
outputfile2 = tc.truecase(inputfile2)




I'm not sure which proposal for the Python interface is more Pythonic or more intuitive to users. Esp. when Perl interface focused on shell interactions while the goal of the Python interface is to encapsulate both the train() and truecase() methods in a single object.



Which is a preferred interface for the Python object + functions?



Are there examples of similar functions in other Python library?










share|improve this question















put on hold as unclear what you're asking by 200_success, Ludisposed, Graipher, Zeta, Nic Hartley 35 mins ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 1




    I don't understand this question, and I think if is because it lacks contextual information about train() and truecase().
    – 200_success
    13 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











In Perl there are two functions that users interacts in shell



perl train-truecaser.perl --model outputmodelfile --corpus inputfile1


perl truecaser.perl --model outputmodelfile < inputfile2 > outputfile2


from:




  • https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/train-truecaser.perl

  • https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/truecase.perl


In Python, if the two functions are going to be an object, it's a little hard to conceive how the user should interact with the function with and without shell interaction.



Assuming that there are two methods in the Truecaser() object in Python





  • train() that does what train-truecaser.perl do


  • truecase() that does what truecaser.perl do


Proposal 1



We could simply follow the perl style functions:



# Initialize an object.
tc = Truecaser()

# Train the model.
tc.train(inputfile1, save_to=outputmodelfile)

# Use the Truecase model from outputmodelfile
outputfile2 = tc.truecase(inputfile2, model=outputmodelfile)


In that case the train(...) returns nothing.
And truecase outputs the outputfile2



Proposal 2



But what if we make it less function and connect the models output without output-ing it to a file, e.g.



# Initialize the object.
tc = Truecaser()

# Still allow output-ing model to file
model = tc.train(inputfile1, save_to=outputmodelfile)

# Apply the truecase
outputfile2 = tc.truecase(inputfile2, model=model)


In that case, possible model has to be loaded as a specific object instead of a file or on top of loading a file.



Proposal 3



We can also implicitly load/override the model when train() is called, e.g.



# Initialize the object.
tc = Truecaser()

# Still allow output-ing model to file
# But the output model is saved to tc.model variable.
tc.train(inputfile1, save_to=outputmodelfile)

# Implicitly calls the tc.model saves from the previous tc.train()
outputfile2 = tc.truecase(inputfile2)




I'm not sure which proposal for the Python interface is more Pythonic or more intuitive to users. Esp. when Perl interface focused on shell interactions while the goal of the Python interface is to encapsulate both the train() and truecase() methods in a single object.



Which is a preferred interface for the Python object + functions?



Are there examples of similar functions in other Python library?










share|improve this question















In Perl there are two functions that users interacts in shell



perl train-truecaser.perl --model outputmodelfile --corpus inputfile1


perl truecaser.perl --model outputmodelfile < inputfile2 > outputfile2


from:




  • https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/train-truecaser.perl

  • https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/truecase.perl


In Python, if the two functions are going to be an object, it's a little hard to conceive how the user should interact with the function with and without shell interaction.



Assuming that there are two methods in the Truecaser() object in Python





  • train() that does what train-truecaser.perl do


  • truecase() that does what truecaser.perl do


Proposal 1



We could simply follow the perl style functions:



# Initialize an object.
tc = Truecaser()

# Train the model.
tc.train(inputfile1, save_to=outputmodelfile)

# Use the Truecase model from outputmodelfile
outputfile2 = tc.truecase(inputfile2, model=outputmodelfile)


In that case the train(...) returns nothing.
And truecase outputs the outputfile2



Proposal 2



But what if we make it less function and connect the models output without output-ing it to a file, e.g.



# Initialize the object.
tc = Truecaser()

# Still allow output-ing model to file
model = tc.train(inputfile1, save_to=outputmodelfile)

# Apply the truecase
outputfile2 = tc.truecase(inputfile2, model=model)


In that case, possible model has to be loaded as a specific object instead of a file or on top of loading a file.



Proposal 3



We can also implicitly load/override the model when train() is called, e.g.



# Initialize the object.
tc = Truecaser()

# Still allow output-ing model to file
# But the output model is saved to tc.model variable.
tc.train(inputfile1, save_to=outputmodelfile)

# Implicitly calls the tc.model saves from the previous tc.train()
outputfile2 = tc.truecase(inputfile2)




I'm not sure which proposal for the Python interface is more Pythonic or more intuitive to users. Esp. when Perl interface focused on shell interactions while the goal of the Python interface is to encapsulate both the train() and truecase() methods in a single object.



Which is a preferred interface for the Python object + functions?



Are there examples of similar functions in other Python library?







python perl machine-learning natural-language-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 13 hours ago

























asked 17 hours ago









alvas

283311




283311




put on hold as unclear what you're asking by 200_success, Ludisposed, Graipher, Zeta, Nic Hartley 35 mins ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






put on hold as unclear what you're asking by 200_success, Ludisposed, Graipher, Zeta, Nic Hartley 35 mins ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    I don't understand this question, and I think if is because it lacks contextual information about train() and truecase().
    – 200_success
    13 hours ago














  • 1




    I don't understand this question, and I think if is because it lacks contextual information about train() and truecase().
    – 200_success
    13 hours ago








1




1




I don't understand this question, and I think if is because it lacks contextual information about train() and truecase().
– 200_success
13 hours ago




I don't understand this question, and I think if is because it lacks contextual information about train() and truecase().
– 200_success
13 hours ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

List directoties down one level, excluding some named directories and files

list processes belonging to a network namespace

list systemd RuntimeDirectory mounts