Parse number with cortana
Asked Answered
P

1

6

I have a Cortana XML file and I need to input a number. What should I do to ensure I can convert it to a number?

<Command Name="AddMoney">
  <Example> Add 10 dollars </Example>
  <ListenFor> add {amount} {currency} </ListenFor>
  <Feedback> Adding some money </Feedback>
  <Navigate/>
</Command>

<PhraseList Label="currency">
    <item>dollar</item>
    <item>euro</item>
    <item>pound</item>
</PhraseList>

<PhraseList Label="amount">
</PhraseList>
Pestilence answered 26/11, 2015 at 14:51 Comment(0)
P
4

I found a way to receive numbers, but it is not perfect.

<PhraseTopic Label="amount" Scenario="Commands">
  <Subject>Phone Number</Subject>
</PhraseTopic>

Note I'm using PhraseTopic instead of PhraseList. I don't really know which Scenario is the best here, but I found Commands to yield better results than having no Scenario set. The PhraseTopic tag must be placed after all PhraseList tags for some odd reason...

When trying subjects, the auto complete feature showed a few options where the most promising were Date/Time, Addresses and Phone Number. When trying with multiple subjects I could never have a match, but with "Phone Number" (or just "Number" even if there's no such option) I was able to receive number values somewhat consistently.

The number cames in digits form, so I only need int.TryParse(myText, out myNumber) and use it or say something as "invalid number input".

Be aware that any thing can be input here, even with the subject and scenario restrictions... The folowing will work:

"Hey Cortana, MyAppName add blah blah blah dollars"

And the amount will literally be "blah blah blah"

Pestilence answered 26/11, 2015 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.