List of usage examples for org.apache.commons.codec.language Soundex Soundex
public Soundex()
From source file:LanguageUsage.java
public void start() throws EncoderException, DecoderException { String word1 = "Wilson"; String word2 = "Wylson"; String foreignWord1 = "Otto"; String foreignWord2 = "Auto"; Soundex sndx = new Soundex(); DoubleMetaphone doubleMetaphone = new DoubleMetaphone(); System.err.println("Soundex Code for Wilson is: " + sndx.encode("Wilson")); System.err.println("Soundex Code for Wylson is: " + sndx.encode("Wylson")); // Use the StringEncoderComparator to compare these two Strings StringEncoderComparator comparator1 = new StringEncoderComparator(sndx); System.err// w ww . j a va 2 s. co m .println("Are Wilson and Wylson same based on Soundex? " + comparator1.compare("Wilson", "Wylson")); System.err.println("Are Auto and Otto same based on Soundex? " + comparator1.compare("Auto", "Otto")); StringEncoderComparator comparator2 = new StringEncoderComparator(doubleMetaphone); System.err .println("Are Auto and Otto same based on DoubleMetaphone? " + comparator2.compare("Auto", "Otto")); System.err.println( "Double Metaphone primary code for Schmidt: " + doubleMetaphone.doubleMetaphone("Schmidt")); System.err.println( "Double Metaphone secondary code for Schmidt: " + doubleMetaphone.doubleMetaphone("Schmidt", true)); }
From source file:com.vangent.hieos.empi.transform.SoundexTransformFunction.java
/** * * @param obj// w ww .j a v a2 s. c o m * @return */ public Object transform(Object obj) { Soundex encoder = new Soundex(); return encoder.encode((String) obj); }
From source file:dkpro.similarity.algorithms.sound.SoundexComparator.java
public SoundexComparator() { encoder = new Soundex(); }
From source file:de.tudarmstadt.ukp.dkpro.core.commonscodec.SoundexPhoneticTranscriptor.java
public SoundexPhoneticTranscriptor() { this.encoder = new Soundex(); }
From source file:com.kodemore.text.KmTextUtilities.java
/** * The soundex algorithm./*from ww w. j a v a 2 s . c om*/ * Primarily used for indexing proper names by sound. * E.g.: both Robert and Rupert => R163. * * http://en.wikipedia.org/wiki/Soundex */ public static String soundex(String s) { return new Soundex().encode(s); }
From source file:ca.sqlpower.matchmaker.munge.SoundexMungeStep.java
public Boolean doCall() throws Exception { MungeStepOutput<String> out = getOut(); MungeStepOutput<String> in = getMSOInputs().get(0); String data = in.getData();/* www. j a v a 2 s .co m*/ if (data != null) { out.setData(new Soundex().soundex(data)); } else { out.setData(null); } return true; }
From source file:com.example.PhoneticTokenFilterFactory.java
@Inject public PhoneticTokenFilterFactory(Index index, IndexSettingsService indexSettingsService, @Assisted String name, @Assisted Settings settings) {//from ww w. j ava2 s . c o m super(index, indexSettingsService.getSettings(), name, settings); this.languageset = null; this.nametype = null; this.ruletype = null; this.maxcodelength = 0; this.replace = settings.getAsBoolean("replace", true); // weird, encoder is null at last step in SimplePhoneticAnalysisTests, so we set it to metaphone as default String encodername = settings.get("encoder", "metaphone"); if ("metaphone".equalsIgnoreCase(encodername)) { this.encoder = new Metaphone(); } else if ("soundex".equalsIgnoreCase(encodername)) { this.encoder = new Soundex(); } else if ("caverphone1".equalsIgnoreCase(encodername)) { this.encoder = new Caverphone1(); } else if ("caverphone2".equalsIgnoreCase(encodername)) { this.encoder = new Caverphone2(); } else if ("caverphone".equalsIgnoreCase(encodername)) { this.encoder = new Caverphone2(); } else if ("refined_soundex".equalsIgnoreCase(encodername) || "refinedSoundex".equalsIgnoreCase(encodername)) { this.encoder = new RefinedSoundex(); } else if ("cologne".equalsIgnoreCase(encodername)) { this.encoder = new ColognePhonetic(); } else if ("double_metaphone".equalsIgnoreCase(encodername) || "doubleMetaphone".equalsIgnoreCase(encodername)) { this.encoder = null; this.maxcodelength = settings.getAsInt("max_code_len", 4); } else if ("bm".equalsIgnoreCase(encodername) || "beider_morse".equalsIgnoreCase(encodername) || "beidermorse".equalsIgnoreCase(encodername)) { this.encoder = null; this.languageset = settings.getAsArray("languageset"); String ruleType = settings.get("rule_type", "approx"); if ("approx".equalsIgnoreCase(ruleType)) { ruletype = RuleType.APPROX; } else if ("exact".equalsIgnoreCase(ruleType)) { ruletype = RuleType.EXACT; } else { throw new IllegalArgumentException( "No matching rule type [" + ruleType + "] for beider morse encoder"); } String nameType = settings.get("name_type", "generic"); if ("GENERIC".equalsIgnoreCase(nameType)) { nametype = NameType.GENERIC; } else if ("ASHKENAZI".equalsIgnoreCase(nameType)) { nametype = NameType.ASHKENAZI; } else if ("SEPHARDIC".equalsIgnoreCase(nameType)) { nametype = NameType.SEPHARDIC; } } else if ("koelnerphonetik".equalsIgnoreCase(encodername)) { this.encoder = new KoelnerPhonetik(); } else if ("haasephonetik".equalsIgnoreCase(encodername)) { this.encoder = new HaasePhonetik(); } else if ("nysiis".equalsIgnoreCase(encodername)) { this.encoder = new Nysiis(); } else if ("daitch_mokotoff".equalsIgnoreCase(encodername)) { this.encoder = new DaitchMokotoffSoundex(); } else { throw new IllegalArgumentException("unknown encoder [" + encodername + "] for phonetic token filter"); } }
From source file:com.jaeksoft.searchlib.analysis.filter.PhoneticFilter.java
@Override public TokenStream create(TokenStream tokenStream) { if (BEIDER_MORSE.equals(codec)) return new BeiderMorseTokenFilter(tokenStream, new EncoderKey(ruleType, maxPhonemes)); if (COLOGNE_PHONETIC.equals(codec)) return new EncoderTokenFilter(tokenStream, new ColognePhonetic()); if (SOUNDEX.equals(codec)) return new EncoderTokenFilter(tokenStream, new Soundex()); if (REFINED_SOUNDEX.equals(codec)) return new EncoderTokenFilter(tokenStream, new RefinedSoundex()); if (METAPHONE.equals(codec)) return new EncoderTokenFilter(tokenStream, new Metaphone()); if (CAVERPHONE1.equals(codec)) return new EncoderTokenFilter(tokenStream, new Caverphone1()); if (CAVERPHONE2.equals(codec)) return new EncoderTokenFilter(tokenStream, new Caverphone2()); return null;// w w w . java 2 s .c om }
From source file:com.perceptive.epm.perkolcentral.action.ajax.EmployeeDetailsAction.java
public String executeGetAllEmployees() throws ExceptionWrapper { try {//from w w w . j av a2 s . com Soundex sndx = new Soundex(); DoubleMetaphone doubleMetaphone = new DoubleMetaphone(); final StringEncoderComparator comparator1 = new StringEncoderComparator(doubleMetaphone); LoggingHelpUtil.printDebug("Page " + getPage() + " Rows " + getRows() + " Sorting Order " + getSord() + " Index Row :" + getSidx()); LoggingHelpUtil.printDebug("Search :" + searchField + " " + searchOper + " " + searchString); // Calcalate until rows ware selected int to = (rows * page); // Calculate the first row to read int from = to - rows; LinkedHashMap<Long, EmployeeBO> employeeLinkedHashMap = new LinkedHashMap<Long, EmployeeBO>(); employeeLinkedHashMap = employeeBL.getAllEmployees(); ArrayList<EmployeeBO> allEmployees = new ArrayList<EmployeeBO>(employeeLinkedHashMap.values()); //Handle search if (searchOper != null && !searchOper.trim().equalsIgnoreCase("") && searchString != null && !searchString.trim().equalsIgnoreCase("")) { if (searchOper.trim().equalsIgnoreCase("eq")) { CollectionUtils.filter(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { return ((EmployeeBO) o).getEmployeeName().equalsIgnoreCase(searchString.trim()); //To change body of implemented methods use File | Settings | File Templates. } }); } else if (searchOper.trim().equalsIgnoreCase("slk")) { CollectionUtils.filter(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { return (new StringEncoderComparator(new Soundex()).compare( ((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new DoubleMetaphone()).compare( ((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new Metaphone()).compare( ((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new RefinedSoundex()).compare( ((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0); //To change body of implemented methods use File | Settings | File Templates. } }); } else { //First check whether there is an exact match if (CollectionUtils.exists(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { return (((EmployeeBO) o).getEmployeeName().toLowerCase() .contains(searchString.trim().toLowerCase())); //To change body of implemented methods use File | Settings | File Templates. } })) { CollectionUtils.filter(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { return (((EmployeeBO) o).getEmployeeName().toLowerCase() .contains(searchString.trim().toLowerCase())); } }); } else { ArrayList<String> matchedEmployeeIds = employeeBL.getLuceneUtil() .getBestMatchEmployeeName(searchString.trim().toLowerCase()); allEmployees = new ArrayList<EmployeeBO>(); for (String id : matchedEmployeeIds) { allEmployees.add(employeeBL.getAllEmployees().get(Long.valueOf(id))); } } } /*{ CollectionUtils.filter(allEmployees, new Predicate() { @Override public boolean evaluate(Object o) { if (((EmployeeBO) o).getEmployeeName().toLowerCase().contains(searchString.trim().toLowerCase())) return true; else if(new StringEncoderComparator(new Soundex()).compare(((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new DoubleMetaphone()).compare(((EmployeeBO) o).getEmployeeName().toLowerCase(), searchString.trim().toLowerCase()) == 0) { return true; } else { for (String empNameParts : ((EmployeeBO) o).getEmployeeName().trim().split(" ")) { if (new StringEncoderComparator(new Soundex()).compare(empNameParts.toLowerCase(), searchString.trim().toLowerCase()) == 0 || new StringEncoderComparator(new DoubleMetaphone()).compare(empNameParts.toLowerCase(), searchString.trim().toLowerCase()) == 0 // || new StringEncoderComparator(new Metaphone()).compare(empNameParts.toLowerCase(), searchString.trim().toLowerCase()) == 0 // || new StringEncoderComparator(new RefinedSoundex()).compare(empNameParts.toLowerCase(), searchString.trim().toLowerCase()) == 0 ) { return true; } } return false; } } }); } */ } //// Handle Order By if (sidx != null && !sidx.equals("")) { Collections.sort(allEmployees, new Comparator<EmployeeBO>() { public int compare(EmployeeBO e1, EmployeeBO e2) { if (sidx.equalsIgnoreCase("employeeName")) return sord.equalsIgnoreCase("asc") ? e1.getEmployeeName().compareTo(e2.getEmployeeName()) : e2.getEmployeeName().compareTo(e1.getEmployeeName()); else if (sidx.equalsIgnoreCase("jobTitle")) return sord.equalsIgnoreCase("asc") ? e1.getJobTitle().compareTo(e2.getJobTitle()) : e2.getJobTitle().compareTo(e1.getJobTitle()); else if (sidx.equalsIgnoreCase("manager")) return sord.equalsIgnoreCase("asc") ? e1.getManager().compareTo(e2.getManager()) : e2.getManager().compareTo(e1.getManager()); else return sord.equalsIgnoreCase("asc") ? e1.getEmployeeName().compareTo(e2.getEmployeeName()) : e2.getEmployeeName().compareTo(e1.getEmployeeName()); } }); } // records = allEmployees.size(); total = (int) Math.ceil((double) records / (double) rows); gridModel = new ArrayList<EmployeeBO>(); to = to > records ? records : to; for (int iCounter = from; iCounter < to; iCounter++) { EmployeeBO employeeBO = allEmployees.get(iCounter); //new EmployeeBO((Employee) employeeLinkedHashMap.values().toArray()[iCounter]); gridModel.add(employeeBO); } } catch (Exception ex) { throw new ExceptionWrapper(ex); } return SUCCESS; }
From source file:com.plugin.UI.Windows.BiblePeopleSearchResultsDialog.java
/** * Checks if is soundex calc.//from ww w . jav a2 s. com * * @param str the str * @param _term the _term * * @return true, if is soundex calc */ private boolean isSoundexCalc(String str, String _term) { Soundex s = new Soundex(); try { if (s.difference(str, _term) == 4) return true; } catch (Exception e) { return false; } if (str.indexOf(" ") != -1) { String[] str2 = str.split("[ ]"); for (int i = 0; i < str2.length; i++) { try { if (s.difference(str.split("[ ]")[i], _term) == 4) return true; } catch (Exception e) { return false; } } } return false; }