Knowledgebase Home Page  >  RapidSpell Web Java
Search the Knowledge Base
How can I modify the text parsing rules so that commas ALWAYS split words?
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=276&catId=45

Options

Print this page
Email this to a friend

Typically you would want words that are connected by commas (without spaces) to be treated as errors.  For example, "I ate an apple,banana and cherry" contains the error 'apple,banana'.


If however you have custom rules, and do not wish to consider this as an error, then you can customize the text parser logic so that commas always split words.  The below is specific to as you type spell checking, but the dialog mode checking can be modified in a similar fashion, email support@keyoti.com if help is needed.


Step 1. By default AJAX calls to the server go to the a.rapidspellweb Servlet, which runs the spell check.  However this does not allow us to override classes or methods, so the first we need to add is this JavaScript in the user page.

<script type="text/javascript">
    rapidSpell.ayt_helperURL = "rswihelper.jsp";
</script>

This makes AJAX calls go to the URL rswihelper.jsp, which will contain the RapidSpell tag and an override.


Step 2. Create the rswihelper.jsp page in the same folder as the user page (or elsewhere and change the ayt_helperURL above). It needs this content.

<%@ taglib uri="http://www.keyoti.com/" prefix="RapidSpellWeb" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
    </head>
    <body>
        <%
        com.keyoti.rapidSpell.RapidSpellChecker rsc = new com.keyoti.rapidSpell.RapidSpellChecker("<insert your license key here>");
        example.CustomTextBoundary customIterator = new example.CustomTextBoundary();
        rsc.setWordIterator(customIterator);
        %>
        <RapidSpellWeb:rapidSpellWInlineHelper
            checkerEngine="<%=rsc%>"
                                               />
    </body>
</html>


Step 3. In your project's 'source packages' add a class call CustomTextBoundary, in a package named 'example' (or change the package name in the code above).

package example;
import com.keyoti.rapidSpell.*;


public class CustomTextBoundary extends AdvancedTextBoundary {
    protected boolean isAtNonWhiteSpace(int position)
    {
        if(theText.charAt(position)==',') return false;
        else return super.isAtNonWhiteSpace(position);
    }
}


You can see how the method that determines whether a character is 'non-whitespace' (ie a character that is part of a word) has been modified to treat ',' as always whitespace.


Related Questions:

Attachments:

No attachments were found.