Exemplo n.º 1
0
        List<KeyValuePair<PrecedenceRelation, int>> DiscoverPrecedence(InstanceDB db, BuildProperties buildP, ListProperties listP1, ListProperties listP2)
        {
            Dictionary<PrecedenceProperty, Dictionary<PrecedenceRelation, int>> good = new Dictionary<PrecedenceProperty, Dictionary<PrecedenceRelation, int>>();
            for (int i = 0; i < db.Count; i++)
            {
                LDAModel ldaDoc = (LDAModel)db[i];
                HashSet<PrecedenceProperty> p1List = PrecedenceProperty.Convert(listP1(db, i));
                List<PrecedenceProperty> p2List = buildP((List<int>)listP2(db, i));

                // clear bad
                if (good.Count > 0)
                {
                    List<PrecedenceRelation> removed = new List<PrecedenceRelation>();
                    for (int j1 = 0; j1 < p2List.Count; j1++)
                    {
                        Dictionary<PrecedenceRelation, int> pps = null;
                        PrecedenceProperty p2 = p2List[j1];
                        if (good.TryGetValue(p2, out pps))
                        {
                            foreach (KeyValuePair<PrecedenceRelation, int> kvp in pps)
                            {
                                PrecedenceProperty p1 = kvp.Key.P1;
                                if (!p1List.Contains(p1))
                                {
                                    removed.Add(kvp.Key);
                                }
                            }
                            for (int l = 0; l < removed.Count; l++)
                            {
                                pps.Remove(removed[l]);
                            }
                            removed.Clear();
                        }
                    }
                    removed = null;
                }

                // add new
                for (int j1 = 0; j1 < p2List.Count; j1++)
                {
                    PrecedenceProperty p2 = p2List[j1];
                    Dictionary<PrecedenceRelation, int> pps = null;
                    if (good.TryGetValue(p2, out pps)) // there exist some instances having p2 may or may not not have p1
                    {
                        foreach (PrecedenceProperty p1 in p1List)
                        {
                            PrecedenceRelation pp = new PrecedenceRelation(p1, p2);
                            int count = 0;
                            if (pps.TryGetValue(pp, out count))
                            {
                                pps[pp] = count + 1;
                            }
                        }
                    }
                    else // p2 not exists
                    {
                        pps = new Dictionary<PrecedenceRelation, int>();
                        foreach (PrecedenceProperty p1 in p1List)
                        {
                            PrecedenceRelation pp = new PrecedenceRelation(p1, p2);
                            pps.Add(pp, 1);
                        }
                        good.Add(p2, pps);
                    }
                }
            }
            return ToPrecedences(good);
        }
Exemplo n.º 2
0
        void LoadInstances(int limit)
        {
            if (dbs == null)
                dbs = new List<InstanceDB>();
            else
                dbs.Clear();

            int[] listOfTopicNumbers = { 500 };
            for (int i = 0; i < listOfTopicNumbers.Length; i++)
            {
                InstanceDB.collectionName = "ldadocs_" + listOfTopicNumbers[i]+ "_all";
                InstanceDB db = new InstanceDB();
                db.LoadFromDBByDataSet("doc_set_cls_1000", limit);
                db.LoadLDAModel("model\\ldamodel_" + listOfTopicNumbers[i] + ".beta", listOfTopicNumbers[i], dictionary);
                dbs.Add(db);
            }
        }
Exemplo n.º 3
0
        public void TestQuery(DocModelDB db)
        {
            PModel.InstanceDB.collectionName = "ldadocs_500_all";
            PModel.InstanceDB pDB = new PModel.InstanceDB();
            pDB.LoadInstances();

            HashSet<PModel.PrecedenceProperty> testingQueries = new HashSet<PModel.PrecedenceProperty>();
            for (int i = 0; i < pModel.PrecedenceRelations.Count; i++)
            {
                PModel.PrecedenceRelation relation = pModel.PrecedenceRelations[i];
                testingQueries.Add(relation.P1);
            }

            int hit = 0, miss = 0, bad = 0;
            foreach (PModel.PrecedenceProperty q in testingQueries)
            {
                for (int i = 0; i < db.Count; i++)
                {
                    bool result = IsSatisfied(db[i], q, pDB, true);
                    Validate(db[i], q, result, ref hit, ref miss, ref bad);
                }
            }
        }