當時只理解到這個層面,是想從園子里刪除的,沒刪成功。 所以重新整理了下。 需求,最近實現了文章的原創度檢測功能,處理思路一是分詞之后做搜索引擎匹配飄紅,另一方面是量化詞組,按文章、段落、句子做數據庫查詢,功能基本滿足實際需求。
接下來,還需要在海量大數據中快速的查找到與一句或者一段話最相關的文章、段落。
上一篇隨筆里記錄有當時的一些想法,今天下午按想法具體實現並測試了一次,速度比直接分組查詢肯定快了很多很多,回顧下我的實現步驟:
壓縮'語料庫,即提取特征詞或詞頻,做量化處理之后以“列向量”形式保存到數據庫;然后按前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);
以上測試在今天下午全部完成編碼及測試,現在我的系統正在做數據抓取和量化處理,初步預計數據集八千萬行左右,做了好幾年程序,這是咱第一次處理超百萬行數據呢。