Example #1
0
 public int Compare(Fragment frag1, Fragment frag2)
 {
     int i = 0;
     switch(sortWord)
     {
         case SortWord.PreviousWord:
             i = string.Compare(frag1.PrevWord.Value, frag2.PrevWord.Value, true);
             if (i == 0) i = string.Compare(frag1.ThisWord.Value, frag2.ThisWord.Value, true);
             if (i == 0) i = string.Compare(frag1.NextWord.Value, frag2.NextWord.Value, true);
             break;
         case SortWord.CurrentWord:
             i = string.Compare(frag1.ThisWord.Value, frag2.ThisWord.Value, true);
             if (i == 0) i = string.Compare(frag1.NextWord.Value, frag2.NextWord.Value, true);
             if (i == 0) i = string.Compare(frag1.PrevWord.Value, frag2.PrevWord.Value, true);
             break;
         case SortWord.NextWord:
             i = string.Compare(frag1.NextWord.Value, frag2.NextWord.Value, true);
             if (i == 0) i = string.Compare(frag1.ThisWord.Value, frag2.ThisWord.Value, true);
             if (i == 0) i = string.Compare(frag1.PrevWord.Value, frag2.PrevWord.Value, true);
             break;
     }
     return i;
 }
Example #2
0
        public FragmentList GetSomePreviousFragments(Fragment frag)
        {
            FragmentList lst = new FragmentList(null);
            OverlapComparer olc = new OverlapComparer(true);
            int i = list.BinarySearch(frag, olc);
            if (i<0) throw new Exception("tilsyneladende blev "+frag+" ikke fundet i denne liste");
            //			int o = ~i;
            while (i > 1 && olc.Compare(this[i-1],frag) == 0 ) i--;

            while(olc.Compare(this[i],frag) == 0)
            {
                lst.Add(this[i]);
                i++;
            }
            if ( (lst.Count < lowerBound && (simpleChance-1 >= rnd.Next(100))) || rnd.Next(100)<ambientSimpleChance ) // 5% chance for spring
            {
                NextComparer ncmp = new NextComparer(true);
                int j = list.BinarySearch(frag, ncmp);
                while (j > 1 && ncmp.Compare(this[j-1],frag) == 0 )  j--;
                while(ncmp.Compare(this[j],frag) == 0)
                {
                    lst.Add(this[j]);
                    j++;
                }
            }
            return lst;
        }
Example #3
0
        // w1 w2 w3
        //    w1 w2 w3
        public FragmentList GetSomeNextFragments(Fragment frag)
        {
            FragmentList lst = new FragmentList(null);
            OverlapComparer olc = new OverlapComparer(false);
            int i = list.BinarySearch(frag, olc);
            if (i<0) throw new Exception("tilsyneladende blev "+frag+" ikke fundet i denne liste");
            //			Console.WriteLine("fandt next: "+list[i]);
            //			int o = ~i;
            while (i > 1 && olc.Compare(this[i-1],frag) == 0 )
            {
                //				Console.WriteLine("backtrack!");
                i--; // ?
            }

            while(olc.Compare(this[i],frag) == 0)
            {
                lst.Add(this[i]);
                i++;
            }
            if ( (lst.Count < lowerBound && (simpleChance-1 >= rnd.Next(100))) || rnd.Next(100)<ambientSimpleChance ) // 5% chance for spring
            {
            //				Console.Write("enabling simple-compare for "+frag.ToString()+" - it only had "+lst.Count+" nextfragments...");
                NextComparer ncmp = new NextComparer(false);
                int j = list.BinarySearch(frag, ncmp);
                while (j > 1 && ncmp.Compare(this[j-1],frag) == 0 )  j--;
                while(ncmp.Compare(this[j],frag) == 0)
                {
                    lst.Add(this[j]);
                    j++;
                }
            //				Console.WriteLine(" now it has "+lst.Count+" to choose from");
            }
            return lst;
        }
Example #4
0
        public FragmentList GetSomeFragmentsByWord(Fragment frag)
        {
            MatchComparer mc = new MatchComparer();
            //
            FragmentList lst = new FragmentList(null);

            int i = list.BinarySearch( frag, mc );
            if (i < 0) log.Warn("GetSomeFragmentsByWord fandt ikke ord, binsearch returnerede "+i+" ("+~i+")");
            while (i>1 && mc.Compare(this[i-1], frag)==0) i--;

            while(i>0 && mc.Compare(this[i],frag) == 0)
            {
                lst.Add(this[i]);
                i++;
            }
            return lst;
        }
