public void RemoveDocument(string[] fragments, int currentIndex, Document pending) { if (currentIndex == fragments.Length - 1) { int index = Documents.IndexOf(pending); if (index >= 0) { Documents.RemoveAt(index); } else { throw new InvalidOperationException("The specified document hasn't been categorized under this clue"); } } else { if (Branches.ContainsKey(fragments[currentIndex + 1])) { Branches[fragments[currentIndex + 1]].RemoveDocument(fragments, currentIndex + 1, pending); } else { throw new InvalidOperationException("The specified document hasn't been categorized under this clue"); } } }
public void AddDocument(string[] fragments, int currentIndex, List <Document> pendings) { if (currentIndex == fragments.Length - 1) { foreach (Document pending in pendings) { bool bAlreadyExist = false; foreach (Document doc in Documents) { if (doc == pending) { bAlreadyExist = true; break; } } if (!bAlreadyExist) { Documents.Add(pending); } } } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { Branches[fragments[currentIndex + 1]] = new ClueTreeNode(fragments[currentIndex + 1], this); } Branches[fragments[currentIndex + 1]].AddDocument(fragments, currentIndex + 1, pendings); } }
/// <summary> /// Get documents that immediately belongs to this node /// </summary> /// <param name="fragment"></param> /// <returns></returns> public List <Document> GetDocuments(string fragment) { if (Branches.ContainsKey(fragment)) { return(Branches[fragment].Documents); } else { return(null); } }
private void LoadBranches(string branchType) { cbManageType.Enabled = false; cbBranches.DataSource = new List <string> { _loading.Text }; if (!Branches.ContainsKey(branchType)) { _task.Load(() => GetBranches(branchType), (branches) => { Branches.Add(branchType, branches); DisplayBranchDatas(); }); } else { DisplayBranchDatas(); } }
public string GetColumn(string path, Project project) { if (string.IsNullOrEmpty(path)) { return(ToString()); } string[] parts = path.Split(new char[] { '.' }, 2); if (parts[0].StartsWith("!")) { string mark = parts[0].Substring(1); if (Marks.ContainsKey(mark)) { return(Marks[mark]); } } else if (parts[0].StartsWith("*")) { Rule r = project.Rules.GetRuleByName(parts[0].Substring(1)); Context c = new Context(); c._Tokens = new List <string>(this.Tokens); r.Execute(c); if (parts.Length > 1) { return(c.GetColumn(parts[1], project)); } else { return(c.ToString()); } } else if (Branches.ContainsKey(parts[0])) { if (parts.Length > 1) { return(Branches[parts[0]].GetColumn(parts[1], project)); } else { return(Branches[parts[0]].ToString()); } } return("N/A"); }
public ClueTreeNode CreateTreeNode(string[] fragments, int currentIndex) { if (currentIndex == fragments.Length - 1) { return(this); } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { Branches[fragments[currentIndex + 1]] = new ClueTreeNode(fragments[currentIndex + 1], this); } return(Branches[fragments[currentIndex + 1]].CreateTreeNode(fragments, currentIndex + 1)); } }
public List <Document> GetDocuments(string[] fragments, int currentIndex) { if (currentIndex == fragments.Length - 1) { return(Documents); } else { if (Branches.ContainsKey(fragments[currentIndex + 1])) { return(Branches[fragments[currentIndex + 1]].GetDocuments(fragments, currentIndex + 1)); } else { return(null); } } }
public List <string> GetPossibleFragments(string[] fragments, int currentIndex) { if (currentIndex == fragments.Length - 1) { return(Branches.Keys.Where(item => item.Contains(fragments[fragments.Length - 1]) && item != fragments[fragments.Length - 1]).ToList()); } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { return(null); } else { return(GetPossibleFragments(fragments, currentIndex + 1)); } } }
public void GetTrailingFragments(string[] fragments, int currentIndex, List <string> appendix) { if (currentIndex == fragments.Length - 1) { appendix.AddRange(Branches.Keys); } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { throw new InvalidOperationException("The specified document hasn't been categorized under this clue"); } else { GetTrailingFragments(fragments, currentIndex + 1, appendix); }; } }
public List <string> GetSiblings(string[] fragments, int currentIndex) { if (currentIndex == fragments.Length - 1) { return(Branches.Keys.ToList()); } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { throw new InvalidOperationException("The specified document hasn't been categorized under this clue"); } else { return(GetSiblings(fragments, currentIndex + 1)); } } }
public ClueTreeNode GetTreeNode(string[] fragments, int currentIndex) { if (currentIndex == fragments.Length - 1) { return(this); } else { if (Branches.ContainsKey(fragments[currentIndex + 1])) { return(Branches[fragments[currentIndex + 1]].GetTreeNode(fragments, currentIndex + 1)); } else { return(null); } } }
public void AddDocument(string[] fragments, int currentIndex, Document pending) { if (currentIndex == fragments.Length - 1) { foreach (Document doc in Documents) { if (doc == pending) { return; } } Documents.Add(pending); } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { Branches[fragments[currentIndex + 1]] = new ClueTreeNode(fragments[currentIndex + 1], this); } Branches[fragments[currentIndex + 1]].AddDocument(fragments, currentIndex + 1, pending); } }
public List <ClueFragment> GetPossibleClueFragments(string[] fragments, int currentIndex) { if (currentIndex == fragments.Length - 1) { string[] possibleFragments = Branches.Keys.Where(item => item.Contains(fragments[fragments.Length - 1]) && item != fragments[fragments.Length - 1]).ToArray(); List <ClueFragment> results = new List <ClueFragment>(); foreach (string frag in possibleFragments) { results.Add(new ClueFragment(frag, Branches[frag].GetDocumentsCount(), Branches[frag].Documents)); } return(results); } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { return(null); } else { return(GetPossibleClueFragments(fragments, currentIndex + 1)); } } }
public DictionaryTree <K, V> this[K key] { get { return(Branches.ContainsKey(key) ? Branches[key] : null); } }
public bool BranchExists(string option) { return(Branches.ContainsKey(option)); }