예제 #1
0
        } // SrSlSlSr

        public static Dictionary <DeltaKey, int> CreateScanVerticalDeltaTable()
        {
            Dictionary <DeltaKey, int> deltaTable = CreateInitialTable(-1);

            // Want to match lefts and rights mostly
            DeltaKey key = new DeltaKey("Su", "Su");

            deltaTable[key] = 1;

            key             = new DeltaKey("Sd", "Sd");
            deltaTable[key] = 1;

            foreach (Token y in tokens)
            {
                // Penalise any kind of insertions
                key             = new DeltaKey("", Wordbook.TokenToString(y));
                deltaTable[key] = -10;

                // and deletions
                key             = new DeltaKey(Wordbook.TokenToString(y), "");
                deltaTable[key] = -10;
            }

            return(deltaTable);
        } // SuSdSdSu
예제 #2
0
        } // SuSdSdSu

        public static Dictionary <DeltaKey, int> CreateScanCornerDeltaTable()
        {
            Dictionary <DeltaKey, int> deltaTable = CreateInitialTable(-5);

            // Want to match lefts and rights, ups and down
            DeltaKey key = new DeltaKey("Su", "Su");

            deltaTable[key] = 1;

            key             = new DeltaKey("Sd", "Sd");
            deltaTable[key] = 1;

            key             = new DeltaKey("Sl", "Sl");
            deltaTable[key] = 1;

            key             = new DeltaKey("Sr", "Sr");
            deltaTable[key] = 1;

            foreach (Token y in tokens)
            {
                // Penalise any kind of insertions
                key             = new DeltaKey("", Wordbook.TokenToString(y));
                deltaTable[key] = -10;

                // and deletions
                key             = new DeltaKey(Wordbook.TokenToString(y), "");
                deltaTable[key] = -10;
            }

            return(deltaTable);
        } // SrSlSuSd, and all variants
예제 #3
0
        public static Dictionary <DeltaKey, int> CreateCompareVerticalDeltaTable() // SuSdSuSd
        {
            Dictionary <DeltaKey, int> deltaTable = CreateInitialTable(-2);

            // Want to match lefts and rights mostly, perfect match == 8
            DeltaKey key = new DeltaKey("Su", "Su");

            deltaTable[key] = 2;

            key             = new DeltaKey("Sd", "Sd");
            deltaTable[key] = 2;

            foreach (Token y in tokens)
            {
                // Penalise any kind of insertions
                key             = new DeltaKey("", Wordbook.TokenToString(y));
                deltaTable[key] = -2;

                // Penalise any kind of deletion
                key             = new DeltaKey(Wordbook.TokenToString(y), "");
                deltaTable[key] = -2;
            }

            // Insertions of short lefts and rights are okay
            key             = new DeltaKey("", "Sl");
            deltaTable[key] = -1;

            key             = new DeltaKey("", "Sr");
            deltaTable[key] = -1;

            // Therefore, for one insertion of an up or down, the threshold will be 7 or higher.
            // Perfect match is 8, minus 1 for 1 insertion of an Su or Sd.

            return(deltaTable);
        }
예제 #4
0
        } // SrSrSrSrLl

        public static Dictionary <DeltaKey, int> CreateLongLineDeltaTable()
        {
            Dictionary <DeltaKey, int> deltaTable = CreateInitialTable(-1);

            DeltaKey key = new DeltaKey("Sr", "Sr");

            deltaTable[key] = 5;

            key             = new DeltaKey("Sr", "Mr");
            deltaTable[key] = 2;

            key             = new DeltaKey("Sr", "Sl");
            deltaTable[key] = 0;

            key             = new DeltaKey("Ll", "Ll");
            deltaTable[key] = 10;

            key             = new DeltaKey("Ll", "");
            deltaTable[key] = -10;

            foreach (Token y in tokens)
            {
                key             = new DeltaKey("", Wordbook.TokenToString(y));
                deltaTable[key] = -10;
            }

            return(deltaTable);
        } // SrSrSrSrLl
