zoukankan      html  css  js  c++  java
  • (已实现)相似度到大数据查找之Mysql 文章匹配的一些思路与提高查询速度

        当时只理解到这个层面,是想从园子里删除的,没删成功。 所以重新整理了下。 需求,最近实现了文章的原创度检测功能,处理思路一是分词之后做搜索引擎匹配飘红,另一方面是量化词组,按文章、段落、句子做数据库查询,功能基本满足实际需求。

    接下来,还需要在海量大数据中快速的查找到与一句或者一段话最相关的文章、段落。

    上一篇随笔里记录有当时的一些想法,今天下午按想法具体实现并测试了一次,速度比直接分组查询肯定快了很多很多,回顾下我的实现步骤:

      压缩'语料库,即提取特征词或词频,做量化处理之后以“列向量”形式保存到数据库;然后按前N组词拼为向量组,以供查询使用,即组合为1到N字的组合,量化后以“行向量”形式保存到数据库(目前是用MYSQL),计算和查询相似度的时候先提取特征,然后量化,再查询各Long型数值字段,速度应该会较一般查询要快一些。

    应用举例:[下午实现了具体想法,目前系统正在处理数据中,预计会在八千万行的数据集,相信查询速度应该还可以]

            【查询测试】查询以下特征

    Dictionary<string, int> words = new Dictionary<string, int>();
    words.Add('五笔', 1);
    words.Add('拼音', 1);
    words.Add('笔画', 1);
    words.Add('其它', 1);
    words.Add('英盘', 1);
    words.Add('美盘', 1);
    words.Add('法盘', 1);
    
    //List<Dictionary<int, long>> WordList = new List<Dictionary<int, long>>();
    
    //for (int i = 0; i < 15; i++)
    //{
    //    WordList.Add(GetWordSecurity(words, i + 1));   
    //}
    //直观看数据
    Dictionary<int, long> R1 = GetWordSecurity(words, 1);
    Dictionary<int, long> R2 = GetWordSecurity(words, 2);
    Dictionary<int, long> R3 = GetWordSecurity(words, 3);
    Dictionary<int, long> R4 = GetWordSecurity(words, 4);
    Dictionary<int, long> R5 = GetWordSecurity(words, 5);
    Dictionary<int, long> R6 = GetWordSecurity(words, 6);
    Dictionary<int, long> R7 = GetWordSecurity(words, 7);
    Dictionary<int, long> R8 = GetWordSecurity(words, 8);
    Dictionary<int, long> R9 = GetWordSecurity(words, 9);
    Dictionary<int, long> R10 = GetWordSecurity(words, 10);
    Dictionary<int, long> R11 = GetWordSecurity(words, 11);
    Dictionary<int, long> R12 = GetWordSecurity(words, 12);
    Dictionary<int, long> R13 = GetWordSecurity(words, 13);
    Dictionary<int, long> R14 = GetWordSecurity(words, 14);

    【量化数据】我选的是MD5->Long做量化

    五笔 -8683246507546018072
    拼音 5720075168044685354
    笔画 6444854990336207024
    其它 -4797408270696495584
    英盘 -1741849883950345011
    美盘 4116094244106799890
    法盘 5071717547464226258

    【查询】 根据实际需求(即相关度要求)仅仅只需要取以下列表中的一个值做为查询条件。即,通过分词-做词行向量排列,特征列向量排列将文章映射成ID,这样我们

    就可以通过 Select .. From T Where Long1= Value 实现文章相关度的查询【根据相关度要求可随时改变查询字段LongN】

       二字词   Dictionary<int, long> R1 = GetWordSecurity(words, 1);
    
    +  [0] {[1, -2963171339501332718]} System.Collections.Generic.KeyValuePair<int,long>
    +  [1] {[2, -2238391517209811048]} System.Collections.Generic.KeyValuePair<int,long>
    +  [2] {[3, 4966089295467037960]} System.Collections.Generic.KeyValuePair<int,long>
    +  [3] {[4, -6281813915328659238]} System.Collections.Generic.KeyValuePair<int,long>
    +  [4] {[5, 922666897348189770]} System.Collections.Generic.KeyValuePair<int,long>
    +  [5] {[6, 3978225284094340343]} System.Collections.Generic.KeyValuePair<int,long>
    +  [6] {[7, -8610574661558066372]} System.Collections.Generic.KeyValuePair<int,long>
    Dictionary<int, long> R2 = GetWordSecurity(words, 2);

    以上测试在今天下午全部完成编码及测试,现在我的系统正在做数据抓取和量化处理,初步预计数据集八千万行左右,做了好几年程序,这是咱第一次处理超百万行数据呢。

  • 相关阅读:
    并发的简单介绍1
    UITableView (4): 在TableView中移动cell和Section 从TableView中删除cell和section 添加系统默认刷新控件
    UITableView (3):显示cell上的菜单
    TableView(2)
    UITableView (1)
    在 Interface Builder 中配置自动布局的约束
    Velocity 的工作原理
    ORA-01858: a non-numeric character was found where a numeric was expected
    Java 8:不要再用循环了
    Lambda表达式
  • 原文地址:https://www.cnblogs.com/yangshaoqing/p/6916908.html
Copyright © 2011-2022 走看看