Difference between revisions of "Documentation/DevGuide/OfficeDev/Using Spellchecker"
OOoWikiBot (talk | contribs) m (FINAL VERSION FOR L10N) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
{{Documentation/DevGuideLanguages|Documentation/DevGuide/OfficeDev/{{SUBPAGENAME}}}} | {{Documentation/DevGuideLanguages|Documentation/DevGuide/OfficeDev/{{SUBPAGENAME}}}} | ||
{{DISPLAYTITLE:Using Spellchecker}} | {{DISPLAYTITLE:Using Spellchecker}} | ||
− | The interface used for spell checking is <idl>com.sun.star.linguistic2.XSpellChecker</idl>. Accessing the | + | The interface used for spell checking is <idl>com.sun.star.linguistic2.XSpellChecker</idl>. Accessing the spellchecker 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]--> | ||
− | + | <syntaxhighlight lang="java"> | |
/** Get the SpellChecker to be used. | /** Get the SpellChecker to be used. | ||
*/ | */ | ||
Line 21: | Line 21: | ||
return mxSpell != null; | return mxSpell != null; | ||
} | } | ||
− | + | </syntaxhighlight> | |
=== Relevant properties === | === Relevant properties === | ||
Line 46: | Line 46: | ||
|- | |- | ||
|<idlm>com.sun.star.linguistic2.LinguProperties:IsSpellCapitalization</idlm> | |<idlm>com.sun.star.linguistic2.LinguProperties:IsSpellCapitalization</idlm> | ||
− | | | + | |Defines if the capitalization of words should be checked or not. |
|} | |} | ||
− | Changing the values of these properties in the <code>LinguProperties</code> affect all subsequent calls to the spell checker. Instantiate a <idl>com.sun.star.linguistic2.LinguProperties</idl> instance and change it by calling | + | Changing the values of these properties in the <code>LinguProperties</code> affect all subsequent calls to the spell checker. Instantiate a <idl>com.sun.star.linguistic2.LinguProperties</idl> instance and change it by calling <idlm>com.sun.star.beans.XPropertySet:setPropertyValue</idlm>(). The changes affect the whole office unless another modifies the properties again. This is done implicitly when changing the linguistic settings through {{menu|Tools|Options|Language Settings|Writing Aids}}. |
The following example shows verifying single words: | The following example shows verifying single words: | ||
<!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | <!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | ||
− | + | <syntaxhighlight lang="java"> | |
// test with correct word | // test with correct word | ||
String aWord = "horseback"; | String aWord = "horseback"; | ||
Line 63: | Line 63: | ||
bIsCorrect = mxSpell.isValid( aWord, aLocale , aEmptyProps ); | bIsCorrect = mxSpell.isValid( aWord, aLocale , aEmptyProps ); | ||
System.out.println( aWord + ": " + bIsCorrect ); | System.out.println( aWord + ": " + bIsCorrect ); | ||
− | + | </syntaxhighlight> | |
The following example shows spelling a single word and retrieving possible corrections: | The following example shows spelling a single word and retrieving possible corrections: | ||
− | + | <syntaxhighlight lang="java"> | |
aWord = "house"; | aWord = "house"; | ||
XSpellAlternatives xAlt = mxSpell.spell( aWord, aLocale, aEmptyProps ); | XSpellAlternatives xAlt = mxSpell.spell( aWord, aLocale, aEmptyProps ); | ||
Line 82: | Line 82: | ||
} | } | ||
} | } | ||
− | + | </syntaxhighlight> | |
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>. | ||
Latest revision as of 14:15, 9 August 2021
The interface used for spell checking is com.sun.star.linguistic2.XSpellChecker. Accessing the spellchecker 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 | Defines if the capitalization 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 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). |