Salience

The Salience Developer Hub

Welcome to the Salience developer hub. You'll find comprehensive guides and documentation to help you start working with Salience as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started

Marked Text

lxaGetNamedEntityMarkup

Summary

Provides a structured representation of the document with annotation of entities identified within the text. The SalienceDocument structure contains a set of SalienceSentence structures, which contain SalienceWord structures that contain information about the entities 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 lxaGetNamedEntityMarkup(SalienceSession *pSession,
                            SalienceDocument *pDocument,
                            const char *acConfigurationID);

Parameters

pSession

Pointer to a [SalienceSession][9] structure previously returned by a call to [lxaOpenSalienceSession][10]

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

std::string sMarkup = "";
         int nPrimaryId = -1;
         int nSecondaryId = -1;
         std::string sType = "";
    
         SalienceDocument oDocument;
         lxaGetNamedEntityMarkup(pSession,&oDocument);
    
         for(size_t i = 0; i < oDocument.nSentenceCount; i++)
         {
              for(size_t j = 0; j < oDocument.pSentences[i].nLength; j++)
              {
                   if(oDocument.pSentences[i].pTokens[j].nId == -1)
                   {
                        if(nPrimaryId != -1)
                        {
                             sMarkup += "</";
                             sMarkup += sType;
                             sMarkup += ">";
                             nPrimaryId = -1;
                             nSecondaryId = -1;
                        }
                        if(oDocument.pSentences[i].pTokens[j].nPostFixed == 0)
                        {
                             sMarkup += " ";
                        }
                        sMarkup += oDocument.pSentences[i].pTokens[j].acToken;
                   }
                   else
                   {
                        if(nPrimaryId == oDocument.pSentences[i].pTokens[j].nId && 
                           nSecondaryId == oDocument.pSentences[i].pTokens[j].nSecondaryId)
                        {
                             if(oDocument.pSentences[i].pTokens[j].nPostFixed == 0)
                             {
                                  sMarkup += " ";
                             }
                             sMarkup += oDocument.pSentences[i].pTokens[j].acToken;
                        }
                        else
                        {
                             if(nPrimaryId != -1)
                             {
                                  sMarkup += "</";
                                  sMarkup += sType;
                                  sMarkup += ">";
                             }
                             if(oDocument.pSentences[i].pTokens[j].nPostFixed == 0)
                             {
                                  sMarkup += " ";
                             }
                             nPrimaryId = oDocument.pSentences[i].pTokens[j].nId;
                             nSecondaryId = oDocument.pSentences[i].pTokens[j].nSecondaryId;
                             sType = oDocument.pSentences[i].pTokens[j].acEntityType;
                             sMarkup += "<";
                             sMarkup += sType;
                             sMarkup += ">";
                             sMarkup += oDocument.pSentences[i].pTokens[j].acToken;
                        }
                   }
              }
         }
         if(nPrimaryId != -1)
         {
              sMarkup += "</";
              sMarkup += sType;
              sMarkup += ">";
              nPrimaryId = -1;
              nSecondaryId = -1;
         }
    
         std::cout << sMarkup << std::endl;
         lxaFreeDocument(&oDocument);

lxaGetUserEntityMarkup

Summary

