Reputation: 3271
So I have this shell script:
echo "Enter text to be classified, hit return to run classification."
read text
if [ `echo "$text" | sed -r 's/ +/ /g' | bin/stupidfilter data/c_rbf` = "1.000000" ]
then
echo "Text is not likely to be stupid."
fi
if [ `echo "$text" | sed -r 's/ +/ /g' | bin/stupidfilter data/c_rbf` = "0.000000" ]
then
echo "Text is likely to be stupid."
fi
I would like to write it in python. How do I do this?
(As you can see it uses the library http://stupidfilter.org/stupidfilter-0.2-1.tar.gz)
Upvotes: 3
Views: 358
Reputation: 753725
You could clearly run the commands as sub-shells and read the return value, just as in the shell script, and then process the result in Python.
This is simpler than loading C functions.
If you really want to load a function from the stupidfilter
library, then first look to see whether someone else has already done it. If you cannot find anyone who has, then read the manual - how to call from Python onto C is covered in there.
It is still simpler to use what others have already done.
Upvotes: 1
Reputation: 222852
To do it just like the shell script does:
import subprocess
text = raw_input("Enter text to be classified: ")
p1 = subprocess.Popen('bin/stupidfilter', 'data/c_trbf')
stupid = float(p1.communicate(text)[0])
if stupid:
print "Text is likely to be stupid"
else:
print "Text is not likely to be stupid"
Upvotes: 8