Example #5
0
 //        public FragmentList GetSomeNextFragments(Fragment frag)
 //        {
 //            bool simple = true;
 //            FragmentList lst = new FragmentList(null);
 //            if (simple)
 //            {
 //                NextComparer ncmp = new NextComparer(false);
 //                int i = list.BinarySearch(frag, ncmp);
 //                while (i > 1 && ncmp.Compare(this[i-1],frag) == 0 )  i--;
 //                while(ncmp.Compare(this[i],frag) == 0)
 //                {
 //                    lst.Add(this[i]);
 //                    i++;
 //                }
 //            }
 //            else
 //            {
 //                //			Console.WriteLine("getsomenext("+frag+") looking in list of "+Count);
 //                OverlapComparer olc = new OverlapComparer(false);
 //                int i = list.BinarySearch(frag, olc);
 //                if (i<0) throw new Exception("tilsyneladende blev "+frag+" ikke fundet i denne liste");
 //                //			Console.WriteLine("fandt next: "+list[i]);
 //                int o = ~i;
 //                while (i > 1 && olc.Compare(this[i-1],frag) == 0 )
 //                {
 //                    //				Console.WriteLine("backtrack!");
 //                    i--; // ?
 //                }
 //
 //                while(olc.Compare(this[i],frag) == 0)
 //                {
 //                    lst.Add(this[i]);
 //                    i++;
 //                }
 //            }
 //            return lst;
 //        }
 public int BinarySearch(Fragment frag, IComparer cmp)
 {
     return list.BinarySearch(frag,cmp);
 }
Example #6
0
 public void Add(Fragment frag)
 {
     if (cmp != null)
     {
         int i = list.BinarySearch(frag,cmp);
         if (i < 0) // indsæt på korrekt plads, hvis den ikke findes
         {
     //					Console.WriteLine("binsearch-add: indsat ("+i+") "+frag.ToString());
             list.Insert(~i,frag);
         }
         else
         {
     //					Console.WriteLine("binsearch-add: kunne ikke indsætte ("+i+") "+frag.ToString());
         }
     }
     else
     {
         list.Add(frag);
     }
 }
Example #7
0
 public int Compare(Fragment f1, Fragment f2)
 {
     try
     {
         return string.Compare(f1.ThisWord.Value, f2.ThisWord.Value, true);
     }
     catch (Exception e) {
     //				Console.WriteLine("matchcomparer: "+e.ToString());
         log.Error("matchcomparer: "+e.ToString());
         throw;
     }
 }
Example #8
0
 // der søges på f2 ...
 public int CompareReverse(Fragment f1, Fragment f2)
 {
     return string.Compare(f1.NextWord.Value, f2.ThisWord.Value, true);
 }
Example #9
0
 // der søges på f2 ...
 // 1: w1 w2 w3		denne er mindre end trp2
 // 2:    w1 w2 w3	denne er større end trp1
 public int CompareReverse(Fragment f1, Fragment f2)
 {
     int i = string.Compare(f2.ThisWord.Value, f1.NextWord.Value, true);
     //			Console.WriteLine("stage 1 compare '"+f2.ThisWord.Value+"','"+f1.NextWord.Value+"' yields "+i);
     if ( i == 0 )
     {
         i = string.Compare(f2.PrevWord.Value, f1.ThisWord.Value, true);
     //				Console.WriteLine("stage 2 compare '"+f2.PrevWord.Value+"','"+f1.ThisWord.Value+"' yields "+i);
     }
     //			Console.WriteLine("frg1: "+f1.ToString()+" <-> frg2: "+f2.ToString()+" => "+i);
     return -1*i;
 }
Example #10
0
 // der søges på f2 ...
 public int CompareForward(Fragment f1, Fragment f2)
 {
     return string.Compare(f1.PrevWord.Value, f2.ThisWord.Value, true);
     // reverse? string.Compare(f2.ThisWord.Value, f1.NextWord.Value, true);
 }
Example #11
0
        public void AddFragment(string prev, string word, string next, bool canStart, bool canEnd)
        {
            wordlist.Add(prev);
            wordlist.Add(word);
            wordlist.Add(next);

            Word wp = wordlist[prev];
            Word w = wordlist[word];
            Word wn = wordlist[next];

            if (wp == null || w == null || wn == null )
            {
                throw new Exception("addfragment fandt ikke word!");
            }

            Fragment frg = new Fragment(wp,w,wn,canStart, canEnd);
            prevSortedFragments.Add(frg);
            centerSortedFragments.Add(frg);
            nextSortedFragments.Add(frg);
            if (canStart) canStartFragments.Add(frg);
        }
Example #12
0
 private void AddFragment(Fragment frag)
 {
     prevSortedFragments.Add(frag);
     centerSortedFragments.Add(frag);
     nextSortedFragments.Add(frag);
 }
Example #13
0
 public Fragment GetPreviousFragment(Fragment frag)
 {
     FragmentList list = nextSortedFragments.GetSomePreviousFragments(frag);
     return list[rnd.Next(list.Count)];
 }
Example #14
0
 public Fragment GetNextFragment(Fragment frag)
 {
     FragmentList list = prevSortedFragments.GetSomeNextFragments(frag);
     return list[rnd.Next(list.Count)];
 }