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);
            }
        }
Esempio n. 2
0
        // 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);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Given a clue string, get the clue corresponding to it
        /// Input clue stirng can be in any order (e.g. C-A-B)
        /// </summary>
        /// <param name="clueString"></param>
        /// <returns></returns>
        public Clue Get(string clueString)
        {
            List <string> segments = ClueHelper.SeperateClueFragments(clueString);

            string[] fullSet = segments.ToArray();
            string   seg;

            for (int i = 0; i < segments.Count; i++)
            {
                seg = segments[i];
                if (CluesTree.ContainsKey(seg))
                {
                    segments.RemoveAt(i); return(CluesTree[seg].GetClue(segments));
                }
            }
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Given a clue string, add it to current set
        /// Input clue stirng can be in any order (e.g. C-A-B)
        /// </summary>
        /// <param name="clueString"></param>
        public Clue Add(string clueString)
        {
            List <string> segments = ClueHelper.SeperateClueFragments(clueString);

            string[] fullSet = segments.ToArray();
            string   seg;

            for (int i = 0; i < segments.Count; i++)
            {
                seg = segments[i];
                if (CluesTree.ContainsKey(seg))
                {
                    segments.RemoveAt(i); return(CluesTree[seg].AddClue(segments, fullSet));
                }
            }
            seg            = segments[0];
            CluesTree[seg] = new ClueNode();
            segments.RemoveAt(0);
            return(CluesTree[seg].AddClue(segments, fullSet));
        }
        /// <summary>
        /// Given a sequence of fragments, find all fragment groups that are either equal or bigger than that sequence; return null if no exact or partial match can be found; Cross-overlap is not legal
        /// </summary>
        private List <string[]> GetMatchingScopes(string[] fragments)
        {
            List <string[]> matchingScopes = new List <string[]>();

            foreach (KeyValuePair <string, List <Document> > fragmentScope in FragmentScopes.Data)
            {
                string[] compareFragments = ClueHelper.SeperateClueFragments(fragmentScope.Key);
                if (ClueHelper.IsClueFragmentsContains(compareFragments, fragments) == true)
                {
                    matchingScopes.Add(compareFragments);
                }
            }

            // If we have any matching scope
            if (matchingScopes.Count > 0)
            {
                return(matchingScopes);
            }
            else
            {
                return(null);
            }
        }
 // 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.
 }
Esempio n. 7
0
 public void Rename(string newClue)
 {
     // When a clue is renamed, it's just renamed; Documents are not affected by this operation for links are based on GUIDs
     Fragments = ClueHelper.SeperateClueFragments(newClue).ToArray();
 }