Using Semantic Data

#include <LV_SRE_Semantic.h>

When the Call engine executes your semantic interpretation tags, the output is an ECMAScript (JavaScript) object.  LumenVox provides a C and C++ API for examining this object.  When the call engine has finished its decode, and processed the resulting parse tree and tags, you may request an interpretation object.  The interpretation object contains information about the decode -- confidence score, matching grammar, etc -- plus a single semantic data object.

 

The function LVCA_GetInterpretationData will retrieve a H_SI handle.  This is handle will be used with the functions found in the header LV_SRE_Semantic.h.  

void* vSI;

LONG count;

LVCA_GetNumberOfSRGSInterpretations(hCA, &count);

for(int i = 0; i < count; i++)

{

LVCA_GetInterpretaionData(hCA, i, vSI)

H_SI hSI = (H_SI) vSI

PrintXML(hSI);

PrintECMA(hSI);

LVIterpretation_Release(hSI);

}

 

The following sample code shows the general procedure of inspecting a semantic data. We will use C interface API to print semantic data in XML format, and use C++ interface API to print  semantic data in ECMAScript format.

Example 1: Use C interface API printing semantic data in XML format

void PrintXML(H_SI_DATA hsi, int depth)

{

//Indent properly

char* indent = (char*)malloc(depth+1);

memset(indent, '\t', depth);

indent[depth] = '\0';

 

int i;

switch(LVSemanticData_GetType(hsi))

{

case SI_TYPE_BOOL:

printf("%s",indent);

if (SI_DATA_GetBool(hsi))

printf("true\n");

else

printf("false\n");

break;

case SI_TYPE_INT:

printf("%s%d\n", indent, LVSemanticData_GetInt(hsi));

break;

case SI_TYPE_DOUBLE:

printf("%s%f\n", indent, LVSemanticData_GetDouble(hsi));

break;

case SI_TYPE_STRING:

printf("%s%s\n", indent, LVSemanticData_GetString(hsi));

break;

case SI_TYPE_OBJECT:

for (i=0;i<SI_DATA_Object_Size(hsi);i++) //Find out the number of properties in this
//object

{

printf("%s", indent);

printf("<%s>\n", SI_DATA_Object_Property_Id(hsi, i)); //Get each property name

 

//Each property has a handle to the data in next level.

//So we print it recursively.

PrintXML(SI_DATA_Object_Property_Value(hsi, SI_DATA_Object_Property_Id(hsi, i)), depth+1);

 

printf("%s", indent);

printf("</%s>\n", SI_DATA_Object_Property_Id(hsi, i));

}

break;

case SI_TYPE_ARRAY: //The processing of array is very similar to object

for (i=0;i<SI_DATA_Array_Size(hsi);i++)

{

printf("%s<item>\n", indent);

 

//Similar to object properties, each array element is a handle.

PrintXML(SI_DATA_Array_Element(hsi,i), depth+1);

printf("%s</item>\n", indent);

}

break;

default:

printf("%s[Undefined]\n", indent);

break;

}

 

free(indent);

}

 

Given the semantic data that we discussed earlier, the print out looks like:

 

<mystring>

abc

</mystring>

<myint>

5

</myint>

<sub_obj>

<mydouble1>

3.400000

</mydouble1>

<mydouble2>

4.500000

</mydouble2>

<mybool>

false

</mybool>

</sub_obj>

<myarray>

<item>

efg

</item>

<item>

hij

</item>

</myarray>

 

See Also


Complete Help Topic List | Speech Platform Product Information