Marked Text

API Reference related to retrieving structured representation of analyzed documents.

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.

Returns: Integer return code. To retrieve more information on the return code use lxaGetLastWarnings on the SalienceSession structure.

More information on errors and warnings can be found in the Errors and Warning Codes section of our documentation.

Function Signature:
int lxaGetNamedEntityMarkup(SalienceSession *pSession, SalienceDocument *pDocument, const char *acConfigurationID);

Parameters

Description

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

Example:
Use lxaLoadLicense to create LexalyticsLicense structure. This will then be given to lxaOpenSalienceSession, which is then used to start a session with Salience.

/* Assuming a SalienceSession (*pSession) has already been opened with
    a valid LexalyticsLicense */

  std::string sMarkup = "";
  int nPrimaryId = -1;
  int nSecondaryId = -1;
  std::string sType = "";

    // Get entity markup and store it in oDocument
  SalienceDocument oDocument;
  lxaGetNamedEntityMarkup(pSession,&oDocument);

    // Convert into markup language
  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;
  }

    // Send to standard output stream and free memory
  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.

Function Signature:
int lxaGetUserEntityMarkup(SalienceSession *pSession, SalienceDocument *pDocument, const char *acConfigurationID);

Returns: Integer return code. To retrieve more information on the return code use lxaGetLastWarnings on the SalienceSession structure.

More information on errors and warnings can be found in the Errors and Warning Codes section of our documentation.

Parameters

Description

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

Example:
Use lxaLoadLicense to create LexalyticsLicense structure. This will then be given to lxaOpenSalienceSession, which is then used to start a session with Salience.

/* Assuming a SalienceSession (*pSession) has already been opened with
    a valid LexalyticsLicense */

  std::string sMarkup = "";
  int nPrimaryId = -1;
  int nSecondaryId = -1;
  std::string sType = "";

    // Get user defined entity markup and store it in oDocument
  SalienceDocument oDocument;
  lxaGetUserEntityMarkup(pSession,&oDocument);

    // Convert to markup language and store it in sMarkup
  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;
  }

    // Send to standard output stream and free memory
  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.

Returns: Integer return code. To retrieve more information on the return code use lxaGetLastWarnings on the SalienceSession structure.

More information on errors and warnings can be found in the Errors and Warning Codes section of our documentation.

Function Signature:
int lxaGetPOSMarkup(SalienceSession *pSession, SalienceDocument *pDocument, const char *acConfigurationID);

Parameters

Desci

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

Example:
Use lxaLoadLicense to create LexalyticsLicense structure. This will then be given to lxaOpenSalienceSession, which is then used to start a session with Salience.

/* Assuming a SalienceSession (*pSession) has already been opened with
    a valid LexalyticsLicense */

  std::string sMarkup = "";

    // Call lxaGetPOSMarkup and store result in oDocument
  SalienceDocument oDocument;      
  lxaGetPOSMarkup(pSession,&oDocument);


    // Convert to markup for parts-of-speech
  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 += ">";
    }
  }

    // Send to standard output stream and free memory
  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.

Returns: Integer return code. To retrieve more information on the return code use lxaGetLastWarnings on the SalienceSession structure.

More information on errors and warnings can be found in the Errors and Warning Codes section of our documentation.

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

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

Example:
Use lxaLoadLicense to create LexalyticsLicense structure. This will then be given to lxaOpenSalienceSession, which is then used to start a session with Salience.

/* Assuming a SalienceSession (*pSession) has already been opened with
    a valid LexalyticsLicense */

  float fPositive = 0.3;
  float fNegative = -0.3;

  std::string sMarkup = "";
    std::string sLastTag = "";

    // Call lxaGetSentimentMarkup and store result in oDocument
  SalienceDocument oDocument; 
  lxaGetSentimentMarkup(pSession,&oDocument);
  
    // Convert to markup for sentiment 
  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 += ">";
    }
  }

    // Send to standard output stream and free memory
  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.

Returns: Integer return code. To retrieve more information on the return code use lxaGetLastWarnings on the SalienceSession structure.

More information on errors and warnings can be found in the Errors and Warning Codes section of our documentation.

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

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

Example:
Use lxaLoadLicense to create LexalyticsLicense structure. This will then be given to lxaOpenSalienceSession, which is then used to start a session with Salience.

/* Assuming a SalienceSession (*pSession) has already been opened with
    a valid LexalyticsLicense */

    // Call to lxaGetNamedOpinion and store in acOpinionTaggedText
  char* acOpinionTaggedText;
  lxaGetNamedOpinionTaggedText(pSession, &acOpinionTaggedText);

    // Send to standard output stream and free memory
  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.

Returns: Integer return code. To retrieve more information on the return code use lxaGetLastWarnings on the SalienceSession structure.

More information on errors and warnings can be found in the Errors and Warning Codes section of our documentation.

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

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

Example:
Use lxaLoadLicense to create LexalyticsLicense structure. This will then be given to lxaOpenSalienceSession, which is then used to start a session with Salience.

/* Assuming a SalienceSession (*pSession) has already been opened with
    a valid LexalyticsLicense */

    // Call to lxaGetUserOpinionTaggedText and store in acOpinionTaggedText
    char* acOpinionTaggedText;
  lxaGetUserOpinionTaggedText(pSession, &acOpinionTaggedText);

    // Send to standard output stream and free memory
  cout << acOpinionTaggedText << endl;
  lxaFreeString(acOpinionTaggedText);