Integration example of the Watson NLC service with the Dialog service - ibm-watson

From the Watson Dialog document, it indicates the configuration setups for connecting with NLC. But it is hard to understand how this works without a running sample application. Most of examples can be googled are without such settings. I were trying to find some examples which using the indicated setups from 'classifier' settings and 'INTENT:{xxxxxx}' settings etc. per docuemnt . It will be great if someone could help on this, very appreciated.

Here is an example using the demo NLC training data. Save that text to a CSV file.
Create your NLC service. Name of the service doesn't matter.
Once created, click the "Access Beta Toolkit". You will need to login again, and allow the toolkit access to the NLC service.
Click the "Upload training data" button. Select your CSV file you saved earlier. If it works, you will see your intents + questions. If it fails, most common issue is not giving it a csv file extension.
Click "Create classifier". Name is not important.
Clicking training data/classifiers to see if it has finished compiling. It can take some time to complete.
Once the classifier finishes compiling it should show you the classifier id value. Example: 3d84bfx43-nlc-10356
Copy the text below to an XML file. Where you see CLASSIFIER_ID_GOES_HERE change to your classifier id.
<?xml version="1.0" encoding="UTF-8"?>
<dialog xsi:noNamespaceSchemaLocation="WatsonDialogDocument_1.1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<flow>
<folder label="Main">
<output>
<prompt selectionType="RANDOM">
<item>Enter your weather related question.</item>
</prompt>
<getUserInput>
<search ref="folder_200143"/>
<default>
<output>
<prompt selectionType="RANDOM">
<item>I couldn't determine what you are asking about.</item>
</prompt>
</output>
</default>
</getUserInput>
</output>
</folder>
<folder label="Library">
<folder label="NLC Intents" id="folder_200143">
<input isAutoLearnCandidate="false" isRelatedNodeCandidate="true">
<grammar>
<item>conditions</item>
</grammar>
<output>
<prompt selectionType="RANDOM">
<item>I believe you are asking about conditions. </item>
</prompt>
</output>
</input>
<input>
<grammar>
<item>temperature</item>
</grammar>
<output>
<prompt selectionType="RANDOM">
<item>I believe you are asking about temperture. </item>
</prompt>
</output>
</input>
</folder>
</folder>
<folder label="Global"/>
<folder label="Concepts"/>
</flow>
<constants>
<var_folder name="Home"/>
</constants>
<variables>
<var_folder name="Home">
<var name="CLASSIFIER_CLASS_0" type="TEXT" description="auto-created"/>
<var name="CLASSIFIER_CONF_0" type="TEXT" description="auto-created"/>
<var name="CLASSIFIER_CLASS_1" type="TEXT" description="auto-created"/>
<var name="CLASSIFIER_CONF_1" type="TEXT" description="auto-created"/>
</var_folder>
</variables>
<settings>
<setting name="AUTOLEARN" type="USER">false</setting>
<setting name="LANGUAGE" type="USER">en-US</setting>
<setting name="RESPONSETIME" type="USER">-2</setting>
<setting name="MAXAUTOLEARNITEMS" type="USER">4</setting>
<setting name="NUMAUTOSETRELATED" type="USER">0</setting>
<setting name="TIMEZONEID" type="USER">Australia/Sydney</setting>
<setting name="AUTOSETRELATEDNODEID" type="USER">0</setting>
<setting name="INPUTMASKTYPE" type="USER">0</setting>
<setting name="CONCEPTMATCHING" type="USER">0</setting>
<setting name="DNR_NODE_ID">-15</setting>
<setting name="MULTISENT">0</setting>
<setting name="USE_CONCEPTS">3</setting>
<setting name="ENTITIES_SCOPE">3</setting>
<setting name="USER_LOGGING">2</setting>
<setting name="USE_TRANSLATIONS">3</setting>
<setting name="USE_STOP_WORDS">3</setting>
<setting name="USE_SPELLING_CORRECTIONS">3</setting>
<setting name="USE_AUTOMATIC_STOPWORDS_DETECTION">0</setting>
<setting name="PLATFORM_VERSION">10.1</setting>
<setting name="UI_COLOUR"></setting>
<setting name="PARENT_ACCOUNT"></setting>
<setting name="AL_NONE_LABEL">None of the above</setting>
<setting name="CLS_SEARCH_MODE">0</setting>
<setting name="CLS_MODEL">0</setting>
<setting name="CLS_ENDPOINT"></setting>
<setting name="CLS_USERNAME"></setting>
<setting name="CLS_PASSWORD"></setting>
<setting name="CLS_MODELNAME">CLASSIFIER_ID_GOES_HERE</setting>
<setting name="CLS_ADVANCED_SETTINGS">false</setting>
<setting name="CLS_MAXNBEST">3</setting>
<setting name="CLS_USE_OFFTOPIC">false</setting>
<setting name="DEFAULT_DNR_RETURN_POINT_CANDIDATE">-1</setting>
</settings>
<specialSettings>
<specialSetting label="DNR Join Statement">
<variations/>
</specialSetting>
<specialSetting label="AutoLearn Statement">
<variations/>
</specialSetting>
</specialSettings>
</dialog>
Upload that file to your dialog service and test it.

