public void inform(ResourceLoader loader) { try { CharArraySet cas = getWordSet(loader, stopTagFiles, false); stopTags = new HashSet<String>(); for (Object element : cas) { char chars[] = (char[]) element; stopTags.add(new String(chars)); } } catch (IOException e) { throw new RuntimeException(e); } }
public GosenPartOfSpeechStopFilterFactory(Map<String, String> args) { super(args); stopTagFiles = require(args, "tags"); if (args.containsKey("enablePositionIncrements")) { throw new IllegalArgumentException("enablePositionIncrements is not a valid option as of Lucene 5.0"); } if (!args.isEmpty()) { throw new IllegalArgumentException("Unknown parameters: " + args); } }
@Test public void testBasics() throws IOException { String tags = "# verb-main:\n" + "動詞-自立\n"; GosenTokenizerFactory tokenizerFactory = new GosenTokenizerFactory(new HashMap<String,String>(){{ put("dictionaryDir", SenTestUtil.IPADIC_DIR); }}); tokenizerFactory.inform(new StringMockResourceLoader("")); Tokenizer tokenizer = tokenizerFactory.create(); tokenizer.setReader(new StringReader("私は制限スピードを超える。")); Map<String,String> args = new HashMap<String,String>(); args.put("luceneMatchVersion", Version.LATEST.toString()); args.put("tags", "stoptags.txt"); GosenPartOfSpeechStopFilterFactory factory = new GosenPartOfSpeechStopFilterFactory(args); factory.inform(new StringMockResourceLoader(tags)); TokenStream ts = factory.create(tokenizer); assertTokenStreamContents(ts, new String[] { "私", "は", "制限", "スピード", "を", "。" } ); }
@Test public void testRequireArguments() throws Exception{ try{ new GosenPartOfSpeechStopFilterFactory(new HashMap<String, String>() {{ put("bogusArg", "bogusValue"); }}); fail(); } catch (IllegalArgumentException expected) { assertTrue(expected.getMessage().contains("Configuration Error: missing parameter ")); } }
@Test public void testBogusArguments() throws Exception{ try{ new GosenPartOfSpeechStopFilterFactory(new HashMap<String, String>() {{ put("tags","tags"); put("bogusArg", "bogusValue"); }}); fail(); } catch (IllegalArgumentException expected) { assertTrue(expected.getMessage().contains("Unknown parameters")); } } }
public GosenPartOfSpeechStopFilterFactory(Map<String, String> args) { super(args); stopTagFiles = require(args, "tags"); if (args.containsKey("enablePositionIncrements")) { throw new IllegalArgumentException("enablePositionIncrements is not a valid option as of Lucene 5.0"); } if (!args.isEmpty()) { throw new IllegalArgumentException("Unknown parameters: " + args); } }
public void inform(ResourceLoader loader) { try { CharArraySet cas = getWordSet(loader, stopTagFiles, false); stopTags = new HashSet<String>(); for (Object element : cas) { char chars[] = (char[]) element; stopTags.add(new String(chars)); } } catch (IOException e) { throw new RuntimeException(e); } }