org.apache.lucene.analysis.es.SpanishAnalyzer Java Examples

The following examples show how to use org.apache.lucene.analysis.es.SpanishAnalyzer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchemaTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseJSONWithNullDefaultAnalyzer() throws IOException {

    String json = "{" +
                  "  analyzers:{" +
                  "    spanish_analyzer : {" +
                  "      type:\"classpath\", " +
                  "      class:\"org.apache.lucene.analysis.es.SpanishAnalyzer\"}," +
                  "    snowball_analyzer : {" +
                  "      type:\"snowball\", " +
                  "      language:\"Spanish\", " +
                  "      stopwords : \"el,la,lo,lo,as,las,a,ante,con,contra\"}" +
                  "  }," +
                  "  fields : { id : {type : \"integer\"} }" +
                  " }'";

    Schema schema = JsonSerializer.fromString(json, Schema.class);

    Analyzer defaultAnalyzer = schema.getDefaultAnalyzer();
    Assert.assertEquals(PreBuiltAnalyzers.DEFAULT.get(), defaultAnalyzer);

    Analyzer spanishAnalyzer = schema.getAnalyzer("spanish_analyzer");
    Assert.assertTrue(spanishAnalyzer instanceof SpanishAnalyzer);

    schema.close();
}
 
Example #2
Source File: SpanishAnalyzerProvider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public SpanishAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, Environment env, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);
    analyzer = new SpanishAnalyzer(Analysis.parseStopWords(env, settings, SpanishAnalyzer.getDefaultStopSet()),
                                   Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET));
    analyzer.setVersion(version);
}
 
Example #3
Source File: FTConnLucene.java    From openprodoc with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new analyzer ¿in a language and with stop words?
 * @return a new Analyzer
 */
static private Analyzer CreateAnalizer()
{
if (GlobLang==null)     
    return(new StandardAnalyzer());
switch (GlobLang)
    {
    case "ES":  if (SW==null)
                   return(new SpanishAnalyzer());
                else
                    return(new SpanishAnalyzer(SW));
    case "EN":  if (SW==null)
                   return(new EnglishAnalyzer());
                else
                    return(new EnglishAnalyzer(SW));
    case "PT":  if (SW==null)
                   return(new PortugueseAnalyzer());
                else
                    return(new PortugueseAnalyzer(SW));
    case "CT":  if (SW==null)
                   return(new CatalanAnalyzer());
                else
                    return(new CatalanAnalyzer(SW));
    default:    if (SW==null)
                   return(new StandardAnalyzer());
                else
                    return(new StandardAnalyzer(SW));
    }
}
 
Example #4
Source File: AnalysisTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegularConstructor() {
    Map<String, AnalyzerBuilder> analyzers = new HashMap<>();
    analyzers.put("custom", new ClasspathAnalyzerBuilder("org.apache.lucene.analysis.es.SpanishAnalyzer"));
    Analysis analysis = new Analysis(analyzers);

    Analyzer englishAnalyzer = analysis.getAnalyzer("English");
    Assert.assertEquals(EnglishAnalyzer.class, englishAnalyzer.getClass());

    Analyzer customAnalyzer = analysis.getAnalyzer("custom");
    Assert.assertEquals(SpanishAnalyzer.class, customAnalyzer.getClass());
}
 
Example #5
Source File: AnalysisUtilsTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() {
    englishAnalyzer = new EnglishAnalyzer();
    spanishAnalyzer = new SpanishAnalyzer();
    Map<String, Analyzer> analyzers = new HashMap<>();
    analyzers.put("english", englishAnalyzer);
    analyzers.put("spanish", spanishAnalyzer);
    perFieldAnalyzer = new PerFieldAnalyzerWrapper(spanishAnalyzer, analyzers);
}
 
Example #6
Source File: SchemaTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseJSON() throws IOException {

    String json = "{" +
                  "  analyzers:{" +
                  "    spanish_analyzer : {type:\"classpath\", " +
                  "                        class:\"org.apache.lucene.analysis.es.SpanishAnalyzer\"}," +
                  "    snowball_analyzer : {type:\"snowball\", " +
                  "                         language:\"Spanish\", " +
                  "                         stopwords : \"el,la,lo,loas,las,a,ante,bajo,cabe,con,contra\"}" +
                  "  }," +
                  "  default_analyzer : \"spanish_analyzer\"," +
                  "  fields : {" +
                  "    id : {type : \"integer\"}," +
                  "    spanish_text : {type:\"text\", analyzer:\"spanish_analyzer\"}," +
                  "    snowball_text : {type:\"text\", analyzer:\"snowball_analyzer\"}" +
                  "  }" +
                  " }'";

    Schema schema = JsonSerializer.fromString(json, Schema.class);

    Analyzer defaultAnalyzer = schema.getDefaultAnalyzer();
    Assert.assertTrue(defaultAnalyzer instanceof SpanishAnalyzer);

    Analyzer spanishAnalyzer = schema.getAnalyzer("spanish_analyzer");
    Assert.assertTrue(spanishAnalyzer instanceof SpanishAnalyzer);

    ColumnMapper idMapper = schema.getMapper("id");
    Assert.assertTrue(idMapper instanceof ColumnMapperInteger);

    ColumnMapper spanishMapper = schema.getMapper("spanish_text");
    Assert.assertTrue(spanishMapper instanceof ColumnMapperText);
    Assert.assertEquals("spanish_analyzer", spanishMapper.analyzer());

    ColumnMapper snowballMapper = schema.getMapper("snowball_text");
    Assert.assertTrue(snowballMapper instanceof ColumnMapperText);
    Assert.assertEquals("snowball_analyzer", snowballMapper.analyzer());

    schema.close();
}
 
