I used SpeechRecognizerUI to read user's voice input. I was expecting to get dollar amount so $200 or $20.32 or $0.43 is an example. However, the response from backend is always like "20 point 32" or "20 dot 32" or "zero point forty five. Is there a better way to use the API samrtly so that I can get "200, 20.32, 0.45"? Thanks!
You could try looking in the alternates, but aside from that, I don't see any way to control text normalization in dictation grammars.
You can load your own grammar to SpeechRecognizer as described here: Adding, loading, and preloading grammars for Windows Phone 8.
In your case will be useful SRGS grammar.
You should create grammar like this (I get this from Microsoft Speech example):
<grammar version="1.0" xml:lang="en-US" mode="voice" root="amount"
xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0">
<rule id="amount">
<item repeat="1-3">
<ruleref uri="#number"/>
</item>
<item repeat="0-1">
<ruleref uri="#dot"/>
<item>
<item repeat="0-2">
<ruleref uri="#number"/>
</item>
</rule>
<rule id="dot">
<one-of>
<item> point <tag> out = "." ; </tag> </item>
<item> dot <tag> out = "." ; </tag> </item>
</one-of>
</rule>
<rule id="number">
<one-of>
<item> one <tag> out = 1; </tag> </item>
<item> two <tag> out = 2; </tag> </item>
<item> three <tag> out = 3; </tag> </item>
<item> four <tag> out = 4; </tag> </item>
<item> five <tag> out = 5; </tag> </item>
<item> six <tag> out = 6; </tag> </item>
<item> seven <tag> out = 7; </tag> </item>
<item> eight <tag> out = 8; </tag> </item>
<item> nine <tag> out = 9; </tag> </item>
<item> ten <tag> out = 10; </tag> </item>
</one-of>
</rule>
</grammar>
Related
Problem to load multiple repeating tags "<image></image>" with data to one <images> table cell.
XML
<posts>
<item>
<id>1</id>
<type>post</type>
<url>www.url.com/1</url>
<date>2016-06-15</date>
<image>some url/1xxx.jpg</image>
<image>some url/1yyy.jpg</image>
<image>some url/1zzz.jpg</image>
</item>
<item>
<id>2</id>
<type>post</type>
<url>www.url.com/2</url>
<date>2016-06-12</date>
<image>some url/2xxx.jpg</image>
<image>some url/2yyy.jpg</image>
<image>some url/2zzz.jpg</image>
<image>some url/2www.jpg</image>
</item>
<item>
<id>3</id>
<type>post</type>
<url>www.url.com/3</url>
<date>2016-06-12</date>
<image>some url/3fff.jpg</image>
</item>
</posts>
Code
Now it loads only last <image> tag from <item>
LOAD XML local infile 'D:\\demo.xml'
REPLACE
INTO TABLE posts CHARACTER SET UTF8
ROWS IDENTIFIED BY '<item>'
(#id, #type, #url, #date, #image)
SET id=#id, type=#type, url=#url, date = str_to_date(#date, '%Y-%m'), images=#image;
How to store all duplicate <image> tags as images VARCHAR or TEXT
Consider transforming your XML with XSLT to normalize the item and images into one-to-many tables. Below uses PHP to run XSLT but most general purpose languages can run XSLT 1.0 scripts including PHP, Perl, Python, Java, C#, VB. Specifically, the transformation will break <image> tags out of <item> keeping corresponding <id> and maintain two sets of tags to upload to two MySQL database tables.
XSLT Script (save as .xsl file)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/posts">
<xsl:copy>
<xsl:apply-templates select="item"/>
<xsl:apply-templates select="item/image"/>
</xsl:copy>
</xsl:template>
<xsl:template match="item">
<xsl:copy>
<xsl:copy-of select="*[local-name()!='image']"/>
</xsl:copy>
</xsl:template>
<xsl:template match="item/image">
<images>
<itemid><xsl:value-of select="ancestor::item/id"/></itemid>
<xsl:copy-of select="."/>
</images>
</xsl:template>
</xsl:stylesheet>
PHP Script
<?php
$cd = dirname(__FILE__);
// LOAD XML AND XSL FILES
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->load('Original.xml');
$xslfile = new DOMDocument('1.0', 'UTF-8');
$xslfile->load('XSLT_Script.xsl');
// TRANSFORM XML with XSLT
$proc = new XSLTProcessor;
$proc->importStyleSheet($xslfile);
$newXml = $proc->transformToXML($xml);
// SAVE TO FILE
file_put_contents('Output.xml', $newXml);
?>
Output (images contain item id)
<?xml version="1.0"?>
<posts>
<item>
<id>1</id>
<type>post</type>
<url>www.url.com/1</url>
<date>2016-06-15</date>
</item>
<item>
<id>2</id>
<type>post</type>
<url>www.url.com/2</url>
<date>2016-06-12</date>
</item>
<item>
<id>3</id>
<type>post</type>
<url>www.url.com/3</url>
<date>2016-06-12</date>
</item>
<images>
<itemid>1</itemid>
<image>some url/1xxx.jpg</image>
</images>
<images>
<itemid>1</itemid>
<image>some url/1yyy.jpg</image>
</images>
<images>
<itemid>1</itemid>
<image>some url/1zzz.jpg</image>
</images>
<images>
<itemid>2</itemid>
<image>some url/2xxx.jpg</image>
</images>
<images>
<itemid>2</itemid>
<image>some url/2yyy.jpg</image>
</images>
<images>
<itemid>2</itemid>
<image>some url/2zzz.jpg</image>
</images>
<images>
<itemid>2</itemid>
<image>some url/2www.jpg</image>
</images>
<images>
<itemid>3</itemid>
<image>some url/3fff.jpg</image>
</images>
</posts>
SQL (two tables to upload)
-- POSTS TABLE
LOAD XML local infile 'C:\\Path\\To\\Output.xml'
REPLACE
INTO TABLE posts CHARACTER SET UTF8
ROWS IDENTIFIED BY '<item>'
(#id, #type, #url, #date)
SET id=#id, type=#type, url=#url, date=str_to_date(#date, '%Y-%m');
-- IMAGES TABLE
LOAD XML local infile 'C:\\Path\\To\\Output.xml'
REPLACE
INTO TABLE images CHARACTER SET UTF8
ROWS IDENTIFIED BY '<images>'
(#itemid, #image)
SET itemid=#itemid, image=#image;
I'm new to XML i have made an XML file and an XSL file. After linking the XSL file to the XML file, the output of the XML in the browser goes blank. I could not find the error.
This is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="cupcake.xsl"?>
<cupcakes>
<item>
<name>Luscious Vanilla</name>
<flavour>Vanilla</flavour>
<colour>Brown</colour>
<energy> 100 cj </energy>
</item>
<item>
<name>Chocolate Hazelnut</name>
<flavour>chocolaty</flavour>
<colour>coffe</colour>
<energy> 100 cj </energy>
<cost> $10 </cost>
</item>
<item>
<name>Risch Red Velvet</name>
<flavour>red velvet</flavour>
<colour>red</colour>
<energy> 100 cj </energy>
<cost> $10 </cost>
</item>
<item>
<name>Classic straberry</name>
<flavour>straberry</flavour>
<colour>pink</colour>
<energy> 100 cj </energy>
<cost> $10 </cost>
</item>
<item>
<name>Lemon Drop</name>
<flavour>lemon</flavour>
<colour>yellow</colour>
<energy> 100 cj </energy>
<cost> $10 </cost>
</item>
</cupcakes>
And this is my XSL:
<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="cupcakes/item">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"><xsl:value-of select="name"/> - </span>
<xsl:value-of select="price"/>
</div>
<div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
<p>
<xsl:value-of select="cost"/>
</p>
</div>
</xsl:for-each>
</body>
</html>
I've been trying to create a SCORM 1.2 manifest file that will create multiple SCOs with sub-files but, although there's plenty written about it online, I've been unable to find any actual examples. Essentially, what I want to do is:
SCO1.html
SCO1.1.html
SCO1.2.html
SCO1.3.html
SCO2.html
SCO2.1.html
SCO2.2.html
SCO2.3.html
In the above scenario, if the user was to launch SCO1.2.html, for example, their progress would be recorded against SCO1. I've got the following in my imsmanifest.xml file, but don't know how to restructure it so that each item is not a separate SCO. I've left out the metadata and resources that don't affect this issue:
<organizations default="TOC1">
<organization identifier="TOC1">
<title>Test</title >
<item identifier="I_SCO1" identifierref="SCO1">
<title>SCO1</title>
</item>
<item identifier="I_SCO1.1" identifierref="SCO1.1">
<title>SCO1.1</title>
</item>
<item identifier="I_SCO1.2" identifierref="SCO1.2">
<title>SCO1.2</title>
</item>
<item identifier="I_SCO1.3" identifierref="SCO1.3">
<title>SCO1.3</title>
</item>
<item identifier="I_SCO2" identifierref="SCO2">
<title>SCO2</title>
</item>
<item identifier="I_SCO2.1" identifierref="SCO2.1">
<title>SCO2.1</title>
</item>
<item identifier="I_SCO2.2" identifierref="SCO2.2">
<title>SCO2.2</title>
</item>
<item identifier="I_SCO2.3" identifierref="SCO2.3">
<title>SCO2.3</title>
</item>
</organization>
</organizations>
<resources>
<resource identifier="SCO1" type="webcontent" adlcp:scormtype="sco" href="SCO1.html">
<file href="SCO1.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO1.1" type="webcontent" adlcp:scormtype="sco" href="SCO1.1.html">
<file href="SCO1.1.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO1.2" type="webcontent" adlcp:scormtype="sco" href="SCO1.2.html">
<file href="SCO1.2.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO1.3" type="webcontent" adlcp:scormtype="sco" href="SCO1.3.html">
<file href="SCO1.3.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2" type="webcontent" adlcp:scormtype="sco" href="SCO2.html">
<file href="SCO2.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2.1" type="webcontent" adlcp:scormtype="sco" href="SCO2.1.html">
<file href="SCO2.1.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2.2" type="webcontent" adlcp:scormtype="sco" href="SCO2.2.html">
<file href="SCO2.2.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2.3" type="webcontent" adlcp:scormtype="sco" href="SCO2.3.html">
<file href="SCO2.3.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
</resources>
Any help would be appreciated.
You'll be looking at something a little closer to this-
<organizations default="ORG-001">
<organization identifier="ORG-001">
<title>Page Progression Sample</title>
<item>
<title>Module 1</title>
<item identifier="ACT-001" identifierref="RES-001">
<title>Name of this page</title>
</item>
<item identifier="ACT-002" identifierref="RES-002">
<title>Name of this page</title>
</item>
<item identifier="ACT-003" identifierref="RES-003">
<title>Name of this page</title>
</item>
<item identifier="ACT-004" identifierref="RES-004">
<title>Name of this page</title>
</item>
</item>
<item>
<title>Module 2</title>
<item identifier="ACT-005" identifierref="RES-005">
<title>Name of this page</title>
</item>
<item identifier="ACT-006" identifierref="RES-006">
<title>Name of this page</title>
</item>
<item identifier="ACT-007" identifierref="RES-007">
<title>Name of this page</title>
</item>
<item identifier="ACT-008" identifierref="RES-008">
<title>Name of this page</title>
</item>
</item>
</organization>
But you could try nesting 2, 3, 4 within 1 to see if that works. I don't have the specification in front of me right now.
In your example -
<item identifier="I_SCO1" identifierref="SCO1">
<title>SCO1</title>
<!-- PUT YOUR NEXT SCO (page) HERE-->
</item> <!-- Close tag of SCO1 -->
I have this ArrayCollection filled with a xml data coming from and HttpService request.
The generated XML
<items>
<item>
<id>1</id>
<name>Tom</name>
</item>
<item>
<id>2</id>
<name>Jerry</name>
</item>
<item>
<id>3</id>
<name>TV</name>
</item>
</items>
The script
[Bindable] private var dp:ArrayCollection;
private function onResult(event:ResultEvent):void{
dp = event.result.items.item;
}
Right, this dp is used as a dataProvider in a ComboBox
Is there a way to add another element (at the begining) of this ArrayCollection ?
I tried using unshift, but that only worked for an Array
Thanks.
Use addItemAt method.
dp.addItemAt(item, 0);
You can use the addItemAt method, adding it at index 0.
According to the ASDoc for the ArrayCollection class you can use the method 'addItemAt'
[EDIT] It seems that there is a bug in the XML Editor I'm using (XmlPad) that prevents the Xpath query from returning the correct results. I've tested the same query using two online tools (http://www.zrinity.com/xml/xpath/xpath.cfm and http://www.futurelab.ch/xmlkurs/xpath.en.html) and it seems to work. biziclop also commented that the query works correctly in Oxygen.
I've got this structure:
<?xml version="1.0" encoding="utf-8"?>
<root>
<itemlist>
<item>
<code>0001.0.00</code>
<category>709</category>
</item>
<item>
<code>0001.0.00</code>
<category>709</category>
</item>
<item>
<code>0002.0.00</code>
<category>708</category>
</item>
</itemlist>
<itemlist>
<item>
<code>0016.0.00</code>
<category>52</category>
</item>
<item>
<code>0016.0.00</code>
<category>52</category>
</item>
<item>
<code>0016.0.00</code>
<category>51</category>
</item>
<item>
<code>0016.0.00</code>
<category>50</category>
</item>
<item>
<code>0869.0.00</code>
<category>52</category>
</item>
<item>
<code>0869.0.00</code>
<category>51</category>
</item>
<item>
<code>0869.0.00</code>
<category>50</category>
</item>
</itemlist>
</root>
I want find all items where the previous item has the same category.
This Xpath query:
//item[category = preceding-sibling::item[1]/category]
returns the following nodes:
<item>
<code>0001.0.00</code>
<category>709</category>
</item>
<item>
<code>0016.0.00</code>
<category>52</category>
</item>
<item>
<code>0869.0.00</code>
<category>52</category>
</item>
The last item node in the result set is incorrect, because the value of the previous item's category in the input is not 52 so it should not be returned.
Is there an Xpath query that will return the results I want?
This XPath is absolutely correct. I've tested it with Saxon XSLT processor as follows:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="//item[category
= preceding-sibling::item[1]/category]"/>
</xsl:template>
</xsl:stylesheet>
With results:
<item>
<code>0001.0.00</code>
<category>709</category>
</item>
<item>
<code>0016.0.00</code>
<category>52</category>
</item>
You might want also try alternatives:
//item[category = ./preceding-sibling::item[1]/category]
/root/itemlist/item[category = ./preceding-sibling::item[1]/category]