Java 快速字符串匹配(将文本与类别关联)
假设我有一篇帖子,标题类似
- :“WEB:2011 年 SEO”
- 描述:“一场讨论 2011 年网络中 SEO 的会议”
另外,我有一个与关键字相关的类别列表:
- “IT”(cat )-> “网页设计”,“搜索引擎优化”,“开发”,“网页开发”(关键词)
我有多个类别(it,艺术,医学,文学,机械等...)
我需要使用java自动升级我的帖子这些类别和关键字(一种标记)可以改善未来的搜索。
上面的示例:应匹配“seo”和“web”,因此 main_category 字段应填写“IT”,subfield_category 应填写“seo”或“web”(或者两者都填写,这还不错)太)
我的问题是,我能想到的唯一解决方案是暴力破解(测试所有单词,当一个单词匹配时,你就有了类别和与之相关的关键字列表),这会减慢我的速度表演...
有什么方法可以更好地进行搜索吗?我也可以修改我的类别->关键字结构来做得更好(我仍然不知道如何......)
提前感谢大家!
编辑:正如阿米特在评论中所要求的那样,准确性并不那么重要。我不需要 100% 的标记准确性,因为我知道我可以根据字符串的原始匹配获得诚实的正确性。
另外,我正在考虑的逻辑是:查看帖子标题/描述,搜索任何匹配的关键字,使用类别标记,在该类别中搜索更多关键字,保存 3 到 5 个匹配的关键字
Suppose i have a post which is something like
- TITLE: "WEB: SEO in 2011"
- DESCRIPTION: "A conference talking about SEO in the web of the 2011"
also, i have a list of categories with keywords associated:
- "IT" (cat) -> "Web design", "seo", "developing", "web developing" (keywords)
i have multiple categories (it, arts, medicals, literature, machinery etc...)
i need to use java to automatically upgrade my posts with those categories and keywords (a sort of tagging) to improve future searching.
The example above: should match "seo" and "web" so the main_category field should be filled up with "IT" and the subfield_category should be filled up with "seo" or "web" (or maybe both, which isn't bad too)
my problem is that the only solution i can come up with is waaaaay into the bruteforcing (test all the words, when one matches you have the category and the list of the keywords associated with it) and it will slower my performances...
is there any way i can do the search in a better way? also i can modify my category->keywords structure to do something better (i still don't know how...)
thanks all in advance!
EDIT: accuracy isn't so much important, as amit asked in a comment. i don't need 100% accuracy on tagging, since i know i can have an honest amount of correctness based on raw matching of the strings.
Also, the logic i was thinkinking about is: look at post title/description, search for any keywords matching, tag with category, search for more keywords into this category, save 3 to 5 matching keywords
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想尝试不同的方法,使用机器学习。
算法描述:
首先,创建学习样本[您确定应该如何标记它们的文档,您可以手动标记样本并将其作为算法的输入]。然后,使用
k
bag 为这些示例创建 Bag Of Words [您需要通过质量基准来确定哪个k
是最佳的,我将在稍后解释]。每个单词都是一个“特征”,接下来,对于每个新文档,您将尝试从学习示例中查找哪个文档是 最近邻居 [即在您的词袋中有最多的共同“单词”],新文档将被标记为其最近邻居。
如何对质量进行基准测试?
您可以通过从学习样本中取出 10% 的文档来检查质量,然后仅学习剩余的 90%。学习完成后,你可以通过检查剩余 10% 的准确性来评估你的算法的准确性。请注意,您可能需要执行几次此操作才能找到如上所述的最佳 k [词袋大小]。
You might want to try a different approach, using Machine Learning.
Algorithm Description:
First, create a learning samples [documents you know for sure how they should be tagged, you can tag a sample manually and give it as input to the algorithm]. Then, create Bag Of Words for these samples, using
k
bag of words [you will need to decide whichk
is optimal, by benchmarking the quality, I'll explain later on].Every word is a 'feature', and next, for each new document, you will try to find which document from the learning sample is the nearest neighbor [i.e. has most 'words' in common in your Bag Of Words], the new document will be tagged as its nearest neighbor.
How to Benchmark Quality?
you can check for quality by taking 10% documents out of the learning sample, and learn only on the remaining 90%. after done learning, you can evaluate how accurate your algorithm is by checking the accuracy of the remaining 10%. Note that you will probably need to do this a few times to find optimal k [Bag Of Words size] as mentioned above.