WordnetSynonymParser in Lucene

别等时光非礼了梦想. 提交于 2020-01-02 08:39:20

问题


I am new to Lucene and I'm trying to use WordnetSynonymParser to expand queries using the wordnet synonyms prolog. Here is what I have till now:

public class CustomAnalyzer extends Analyzer {

@Override
protected TokenStreamComponents createComponents(String fieldName, Reader reader){
    // TODO Auto-generated method stub
    Tokenizer source = new ClassicTokenizer(Version.LUCENE_47, reader);
    TokenStream filter = new StandardFilter(Version.LUCENE_47, source);
    filter = new LowerCaseFilter(Version.LUCENE_47,filter);
    SynonymMap mySynonymMap = null;
    try {
        mySynonymMap = buildSynonym();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    filter = new SynonymFilter(filter, mySynonymMap, false);        
    return new TokenStreamComponents(source, filter);
}

private SynonymMap buildSynonym() throws IOException
{
    File file = new File("wn/wn_s.pl");
    InputStream stream = new FileInputStream(file);
    Reader rulesReader = new InputStreamReader(stream); 
    SynonymMap.Builder parser = null;
    parser = new WordnetSynonymParser(true, true, new StandardAnalyzer(Version.LUCENE_47));
    ((WordnetSynonymParser) parser).add(rulesReader);         
    SynonymMap synonymMap = parser.build();
    return synonymMap;
}
}

I get the error "The method add(CharsRef, CharsRef, boolean) in the type SynonymMap.Builder is not applicable for the arguments (Reader)"

However, the documentation of WordnetSynonymParser expects a Reader argument for the add function.

What am I doing wrong here? Any help is appreciated.


回答1:


If you are seeing documentation stating that WordNetSynonymParser has a method add(Reader), you are probably looking at documentation for an older version. The method certainly isn't there in the source code for 4.7. As of version 4.6.0, the method you are looking for is WordnetSynonymParser.parse(Reader).



来源:https://stackoverflow.com/questions/22585587/wordnetsynonymparser-in-lucene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!