public HashSet <int> Compatible(string str, HashSet <int> dfas) { HashSet <int> res = new HashSet <int> (); foreach (int i in dfas) { FAResponse response = _dfas [i].Parse(str); if ((response == FAResponse.ACCEPT) || (response == FAResponse.NOT_REJECT)) { res.Add(i); } } return(res); }
public List <Tuple <string, int> > FindMatchingEntries(string entry, HashSet <int> dfas) { List <Tuple <string, int> > res = new List <Tuple <string, int> > (); List <Tuple <string, HashSet <int> > > unexplored = new List <Tuple <string, HashSet <int> > > (); unexplored.Add(new Tuple <string, HashSet <int> > (entry, dfas)); while (unexplored.Count != 0) { string curPath = unexplored [0].Item1; HashSet <int> curDfaList = unexplored [0].Item2; HashSet <int> tempDfaList = new HashSet <int> (); HashSet <string> children = new HashSet <string> (); if (curPath.EndsWith(".xml")) { XmlDocument doc = new XmlDocument(); doc.Load(curPath); children.Add(curPath + "{" + doc.DocumentElement.Name + "}"); } else if (curPath.Contains(".xml")) { int index = curPath.IndexOf(".xml") + 4; string filepath = curPath.Substring(0, index); string xmlpath = curPath.Substring(index); string[] xmlFields = xmlpath.Split('{', '}'); XmlDocument doc = new XmlDocument(); string xpath = xmlFields [0]; XmlNodeList xmlNodeList; for (int i = 1; i < xmlFields.Length; i++) { xpath += '/' + xmlFields [i]; } doc.Load(filepath); xmlNodeList = doc.SelectNodes(xpath); foreach (XmlNode node in xmlNodeList) { if (node.HasChildNodes) { foreach (XmlNode childNode in node.ChildNodes) { children.Add(curPath + "{" + childNode.Name + "}"); } } } } else if (Directory.Exists(curPath) || curPath == "") { string path = (curPath == "") ? Directory.GetCurrentDirectory() : curPath; DirectoryInfo curDir = new DirectoryInfo(path); FileInfo[] files = curDir.GetFiles("*", SearchOption.TopDirectoryOnly); DirectoryInfo[] dirs = curDir.GetDirectories("*", SearchOption.TopDirectoryOnly); path = (curPath == "") ? curPath : curPath + '/'; foreach (FileInfo file in files) { children.Add(path + file.Name); } foreach (DirectoryInfo dir in dirs) { children.Add(path + dir.Name); } } foreach (int i in dfas) { FAResponse response = _dfas [i].Parse(curPath); switch (response) { case FAResponse.ACCEPT: res.Add(new Tuple <string, int> (curPath, i)); break; case FAResponse.NOT_REJECT: tempDfaList.Add(i); break; case FAResponse.REJECT: break; } } if (tempDfaList.Count != 0) { foreach (string child in children) { unexplored.Add(new Tuple <string, HashSet <int> > (child, tempDfaList)); } } unexplored.RemoveAt(0); } return(res); }