Package org.apache.lucene.analysis.util

Examples of org.apache.lucene.analysis.util.AbstractAnalysisFactory


        }
      }
      if (!argMap.containsKey("luceneMatchVersion")) {
        argMap.put("luceneMatchVersion", Version.LUCENE_CURRENT.toString());
      }
      final AbstractAnalysisFactory instance;
      try {
        instance = clazz.getConstructor(Map.class).newInstance(argMap);
      } catch (Exception e) {
        throw new RuntimeException("Line #" + lineno(stok) + ": ", e);
      }
View Full Code Here


    if (factory != null) {
      // we managed to fully create an instance. check a few more things:
     
      // if it implements MultiTermAware, sanity check its impl
      if (factory instanceof MultiTermAwareComponent) {
        AbstractAnalysisFactory mtc = ((MultiTermAwareComponent) factory).getMultiTermComponent();
        assertNotNull(mtc);
        // its not ok to return e.g. a charfilter here: but a tokenizer could wrap a filter around it
        assertFalse(mtc instanceof CharFilterFactory);
      }
     
View Full Code Here

    if (factory != null) {
      // we managed to fully create an instance. check a few more things:
     
      // if it implements MultiTermAware, sanity check its impl
      if (factory instanceof MultiTermAwareComponent) {
        AbstractAnalysisFactory mtc = ((MultiTermAwareComponent) factory).getMultiTermComponent();
        assertNotNull(mtc);
        // its not ok to return a charfilter or tokenizer here, this makes no sense
        assertTrue(mtc instanceof TokenFilterFactory);
      }
     
View Full Code Here

    if (factory != null) {
      // we managed to fully create an instance. check a few more things:
     
      // if it implements MultiTermAware, sanity check its impl
      if (factory instanceof MultiTermAwareComponent) {
        AbstractAnalysisFactory mtc = ((MultiTermAwareComponent) factory).getMultiTermComponent();
        assertNotNull(mtc);
        // its not ok to return a tokenizer or tokenfilter here, this makes no sense
        assertTrue(mtc instanceof CharFilterFactory);
      }
     
View Full Code Here

      ctor = factoryClazz.getConstructor(Map.class);
    } catch (Exception e) {
      throw new RuntimeException("factory '" + factoryClazz + "' does not have a proper ctor!");
    }
   
    AbstractAnalysisFactory factory = null;
    try {
      factory = ctor.newInstance(args);
    } catch (InstantiationException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
View Full Code Here

    if (initialize(factory)) {
      // we managed to fully create an instance. check a few more things:
     
      // if it implements MultiTermAware, sanity check its impl
      if (factory instanceof MultiTermAwareComponent) {
        AbstractAnalysisFactory mtc = ((MultiTermAwareComponent) factory).getMultiTermComponent();
        assertNotNull(mtc);
        // its not ok to return e.g. a charfilter here: but a tokenizer could wrap a filter around it
        assertFalse(mtc instanceof CharFilterFactory);
      }
     
View Full Code Here

    if (initialize(factory)) {
      // we managed to fully create an instance. check a few more things:
     
      // if it implements MultiTermAware, sanity check its impl
      if (factory instanceof MultiTermAwareComponent) {
        AbstractAnalysisFactory mtc = ((MultiTermAwareComponent) factory).getMultiTermComponent();
        assertNotNull(mtc);
        // its not ok to return a charfilter or tokenizer here, this makes no sense
        assertTrue(mtc instanceof TokenFilterFactory);
      }
     
View Full Code Here

    if (initialize(factory)) {
      // we managed to fully create an instance. check a few more things:
     
      // if it implements MultiTermAware, sanity check its impl
      if (factory instanceof MultiTermAwareComponent) {
        AbstractAnalysisFactory mtc = ((MultiTermAwareComponent) factory).getMultiTermComponent();
        assertNotNull(mtc);
        // its not ok to return a tokenizer or tokenfilter here, this makes no sense
        assertTrue(mtc instanceof CharFilterFactory);
      }
     
View Full Code Here

   * @param stok stream tokenizer from which to draw analysis factory params
   * @param clazz analysis factory class to instantiate
   */
  private void createAnalysisPipelineComponent
      (StreamTokenizer stok, Class<? extends AbstractAnalysisFactory> clazz) {
    final AbstractAnalysisFactory instance;
    try {
     instance = clazz.newInstance();
    } catch (Exception e) {
      throw new RuntimeException("Line #" + lineno(stok) + ": ", e);
    }
    Version luceneMatchVersion = null;
    Map<String,String> argMap = new HashMap<String,String>();
    boolean parenthetical = false;
    try {
      WHILE_LOOP: while (stok.nextToken() != StreamTokenizer.TT_EOF) {
        switch (stok.ttype) {
          case ',': {
            if (parenthetical) {
              // Do nothing
              break;
            } else {
              // Finished reading this analysis factory configuration
              break WHILE_LOOP;
            }
          }
          case '(': {
            if (parenthetical) {
              throw new RuntimeException
                  ("Line #" + lineno(stok) + ": Unexpected opening parenthesis.");
            }
            parenthetical = true;
            break;
          }
          case ')': {
            if (parenthetical) {
              parenthetical = false;
            } else {
              throw new RuntimeException
                  ("Line #" + lineno(stok) + ": Unexpected closing parenthesis.");
            }
            break;
          }
          case StreamTokenizer.TT_WORD: {
            if ( ! parenthetical) {
              throw new RuntimeException("Line #" + lineno(stok) + ": Unexpected token '" + stok.sval + "'");
            }
            String argName = stok.sval;
            stok.nextToken();
            if (stok.ttype != ':') {
              throw new RuntimeException
                  ("Line #" + lineno(stok) + ": Missing ':' after '" + argName + "' param to " + clazz.getSimpleName());
            }
            stok.nextToken();
            String argValue = stok.sval;
            switch (stok.ttype) {
              case StreamTokenizer.TT_NUMBER: {
                  argValue = Double.toString(stok.nval);
                  // Drop the ".0" from numbers, for integer arguments
                  argValue = TRAILING_DOT_ZERO_PATTERN.matcher(argValue).replaceFirst("");
                  // Intentional fall-through
              }
              case '"':
              case '\'':
              case StreamTokenizer.TT_WORD: {
                if (argName.equalsIgnoreCase("luceneMatchVersion")) {
                  try {
                    luceneMatchVersion = Version.parseLeniently(argValue);
                  } catch (IllegalArgumentException e) {
                    throw new RuntimeException
                        ("Line #" + lineno(stok) + ": Unrecognized luceneMatchVersion '" + argValue + "'", e);
                  }
                } else {
                  argMap.put(argName, argValue);
                }
                break;
              }
              case StreamTokenizer.TT_EOF: {
                throw new RuntimeException("Unexpected EOF: " + stok.toString());
              }
              default: {
                throw new RuntimeException
                    ("Line #" + lineno(stok) + ": Unexpected token: " + stok.toString());
              }
            }
          }
        }
      }

      instance.setLuceneMatchVersion
          (null == luceneMatchVersion ? Version.LUCENE_CURRENT : luceneMatchVersion);
      instance.init(argMap);
      if (instance instanceof ResourceLoaderAware) {
        File baseDir = new File(getRunData().getConfig().get("work.dir", "work")).getAbsoluteFile();
        ((ResourceLoaderAware)instance).inform(new FilesystemResourceLoader(baseDir));
      }
      if (CharFilterFactory.class.isAssignableFrom(clazz)) {
View Full Code Here

        }
      }
      if (!argMap.containsKey("luceneMatchVersion")) {
        argMap.put("luceneMatchVersion", Version.LUCENE_CURRENT.toString());
      }
      final AbstractAnalysisFactory instance;
      try {
        instance = clazz.getConstructor(Map.class).newInstance(argMap);
      } catch (Exception e) {
        throw new RuntimeException("Line #" + lineno(stok) + ": ", e);
      }
View Full Code Here

TOP

Related Classes of org.apache.lucene.analysis.util.AbstractAnalysisFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.