Lucene PorterStemmer 问题
给出以下代码:
Dim stemmer As New Lucene.Net.Analysis.PorterStemmer()
Response.Write(stemmer.Stem("mattress table") & "<br />") // Outputs: mattress t
Response.Write(stemmer.Stem("mattress") & "<br />") // Outputs: mattress
Response.Write(stemmer.Stem("table") & "<br />") // Outputs: tabl
有人可以解释为什么当单词中有空格时 PorterStemmer 会产生不同的结果吗?我原以为“床垫桌”会被词干为“床垫桌”。
另外,以下代码进一步令人困惑:
Dim parser As Lucene.Net.QueryParsers.QueryParser = New Lucene.Net.QueryParsers.QueryParser("MyField", New PorterStemmerAnalyzer)
Dim q As Lucene.Net.Search.Query = parser.Parse("mattress table")
Response.Write(q.ToString & "<br />") // Outputs: MyField:mattress MyField: tabl
q = parser.Parse("""mattress table""")
Response.Write(q.ToString & "<br />") // Outputs My Field:"mattress tabl"
有人可以解释为什么我使用相同的分析器从 QueryParser() 和 Stem() 函数得到相同单词的不同结果吗?
谢谢, 凯尔
Given the following code:
Dim stemmer As New Lucene.Net.Analysis.PorterStemmer()
Response.Write(stemmer.Stem("mattress table") & "<br />") // Outputs: mattress t
Response.Write(stemmer.Stem("mattress") & "<br />") // Outputs: mattress
Response.Write(stemmer.Stem("table") & "<br />") // Outputs: tabl
Could someone explain why the PorterStemmer produces different results when there is a space in the word? I was expecting 'mattress table' to be stemmed to 'mattress tabl'.
Also, this is further confusing by the following code:
Dim parser As Lucene.Net.QueryParsers.QueryParser = New Lucene.Net.QueryParsers.QueryParser("MyField", New PorterStemmerAnalyzer)
Dim q As Lucene.Net.Search.Query = parser.Parse("mattress table")
Response.Write(q.ToString & "<br />") // Outputs: MyField:mattress MyField: tabl
q = parser.Parse("""mattress table""")
Response.Write(q.ToString & "<br />") // Outputs My Field:"mattress tabl"
Could someone explain why I am getting different results from the QueryParser() and the Stem() function for the same word(s) using the same Analyzer?
Thanks,
Kyle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查询解析器首先将其标记为两个标记。波特认为这一切都是一个“词”,因此只提取最后一部分。
The query parser tokenizes it first into two tokens. Porter considers it all as one "word" and so only stems the last portion.
PorterStemmerAnalyzer 由一系列分词器和过滤器组成。 PorterStemmer 是生成令牌流的过滤器之一。如果您想验证这一点,请尝试更改查询的大小写。由于 tokenstream 上的 LowerCaseFilter,QueryParser 输出将为小写。
可以在此处查看自定义分析器的一些示例代码。这将使您了解分析器的内部情况。
PorterStemmerAnalyzer is composed of series of tokenizers and filters. PorterStemmer is one of the filters to the tokenstream generated. If you want to verify that, try changing the case of the query. QueryParser output will be in the lowercase due to LowerCaseFilter on tokenstream.
Some sample code for custom analyzer can be checked here. This will give you a peek inside an Analyzer.