org.apache.lucene.analysis.Analyzer.TokenStreamComponents Java Examples

The following examples show how to use org.apache.lucene.analysis.Analyzer.TokenStreamComponents. 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: LuceneTokenizer.java    From jstarcraft-nlp with Apache License 2.0 5 votes vote down vote up
public LuceneTokenizer(Analyzer analyzer) {
    try (LuceneAdapter lucene = new LuceneAdapter(analyzer)) {
        TokenStreamComponents component = lucene.createComponents("text");
        this.reader = component.getSource();
        this.stream = component.getTokenStream();
    }
}
 
Example #2
Source File: PatternAnalyzerImpl.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected TokenStreamComponents createComponents(final String field) {
	//Use default grouping
	final Tokenizer tokenizer = new PatternTokenizer(pattern,-1);
	final TokenStream filter = new LowerCaseFilter(tokenizer);
	return new TokenStreamComponents(tokenizer, filter);
}
 
Example #3
Source File: EntityAnalyzer.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Override
protected TokenStreamComponents createComponents(String fieldName) {
  Tokenizer tokenizer = new WhitespaceTokenizer();
  TokenStream result =
      new PatternReplaceFilter(tokenizer,
          Pattern.compile("^([\\.!\\?,:;\"'\\(\\)]*)(.*?)([\\.!\\?,:;\"'\\(\\)]*)$"), "$2", true);
  result = new PatternReplaceFilter(result, Pattern.compile("'s"), "s", true);
  return new TokenStreamComponents(tokenizer, result);
}
 
Example #4
Source File: IndexingTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
    super.setUp();

    // Create it in-memory
    indexApi = new IndexApi(new RAMDirectory(), true);
    indexApi.registerTokenizer(IFields.PYTHON, CodeAnalyzer.createPythonStreamComponents());
    TokenStreamComponents stringOrComment = CodeAnalyzer.createStringsOrCommentsStreamComponents();
    indexApi.registerTokenizer(IFields.STRING, stringOrComment);
    indexApi.registerTokenizer(IFields.COMMENT, stringOrComment);
}
 
Example #5
Source File: IndexApi.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void registerTokenizer(String fieldName, TokenStreamComponents tokenStream) {
    this.analyzer.registerTokenizer(fieldName, tokenStream);
}