Related

How to map Administrator claim for Sitecore Active Directory SSO?

I'm configuring Active Directory Login for Sitecore 9.0.0. And I have issues with IsAdministrator role. I used the following map, but it didn't work.
Any idea about how to configure it?
<map name="Administrator Claim" type="Sitecore.Owin.Authentication.Services.DefaultClaimToPropertyMapper, Sitecore.Owin.Authentication">
<data hint="raw:AddData">
<source name="Administrator" />
<target name="IsAdministrator" value="true" />
</data>
</map>
You have to map http://www.sitecore.net/identity/claims/isAdmin claim in Sitecore.Owin.Authentication.IdentityServer.config file in the propertyInitializer section as follows:
<propertyInitializer>
<maps>
<map name="set IsAdministrator" type="Sitecore.Owin.Authentication.Services.DefaultClaimToPropertyMapper, Sitecore.Owin.Authentication">
<data hint="raw:AddData">
<source name="http://www.sitecore.net/identity/claims/isAdmin" value="true" />
<target name="IsAdministrator" value="true" />
</data>
</map>
</maps>
</propertyInitializer>
Read more details here.

log4net logger logging unexpected levels based on config

I have been trying to understand the config of the log4net library and I think I have it except for some unexpected behavior.
I have a root logger that has a level set to INFO and another logger for a specific class that has level set to ERROR.
What I expected from this was that the class logger would only log at error and ignore the roots level since I had additivity set to false for the class logger. Here is the log4net.config I have at the moment:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<logger name="EveStatic.Config.ViewModel" additivity="false">
<level value="error"/>
<appender-ref ref="ConsoleAppender"/>
<appender-ref ref="RollingFileAppender"/>
</logger>
<root>
<level value="debug" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
</configuration>
In my AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
And in the class that loads the configuration:
log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config"));
These two seem redundant but the configuration wont load unless I have the code part. Everything here is in a class library being used by another project.
Is this behavior expected and I don't understand the configuration and level overrides or am I forgetting something?
EDIT:
Here is how I instantiate and call the ILog. The the full class name is the name of the logger in the config plus the ConfiInfoViewModel:
private static readonly ILog LOG = LogManager.GetLogger(typeof(ConfigInfoViewModel));
...
LOG.Debug("Something buggy");
Also note that when testing the logging levels I had a log statement for each level in a series.
Your problem lays here
LogManager.GetLogger(typeof(ConfigInfoViewModel));
Internally this get resolved to
LogManager.GetLogger(typeof(ConfigInfoViewModel).FullName);
Now log4net is looking for a Logger named "EveStatic.Config.ConfigInfoViewModel" (result of typeof(ConfigInfoViewModel).FullName)
Because no Logger with that name is specified a new one with your default settings is used.
Also note that level specify a threshold, not a single level.
Example: level=warn means log warn an all levels above (error and fatal)

Parsing XML in T-SQL - ABS data

