1
votes

I am new to python script i want to create sentiment analysis for the word or phrase whether the text or phrase is positive or negative.by using php post the phrase or text through $_POST['textarea'] and get in python script and check whether the phrase or text is positive or negative i want to use python nltk for example like this(pls see the link)

http://text-processing.com/demo/sentiment/

if(isset($_POST['submit']) && $_POST['submit'] == 'Analyze') {

$data = $_POST['text'];
$tmp = exec("/home/Ismath/Desktop/check.py $data");
echo $tmp;

}

//in check.py i want the word or phrase is positive and negative and neutral and how i can get the post value from textarea box in check.py if i use

  import sys
  print sys.argv[1]

//if i use above code suppose i enter "this is good thing" in php textarea box i got only the first text "this" only in my check.py file i want to print the whole words available in textarea box and through this word i want to check the sentence("this is good thing") is positive or negative by sentimental analysis how

?>

<body >
    <div id="main">
        <form action="sentiment.php" method="post" >
            <div id="text-div">Enter Text:</div>
            <textarea rows="12" cols="38" name="text"></textarea>
        <input type="submit" name="submit" value="Analyze">
        </form>
    </div>
</body>

so please anyone can help me how can i proceed with this with php and python dont use the api.i wnat to create new corpus ,text in my own pls tell how can i proceed with the steps for exp my php page like this

thanks in advance

2
why not use the api? text-processing.com/docs/sentiment.html - user557846
Yeah, if you're happy with what the demo does, then use the API. If not, the source code for the classifier is here, and you can change how it works and the corpus you're using yourself. - Marius

2 Answers

2
votes

Here is an idea.

You can use File Handling in your Php code and write the content of $data to a file. Then instead of passing $data as argument, read the file contents from your python code, perform whatever algorithm you want to and print the result so that it gets stored in $tmp.

0
votes

You can wrap $data by single quotes

$data = htmlentities($data, ENT_QUOTES);
$tmp = exec("/home/Ismath/Desktop/check.py '$data'");

python:

import sys
from HTMLParser import HTMLParser
print HTMLParser().unescape(sys.argv[1])