Difference between revisions of "Documentation/DevGuide/OfficeDev/Using Spellchecker"
m (1 revision(s)) |
m |
||
Line 9: | Line 9: | ||
The interface used for spell checking is <idl>com.sun.star.linguistic2.XSpellChecker</idl>. Accessing the spell checker through the <code>LinguServiceManager</code> and initializing the <code>mxSpell</code> object is done by: | The interface used for spell checking is <idl>com.sun.star.linguistic2.XSpellChecker</idl>. Accessing the spell checker through the <code>LinguServiceManager</code> and initializing the <code>mxSpell</code> object is done by: | ||
<!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | <!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | ||
− | + | <source lang="java"> | |
/** Get the SpellChecker to be used. | /** Get the SpellChecker to be used. | ||
*/ | */ | ||
Line 20: | Line 20: | ||
return mxSpell != null; | return mxSpell != null; | ||
} | } | ||
− | + | </source> | |
=== Relevant properties === | === Relevant properties === | ||
Line 52: | Line 52: | ||
The following example shows verifying single words: | The following example shows verifying single words: | ||
<!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | <!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | ||
− | + | <source lang="java"> | |
// test with correct word | // test with correct word | ||
String aWord = "horseback"; | String aWord = "horseback"; | ||
Line 62: | Line 62: | ||
bIsCorrect = mxSpell.isValid( aWord, aLocale , aEmptyProps ); | bIsCorrect = mxSpell.isValid( aWord, aLocale , aEmptyProps ); | ||
System.out.println( aWord + ": " + bIsCorrect ); | System.out.println( aWord + ": " + bIsCorrect ); | ||
− | + | </source> | |
The following example shows spelling a single word and retrieving possible corrections: | The following example shows spelling a single word and retrieving possible corrections: | ||
− | + | <source lang="java"> | |
aWord = "house"; | aWord = "house"; | ||
XSpellAlternatives xAlt = mxSpell.spell( aWord, aLocale, aEmptyProps ); | XSpellAlternatives xAlt = mxSpell.spell( aWord, aLocale, aEmptyProps ); | ||
Line 81: | Line 81: | ||
} | } | ||
} | } | ||
− | + | </source> | |
For a description of the return types interface, refer to <idl>com.sun.star.linguistic2.XSpellAlternatives</idl>. | For a description of the return types interface, refer to <idl>com.sun.star.linguistic2.XSpellAlternatives</idl>. | ||
{{PDL1}} | {{PDL1}} | ||
[[Category: Office Development]] | [[Category: Office Development]] |
Revision as of 16:41, 29 March 2008
The interface used for spell checking is com.sun.star.linguistic2.XSpellChecker. Accessing the spell checker through the LinguServiceManager
and initializing the mxSpell
object is done by:
/** Get the SpellChecker to be used. */ public boolean GetSpell() throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException { if (mxLinguSvcMgr != null) mxSpell = mxLinguSvcMgr.getSpellChecker(); return mxSpell != null; }
Relevant properties
The properties of the LinguProperties
service evaluated by the spell checker are:
Spell-checking Properties of com.sun.star.linguistic2.LinguProperties Description | |
---|---|
IsIgnoreControlCharacters | Defines if control characters should be ignored or not. |
IsUseDictionaryList | Defines if the dictionary-list should be used or not. |
IsGermanPreReform | Defines if the new German spelling rules should be used for German language text or not. |
IsSpellUpperCase | Defines if words with only uppercase letters should be subject to spellchecking or not. |
IsSpellWithDigits | Defines if words containing digits or numbers should be subject to spellchecking or not. |
IsSpellCapitalization | dDefines if the captitalization of words should be checked or not. |
Changing the values of these properties in the LinguProperties
affect all subsequent calls to the spell checker. Instantiate a com.sun.star.linguistic2.LinguProperties instance and change it by calling com.sun.star.beans.XPropertySet:setPropertyValue(). The changes affect the whole office unless another modifies the properties again. This is done implicitly when changing the linguistic settings through Tools - Options - Language Settings - Writing Aids.
The following example shows verifying single words:
// test with correct word String aWord = "horseback"; boolean bIsCorrect = mxSpell.isValid( aWord, aLocale, aEmptyProps ); System.out.println( aWord + ": " + bIsCorrect ); // test with incorrect word aWord = "course"; bIsCorrect = mxSpell.isValid( aWord, aLocale , aEmptyProps ); System.out.println( aWord + ": " + bIsCorrect );
The following example shows spelling a single word and retrieving possible corrections:
aWord = "house"; XSpellAlternatives xAlt = mxSpell.spell( aWord, aLocale, aEmptyProps ); if (xAlt == null) System.out.println( aWord + " is correct." ); else { System.out.println( aWord + " is not correct. A list of proposals follows." ); String[] aAlternatives = xAlt.getAlternatives(); if (aAlternatives.length == 0) System.out.println( "no proposal found." ); else { for (int i = 0; i < aAlternatives.length; ++i) System.out.println( aAlternatives[i] ); } }
For a description of the return types interface, refer to com.sun.star.linguistic2.XSpellAlternatives.
Content on this page is licensed under the Public Documentation License (PDL). |