Difference between revisions of "Documentation/DevGuide/OfficeDev/Implementing a Spell Checker"
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Documentation/Developers Guide/Office Development) |
m |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 6: | Line 6: | ||
|NextPage=Documentation/DevGuide/OfficeDev/Implementing a Hyphenator | |NextPage=Documentation/DevGuide/OfficeDev/Implementing a Hyphenator | ||
}} | }} | ||
− | {{DISPLAYTITLE:Implementing a Spell Checker}} | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/OfficeDev/{{SUBPAGENAME}}}} |
+ | {{DISPLAYTITLE:Implementing a Spell Checker}} | ||
A sample implementation of a spell checker is found in the examples for linguistics. | A sample implementation of a spell checker is found in the examples for linguistics. | ||
Line 20: | Line 21: | ||
and | and | ||
− | * <idl>com.sun.star.lang.XTypeProvider</idl>, to access your add-in interfaces from {{ | + | * <idl>com.sun.star.lang.XTypeProvider</idl>, to access your add-in interfaces from {{AOo}} Basic, otherwise, this interface is not mandatory. |
To implement a spell checker of your own, modify the sample in the following ways: | To implement a spell checker of your own, modify the sample in the following ways: | ||
Choose a ''unique'' service implementation name to distinguish your service implementation from any other. To do this, edit the string in the line | Choose a ''unique'' service implementation name to distinguish your service implementation from any other. To do this, edit the string in the line | ||
− | + | <syntaxhighlight lang="java">> | |
public static String _aSvcImplName = "com.sun.star.linguistic2.JavaSamples.SampleSpellChecker"; | public static String _aSvcImplName = "com.sun.star.linguistic2.JavaSamples.SampleSpellChecker"; | ||
− | + | </syntaxhighlight> | |
Then, specify the list of languages supported by your service. Edit the | Then, specify the list of languages supported by your service. Edit the | ||
− | + | <syntaxhighlight lang="java"> | |
public Locale[] getLocales() | public Locale[] getLocales() | ||
− | + | </syntaxhighlight> | |
function and modify the | function and modify the | ||
− | + | <syntaxhighlight lang="java"> | |
public boolean hasLocale( Locale aLocale ) | public boolean hasLocale( Locale aLocale ) | ||
− | + | </syntaxhighlight> | |
function accordingly. The next step is to change the | function accordingly. The next step is to change the | ||
− | + | <syntaxhighlight lang="java"> | |
private short GetSpellFailure(...) | private short GetSpellFailure(...) | ||
− | + | </syntaxhighlight> | |
as required. This function determines if a word is spelled correctly in a given language. If the word is OK return -1, otherwise return an appropriate value of the type <idl>com.sun.star.linguistic2.SpellFailure</idl>. | as required. This function determines if a word is spelled correctly in a given language. If the word is OK return -1, otherwise return an appropriate value of the type <idl>com.sun.star.linguistic2.SpellFailure</idl>. | ||
Check if you need to edit or remove the | Check if you need to edit or remove the | ||
− | + | <syntaxhighlight lang="java"> | |
private boolean IsUpper(...) | private boolean IsUpper(...) | ||
− | + | </syntaxhighlight> | |
and | and | ||
− | + | <syntaxhighlight lang="java"> | |
private boolean HasDigits(...) | private boolean HasDigits(...) | ||
− | + | </syntaxhighlight> | |
functions. Consider this only if you are planning to support non-western languages and need sophisticated versions of those, or do not need them at all. Do not forget to change the code at the end of | functions. Consider this only if you are planning to support non-western languages and need sophisticated versions of those, or do not need them at all. Do not forget to change the code at the end of | ||
− | + | <syntaxhighlight lang="java"> | |
public boolean isValid(...) | public boolean isValid(...) | ||
− | + | </syntaxhighlight> | |
accordingly. | accordingly. | ||
Supply your own version of | Supply your own version of | ||
− | + | <syntaxhighlight lang="java"> | |
private XSpellAlternatives GetProposals(...) | private XSpellAlternatives GetProposals(...) | ||
− | + | </syntaxhighlight> | |
It provides the return value for the | It provides the return value for the | ||
− | + | <syntaxhighlight lang="java"> | |
public XSpellAlternatives spell(...) | public XSpellAlternatives spell(...) | ||
− | + | </syntaxhighlight> | |
− | function call if the word was found to be incorrect. The main purpose is to provide proposals for how the word might be written correctly. Note the list | + | function call if the word was found to be incorrect. The main purpose is to provide proposals for how the word might be written correctly. Note the list may be empty. |
Next, edit the text in | Next, edit the text in | ||
− | + | <syntaxhighlight lang="java"> | |
public String getServiceDisplayName(...) | public String getServiceDisplayName(...) | ||
− | + | </syntaxhighlight> | |
It should be unique but it is not necessary. If you are developing a set of services, that is, spellchecker, hyphenator and thesaurus, it should be the same for all of them. This text is displayed in dialogs to show a more meaningful text than the service implementation name. | It should be unique but it is not necessary. If you are developing a set of services, that is, spellchecker, hyphenator and thesaurus, it should be the same for all of them. This text is displayed in dialogs to show a more meaningful text than the service implementation name. | ||
Now, have a look in the constructor | Now, have a look in the constructor | ||
− | + | <syntaxhighlight lang="java"> | |
public SampleSpellChecker() | public SampleSpellChecker() | ||
− | + | </syntaxhighlight> | |
at the property names. Remove the entries for the properties that are not relevant to your service implementation. If you make modification, also look in the file PropChgHelper_Spell.java in the function | at the property names. Remove the entries for the properties that are not relevant to your service implementation. If you make modification, also look in the file PropChgHelper_Spell.java in the function | ||
− | + | <syntaxhighlight lang="java"> | |
public void propertyChange(...) | public void propertyChange(...) | ||
− | + | </syntaxhighlight> | |
and change it accordingly. | and change it accordingly. | ||
Set the values of <code>bSCWA</code> and <code>bSWWA</code> to true only for those properties that are relevant to your implementation, thus avoiding sending unnecessary <idl>com.sun.star.linguistic2.LinguServiceEvent</idl> events, that is, avoid triggering spell-checking in clients if there is no requirement. | Set the values of <code>bSCWA</code> and <code>bSWWA</code> to true only for those properties that are relevant to your implementation, thus avoiding sending unnecessary <idl>com.sun.star.linguistic2.LinguServiceEvent</idl> events, that is, avoid triggering spell-checking in clients if there is no requirement. | ||
− | Finally, after registration of the service (see [[Documentation/DevGuide/WritingUNO/Deployment Options for Components|Deployment Options for Components]]) it has to be activated to be used by the <code>LinguServiceManager</code>. After restarting {{ | + | Finally, after registration of the service (see [[Documentation/DevGuide/WritingUNO/Deployment Options for Components|Deployment Options for Components]]) it has to be activated to be used by the <code>LinguServiceManager</code>. After restarting {{AOo}}, this is done in the following manner: |
− | Open the dialog | + | Open the dialog {{menu|Tools|Options|Language Settings|Writing Aids}}. In the section '''Writing Aids''', in the box '''Available Language Modules''', a new entry with text of the Service Display Name that you chose is displayed in the implementation. Check the empty checkbox to the left of that entry. If you want to use your module, uncheck any other listed entry. If you want to make more specific settings per language, press the {{button|Edit}} button next to the modules box and use that dialog. |
<!--[BUG641+]--> | <!--[BUG641+]--> |
Latest revision as of 14:25, 9 August 2021
- Using Spellchecker
- Using Hyphenator
- Using Thesaurus
- Events
- Implementing a Spell Checker
- Implementing a Hyphenator
- Implementing a Thesaurus
A sample implementation of a spell checker is found in the examples for linguistics.
The spell checker implements the following interfaces:
- com.sun.star.linguistic2.XSpellChecker
- com.sun.star.linguistic2.XLinguServiceEventBroadcaster
- com.sun.star.lang.XInitialization
- com.sun.star.lang.XServiceDisplayName
- com.sun.star.lang.XServiceInfo
- com.sun.star.lang.XComponent
and
- com.sun.star.lang.XTypeProvider, to access your add-in interfaces from Apache OpenOffice Basic, otherwise, this interface is not mandatory.
To implement a spell checker of your own, modify the sample in the following ways:
Choose a unique service implementation name to distinguish your service implementation from any other. To do this, edit the string in the line
> public static String _aSvcImplName = "com.sun.star.linguistic2.JavaSamples.SampleSpellChecker";
Then, specify the list of languages supported by your service. Edit the
public Locale[] getLocales()
function and modify the
public boolean hasLocale( Locale aLocale )
function accordingly. The next step is to change the
private short GetSpellFailure(...)
as required. This function determines if a word is spelled correctly in a given language. If the word is OK return -1, otherwise return an appropriate value of the type com.sun.star.linguistic2.SpellFailure.
Check if you need to edit or remove the
private boolean IsUpper(...)
and
private boolean HasDigits(...)
functions. Consider this only if you are planning to support non-western languages and need sophisticated versions of those, or do not need them at all. Do not forget to change the code at the end of
public boolean isValid(...)
accordingly.
Supply your own version of
private XSpellAlternatives GetProposals(...)
It provides the return value for the
public XSpellAlternatives spell(...)
function call if the word was found to be incorrect. The main purpose is to provide proposals for how the word might be written correctly. Note the list may be empty.
Next, edit the text in
public String getServiceDisplayName(...)
It should be unique but it is not necessary. If you are developing a set of services, that is, spellchecker, hyphenator and thesaurus, it should be the same for all of them. This text is displayed in dialogs to show a more meaningful text than the service implementation name.
Now, have a look in the constructor
public SampleSpellChecker()
at the property names. Remove the entries for the properties that are not relevant to your service implementation. If you make modification, also look in the file PropChgHelper_Spell.java in the function
public void propertyChange(...)
and change it accordingly.
Set the values of bSCWA
and bSWWA
to true only for those properties that are relevant to your implementation, thus avoiding sending unnecessary com.sun.star.linguistic2.LinguServiceEvent events, that is, avoid triggering spell-checking in clients if there is no requirement.
Finally, after registration of the service (see Deployment Options for Components) it has to be activated to be used by the LinguServiceManager
. After restarting Apache OpenOffice, this is done in the following manner:
Open the dialog Tools → Options → Language Settings → Writing Aids. In the section Writing Aids, in the box Available Language Modules, a new entry with text of the Service Display Name that you chose is displayed in the implementation. Check the empty checkbox to the left of that entry. If you want to use your module, uncheck any other listed entry. If you want to make more specific settings per language, press the Edit button next to the modules box and use that dialog.
The Context menu of the Writer that pops up when pressing the right-mouse button over an incorrectly spelled word currently has a bug that may crash the program when the Java implementation of a spell checker is used. The spell check dialog is functioning.
Content on this page is licensed under the Public Documentation License (PDL). |