Difference between revisions of "Documentation/DevGuide/OfficeDev/Using Spellchecker"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
m (typos)
(3 intermediate revisions by one other user not shown)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/OfficeDev/Using Hyphenator
 
|NextPage=Documentation/DevGuide/OfficeDev/Using Hyphenator
 
}}
 
}}
{{DISPLAYTITLE:Using Spellchecker}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/OfficeDev/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Using Spellchecker}}
 
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]-->
Line 45: Line 46:
 
|-
 
|-
 
|<idlm>com.sun.star.linguistic2.LinguProperties:IsSpellCapitalization</idlm>  
 
|<idlm>com.sun.star.linguistic2.LinguProperties:IsSpellCapitalization</idlm>  
|dDefines if the captitalization of words should be checked or not.  
+
|Defines if the capitalization of words should be checked or not.  
 
|}
 
|}
  
Line 85: Line 86:
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Office Development]]
+
 
 +
[[Category:Documentation/Developer's Guide/Office Development]]

Revision as of 19:01, 21 January 2010



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 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 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).
Personal tools
In other languages