I'm after some assistance parsing an xml file provided by the Australian Bureau of Statistics. I've read over everything I can find here and online, and am not having much luck reading this data.
This is a sample of the XML:
<?xml version='1.0' encoding='UTF-8'?>
<message:MessageGroup xmlns:message="http://www.w3.org/2001/XMLSchema" xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic" xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic http://www.sdmx.org/docs/2_0/SDMXGenericData.xsd http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message http://www.sdmx.org/docs/2_0/SDMXMessage.xsd">
<Header xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message">
<ID>none</ID>
<Test>false</Test>
<Truncated>false</Truncated>
<Prepared>2018-02-14T22:41:03</Prepared>
<Sender id="ABS">
<Name xml:lang="en">Australian Bureau of Statistics</Name>
<Name xml:lang="fr">Australian Bureau of Statistics</Name>
</Sender>
</Header>
<DataSet keyFamilyURI="http://stat.data.abs.gov.au/restsdmx/sdmx.ashx/GetKeyFamily/RES_PROP_INDEX">
<KeyFamilyRef>RES_PROP_INDEX</KeyFamilyRef>
<Series>
<SeriesKey>
<Value concept="MEASURE" value="1" />
<Value concept="PROP_TYPE" value="3" />
<Value concept="ASGS_2011" value="3GBRI" />
<Value concept="FREQUENCY" value="Q" />
</SeriesKey>
<Attributes>
<Value concept="TIME_FORMAT" value="P3M" />
</Attributes>
<Obs>
<Time>2015-Q1</Time>
<ObsValue value="112.7" />
</Obs>
<Obs>
<Time>2015-Q2</Time>
<ObsValue value="113.7" />
</Obs>
</Series>
<Series>
<SeriesKey>
<Value concept="MEASURE" value="1" />
<Value concept="PROP_TYPE" value="3" />
<Value concept="ASGS_2011" value="5GPER" />
<Value concept="FREQUENCY" value="Q" />
</SeriesKey>
<Attributes>
<Value concept="TIME_FORMAT" value="P3M" />
</Attributes>
<Obs>
<Time>2015-Q1</Time>
<ObsValue value="114.4" />
</Obs>
<Obs>
<Time>2015-Q2</Time>
<ObsValue value="113.4" />
</Obs>
</Series>
<Annotations>
<common:Annotation>
<common:AnnotationTitle>Statistical usage warning</common:AnnotationTitle>
<common:AnnotationText>ABS.Stat beta is continuing to be developed. Data will be updated as soon as possible following its 11:30 am release on the ABS website.</common:AnnotationText>
</common:Annotation>
</Annotations>
</DataSet>
</message:MessageGroup>
The result set should return 3 values:
SeriesKey Value where Concept = 'ASGS_2011'
Obs "Time" Value
Obs "Obsvalue" Value
e.g the first record would return a row like:
3GBRI | 2015-Q1 | 112.7
This sample would return 4 rows of data like this.
I've tried inserting the XML into an XML variable or a column in a DB with an XML datatype, and then using SQL's XML functionality, but I'm an absolute novice at this and am having trouble with the correct coding/approach.
Any advice or sample code would be greatly appreciated.
I'd suggest do get rid of the <?xml blah ?> declaration. This is only useful when you store an XML to a file. Within SQL-Server any XML's encoding is fixed to unicode / UCS-2. This can lead to encoding problems...
There are namespaces involved...
DECLARE #xml XML=
'<?xml version=''1.0'' encoding=''UTF-8''?>
<message:MessageGroup xmlns:message="http://www.w3.org/2001/XMLSchema" xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic" xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic http://www.sdmx.org/docs/2_0/SDMXGenericData.xsd http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message http://www.sdmx.org/docs/2_0/SDMXMessage.xsd">
<Header xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message">
<ID>none</ID>
<Test>false</Test>
<Truncated>false</Truncated>
<Prepared>2018-02-14T22:41:03</Prepared>
<Sender id="ABS">
<Name xml:lang="en">Australian Bureau of Statistics</Name>
<Name xml:lang="fr">Australian Bureau of Statistics</Name>
</Sender>
</Header>
<DataSet keyFamilyURI="http://stat.data.abs.gov.au/restsdmx/sdmx.ashx/GetKeyFamily/RES_PROP_INDEX">
<KeyFamilyRef>RES_PROP_INDEX</KeyFamilyRef>
<Series>
<SeriesKey>
<Value concept="MEASURE" value="1" />
<Value concept="PROP_TYPE" value="3" />
<Value concept="ASGS_2011" value="3GBRI" />
<Value concept="FREQUENCY" value="Q" />
</SeriesKey>
<Attributes>
<Value concept="TIME_FORMAT" value="P3M" />
</Attributes>
<Obs>
<Time>2015-Q1</Time>
<ObsValue value="112.7" />
</Obs>
<Obs>
<Time>2015-Q2</Time>
<ObsValue value="113.7" />
</Obs>
</Series>
<Series>
<SeriesKey>
<Value concept="MEASURE" value="1" />
<Value concept="PROP_TYPE" value="3" />
<Value concept="ASGS_2011" value="5GPER" />
<Value concept="FREQUENCY" value="Q" />
</SeriesKey>
<Attributes>
<Value concept="TIME_FORMAT" value="P3M" />
</Attributes>
<Obs>
<Time>2015-Q1</Time>
<ObsValue value="114.4" />
</Obs>
<Obs>
<Time>2015-Q2</Time>
<ObsValue value="113.4" />
</Obs>
</Series>
<Annotations>
<common:Annotation>
<common:AnnotationTitle>Statistical usage warning</common:AnnotationTitle>
<common:AnnotationText>ABS.Stat beta is continuing to be developed. Data will be updated as soon as possible following its 11:30 am release on the ABS website.</common:AnnotationText>
</common:Annotation>
</Annotations>
</DataSet>
</message:MessageGroup>';
--The query will declare the needed namespaces and then use .nodes() to get the <Series> and a second call to .nodes() to get the nested <Obs>:
WITH XMLNAMESPACES(DEFAULT 'http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic'
,'http://www.w3.org/2001/XMLSchema' AS message)
SELECT ser.value(N'(SeriesKey/Value[#concept="ASGS_2011"]/#value)[1]',N'nvarchar(max)') AS Concept
,obs.value(N'(Time/text())[1]',N'nvarchar(max)') AS [Time]
,obs.value(N'(ObsValue/#value)[1]',N'decimal(10,4)') AS ObsValue
FROM #xml.nodes(N'/message:MessageGroup/DataSet/Series') AS A(ser)
OUTER APPLY A.ser.nodes(N'Obs') AS B(obs);
The result
Concept Time ObsValue
3GBRI 2015-Q1 112.7000
3GBRI 2015-Q2 113.7000
5GPER 2015-Q1 114.4000
5GPER 2015-Q2 113.4000

