lxaGetSentiment

<< lxaGetSummary | Back to Salience 6 C API Index | lxaGetThemes >>

Summary

Retrieves sentiment analysis of the document text. This consists of results for phrase-based and model-based sentiment analysis.
The acConfigurationID parameter specifies the configuration for the results, which are returned in a SalienceSentimentResult structure. Configurations are defined using the method lxaAddSalienceConfiguration.
Call lxaFreeSentimentResult when you are finished with the information to free any allocated memory.

Syntax

int lxaGetSentiment(SalienceSession *pSession, 
                    int nUseChains, 
                    SalienceSentimentResult *pResult,
                    const char *acConfigurationID);

Parameters

pSession Pointer to a SalienceSession structure previously returned by a call to lxaOpenSalienceSession
nUseChains Determines if chains are used to calculate sentiment
pResult Pointer to a SalienceSentimentResult structure
acConfigurationID Character string specifying the configuration for the results, blank for the default configuration

Returns

This function returns an integer return code.

Comments

TODO: Insert explanation when to set nUseChains to 0 or 1

Example

     char* acPath = "/path/to/content";
     ...
     SalienceSession* pSession;
     if(lxaOpenSalienceSession(oLicense, &oStartup, &pSession) != LXA_OK)
          return 1;
     lxaPrepareTextFromFile(pSession,acPath);
     SalienceSentimentResult oResult;
     lxaGetSentiment(pSession,1,&oResult);

     //Phrase-based sentiment results
     std::cout << "Document Sentiment: " << oResult.fScore << std::endl;

     SalienceSentimentPhraseList sspList = oResult.oPhrases;
     for(int i = 0; i < sspList.nLength; i++)
     {
          std::cout << "oPhrase: " << sspList.pPhrases->oPhrase.acText << std::endl;
          std::cout << "oSupportingPhrase: " << sspList.pPhrases->oSupportingPhrase.acText;
     }

     //Model-based sentiment results
     SalienceSentimentModel* ssm = oResult.pModel;
     std::cout << "Model:\t" << ssm->acModelName << std::endl;
     std::cout << "Best:\t" << ssm->nBest << std::endl;
     std::cout << "Pos:\t" << ssm->fPositive << std::endl;
     std::cout << "Neg:\t" << ssm->fNegative << std::endl;
     std::cout << "Mixed:\t" << ssm->fMixed << std::endl;
     std::cout << "Count:\t" << oResult.nModelCount << std::endl;

     lxaFreeSentimentResult(&oResult);
     lxaCloseSalienceSession(pSession);

<< lxaGetSummary | Back to Salience 6 C API Index | lxaGetThemes >>