我正在尝试CustomAnalyzer
使用 Lucene 8.5 来实现。其目的是使用 wordnet 中的同义词扩展查询。我的代码如下:
private static CustomAnalyzer customAnalyzer() throws IOException {
Map<String, String> sargs = new HashMap<>();
sargs.put("synonyms", "wn_s.pl");
sargs.put("format", "wordnet");
CustomAnalyzer.Builder builder = CustomAnalyzer.builder()
.withTokenizer(StandardTokenizerFactory.class)
.addTokenFilter(EnglishPossessiveFilterFactory.class)
.addTokenFilter(LowerCaseFilterFactory.class)
.addTokenFilter(StopFilterFactory.class)
.addTokenFilter(PorterStemFilterFactory.class)
.addTokenFilter(SynonymGraphFilterFactory.class, sargs);
return builder.build();
}
但是,当我运行它时,我得到了这个异常
java.io.IOException: Resource not found: wn_s.pl
at org.apache.lucene.analysis.util.ClasspathResourceLoader.openResource(ClasspathResourceLoader.java:77)
at org.apache.lucene.analysis.synonym.SynonymGraphFilterFactory.loadSynonyms(SynonymGraphFilterFactory.java:179)
at org.apache.lucene.analysis.synonym.SynonymGraphFilterFactory.inform(SynonymGraphFilterFactory.java:154)
at org.apache.lucene.analysis.custom.CustomAnalyzer$Builder.applyResourceLoader(CustomAnalyzer.java:544)
at org.apache.lucene.analysis.custom.CustomAnalyzer$Builder.addTokenFilter(CustomAnalyzer.java:321)
at Main.customAnalyzer(Main.java:78)
at Main.main(Main.java:34)
该文件存在,它的权限是正确的,即使我使用绝对路径也会发生指定的异常。
任何帮助将不胜感激。