Structuring recovery message for invalid input in Watson Dialog

I'm designing Watson dialog to support following scenario: user to select intent 1,2, or 3. When user select intent 2, Watson will ask user to specify either option 1 or 2 or alternatively other valid intents.
Following is my current dialog file:
<?xml version="1.0" encoding="UTF-8"?>
<dialog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="WatsonDialogDocument_1.0.xsd">
<flow>
<folder label="Main" id="Main">
<output id="start">
<prompt selectionType="RANDOM">
<item>DIALOG START - asking for user input</item>
</prompt>
<goto ref="processUserInput_start"/>
</output>
<getUserInput id="processUserInput_start">
<search ref="library_supported-intents"/>
<default>
<output>
<prompt selectionType="RANDOM">
<item>I am sorry, I did not understand your intents. Please choose intent1, intent2, or intent3.</item>
</prompt>
</output>
</default>
</getUserInput>
<getUserInput id="processUserInput_intent2">
<search ref="library_supported-intents"/>
<input>
<grammar>
<item>option1</item>
</grammar>
<output>
<prompt selectionType="RANDOM">
<item>OK. Executing intent 2 with option 1</item>
</prompt>
</output>
<goto ref="processUserInput_start"/>
</input>
<input>
<grammar>
<item>option2</item>
</grammar>
<output>
<prompt selectionType="RANDOM">
<item>OK. Executing intent 2 with option 2</item>
</prompt>
</output>
<goto ref="processUserInput_start"/>
</input>
<output>
<prompt selectionType="RANDOM">
<item>Sorry, I can only understand option1 and option2 for intent2. Try again</item>
</prompt>
<goto ref="processUserInput_intent2"/>
</output>
</getUserInput>
</folder>
<folder label="Library" id="Library">
<folder label="Main Input" id="library_supported-intents">
<input>
<grammar>
<item>intent1</item>
</grammar>
<output>
<prompt selectionType="RANDOM">
<item>OK. Executing intent 1</item>
</prompt>
</output>
</input>
<input>
<grammar>
<item>intent2</item>
</grammar>
<goto ref="intent2-detail"/>
</input>
<input>
<grammar>
<item>intent3</item>
</grammar>
<output>
<prompt selectionType="RANDOM">
<item>OK. Executing intent 3</item>
</prompt>
</output>
</input>
</folder>
<folder label="Intent 2 Input" id="library_intent2">
<output id="intent2-detail">
<prompt selectionType="RANDOM">
<item>OK. I need further info to execute intent 2. Choose option1 or option2</item>
</prompt>
<goto ref="processUserInput_intent2"/>
</output>
</folder>
</folder>
<folder label="Concepts" id="Concepts"></folder>
</flow>
</dialog>
Unfortunately, I could not get appropriate invalid dialog message being displayed - e.g. Watson shows invalid option instead of invalid intent message, as following:
How should I structure recovery dialog flow to achieve above scenario?
try to put the goto inside the output node
<input>
<grammar>
<item>option1</item>
</grammar>
<output>
<prompt selectionType="RANDOM">
<item>OK. Executing intent 2 with option 1</item>
</prompt>
<goto ref="processUserInput_start"/>
</output>
</input>

