I'm using this code from Google NL processor API:
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\NaturalLanguage\NaturalLanguageClient;
$projectId = 'YOUR_PROJECT_ID';
$language = new NaturalLanguageClient([
'projectId' => $projectId
]);
$text = 'Hello, world!'; //THIS LINE IS THE ISSUE
# Detects the sentiment of the text
$annotation = $language->analyzeSentiment($text);
$sentiment = $annotation->sentiment();
echo 'Text: ' . $text . '
Sentiment: ' . $sentiment['score'] . ', ' . $sentiment['magnitude'];
return $sentiment;
Everything works fine with whatever text I put in. However, the API is capable of analyzing each individual line of text separately (you can try it here: https://cloud.google.com/natural-language/). If you put in two different lines, then you get sentiments for each.
I'd like to recreate this, but no matter how I try to include a line break (using all the methods here: Writing TXT File with PHP, Want to Add an Actual Line Break), it's all being analyzed as one big text block.
Google says that content is sent in the following format (if this helps):
{
"document":{
"type":"PLAIN_TEXT",
"language": "EN",
"content":"'Lawrence of Arabia' is a highly rated film biography about \
British Lieutenant T. E. Lawrence. Peter O'Toole plays \
Lawrence in the film."
},
"encodingType":"UTF8"
}
\n'\r\'and several others. I've looked all through the documentation, but can't find anything.