List of usage examples for org.apache.lucene.analysis.compound HyphenationCompoundWordTokenFilter getHyphenationTree
public static HyphenationTree getHyphenationTree(InputSource hyphenationSource) throws IOException
From source file:org.apache.solr.analysis.HyphenationCompoundWordTokenFilterFactory.java
License:Apache License
public void inform(ResourceLoader loader) { InputStream stream = null;/*from www .ja v a 2 s . co m*/ try { if (dictFile != null) // the dictionary can be empty. dictionary = getWordSet(loader, dictFile, false); // TODO: Broken, because we cannot resolve real system id // ResourceLoader should also supply method like ClassLoader to get resource URL stream = loader.openResource(hypFile); final InputSource is = new InputSource(stream); is.setEncoding(encoding); // if it's null let xml parser decide is.setSystemId(hypFile); hyphenator = HyphenationCompoundWordTokenFilter.getHyphenationTree(is); } catch (Exception e) { // TODO: getHyphenationTree really shouldn't throw "Exception" throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); } }
From source file:org.elasticsearch.analysis.common.HyphenationCompoundWordTokenFilterFactory.java
License:Apache License
HyphenationCompoundWordTokenFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {// w w w. j a v a2 s .c om super(indexSettings, env, name, settings); String hyphenationPatternsPath = settings.get("hyphenation_patterns_path", null); if (hyphenationPatternsPath == null) { throw new IllegalArgumentException("hyphenation_patterns_path is a required setting."); } Path hyphenationPatternsFile = env.configFile().resolve(hyphenationPatternsPath); try { InputStream in = Files.newInputStream(hyphenationPatternsFile); hyphenationTree = HyphenationCompoundWordTokenFilter.getHyphenationTree(new InputSource(in)); } catch (Exception e) { throw new IllegalArgumentException("Exception while reading hyphenation_patterns_path.", e); } }
From source file:org.elasticsearch.index.analysis.compound.HyphenationCompoundWordTokenFilterFactory.java
License:Apache License
@Inject public HyphenationCompoundWordTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { super(index, indexSettings, env, name, settings); String hyphenationPatternsPath = settings.get("hyphenation_patterns_path", null); if (hyphenationPatternsPath == null) { throw new ElasticsearchIllegalArgumentException("hyphenation_patterns_path is a required setting."); }/* www. j a v a2s. c o m*/ URL hyphenationPatternsFile = env.resolveConfig(hyphenationPatternsPath); try { hyphenationTree = HyphenationCompoundWordTokenFilter .getHyphenationTree(new InputSource(hyphenationPatternsFile.toExternalForm())); } catch (Exception e) { throw new ElasticsearchIllegalArgumentException( "Exception while reading hyphenation_patterns_path: " + e.getMessage()); } }