Example #7
Source File: SchemaTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseJSONWithNullAnalyzers() throws IOException {

    String json = "{" +
                  "  default_analyzer : \"org.apache.lucene.analysis.en.EnglishAnalyzer\"," +
                  "  fields : {" +
                  "    id : {type : \"integer\"}," +
                  "    spanish_text : {" +
                  "      type:\"text\", " +
                  "      analyzer:\"org.apache.lucene.analysis.es.SpanishAnalyzer\"}," +
                  "    snowball_text : {" +
                  "      type:\"text\", " +
                  "      analyzer:\"org.apache.lucene.analysis.en.EnglishAnalyzer\"}" +
                  "  }" +
                  " }'";

    Schema schema = JsonSerializer.fromString(json, Schema.class);

    Analyzer defaultAnalyzer = schema.getDefaultAnalyzer();
    Assert.assertTrue(defaultAnalyzer instanceof EnglishAnalyzer);

    ColumnMapper idMapper = schema.getMapper("id");
    Assert.assertTrue(idMapper instanceof ColumnMapperInteger);

    ColumnMapper spanishMapper = schema.getMapper("spanish_text");
    Assert.assertTrue(spanishMapper instanceof ColumnMapperText);
    Assert.assertEquals(SpanishAnalyzer.class.getName(), spanishMapper.analyzer());

    ColumnMapper snowballMapper = schema.getMapper("snowball_text");
    Assert.assertTrue(snowballMapper instanceof ColumnMapperText);
    Assert.assertEquals(EnglishAnalyzer.class.getName(), snowballMapper.analyzer());

    schema.close();
}
 
Example #8
Source File: SchemaTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseJSONWithEmptyAnalyzers() throws IOException {

    String json = "{" +
                  "  analyzers:{}, " +
                  "  default_analyzer : \"org.apache.lucene.analysis.en.EnglishAnalyzer\"," +
                  "  fields : {" +
                  "    id : {type : \"integer\"}," +
                  "    spanish_text : {type:\"text\", " +
                  "                    analyzer:\"org.apache.lucene.analysis.es.SpanishAnalyzer\"}," +
                  "    snowball_text : {type:\"text\", " +
                  "                     analyzer:\"org.apache.lucene.analysis.en.EnglishAnalyzer\"}" +
                  "  }" +
                  " }'";

    Schema schema = JsonSerializer.fromString(json, Schema.class);

    Analyzer defaultAnalyzer = schema.getDefaultAnalyzer();
    Assert.assertTrue(defaultAnalyzer instanceof EnglishAnalyzer);

    ColumnMapper idMapper = schema.getMapper("id");
    Assert.assertEquals(ColumnMapperInteger.class, idMapper.getClass());

    ColumnMapper spanishMapper = schema.getMapper("spanish_text");
    Assert.assertTrue(spanishMapper instanceof ColumnMapperText);
    Assert.assertEquals(SpanishAnalyzer.class.getName(), spanishMapper.analyzer());

    ColumnMapper snowballMapper = schema.getMapper("snowball_text");
    Assert.assertTrue(snowballMapper instanceof ColumnMapperText);
    Assert.assertEquals(EnglishAnalyzer.class.getName(), snowballMapper.analyzer());

    schema.close();
}
 
Example #9
Source File: SpanishAnalyzerProvider.java    From crate with Apache License 2.0 5 votes vote down vote up
SpanishAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
    super(indexSettings, name, settings);
    analyzer = new SpanishAnalyzer(
        Analysis.parseStopWords(env, settings, SpanishAnalyzer.getDefaultStopSet()),
        Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
    );
    analyzer.setVersion(version);
}
 
Example #10
Source File: SpanishAnalyzerProvider.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public SpanishAnalyzer get() {
    return this.analyzer;
}
 
Example #11
Source File: SnowballAnalyzerBuilder.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the default stopwords set used by Lucene language analyzer for the specified language.
 *
 * @param language The language for which the stopwords are. The supported languages are English, French, Spanish,
 *                 Portuguese, Italian, Romanian, German, Dutch, Swedish, Norwegian, Danish, Russian, Finnish,
 *                 Irish, Hungarian, Turkish, Armenian, Basque and Catalan.
 * @return The default stopwords set used by Lucene language analyzers.
 */
