Example #1
0
        public bool IsSatisfied(DocModel instance, PModel.PrecedenceProperty p1, PModel.InstanceDB pDB, bool usePQuery)
        {
            if (usePQuery)
            {
                LDAModel ldaDoc = (LDAModel)pDB[pDB.SearchByDocID(instance.DocID)];
                if (ldaDoc != null)
                {
                    for (int i = 0; i < pModel.PrecedenceRelations.Count; i++)
                    {
                        PModel.PrecedenceRelation relation = pModel.PrecedenceRelations[i];
                        if (relation.P1 == p1)
                        {
                            int[] p = relation.P2.Values;
                            bool isSatisfied = true;
                            foreach (int v in p)
                            {
                                if (!ldaDoc.WordList.Contains(v))
                                {
                                    isSatisfied = false;
                                    break;
                                }
                            }
                            if (isSatisfied)
                                return isSatisfied;
                        }
                    }
                }
            }

            for (int i = 0; i < p1.Values.Length; i++)
            {
                string s = classLabelDictionary.GetKey(p1.Values[i]);
                List<int> queryWords = new List<int>();
                string l = s.ToLower();
                Match m;
                Regex r = new Regex(@"[a-zA-Z]+[0-9]*");
                for (m = r.Match(l); m.Success; m = m.NextMatch())
                {
                    int word = -1;
                    wordDictionary.Dictionary.TryGetValue(Detachment.Instance.Detach(m.Value), out word);
                    if (word >= 0)
                    {
                        queryWords.Add(word);
                    }
                    else
                    {
                        Debug.Assert(1 == 1);
                    }
                }
                for (int j = 0; j < queryWords.Count; j++)
                {
                    if (instance[queryWords[j]] <= 0)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
Example #2
0
        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();
        }
Example #3
0
        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);
        }
Example #4
0
 public PrecedenceQuery(PModel.PrecedenceModel pModel, DocModelDictionary wordDictionary, DocModelDictionary classLabelDictionary)
 {
     this.pModel = pModel;
     this.wordDictionary = wordDictionary;
     this.classLabelDictionary = classLabelDictionary;
 }
Example #5
0
 bool IsSatisfied(LDAModel ldaDoc, PModel.PrecedenceProperty p2)
 {
     return true;
 }
Example #6
0
        public void Validate(DocModel instance, PModel.PrecedenceProperty p1, bool isSatisfied,ref int hit, ref int miss, ref int bad)
        {
            int[] p = p1.Values;
            foreach (int v in p)
            {
                if (!instance.HasClassLabel(v))
                {
                    if (isSatisfied)
                    {
                        bad++;
                        return;
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (isSatisfied)
                hit++;
            else
                miss++;
        }