Because of a lapse in government funding, the information on this website may not be up to date, transactions submitted via the website may not be processed, and the agency may not be able to respond to inquiries until appropriations are enacted. The NIH Clinical Center (the research hospital of NIH) is open. For more details about its operating status, please visit cc.nih.gov. Updates regarding government operating status and resumption of normal operations can be found at OPM.gov
Application: CSpellBasic
I. Objective
To use CSpell APIs to correct spelling errors from the input term.
In NLP applications, we often want to correct spelling errors in the pre-process before further core process (such as name entity recognition, concept mapping, question answering, etc.). CSpell API can be implemented in Java for this purpose. This example illustrates the basic way to use CSpell APIs in the applications.
II. Pre-Requirements
install cSpell.${YEAR} package to "/Projects/cSpell${YEAR}"
III. Source Code
package cSpellExample; import gov.nih.nlm.nls.cSpell.Api.*; /***************************************************************************** * This class is the basic example to use CSpellApi to process an input string. * * @author chlu * * @version V-2018 *****************************************************************************/ public class CSpellBasic { // test driver public static void main(String[] args) { String configFile = "../../data/Config/cSpell.properties"; if(args.length == 1) { configFile = args[0]; } else if(args.length > 0) { System.out.println("Usage: java CSpellBasic <configFile>"); System.exit(0); } // init, use default function mode (RW) and ranking mode (CSpell) CSpellApi cSpellApi = new CSpellApi(configFile); // Process // read in file and process String inText = "CSpell corrects speling errorrs, mer ge andsplit for along time"; String outText = cSpellApi.ProcessToStr(inText); // print out System.out.println("----- Sample Code: CSpellBasic -----"); System.out.println("- In: [" + inText + "]"); System.out.println("- Out: [" + outText + "]"); // close cSpellApi.Close(); } }
IV. Compile
shell>javac -classpath ../lib/cSpell2018dist.jar CSpellBasic.java
V. Run & Results
shell>java -classpath ./:../lib/cSpell2018dist.jar:/Projects/cSpell2018/ CSpellBasic ----- Sample Code: CSpellBasic ----- - In: [CSpell corrects speling errorrs, mer ge andsplit for along time] - Out: [CSpell corrects spelling errors, merge and split for a long time]