private static CharArraySet getDefaultStopwords(String language) {
    switch (language) {
        case "English":
            return EnglishAnalyzer.getDefaultStopSet();
        case "French":
            return FrenchAnalyzer.getDefaultStopSet();
        case "Spanish":
            return SpanishAnalyzer.getDefaultStopSet();
        case "Portuguese":
            return PortugueseAnalyzer.getDefaultStopSet();
        case "Italian":
            return ItalianAnalyzer.getDefaultStopSet();
        case "Romanian":
            return RomanianAnalyzer.getDefaultStopSet();
        case "German":
            return GermanAnalyzer.getDefaultStopSet();
        case "Dutch":
            return DutchAnalyzer.getDefaultStopSet();
        case "Swedish":
            return SwedishAnalyzer.getDefaultStopSet();
        case "Norwegian":
            return NorwegianAnalyzer.getDefaultStopSet();
        case "Danish":
            return DanishAnalyzer.getDefaultStopSet();
        case "Russian":
            return RussianAnalyzer.getDefaultStopSet();
        case "Finnish":
            return FinnishAnalyzer.getDefaultStopSet();
        case "Irish":
            return IrishAnalyzer.getDefaultStopSet();
        case "Hungarian":
            return HungarianAnalyzer.getDefaultStopSet();
        case "Turkish":
            return SpanishAnalyzer.getDefaultStopSet();
        case "Armenian":
            return SpanishAnalyzer.getDefaultStopSet();
        case "Basque":
            return BasqueAnalyzer.getDefaultStopSet();
        case "Catalan":
            return CatalanAnalyzer.getDefaultStopSet();
        default:
            return CharArraySet.EMPTY_SET;
    }
}
 
Example #12
Source File: SpanishAnalyzerProvider.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public SpanishAnalyzer get() {
    return this.analyzer;
}
 
Example #13
Source File: CommonAnalysisPlugin.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public List<PreBuiltAnalyzerProviderFactory> getPreBuiltAnalyzerProviderFactories() {
    List<PreBuiltAnalyzerProviderFactory> analyzers = new ArrayList<>();
    analyzers.add(new PreBuiltAnalyzerProviderFactory("standard_html_strip", CachingStrategy.ELASTICSEARCH,
        () -> new StandardHtmlStripAnalyzer(CharArraySet.EMPTY_SET)));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("pattern", CachingStrategy.ELASTICSEARCH,
        () -> new PatternAnalyzer(Regex.compile("\\W+" /*PatternAnalyzer.NON_WORD_PATTERN*/, null), true,
        CharArraySet.EMPTY_SET)));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("snowball", CachingStrategy.LUCENE,
        () -> new SnowballAnalyzer("English", EnglishAnalyzer.ENGLISH_STOP_WORDS_SET)));

    // Language analyzers:
    analyzers.add(new PreBuiltAnalyzerProviderFactory("arabic", CachingStrategy.LUCENE, ArabicAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("armenian", CachingStrategy.LUCENE, ArmenianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("basque", CachingStrategy.LUCENE, BasqueAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("bengali", CachingStrategy.LUCENE, BengaliAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("brazilian", CachingStrategy.LUCENE, BrazilianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("bulgarian", CachingStrategy.LUCENE, BulgarianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("catalan", CachingStrategy.LUCENE, CatalanAnalyzer::new));
    // chinese analyzer: only for old indices, best effort
    analyzers.add(new PreBuiltAnalyzerProviderFactory("chinese", CachingStrategy.ONE, StandardAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("cjk", CachingStrategy.LUCENE, CJKAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("czech", CachingStrategy.LUCENE, CzechAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("danish", CachingStrategy.LUCENE, DanishAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("dutch", CachingStrategy.LUCENE, DutchAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("english", CachingStrategy.LUCENE, EnglishAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("finnish", CachingStrategy.LUCENE, FinnishAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("french", CachingStrategy.LUCENE, FrenchAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("galician", CachingStrategy.LUCENE, GalicianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("german", CachingStrategy.LUCENE, GermanAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("greek", CachingStrategy.LUCENE, GreekAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("hindi", CachingStrategy.LUCENE, HindiAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("hungarian", CachingStrategy.LUCENE, HungarianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("indonesian", CachingStrategy.LUCENE, IndonesianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("irish", CachingStrategy.LUCENE, IrishAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("italian", CachingStrategy.LUCENE, ItalianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("latvian", CachingStrategy.LUCENE, LatvianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("lithuanian", CachingStrategy.LUCENE, LithuanianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("norwegian", CachingStrategy.LUCENE, NorwegianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("persian", CachingStrategy.LUCENE, PersianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("portuguese", CachingStrategy.LUCENE, PortugueseAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("romanian", CachingStrategy.LUCENE, RomanianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("russian", CachingStrategy.LUCENE, RussianAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("sorani", CachingStrategy.LUCENE, SoraniAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("spanish", CachingStrategy.LUCENE, SpanishAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("swedish", CachingStrategy.LUCENE, SwedishAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("turkish", CachingStrategy.LUCENE, TurkishAnalyzer::new));
    analyzers.add(new PreBuiltAnalyzerProviderFactory("thai", CachingStrategy.LUCENE, ThaiAnalyzer::new));
    return analyzers;
}