Example usage for org.apache.lucene.analysis MockAnalyzer MockAnalyzer

List of usage examples for org.apache.lucene.analysis MockAnalyzer MockAnalyzer

Introduction

In this page you can find the example usage for org.apache.lucene.analysis MockAnalyzer MockAnalyzer.

Prototype

public MockAnalyzer(Random random) 

Source Link

Document

Create a Whitespace-lowercasing analyzer with no stopwords removal.

Usage

From source file:brightsolid.solr.plugins.TestTargetPositionQuerySynonyms.java

License:Apache License

@Override
public void setUp() throws Exception {
    super.setUp();

    String testFile = "one, uno, un\n" + "two, dos, too\n" + "three, free, tres";

    SolrSynonymParser parser = new SolrSynonymParser(true, true, new MockAnalyzer(random()));
    parser.parse(new StringReader(testFile));

    final SynonymMap map = parser.build();
    Analyzer analyzer = new Analyzer() {
        @Override//from w  ww .  j  a va  2  s.c o  m
        protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
            Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, true);
            return new TokenStreamComponents(tokenizer, new SynonymFilter(tokenizer, map, false));
        }
    };

    directory = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), directory, analyzer);
    Document doc = new Document();
    FieldType newType = new FieldType(org.apache.lucene.document.TextField.TYPE_STORED);
    newType.setOmitNorms(true);
    Field field = newField("field", "", newType);
    field.fieldType().setOmitNorms(true);

    doc.add(field);

    field.setStringValue("one two three");
    iw.addDocument(doc);
    field.setStringValue("two three one");
    iw.addDocument(doc);
    field.setStringValue("three one two");
    iw.addDocument(doc);

    reader = iw.getReader();
    iw.close();
    searcher = newSearcher(reader);
}

From source file:com.meizu.nlp.classification.BooleanPerceptronClassifierTest.java

License:Apache License

@Test
public void testBasicUsage() throws Exception {
    checkCorrectClassification(new BooleanPerceptronClassifier(), TECHNOLOGY_INPUT, false,
            new MockAnalyzer(random()), textFieldName, booleanFieldName);
}

From source file:com.meizu.nlp.classification.BooleanPerceptronClassifierTest.java

License:Apache License

@Test
public void testExplicitThreshold() throws Exception {
    checkCorrectClassification(new BooleanPerceptronClassifier(100d, 1), TECHNOLOGY_INPUT, false,
            new MockAnalyzer(random()), textFieldName, booleanFieldName);
}

From source file:com.meizu.nlp.classification.BooleanPerceptronClassifierTest.java

License:Apache License

@Test
public void testBasicUsageWithQuery() throws Exception {
    checkCorrectClassification(new BooleanPerceptronClassifier(), TECHNOLOGY_INPUT, false,
            new MockAnalyzer(random()), textFieldName, booleanFieldName,
            new TermQuery(new Term(textFieldName, "it")));
}

From source file:com.meizu.nlp.classification.BooleanPerceptronClassifierTest.java

License:Apache License

@Test
public void testPerformance() throws Exception {
    checkPerformance(new BooleanPerceptronClassifier(), new MockAnalyzer(random()), booleanFieldName);
}

From source file:com.meizu.nlp.classification.KNearestNeighborClassifierTest.java

License:Apache License

@Test
public void testBasicUsage() throws Exception {
    // usage with default MLT min docs / term freq
    checkCorrectClassification(new KNearestNeighborClassifier(3), POLITICS_INPUT, POLITICS_RESULT,
            new MockAnalyzer(random()), textFieldName, categoryFieldName);
    // usage without custom min docs / term freq for MLT
    checkCorrectClassification(new KNearestNeighborClassifier(3, 2, 1), TECHNOLOGY_INPUT, TECHNOLOGY_RESULT,
            new MockAnalyzer(random()), textFieldName, categoryFieldName);
}

From source file:com.meizu.nlp.classification.KNearestNeighborClassifierTest.java

License:Apache License

@Test
public void testBasicUsageWithQuery() throws Exception {
    checkCorrectClassification(new KNearestNeighborClassifier(1), TECHNOLOGY_INPUT, TECHNOLOGY_RESULT,
            new MockAnalyzer(random()), textFieldName, categoryFieldName,
            new TermQuery(new Term(textFieldName, "it")));
}

From source file:com.meizu.nlp.classification.KNearestNeighborClassifierTest.java

License:Apache License

@Test
public void testPerformance() throws Exception {
    checkPerformance(new KNearestNeighborClassifier(100), new MockAnalyzer(random()), categoryFieldName);
}

From source file:com.meizu.nlp.classification.SimpleNaiveBayesClassifierTest.java

License:Apache License

@Test
public void testBasicUsage() throws Exception {
    checkCorrectClassification(new SimpleNaiveBayesClassifier(), TECHNOLOGY_INPUT, TECHNOLOGY_RESULT,
            new MockAnalyzer(random()), textFieldName, categoryFieldName);
    checkCorrectClassification(new SimpleNaiveBayesClassifier(), POLITICS_INPUT, POLITICS_RESULT,
            new MockAnalyzer(random()), textFieldName, categoryFieldName);
}

From source file:com.meizu.nlp.classification.SimpleNaiveBayesClassifierTest.java

License:Apache License

@Test
public void testBasicUsageWithQuery() throws Exception {
    checkCorrectClassification(new SimpleNaiveBayesClassifier(), TECHNOLOGY_INPUT, TECHNOLOGY_RESULT,
            new MockAnalyzer(random()), textFieldName, categoryFieldName,
            new TermQuery(new Term(textFieldName, "it")));
}