blob: c51e4acfc290c0c68eb4d072ad0f97f453cb5393 [file] [log] [blame]
<?xml version="1.0" encoding="utf-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!---
* @exampleText The following SpellingServiceEsg MXML demonstrates the use of SpellingService class.
* Note that the results from this example may differ based on dictionary file.
*
* The following steps are taken:
* <ol>
* <li>A <code>ResourceTable</code> object is created and locales are mapped to file URLs.</li>
* <li><code>SpellingService</code> object is created and initialized</li>
* <li><code>SpellingServicecheckWord</code> method is used to check word and output is displayed</li>
* <li>A <code>UserDictionary</code> object is created and a word is added to it.</li>
* <li>A word is added to the user dictionary which in turn is added to SpellingService Object using <code>SpellingService.addUserDictionary</code> method.</li>
* <li> <code>SpellingService.checkWord</code> API is again called.</li>
* <li>The userDictionary is removed using <code>SpellingService.removeUserDictionary</code> method.</li>
* </ol>
*
* Note: to make this example work properly, please make sure you have the proper dictionary file in the specified folder
* and put the Squiggly library(AdobeSpellingEngine.swc) in your libs folder. Please see the reference "How to generate Squiggly dictionary".
-->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="init();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.adobe.linguistics.spelling.framework.*;
import com.adobe.linguistics.spelling.*;
private var spellingService:SpellingService = null;
private function init():void {
result.text += "AdobeSpellingServiceFramework tests\n===================\n";
result.text += "Setting SpellingConfiguration and initializing SpellingService ...\n";
var resourceTable:ResourceTable = new ResourceTable();
resourceTable.setResource("en_US", {rule:"data/en_US.aff", dict:"data/en_US.dic"});
SpellingConfiguration.resourceTable = resourceTable;
spellingService = new SpellingService("en_US");
spellingService.addEventListener(Event.COMPLETE, spellingServiceReady);
spellingService.init();
}
private function spellingServiceReady(e:Event):void {
result.text += "SpellingService ready for use\n";
result.text += "Checking \"hello\" ... " + spellingService.checkWord("hello") + "\n";
result.text += "Checking \"heello\" ... " + spellingService.checkWord("heello") + "\n";
result.text += "Getting suggestions for \"heello\" ... " + spellingService.getSuggestions("heello") + "\n";
var ud:UserDictionary = new UserDictionary();
result.text += "Adding \"heello\" to UserDictionary ..." + ud.addWord("heello") + "\n";
result.text += "Adding UserDicitonary to SpellingService ..." + spellingService.addUserDictionary(ud) +"\n";
result.text += "Checking \"heello\" again, expect true ..." + spellingService.checkWord("heello") + "\n";
result.text += "Removing \"heello\" from UserDictionary ..." + ud.removeWord("heello") + "\n"
result.text += "Checking \"heello\" again, expect false ..." + spellingService.checkWord("heello") + "\n";
result.text += "Number of UserDictionary, expect 1 ..." + spellingService.userDictionaries.length + "\n";
var ud2:UserDictionary = new UserDictionary();
result.text += "Adding UserDicitonary 2 to SpellingService ..." + spellingService.addUserDictionary(ud2) +"\n";
result.text += "Adding \"heello\" to UserDictionary 2 ..." + ud2.addWord("heello") + "\n";
result.text += "Checking \"heello\" again, expect true ..." + spellingService.checkWord("heello") + "\n";
result.text += "Number of UserDictionary, expect 2 ..." + spellingService.userDictionaries.length + "\n";
spellingService.removeUserDictionary(ud);
spellingService.removeUserDictionary(ud2);
result.text += "Checking \"heello\" again after removing all UserDictionaries, expect false ..." + spellingService.checkWord("heello") + "\n";
result.text += "Number of UserDictionary, expect 0 ..." + spellingService.userDictionaries.length + "\n";
}
]]>
</fx:Script>
<mx:Text id="result"/>
</s:Application>