Exemplo n.º 1
0
        public void GetRemainingCandidates(Relation relation, string v, string[] dimensions, string[] dim, List <string> diff)
        {
            int      nbAttr  = dimensions.Length;
            Lattice  lattice = new HybridLattice(relation);
            Iterator it      = lattice.conceptIterator(Traversal.TOP_ATTRSIZE);

            XmlDocument    doc = new XmlDocument();
            XmlDeclaration xmldecl;

            xmldecl          = doc.CreateXmlDeclaration("1.0", null, null);
            xmldecl.Encoding = "UTF-8";
            XmlElement root = (XmlElement)doc.AppendChild(doc.CreateElement("Elementary_Events"));

            while (it.hasNext())
            {
                Concept         c = it.next() as Concept;
                ElementaryEvent elementaryEvent = new ElementaryEvent();
                if (c.getAttributes().size() > nbAttr && c.getObjects().isEmpty() == false)
                {
                    ComparableSet cs         = c.getObjects();
                    Iterator      objects    = cs.iterator();
                    ComparableSet cs1        = c.getAttributes();
                    Iterator      attributes = cs1.iterator();
                    string[]      compare    = new string[dim.Length];
                    int           j          = 0;
                    while (attributes.hasNext())
                    {
                        string temp = attributes.next().ToString();
                        compare[j] = temp.Split('_')[0];
                        j++;
                    }

                    bool areEqual = true;
                    foreach (var item in dimensions)
                    {
                        areEqual &= compare.Contains(item);
                    }

                    List <string> photos = new List <string>();
                    string        photo  = "";
                    if (areEqual)
                    {
                        XmlElement ee     = doc.CreateElement("EE");
                        var        attrId = Guid.NewGuid().ToString();
                        ee.SetAttribute("Id", attrId);
                        elementaryEvent.Id = attrId;
                        List <string> imagesId = new List <string>();

                        while (objects.hasNext())
                        {
                            photo = objects.next().ToString();
                            if (diff.Contains(photo))
                            {
                                photos.Add(photo);
                            }
                        }
                        if (photos.Count > 0)
                        {
                            foreach (var item in photos)
                            {
                                XmlElement obj      = doc.CreateElement("Photos");
                                XmlText    objValue = doc.CreateTextNode(item);
                                imagesId.Add(item);
                                obj.AppendChild(objValue);
                                ee.AppendChild(obj);
                            }
                            attributes             = cs1.iterator();
                            elementaryEvent.Images = imagesId;
                            List <MetadataAttributes> attributesList = new List <MetadataAttributes>();

                            while (attributes.hasNext())
                            {
                                XmlElement         obj         = doc.CreateElement("Attributes");
                                string             attrValue   = attributes.next().ToString();
                                XmlText            objValue    = doc.CreateTextNode(attrValue);
                                MetadataAttributes currentAttr = ConvertStringMetadataAttribute(attrValue);
                                attributesList.Add(currentAttr);
                                obj.AppendChild(objValue);
                                ee.AppendChild(obj);
                            }
                            root.AppendChild(ee);
                            elementaryEvent.MetadataAttributes = attributesList;
                            ElementaryEvents.Add(elementaryEvent);
                        }
                    }
                }
            }
            doc.AppendChild(root);
            doc.InsertBefore(xmldecl, root);

            doc.Save(BaseUri + @"Results\Elementary Event Candidates\EEC2.xml");
            //Console.WriteLine(doc.OuterXml);
            StringBuilder sb = new StringBuilder();
            TextWriter    tr = new StringWriter(sb);
            XmlTextWriter wr = new XmlTextWriter(tr);

            wr.Formatting = Formatting.Indented;
            doc.Save(wr);
            wr.Close();
        }
Exemplo n.º 2
0
        public void GetElementaryEventCandidates(Relation relation, string[] dimensions)
        {
            int      nbAttr  = dimensions.Length;
            Lattice  lattice = new HybridLattice(relation);
            Iterator it      = lattice.conceptIterator(Traversal.TOP_ATTRSIZE);

            XmlDocument    doc = new XmlDocument();
            XmlDeclaration xmldecl;

            xmldecl          = doc.CreateXmlDeclaration("1.0", null, null);
            xmldecl.Encoding = "UTF-8";
            XmlElement root = (XmlElement)doc.AppendChild(doc.CreateElement("Elementary_Events"));

            while (it.hasNext())
            {
                Concept         concept         = it.next() as Concept;
                ElementaryEvent elementaryEvent = new ElementaryEvent();
                if (concept.getAttributes().size() == nbAttr)
                {
                    ComparableSet cs         = concept.getObjects();
                    Iterator      objects    = cs.iterator();
                    ComparableSet cs1        = concept.getAttributes();
                    Iterator      attributes = cs1.iterator();
                    String[]      compare    = new String[nbAttr];
                    int           j          = 0;
                    while (attributes.hasNext())
                    {
                        string temp = attributes.next().ToString();
                        compare[j] = temp.Split('_')[0];
                        //int prefix = temp.indexOf("|");
                        //compare[j] = temp.substring(0, prefix);
                        j++;
                    }
                    Array.Sort(compare);
                    bool areEqual = compare.SequenceEqual(dimensions);
                    //bool areEqual = this.bruteforce2(compare, dimensions);
                    if (areEqual)
                    {
                        XmlElement ee     = doc.CreateElement("EE");
                        string     attrId = Guid.NewGuid().ToString();
                        elementaryEvent.Id = attrId;
                        ee.SetAttribute("Id", attrId);
                        List <string> imagesId = new List <string>();

                        while (objects.hasNext())
                        {
                            //Element obj = new Element("Photos");
                            XmlElement obj      = doc.CreateElement("Photos");
                            string     objectId = objects.next().ToString();
                            XmlText    objValue = doc.CreateTextNode(objectId);
                            imagesId.Add(objectId);
                            obj.AppendChild(objValue);
                            ee.AppendChild(obj);
                        }
                        elementaryEvent.Images = imagesId;
                        List <MetadataAttributes> attributesList = new List <MetadataAttributes>();

                        attributes = cs1.iterator();
                        while (attributes.hasNext())
                        {
                            XmlElement         obj         = doc.CreateElement("Attributes");
                            string             attrValue   = attributes.next().ToString();
                            XmlText            objValue    = doc.CreateTextNode(attrValue);
                            MetadataAttributes currentAttr = ConvertStringMetadataAttribute(attrValue);
                            attributesList.Add(currentAttr);
                            obj.AppendChild(objValue);
                            ee.AppendChild(obj);
                        }
                        root.AppendChild(ee);
                        elementaryEvent.MetadataAttributes = attributesList;
                        ElementaryEvents.Add(elementaryEvent);
                    }
                }
            }
            doc.AppendChild(root);
            doc.InsertBefore(xmldecl, root);

            doc.Save(BaseUri + @"Results\Elementary Event Candidates\EEC1.xml");
            //Console.WriteLine(doc.OuterXml);
            StringBuilder sb = new StringBuilder();
            TextWriter    tr = new StringWriter(sb);
            XmlTextWriter wr = new XmlTextWriter(tr);

            wr.Formatting = Formatting.Indented;
            doc.Save(wr);
            wr.Close();
        }