예제 #5
0
        // Returns a delta table all initialised to -1.
        public static Dictionary <DeltaKey, int> CreateInitialTable(int initialValue)
        {
            Dictionary <DeltaKey, int> deltaTable = new Dictionary <DeltaKey, int>();

            // Add all possibilities
            foreach (Token x in tokens)
            {
                foreach (Token y in tokens)
                {
                    DeltaKey key = new DeltaKey(Wordbook.TokenToString(x), Wordbook.TokenToString(y));
                    deltaTable[key] = initialValue;
                }
            }

            // Add epsilons for deletion and insertions
            foreach (Token y in tokens)
            {
                DeltaKey key = new DeltaKey("", Wordbook.TokenToString(y));
                deltaTable[key] = -1;
            }

            foreach (Token x in tokens)
            {
                DeltaKey key = new DeltaKey(Wordbook.TokenToString(x), "");
                deltaTable[key] = -1;
            }

            return(deltaTable);
        }
예제 #6
0
        } // SuSuSuSu

        public static Dictionary <DeltaKey, int> CreateStringRightDeltaTable()
        {
            Dictionary <DeltaKey, int> deltaTable = CreateInitialTable(-1);

            // Want to match only rights. Perfect match would score 8.
            DeltaKey key = new DeltaKey("Sr", "Sr");

            deltaTable[key] = 2;

            // Replacing Sr with any number of Mr is okay too.
            key             = new DeltaKey("Sr", "Mr");
            deltaTable[key] = 2;

            // Replacing a short right in the string with a short left is okay.
            key             = new DeltaKey("Sr", "Sl");
            deltaTable[key] = 1;

            // Short ups and downs are okay
            key             = new DeltaKey("Sr", "Su");
            deltaTable[key] = 1;

            key             = new DeltaKey("Sr", "Sd");
            deltaTable[key] = 1;

            // If there is one replacement of an Sr either with Sl Su Sd, and the rest match with Sr, then the matching score would be 7. 6 for two replacements, etc.
            // We want to allow only one replacement somewhere in the string. So we will want a threshold of 7 when finding matches.

            // todo: need a way to specify the first and last tokens in the atom cannot change
            //          perhaps something like Sr - - Sr, where Sr matching with Sr score is high and whatever the dummy - char is has an equally high score for being replace with Sr, whilst slightly lower score for being replaced with Su, Sl, Sd.

            foreach (Token y in tokens)
            {
                // Penalise any kind of insertions
                key             = new DeltaKey("", Wordbook.TokenToString(y));
                deltaTable[key] = -10;

                // Penalise any kind of deletion
                key             = new DeltaKey(Wordbook.TokenToString(y), "");
                deltaTable[key] = -10;
            }

            return(deltaTable);
        } // SrSrSrSr, see notes for matching information
예제 #7
0
        } // SdSdSdSd

        public static Dictionary <DeltaKey, int> CreateStringLeftDeltaTable()
        {
            Dictionary <DeltaKey, int> deltaTable = CreateInitialTable(-1);

            // Want to match only lefts. Perfect match would score 8.
            DeltaKey key = new DeltaKey("Sl", "Sl");

            deltaTable[key] = 2;

            // Replacing Sl with any number of Ml is okay too.
            key             = new DeltaKey("Sl", "Ml");
            deltaTable[key] = 2;

            // Short left rights and ups are okay.
            key             = new DeltaKey("Sl", "Sd");
            deltaTable[key] = 1;

            key             = new DeltaKey("Sl", "Sr");
            deltaTable[key] = 1;

            key             = new DeltaKey("Sl", "Su");
            deltaTable[key] = 1;

            foreach (Token y in tokens)
            {
                // Penalise any kind of insertions
                key             = new DeltaKey("", Wordbook.TokenToString(y));
                deltaTable[key] = -10;

                // Penalise any kind of deletion
                key             = new DeltaKey(Wordbook.TokenToString(y), "");
                deltaTable[key] = -10;
            }

            return(deltaTable);
        } // SlSlSlSl