Provides a structured representation of the document with annotation of user-defined entities identified within the text. The SalienceDocument structure contains a set of SalienceSentence structures, which contain SalienceWord structures that contain information about the entities 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 lxaGetUserEntityMarkup(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

std::string sMarkup = "";
         int nPrimaryId = -1;
         int nSecondaryId = -1;
         std::string sType = "";
    
         SalienceDocument oDocument;
         lxaGetUserEntityMarkup(pSession,&oDocument);
    
         for(size_t i = 0; i < oDocument.nSentenceCount; i++)
         {
              for(size_t j = 0; j < oDocument.pSentences[i].nLength; j++)
              {
                   if(oDocument.pSentences[i].pTokens[j].nId == -1)
                   {
                        if(nPrimaryId != -1)
                        {
                             sMarkup += "</";
                             sMarkup += sType;
                             sMarkup += ">";
                             nPrimaryId = -1;
                             nSecondaryId = -1;
                        }
                        if(oDocument.pSentences[i].pTokens[j].nPostFixed == 0)
                        {
                             sMarkup += " ";
                        }
                        sMarkup += oDocument.pSentences[i].pTokens[j].acToken;
                   }
                   else
                   {
                        if(nPrimaryId == oDocument.pSentences[i].pTokens[j].nId && 
                           nSecondaryId == oDocument.pSentences[i].pTokens[j].nSecondaryId)
                        {
                             if(oDocument.pSentences[i].pTokens[j].nPostFixed == 0)
                             {
                                  sMarkup += " ";
                             }
                             sMarkup += oDocument.pSentences[i].pTokens[j].acToken;
                        }
                        else
                        {
                             if(nPrimaryId != -1)
                             {
                                  sMarkup += "</";
                                  sMarkup += sType;
                                  sMarkup += ">";
                             }
                             if(oDocument.pSentences[i].pTokens[j].nPostFixed == 0)
                             {
                                  sMarkup += " ";
                             }
                             nPrimaryId = oDocument.pSentences[i].pTokens[j].nId;
                             nSecondaryId = oDocument.pSentences[i].pTokens[j].nSecondaryId;
                             sType = oDocument.pSentences[i].pTokens[j].acEntityType;
                             sMarkup += "<";
                             sMarkup += sType;
                             sMarkup += ">";
                             sMarkup += oDocument.pSentences[i].pTokens[j].acToken;
                        }
                   }
              }
         }
         if(nPrimaryId != -1)
         {
              sMarkup += "</";
              sMarkup += sType;
              sMarkup += ">";
              nPrimaryId = -1;
              nSecondaryId = -1;
         }
    
         std::cout << sMarkup << std::endl;
         lxaFreeDocument(&oDocument);

lxaGetPOSMarkup

Summary

Provides a structured representation of the document with annotation of the part-of-speech tag for each word. The SalienceDocument structure contains a set of SalienceSentence structures, which contain SalienceWord structures that contain information about the part-of-speech tag identified for each word.

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 lxaGetPOSMarkup(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

std::string sMarkup = "";
         SalienceDocument oDocument;      
         lxaGetPOSMarkup(pSession,&oDocument);
    
         for (int i = 0; i < oDocument.nSentenceCount; i++)
         {
              for (int j = 0; j < oDocument.pSentences[i].nLength; j++)
              {
                   if(oDocument.pSentences[i].pTokens[j].nPostFixed == 0)
                   {
                        sMarkup += " ";
                   }
                   std::string sTag(oDocument.pSentences[i].pTokens[j].acPOSTag);
                   sMarkup += "<";
                   sMarkup += sTag;
                   sMarkup += ">";
                   sMarkup += oDocument.pSentences[i].pTokens[j].acToken;
                   sMarkup += "</";
                   sMarkup += sTag;
                   sMarkup += ">";
              }
         }
    
         std::cout << sMarkup << std::endl;
         lxaFreeDocument(&oDocument);

lxaGetSentimentMarkup

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);

lxaGetNamedOpinionTaggedText

Summary

Retrieves the text marked up with the opinions, where the opinions involve entities within the text. This function sets the passed in char* to point to an null terminated string containing the tagged text.

The acConfigurationID parameter specifies the configuration for the results. Configurations are defined using the method lxaAddSalienceConfiguration.

After use you should free the allocated memory by calling lxaFreeString.

Syntax

int lxaGetNamedOpinionTaggedText(SalienceSession *pSession,
                                 char **acTaggedText,
                                 const char *acConfigurationID);

Parameters

pSession

Pointer to a SalienceSession structure previously returned by a call to lxaOpenSalienceSession

acTaggedText

Pointer to a char* buffer

acConfigurationID

Character string specifying the configuration for the results, blank for the default configuration

Returns

This method returns an integer return code.

Example

char* acOpinionTaggedText;
         lxaGetNamedOpinionTaggedText(pSession, &acOpinionTaggedText);
         cout << acOpinionTaggedText << endl;
         lxaFreeString(acOpinionTaggedText);

lxaGetUserOpinionTaggedText

Summary

Retrieves the text marked up with the opinions, where the opinions involve user-defined entities within the text. This function sets the passed in char* to point to an null terminated string containing the tagged text.

The acConfigurationID parameter specifies the configuration for the results. Configurations are defined using the method lxaAddSalienceConfiguration.

After use you should free the allocated memory by calling lxaFreeString.

Syntax

int lxaGetUserOpinionTaggedText(SalienceSession *pSession,
                                char **acTaggedText,
                                const char *acConfigurationID);

Parameters

pSession

Pointer to a SalienceSession structure previously returned by a call to lxaOpenSalienceSession

acTaggedText

Pointer to a char* buffer

acConfigurationID

Character string specifying the configuration for the results, blank for the default configuration

Returns

This method returns an integer return code.

Example

char* acOpinionTaggedText;
         lxaGetUserOpinionTaggedText(pSession, &acOpinionTaggedText);
         cout << acOpinionTaggedText << endl;
         lxaFreeString(acOpinionTaggedText);

Updated 7 months ago

Marked Text


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.