Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            FcaMatrix matrix = new FcaMatrix();
            FileScanner fscan = new FileScanner();
            String[] processingFiles = Directory.GetFiles(txtSourceDir.Text);

            matrix = fscan.processFiles(processingFiles);

            FcaTree tree = new FcaTree();
            tree.closureOneByOne(matrix,tree);
            FcaObjectSet lattice = new FcaObjectSet();
            lattice.buildLattice(tree, matrix);
            fscan.RefactorHierarchy(lattice);
        }
Esempio n. 2
0
 public void closureOneByOne(FcaMatrix matrix, FcaTree tree)
 {
     FcaObject nextObject = new FcaObject();
     FcaTree node;
     do
     {
         do
         {
             nextObject = matrix.getElemById(tree.getNextId() + 1);
             if (nextObject != null)
             {
                 FcaObjectSet q = new FcaObjectSet();
                 q = tree.getMainSet().clone();
                 q.closure(nextObject, matrix);
                 FcaObjectSet dif =q.difference(tree.getMainSet());
                 if (dif.minObject() == nextObject)
                 {
                     node = new FcaTree();
                     node.setMainSet(q);
                     listOfSets.Add(q);
                     node.setNextId(q.maxObject().getId());
                     node.setParent(tree);
                     tree.addDescendant(node);
                     listOfNodes.Add(node);
                     closureOneByOne(matrix, node);
                     tree.setNextId(nextObject.getId());
                 }
                 else
                 {
                     tree.setNextId(nextObject.getId());
                 }
             }
         } while (nextObject != null);
         if (tree.getParent() != null)
             tree = tree.getParent();
     } while ((tree.getParent() != null) && (nextObject != null));
 }
Esempio n. 3
0
        public void buildLattice(FcaTree tree, FcaMatrix matrix)
        {
            FcaObjectSet A = new FcaObjectSet();
            FcaObjectSet G = matrix.UltimateSet();
            List<FcaObjectSet> sup = minimal(A, G, matrix); // множесво всех возможных соседей в решетке
            head = A;
            AllSets = tree.returnListOfSets(tree);
            int i = AllSetsContains(G);
            if (i == -1)
            {
                addAllSets(G);
                i = AllSetsContains(G);
            }
            tail = AllSets[i];

            foreach (FcaObjectSet obj in sup)
            {
                i = AllSetsContains(obj);
                FcaObjectSet existObject = AllSets[i];
                A.addASupr(existObject);
                existObject.addAInf(A);
                addVisited(existObject);
            }

            // найти связь между  1 и 123.
            while (Visited.Count != 0)
            {
                List<FcaObjectSet> list = Visited.ToList<FcaObjectSet>();
                foreach (FcaObjectSet s in list)
                {
                    sup = minimal(s, G, matrix); // множесво всех возможных соседей в решетке
                    Visited.Remove(s);

                    foreach (FcaObjectSet obj in sup)
                    {
                        i = AllSetsContains(obj);
                        if (i == -1)
                        {
                            addAllSets(obj);
                            i = AllSetsContains(obj);
                        }
                        FcaObjectSet existObject = AllSets[i];
                        s.addASupr(existObject);
                        existObject.addAInf(s);
                        addVisited(existObject);
                    }
                }
            }

            foreach (FcaObjectSet set in AllSets)
            {
                FcaObjectSet check = new FcaObjectSet();
                foreach (FcaObjectSet l in set.AInf)
                {
                    foreach (FcaObject o in l.getObjects())
                    {
                        check.addObject(o);
                    }
                }

                if (!set.Equals(check))
                {
                    i = AllSetsContains(set);
                    set.addAInf(tree.findInList(set).getParent().getMainSet());
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     Список соседей в решетке
        /// </summary>
        /// <param name="A"> узел решетки</param>
        /// <param name="G"> универсальное множество, в котором содержается все понятия</param>
        /// <returns></returns>
        private List<FcaObjectSet> minimal(FcaObjectSet A, FcaObjectSet G, FcaMatrix matrix)
        {
            List<FcaObjectSet> resultSet = new List<FcaObjectSet>();
            FcaObjectSet subtr = G.difference(A);   // находим разниу между множествами

            List<FcaObject> iterableSet = subtr.getObjects();
            foreach (FcaObject obj in iterableSet)
            {
                FcaObjectSet B = new FcaObjectSet();
                B = A.clone();
                B.closure(obj, matrix);
                resultSet.Add(B);
            }

            // найдем минимальные из порожденных множеств
            List<FcaObjectSet> minSet = new List<FcaObjectSet>();
            if (resultSet.Count != 0)
            {
                int minCount = resultSet[0].count();

                foreach (FcaObjectSet obj in resultSet)
                {
                    if (obj.count() < minCount)
                    {
                        minSet.Clear();
                        minCount = obj.count();
                        minSet.Add(obj);
                    }
                    else if (obj.count() == minCount)
                    {
                        minSet.Add(obj);
                    }
                }

                //foreach (FcaObjectSet obj in minSet)
                //{
                //    if ((AllSets == null) || (!AllSets.Contains(obj)))
                //        AllSets.Add(obj);
                //}
            }
            return minSet;
        }
Esempio n. 5
0
 /// <summary>
 ///  Замыкание множества
 /// </summary>
 /// <param name="elem">добавляемый элемент</param>
 /// <param name="matrix">универсальное множество</param>
 public void closure(FcaObject elem, FcaMatrix matrix)
 {
     addObject(elem);
     int i = 0;
     int len = matrix.count();
     int[] vect = new int[this.attributes.Length];
     while (i < len){
         vect = intersect(matrix.getElemById(i).getAttributes());
         if (attrEquals(vect)&&(i!=elem.getId())) {
             addObject(matrix.getElemById(i));
         }
         i++;
     }
 }