@Override public TokenStream create(TokenStream tokenStream) { if (encoder == null) { if (ruletype != null && nametype != null) { if (languageset != null) { final LanguageSet languages = LanguageSet.from(new HashSet<>(Arrays.asList(languageset))); return new BeiderMorseFilter(tokenStream, new PhoneticEngine(nametype, ruletype, true), languages); } return new BeiderMorseFilter(tokenStream, new PhoneticEngine(nametype, ruletype, true)); } if (maxcodelength > 0) { return new DoubleMetaphoneFilter(tokenStream, maxcodelength, !replace); } } else { return new PhoneticFilter(tokenStream, encoder, !replace); } throw new IllegalArgumentException("encoder error"); }
/** * Ensure that reset() removes any state (buffered tokens) */ public void testReset() throws Exception { DoubleMetaphoneFilterFactory factory = new DoubleMetaphoneFilterFactory(); factory.init(new HashMap<String, String>()); TokenStream inputStream = new MockTokenizer(new StringReader("international"), MockTokenizer.WHITESPACE, false); TokenStream filteredStream = factory.create(inputStream); CharTermAttribute termAtt = filteredStream.addAttribute(CharTermAttribute.class); assertEquals(DoubleMetaphoneFilter.class, filteredStream.getClass()); filteredStream.reset(); assertTrue(filteredStream.incrementToken()); assertEquals(13, termAtt.length()); assertEquals("international", termAtt.toString()); filteredStream.reset(); // ensure there are no more tokens, such as ANTRNXNL assertFalse(filteredStream.incrementToken()); }
public void testDefaults() throws Exception { DoubleMetaphoneFilterFactory factory = new DoubleMetaphoneFilterFactory(new HashMap<String, String>()); TokenStream inputStream = new MockTokenizer(new StringReader("international"), MockTokenizer.WHITESPACE, false); TokenStream filteredStream = factory.create(inputStream); assertEquals(DoubleMetaphoneFilter.class, filteredStream.getClass()); assertTokenStreamContents(filteredStream, new String[] { "international", "ANTR" }); }
public void testSettingSizeAndInject() throws Exception { Map<String,String> parameters = new HashMap<>(); parameters.put("inject", "false"); parameters.put("maxCodeLength", "8"); DoubleMetaphoneFilterFactory factory = new DoubleMetaphoneFilterFactory(parameters); TokenStream inputStream = new MockTokenizer(new StringReader("international"), MockTokenizer.WHITESPACE, false); TokenStream filteredStream = factory.create(inputStream); assertEquals(DoubleMetaphoneFilter.class, filteredStream.getClass()); assertTokenStreamContents(filteredStream, new String[] { "ANTRNXNL" }); }
public void testDefaults() throws Exception { DoubleMetaphoneFilterFactory factory = new DoubleMetaphoneFilterFactory(); factory.init(new HashMap<String, String>()); TokenStream inputStream = new MockTokenizer(new StringReader("international"), MockTokenizer.WHITESPACE, false); TokenStream filteredStream = factory.create(inputStream); assertEquals(DoubleMetaphoneFilter.class, filteredStream.getClass()); assertTokenStreamContents(filteredStream, new String[] { "international", "ANTR" }); }
public void testSettingSizeAndInject() throws Exception { DoubleMetaphoneFilterFactory factory = new DoubleMetaphoneFilterFactory(); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("inject", "false"); parameters.put("maxCodeLength", "8"); factory.init(parameters); TokenStream inputStream = new MockTokenizer(new StringReader("international"), MockTokenizer.WHITESPACE, false); TokenStream filteredStream = factory.create(inputStream); assertEquals(DoubleMetaphoneFilter.class, filteredStream.getClass()); assertTokenStreamContents(filteredStream, new String[] { "ANTRNXNL" }); }
public void testSettingSizeAndInject() throws Exception { Map<String,String> parameters = new HashMap<String,String>(); parameters.put("inject", "false"); parameters.put("maxCodeLength", "8"); DoubleMetaphoneFilterFactory factory = new DoubleMetaphoneFilterFactory(parameters); TokenStream inputStream = new MockTokenizer(new StringReader("international"), MockTokenizer.WHITESPACE, false); TokenStream filteredStream = factory.create(inputStream); assertEquals(DoubleMetaphoneFilter.class, filteredStream.getClass()); assertTokenStreamContents(filteredStream, new String[] { "ANTRNXNL" }); }
@Override public DoubleMetaphoneFilter create(TokenStream input) { return new DoubleMetaphoneFilter(input, maxCodeLength, inject); }