Adding SQL Stored Procedure Parameters to an existing Schema and SendPort

This biztalk Orch was working perfectly before I touched it. I did two things:
Modified the schema below adding 3 key, type and c_date
Modified my message transform so that those 3 additional parameters were mapped to the destination schema.
<?xml version="1.0" encoding="utf-16"?>
<schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:ns3="http://schemas.datacontract.org/2004/07/System.Data" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo" version="1.0" xmlns="http://www.w3.org/2001/XMLSchema">
<import schemaLocation=".\sqlBinding_System_x2eData.xsd" namespace="http://schemas.datacontract.org/2004/07/System.Data" />
<annotation>
<appinfo>
<fileNameHint xmlns="http://schemas.microsoft.com/servicemodel/adapters/metadata/xsd">Procedure.dbo</fileNameHint>
<references xmlns="http://schemas.microsoft.com/BizTalk/2003">
<reference targetNamespace="http://schemas.datacontract.org/2004/07/System.Data" />
</references>
</appinfo>
</annotation>
<element name="Vendor_Receive_IPN_Message_sp">
<annotation>
<documentation>
<doc:action xmlns:doc="http://schemas.microsoft.com/servicemodel/adapters/metadata/documentation">Procedure/dbo/Vendor_Receive_IPN_Message_sp</doc:action>
</documentation>
</annotation>
<complexType>
<sequence>
<element minOccurs="0" maxOccurs="1" name="data" nillable="true" type="string" />
<element minOccurs="0" maxOccurs="1" name="key" nillable="true" type="string" />
<element minOccurs="0" maxOccurs="1" name="type" nillable="true" type="string" />
<element minOccurs="0" maxOccurs="1" name="c_date" nillable="true" type="dateTime" />
</sequence>
</complexType>
</element>
<element name="Vendor_Receive_IPN_Message_spResponse">
<annotation>
<documentation>
<doc:action xmlns:doc="http://schemas.microsoft.com/servicemodel/adapters/metadata/documentation">Procedure/dbo/Vendor_Receive_IPN_Message_sp/response</doc:action>
</documentation>
</annotation>
<complexType>
<sequence>
<element minOccurs="0" maxOccurs="1" name="Vendor_Receive_IPN_Message_spResult" nillable="true" type="ns3:ArrayOfDataSet" />
<element minOccurs="1" maxOccurs="1" name="ReturnValue" type="int" />
</sequence>
</complexType>
</element>
</schema>
I'm getting this error:
The adapter failed to transmit message going to send port "SendPort IPN Message to SQL" with
URL "mssql://myserver:1433//mydb?". It will be retransmitted after
the retry interval specified for this Send Port.
Details:"Microsoft.ServiceModel.Channels.Common.XmlReaderParsingException:
The start element with name "key" and namespace
"http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo" was unexpected.
Please ensure that your input XML conforms to the schema for the operation.
What step am I missing?
When you add nodes to a SP schema, they have to be
In the same order as in the procedure (is #key the second param, or did you put it before #data?).
Use the same spelling and casing as the procedure (is it called #key or #Key in the procedure?).
Use an XSD data type that corresponds to the datatype the procedure expects (is #key a (N)VARCHAR or (N)CHAR?).
The error you're getting indicates either 1 or 2 isn't correct. Show us your procedure definition to be sure. You could also regenerate the schema for the procedure in a separate (throw away) project and compare it with your changes.

Resources