public void RemoveDocumentClue(string clue, Document doc) { string[] fragments = ClueHelper.SeperateClueFragments(clue); // Remove from scope if (fragments.Length > 1) { FragmentScopes.Remove(clue, doc); } // Remove from fragments foreach (string fragment in fragments) { if (Fragments.ContainsKey(fragment) == false) { throw new InvalidOperationException("Key/Value isn't balanced for current operation doesn't have a previous counterpart."); } else { Fragments[fragment].Documents.Remove(doc); } // Remove from that fragment's scope if it's no longer used by anyone if (FragmentScopes.Get(clue) == null) { Fragments[fragment].FragmentScopes.Remove(clue); } } // Remove clue from collection if not used by others if (FragmentScopes.Get(clue) == null) { AllClues.Remove(clue); } }
// Given a particular clue string (e.g. A-B-C) for the document, record it; This clue constraints a fragment scope for that particular document // Input clue stirng can be in any order (e.g. C-A-B) public void AddDocumentClue(string clue, Document doc) { // Lower case is required clue = clue.ToLower(); // Condition on quantity of fragments List <string> fragments = ClueHelper.SeperateClueFragments(clue); // Add to all collection Clue addedOrExisting = ClueSet.Add(clue); // Add to scope if (fragments.Count > 1) { FragmentScopes.Add(addedOrExisting, doc); } // Add to fragments foreach (string fragment in fragments) { if (Fragments.ContainsKey(fragment)) { Fragments[fragment].Documents.Add(doc); } else { Fragments[fragment] = new FragmentInfo(fragment, doc); } Fragments[fragment].FullClues.Add(addedOrExisting); } }
// Given a particular clue A-B-C for the document; This clue constraints a fragment scope for that particular document public void AddDocumentClue(string clue, Document doc) // Assumed clue lower cased { string[] fragments = ClueHelper.SeperateClueFragments(clue); // Add to scope if (fragments.Length > 1) { FragmentScopes.Add(clue, doc); } // Add to fragments foreach (string fragment in fragments) { if (Fragments.ContainsKey(fragment)) { Fragments[fragment].Documents.Add(doc); } else { Fragments[fragment] = new FragmentInfo(fragment, doc); } Fragments[fragment].FragmentScopes.Add(clue); } // Add to all collection AllClues.Add(clue); // Notice by design (i.e. from where this function is called) clue is guaranteed to be non-duplicate to other already added ones; E.g. if it's manually created in clue creator we will rearrange it if it matches any existing ones. }