lxaGetSentimentMarkup

<< lxaGetPOSMarkup | Back to Salience 6 C API Index | lxaGetNamedOpinionTaggedText >>

Summary

Provides a structured representation of the document with annotation of sentiment-bearing phrases identified within the text. The SalienceDocument structure contains a set of SalienceSentence structures, which contain SalienceWord structures that contain information about the sentiment-bearing phrases within the document.
The acConfigurationID parameter specifies the configuration for the results. Configurations are defined using the method lxaAddSalienceConfiguration.
After use, you should free allocated memory by calling lxaFreeDocument.

Syntax

int lxaGetSentimentMarkup(SalienceSession *pSession,
                          SalienceDocument *pDocument,
                          const char *acConfigurationID);

Parameters

pSession Pointer to a SalienceSession structure previously returned by a call to lxaOpenSalienceSession
pDocument Pointer to a SalienceDocument structure that will get filled in by the call
acConfigurationID Character string specifying the configuration for the results, blank for the default configuration

Returns

This method returns an integer return code.

Example

     float fPositive = 0.3;
     float fNegative = -0.3;

     std::string sMarkup = "";
     SalienceDocument oDocument; 
     lxaGetSentimentMarkup(pSession,&oDocument);
     std::string sLastTag = "";

     for (int i = 0; i < oDocument.nSentenceCount; i++)
     {
          for (int j = 0; j < oDocument.pSentences[i].nLength; j++)
          {
               std::string sTag = "";
               int nType = oDocument.pSentences[i].pTokens[j].nSentimentType;
               if(nType != -1)
               {
                    if(nType == 0)
                    {
                         sTag = "LXA_STOP";
                    }
                    else if(nType == 2)
                    {
                         sTag = "LXA_POSSIBLE";
                    }
                    else if(oDocument.pSentences[i].pTokens[j].nInvert != 0)
                    {
                         sTag = "LXA_INVERT";
                    }
                    else
                    {
                         if(nType == 1)
                         {
                              sTag = "LXA_HANDSCORE_";
                         }
                         else
                         {
                              sTag = "LXA_INTERNAL_";
                         }
                         if(oDocument.pSentences[i].pTokens[j].fSentiment < fNegative)
                         {
                              sTag += "NEGATIVE";
                         }
                         else if(oDocument.pSentences[i].pTokens[j].nSentimentType > fPositive)
                         {
                              sTag += "POSITIVE";
                         }
                         else
                         {
                              sTag += "NEUTRAL";
                         }
                    }
               }
               if(sTag.compare(sLastTag))
               {
                    if(!sLastTag.empty())
                    {
                         sMarkup += "</";
                         sMarkup += sLastTag;
                         sMarkup += ">";
                    }
                    if(oDocument.pSentences[i].pTokens[j].nPostFixed == 0)
                    {
                         sMarkup += " ";
                    }
                    if(!sTag.empty())
                    {
                         sMarkup += "<";
                         sMarkup += sTag;
                         sMarkup += ">";
                    }
                    sMarkup += oDocument.pSentences[i].pTokens[j].acToken;
                    sLastTag = sTag;
               }
               else
               {
                    if(oDocument.pSentences[i].pTokens[j].nPostFixed == 0)
                    {
                         sMarkup += " ";
                    }
                    sMarkup += oDocument.pSentences[i].pTokens[j].acToken;
               }
          }
          if (!sLastTag.empty())
          {
               sMarkup += "</";
               sMarkup += sLastTag;
               sMarkup += ">";
          }
     }

     std::cout << sMarkup << std::endl;
     lxaFreeDocument(&oDocument);

<< lxaGetPOSMarkup | Back to Salience 6 C API Index | lxaGetNamedOpinionTaggedText >>