List of usage examples for org.apache.lucene.analysis.util ClasspathResourceLoader ClasspathResourceLoader
public ClasspathResourceLoader(Class<?> clazz)
From source file:at.ac.tuwien.ifs.lupu.LangDetFilterFactoryTest.java
/** * Test of create method, of class LangDetFilterFactory. *///from w ww .ja v a 2 s . c o m @Test public void testCreate() { try { System.out.println("create"); Map<String, String> args = new HashMap<>(); args.put("languages", "languages.txt"); args.put("windowWidth", "1"); LangDetFilterFactory factory = new LangDetFilterFactory(args); ResourceLoader loader = new ClasspathResourceLoader(getClass()); factory.inform(loader); StringReader reader = new StringReader(" 34234 voil la France, hello@email.com here is England"); StandardTokenizer st = new StandardTokenizer(TEST_VERSION_CURRENT, reader); st.reset(); LangDetFilter filter = (LangDetFilter) factory.create(st); //filter.reset(); while (filter.incrementToken()) { System.out.println("!!!" + filter.toString()); } } catch (IOException ex) { Logger.getLogger(LangDetFilterFactoryTest.class.getName()).log(Level.SEVERE, null, ex); fail("Exception thrown"); } }
From source file:com.grantingersoll.opengrok.analysis.BaseTokenStreamFactoryTestCase.java
License:Apache License
/** * Returns a fully initialized TokenizerFactory with the specified name and key-value arguments. * {@link ClasspathResourceLoader} is used for loading resources, so any required ones should * be on the test classpath./*from w w w. java2s. c om*/ */ protected TokenizerFactory tokenizerFactory(String name, Version version, String... keysAndValues) throws Exception { return tokenizerFactory(name, version, new ClasspathResourceLoader(getClass()), keysAndValues); }
From source file:com.grantingersoll.opengrok.analysis.BaseTokenStreamFactoryTestCase.java
License:Apache License
/** * Returns a fully initialized TokenFilterFactory with the specified name and key-value arguments. * {@link ClasspathResourceLoader} is used for loading resources, so any required ones should * be on the test classpath.// w w w . ja v a2 s . com */ protected TokenFilterFactory tokenFilterFactory(String name, Version version, String... keysAndValues) throws Exception { return tokenFilterFactory(name, version, new ClasspathResourceLoader(getClass()), keysAndValues); }
From source file:com.grantingersoll.opengrok.analysis.BaseTokenStreamFactoryTestCase.java
License:Apache License
/** * Returns a fully initialized CharFilterFactory with the specified name and key-value arguments. * {@link ClasspathResourceLoader} is used for loading resources, so any required ones should * be on the test classpath./*from www. j a v a2 s . c o m*/ */ protected CharFilterFactory charFilterFactory(String name, String... keysAndValues) throws Exception { return charFilterFactory(name, Version.LATEST, new ClasspathResourceLoader(getClass()), keysAndValues); }
From source file:gov.nih.nlm.ncbi.seqr.tokenizer.BaseTokenStreamFactoryTestCase.java
License:Apache License
/** * Returns a fully initialized CharFilterFactory with the specified name and key-value arguments. * {@link ClasspathResourceLoader} is used for loading resources, so any required ones should * be on the test classpath.//from w w w. ja v a2 s .c o m */ protected CharFilterFactory charFilterFactory(String name, String... keysAndValues) throws Exception { return charFilterFactory(name, TEST_VERSION_CURRENT, new ClasspathResourceLoader(getClass()), keysAndValues); }
From source file:gov.nih.nlm.ncbi.seqr.tokenizer.TestRawSequence2TokenizerFactory.java
License:Apache License
public void testFactory2() throws Exception { ResourceLoader loader = new ClasspathResourceLoader(getClass()); assertTrue("loader is null and it shouldn't be", loader != null); RawSequence2TokenizerFactory sf = (RawSequence2TokenizerFactory) tokenizerFactory("rawsequence2", "nmer", "5"); for (int i = 0; i <= 1000; i++) { TokenStream stream = sf.create(newAttributeFactory(), new StringReader("ABCDEFGHIJKLMN")); assertTokenStreamContents(stream, new String[] { "ABCDE", "FGHIJ" }); TokenStream stream2 = sf.create(newAttributeFactory(), new StringReader("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); assertTokenStreamContents(stream2, new String[] { "AAAAA", "AAAAA", "AAAAA", "AAAAA", "AAAAA", "AAAAA", "AAAAA", "AAAAA" }); }/*w ww .ja va 2s.c om*/ }
From source file:gov.nih.nlm.ncbi.seqr.tokenizer.TestSequenceTokenizerFactory.java
License:Apache License
public void testFactory2() throws Exception { final Reader reader = new StringReader("AAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAA"); ResourceLoader loader = new ClasspathResourceLoader(getClass()); assertTrue("loader is null and it shouldn't be", loader != null); SequenceTokenizerFactory sf = (SequenceTokenizerFactory) tokenizerFactory("sequence", "indexer", "good_one.11.index"); TokenStream stream = sf.create(newAttributeFactory(), reader); // assertTokenStreamContents(stream, new String[]{"141351", "141351", "141351", "240382", "141351", "141351", "141351", "141351"}); TokenStream stream2 = sf.create(newAttributeFactory(), new StringReader("AAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAA")); //assertTokenStreamContents(stream2, new String[]{"141351", "141351", "141351", "240382", "141351", "141351", "141351", "141351"}); }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.NodeStateAnalyzerFactory.java
License:Apache License
public NodeStateAnalyzerFactory(Version defaultVersion) { this(new ClasspathResourceLoader(NodeStateAnalyzerFactory.class.getClassLoader()), defaultVersion); }
From source file:org.apache.tika.eval.tokens.AnalyzerDeserializer.java
License:Apache License
private static TokenizerFactory buildTokenizerFactory(JsonElement map, String analyzerName) throws IOException { if (!(map instanceof JsonObject)) { throw new IllegalArgumentException("Expecting a map with \"factory\" string and " + "\"params\" map in tokenizer factory;" + " not: " + map.toString() + " in " + analyzerName); }/*from ww w . j a va 2 s .co m*/ JsonElement factoryEl = ((JsonObject) map).get(FACTORY); if (factoryEl == null || !factoryEl.isJsonPrimitive()) { throw new IllegalArgumentException( "Expecting value for factory in char filter factory builder in:" + analyzerName); } String factoryName = factoryEl.getAsString(); factoryName = factoryName.startsWith("oala.") ? factoryName.replaceFirst("oala.", "org.apache.lucene.analysis.") : factoryName; JsonElement paramsEl = ((JsonObject) map).get(PARAMS); Map<String, String> params = mapify(paramsEl); String spiName = ""; for (String s : TokenizerFactory.availableTokenizers()) { Class clazz = TokenizerFactory.lookupClass(s); if (clazz.getName().equals(factoryName)) { spiName = s; break; } } if (spiName.equals("")) { throw new IllegalArgumentException( "A SPI class of type org.apache.lucene.analysis.util.TokenizerFactory with name" + "'" + factoryName + "' does not exist."); } try { TokenizerFactory tokenizerFactory = TokenizerFactory.forName(spiName, params); if (tokenizerFactory instanceof ResourceLoaderAware) { ((ResourceLoaderAware) tokenizerFactory) .inform(new ClasspathResourceLoader(AnalyzerDeserializer.class)); } return tokenizerFactory; } catch (IllegalArgumentException e) { throw new IllegalArgumentException("While working on " + analyzerName, e); } }
From source file:org.apache.tika.eval.tokens.AnalyzerDeserializer.java
License:Apache License
private static CharFilterFactory[] buildCharFilters(JsonElement el, String analyzerName) throws IOException { if (el == null || el.isJsonNull()) { return null; }/* w w w .java 2 s. c o m*/ if (!el.isJsonArray()) { throw new IllegalArgumentException( "Expecting array for charfilters, but got:" + el.toString() + " for " + analyzerName); } JsonArray jsonArray = (JsonArray) el; List<CharFilterFactory> ret = new LinkedList<CharFilterFactory>(); for (JsonElement filterMap : jsonArray) { if (!(filterMap instanceof JsonObject)) { throw new IllegalArgumentException( "Expecting a map with \"factory\" string and \"params\" map in char filter factory;" + " not: " + filterMap.toString() + " in " + analyzerName); } JsonElement factoryEl = ((JsonObject) filterMap).get(FACTORY); if (factoryEl == null || !factoryEl.isJsonPrimitive()) { throw new IllegalArgumentException( "Expecting value for factory in char filter factory builder in:" + analyzerName); } String factoryName = factoryEl.getAsString(); factoryName = factoryName.replaceAll("oala.", "org.apache.lucene.analysis."); JsonElement paramsEl = ((JsonObject) filterMap).get(PARAMS); Map<String, String> params = mapify(paramsEl); String spiName = ""; for (String s : CharFilterFactory.availableCharFilters()) { Class clazz = CharFilterFactory.lookupClass(s); if (clazz.getName().equals(factoryName)) { spiName = s; break; } } if (spiName.equals("")) { throw new IllegalArgumentException( "A SPI class of type org.apache.lucene.analysis.util.CharFilterFactory with name" + "'" + factoryName + "' does not exist."); } try { CharFilterFactory charFilterFactory = CharFilterFactory.forName(spiName, params); if (charFilterFactory instanceof ResourceLoaderAware) { ((ResourceLoaderAware) charFilterFactory) .inform(new ClasspathResourceLoader(AnalyzerDeserializer.class)); } ret.add(charFilterFactory); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("While trying to load " + analyzerName + ": " + e.getMessage(), e); } } if (ret.size() == 0) { return new CharFilterFactory[0]; } return ret.toArray(new CharFilterFactory[ret.size()]); }