List of usage examples for org.apache.lucene.analysis.util ResourceLoader openResource
public InputStream openResource(String resource) throws IOException;
From source file:cn.howardliu.lucene.extension.ManagedSynonymFilterFactory.java
License:Apache License
/** * Called once, during core initialization, to initialize any analysis components * that depend on the data managed by this resource. It is important that the * analysis component is only initialized once during core initialization so that * text analysis is consistent, especially in a distributed environment, as we * don't want one server applying a different set of stop words than other servers. *//*from w w w . j av a 2s . c o m*/ @SuppressWarnings("unchecked") @Override public void onManagedResourceInitialized(NamedList<?> initArgs, final ManagedResource res) throws SolrException { NamedList<Object> args = (NamedList<Object>) initArgs; args.add("synonyms", getResourceId()); args.add("expand", "false"); args.add("format", "solr"); Map<String, String> filtArgs = new HashMap<>(); for (Map.Entry<String, ?> entry : args) { filtArgs.put(entry.getKey(), entry.getValue().toString()); } // create the actual filter factory that pulls the synonym mappings // from synonymMappings using a custom parser implementation delegate = new SynonymFilterFactory(filtArgs) { @Override protected SynonymMap loadSynonyms(ResourceLoader loader, String cname, boolean dedup, Analyzer analyzer) throws IOException, ParseException { CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder() .onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT); ManagedSynonymParser parser = new ManagedSynonymParser((SynonymManager) res, dedup, analyzer); // ??? InputStreamReader in = null; if (StringUtils.isNotBlank(synonymFile)) { in = new InputStreamReader(loader.openResource(synonymFile), decoder); } parser.parse(in); return parser.build(); } }; try { delegate.inform(res.getResourceLoader()); } catch (IOException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e); } }
From source file:com.github.cstoku.neologd.unidic.lucene.analysis.ja.JapaneseTokenizerFactory.java
License:Apache License
@Override public void inform(ResourceLoader loader) throws IOException { if (userDictionaryPath != null) { InputStream stream = loader.openResource(userDictionaryPath); String encoding = userDictionaryEncoding; if (encoding == null) { encoding = IOUtils.UTF_8;/* w w w .jav a 2 s. c o m*/ } CharsetDecoder decoder = Charset.forName(encoding).newDecoder() .onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT); Reader reader = new InputStreamReader(stream, decoder); userDictionary = UserDictionary.open(reader); } else { userDictionary = null; } }
From source file:com.o19s.solr.swan.SwanQParserPlugin.java
License:Apache License
@Override public void inform(ResourceLoader loader) throws IOException { if (fieldAliasesFileName != null) { InputStream is = loader.openResource(fieldAliasesFileName); DataInputStream in = new DataInputStream(is); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine;/*from w w w . jav a2 s. co m*/ while ((strLine = br.readLine()) != null) { String[] keysVal = strLine.split("=>"); if (keysVal.length != 2) { throw new IOException("keysVal.length != 2 after split"); } String[] keys = keysVal[0].trim().split("\\s*,\\s*"); String val = keysVal[1].trim().toLowerCase(); if (!val.matches("[a-zA-Z0-9_-]+")) { throw new IOException("value doesn't match regex [a-zA-Z0-9_]+"); } for (String k : keys) { if (!k.matches("[a-zA-Z0-9_-]+")) { throw new IOException("key doesn't match regex [a-zA-Z0-9_]+"); } fieldAliases.put(k.toLowerCase(), val); } } in.close(); } }
From source file:com.radialpoint.word2vec.lucene.Word2VecFilterFactory.java
License:Open Source License
@Override public void inform(ResourceLoader loader) throws IOException { File vectorsFile = new File(this.vectorsFile); Vectors vectors = new Vectors( vectorsFile.exists() ? new FileInputStream(vectorsFile) : loader.openResource(this.vectorsFile)); this.expander = new QueryExpander(vectors, true, termSelectionStrategy); }
From source file:com.searchbox.SuggesterComponent.java
License:Apache License
protected final List<String> getLines(ResourceLoader loader, String resource) throws IOException { return WordlistLoader.getLines(loader.openResource(resource), IOUtils.CHARSET_UTF_8); }
From source file:com.sindicetech.siren.solr.qparser.SirenQParserPlugin.java
License:Open Source License
/** * Load QNames mapping from the properties file * <p>/*from w w w .java2s .c o m*/ * The mapping file contains lines such as: * <ul> * <li> foaf=http://xmlns.com/foaf/0.1/ * </ul> * which means that the qname <code>foaf:name</code> will be expanded to * <code>http://xmlns.com/foaf/0.1/name</code>. */ protected void loadQNamesFile(final ResourceLoader loader) { try { logger.info("Loading of the QNames mapping file: {}", qnamesFile); qnames = new Properties(); qnames.load(loader.openResource(qnamesFile)); } catch (final IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Loading of the QNames mapping file failed: [" + qnamesFile + "]", e); } }
From source file:gov.nih.nlm.ncbi.seqr.tokenizer.SequenceTokenizerFactory.java
License:Apache License
private MappedByteBuffer getMappedByteBuffer(ResourceLoader loader) { long bufferSize = 3368800 * 4; FileChannel fc = null;//from www. j a v a2 s. co m try { logger.warn("Loading " + seqrIndexerFiles + " by ResourceLoader"); InputStream is = loader.openResource(seqrIndexerFiles); File f = new File("null"); fc = new RandomAccessFile(f, "rw").getChannel(); //reader = new InputStreamReader(new FileInputStream(filename)); mem = fc.map(FileChannel.MapMode.READ_ONLY, 0, bufferSize); mem.order(ByteOrder.LITTLE_ENDIAN); return mem; } catch (Exception e) { e.printStackTrace(); logger.error("Failed: read in the index file:" + seqrIndexerFiles); return null; } }
From source file:jp.sf.fess.solr.plugin.analysis.synonym.NGramSynonymTokenizerFactory.java
License:Apache License
private SynonymMap loadSynonyms(final ResourceLoader loader, final String cname, final boolean dedup, final Analyzer analyzer, final boolean expand, final String synonyms) throws IOException, ParseException { final CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder() .onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT); SynonymMap.Parser parser;/*w w w . ja v a2 s . co m*/ final Class<? extends SynonymMap.Parser> clazz = loader.findClass(cname, SynonymMap.Parser.class); try { parser = clazz.getConstructor(boolean.class, boolean.class, Analyzer.class).newInstance(dedup, expand, analyzer); } catch (final Exception e) { throw new RuntimeException(e); } final File synonymFile = new File(synonyms); if (synonymFile.exists()) { decoder.reset(); parser.parse(new InputStreamReader(loader.openResource(synonyms), decoder)); } else { final List<String> files = splitFileNames(synonyms); for (final String file : files) { decoder.reset(); parser.parse(new InputStreamReader(loader.openResource(file), decoder)); } } return parser.build(); }
From source file:no.bekk.bekkopen.tokenfilter.TransformationFilterFactory.java
License:Open Source License
public void inform(ResourceLoader loader) throws IOException { BufferedReader ruleReader = new BufferedReader(new InputStreamReader(loader.openResource(ruleFile))); rules = TransformationRule.buildRules(ruleReader); }
From source file:org.apache.solr.analysis.JapaneseTokenizerFactory.java
License:Apache License
@Override public void inform(ResourceLoader loader) { mode = getMode(args);//w w w .j av a 2 s . c o m String userDictionaryPath = args.get(USER_DICT_PATH); try { if (userDictionaryPath != null) { InputStream stream = loader.openResource(userDictionaryPath); String encoding = args.get(USER_DICT_ENCODING); if (encoding == null) { encoding = IOUtils.UTF_8; } CharsetDecoder decoder = Charset.forName(encoding).newDecoder() .onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT); Reader reader = new InputStreamReader(stream, decoder); userDictionary = new UserDictionary(reader); } else { userDictionary = null; } } catch (Exception e) { throw new InitializationException("Exception thrown while loading dictionary", e); } }