static void Main(string[] args) { ClassLabelDictionary classLabelDict = new ClassLabelDictionary(); classLabelDict.LoadFromDB(); TFIDFDictionary tfidfDict = new TFIDFDictionary(); tfidfDict.LoadFromDB(); PrecedenceModel precedenceModel = new PrecedenceModel(tfidfDict, classLabelDict); precedenceModel.DiscoverPrecedence(); }
public void GenerateTFIDFDictionary() { Dictionary<int, TFIDF> tfidfDict = new Dictionary<int, TFIDF>(); foreach (DocModel m in docDB) { for (int i = 0; i < m.Length; i++) { int wordKey = m.Word(i); TFIDF tfidf; if (!tfidfDict.TryGetValue(wordKey, out tfidf)) { tfidf = new TFIDF(wordKey, docDB.Count); tfidf.key = wordKey; tfidfDict.Add(wordKey, tfidf); } tfidf.tf += m.Count(i); tfidf.df++; } } List<KeyValuePair<int, TFIDF>> tfidfs = tfidfDict.ToList(); tfidfs.Sort( (x1, x2) => { if (x1.Value.tfidf > x2.Value.tfidf) { return -1; } else if (x1.Value.tfidf == x2.Value.tfidf) { return 0; } else { return 1; } }); TFIDFDictionary tfidfDictionary = new TFIDFDictionary(); for (int i = 0; i < tfidfs.Count && i < 20000; i++) { tfidfDictionary.AddValue(wordDict.GetKey(tfidfs[i].Key), tfidfs[i].Key); } tfidfDictionary.StoreToDB(); }
static void Main(string[] args) { ClassLabelDictionary classLabelDict = new ClassLabelDictionary(); classLabelDict.LoadFromDB(); WordDictionary wordDict = new WordDictionary(); wordDict.LoadFromDB(); TFIDFDictionary tfidfDict = new TFIDFDictionary(); tfidfDict.LoadFromDB(); BoWModelDB docDB = new BoWModelDB(wordDict); docDB.LoadFromDBByDataSet("doc_set_cls_1000"); PModel.PrecedenceModel pModel = new PModel.PrecedenceModel(tfidfDict, classLabelDict); pModel.DiscoverPrecedence(); PrecedenceQuery pQuery = new PrecedenceQuery(pModel, wordDict, classLabelDict); pQuery.TestQuery(docDB); }
static void InitTFIDFDict() { classLabelDict = new ClassLabelDictionary(); classLabelDict.LoadFromDB(); tfidfDict = new TFIDFDictionary(); tfidfDict.LoadFromDB(); }