/**/ public static void main(string[] strarr)
    {
        string text  = strarr[0];
        string text2 = strarr[1];

        char[]     charr       = java.lang.String.instancehelper_toCharArray(text);
        char[]     charr2      = java.lang.String.instancehelper_toCharArray(text2);
        BoyerMoore boyerMoore  = new BoyerMoore(text);
        BoyerMoore boyerMoore2 = new BoyerMoore(charr, 256);
        int        num         = boyerMoore.search(text2);
        int        num2        = boyerMoore2.search(charr2);

        StdOut.println(new StringBuilder().append("text:    ").append(text2).toString());
        StdOut.print("pattern: ");
        for (int i = 0; i < num; i++)
        {
            StdOut.print(" ");
        }
        StdOut.println(text);
        StdOut.print("pattern: ");
        for (int i = 0; i < num2; i++)
        {
            StdOut.print(" ");
        }
        StdOut.println(text);
    }
Exemple #2
0
        public void TestFind()
        {
            BoyerMoore finder = new BoyerMoore("bad");
            string     text   = "It’s too bad she won’t live. But then again, who does?";

            Assert.AreEqual(9, finder.Find(text));
        }
Exemple #3
0
        public void TestBoyerMoore()
        {
            var search = new BoyerMoore();

            //Assert.AreEqual(search.Search("this is a string", "is"), 2);
            Assert.AreEqual(search.Search("this this a ac tac string", "tac"), 15);
        }
Exemple #4
0
        private static void SearchPattern(string pat, string txt)
        {
            var pattern = pat.ToCharArray();
            var text    = txt.ToCharArray();

            var boyerMoore1 = new BoyerMoore(pat);
            var offset1     = boyerMoore1.Search(txt);

            var boyerMoore2 = new BoyerMoore(pattern, 256);
            var offset2     = boyerMoore2.Search(text);

            // print results
            Console.WriteLine("text:    " + txt);

            Console.Write("pattern: ");
            for (var i = 0; i < offset1; i++)
            {
                Console.Write(" ");
            }
            Console.WriteLine(pat);

            Console.Write("pattern: ");
            for (var i = 0; i < offset2; i++)
            {
                Console.Write(" ");
            }
            Console.WriteLine(pat);
        }
Exemple #5
0
        public Cheatbox(Process process)
        {
            _processHandle = OpenProcess((uint)Access.AllAccess, false, (uint)process.Id);

            Inspect   = new Inspector(_processHandle);
            BoyerScan = new BoyerMoore(_processHandle);
            Editor    = new Editor(_processHandle);
        }
Exemple #6
0
             public MeMorybox(Process process)
             {
                 _processHandle = OpenProcess((uint)Access.AllAccess, false, (uint)process.Id);
 
 
                 BoyerScan = new BoyerMoore(_processHandle);
 
             }
Exemple #7
0
        public void extractFiles()
        {
            FileStream fs         = File.OpenRead(@"D:\Dynasty Warrior Gundam 3 extract\2963.unknown");
            string     outputPath = @"D:\Dynasty Warrior Gundam 3 extract\Voice Lines";
            string     extension  = ".at3";

            byte[] seperationMagic = new byte[] { 0x52, 0x49, 0x46, 0x46 };

            MemoryStream fss = new MemoryStream();

            fs.Seek(0, SeekOrigin.Begin);
            fs.CopyTo(fss);
            fss.Seek(0, SeekOrigin.Begin);

            byte[]     ba            = fss.ToArray();
            List <int> boyerPointers = new BoyerMoore(seperationMagic).Search(ba).ToList();

            for (int i = 0; i < boyerPointers.Count; i++)
            {
                uint pointer     = (uint)boyerPointers[i];
                uint nextpointer = 0;

                if (i == boyerPointers.Count - 1)
                {
                    nextpointer = (uint)fs.Length;
                }
                else
                {
                    nextpointer = (uint)boyerPointers[i + 1];
                }

                byte[] fileChunk = extractChunk(fs, pointer, nextpointer - pointer);


                fss.Seek(pointer + 0x4, SeekOrigin.Begin);
                uint fileSize = readUIntSmallEndian(fss);


                int a = fileChunk[0x28];
                if (a == 1)
                {
                    fileChunk[0x28] = 0x3; // for cases where you need to change the channel to stereo
                }


                MemoryStream ms = new MemoryStream(fileChunk);

                ms.Seek(0, SeekOrigin.Begin);

                FileStream ofs = File.Create(outputPath + @"\" + i + extension);
                ms.CopyTo(ofs);
                ms.Close();

                ofs.Close();
            }

            fs.Close();
        }
        public void DoNotGoOutOfBounds()
        {
            const string text = "The quick brown fox jumps over the lazy dog maybe also a cat a sheep and another dog";
            const string word = "dog";

            var occurrences = BoyerMoore.FindAll(text, word).ToList();

            Assert.Equal(2, occurrences.Count);
        }
Exemple #9
0
        public void BoyerMooreSearch()
        {
            string input    = "That the string for scan that would be converted to binary format.";
            string fragment = "the string for scan";

            int index = BoyerMoore.IndexOf(input, fragment);

            Assert.IsTrue(index == 5, index.ToString());
        }
Exemple #10
0
        private static int GetFirstEndOfJpeg(byte[] fileBytes, out BoyerMoore bm)
        {
            var endOfJpegBytes = MovingPhotoExtraction.ToBytes("FF D9".Split(' '));

            bm = new BoyerMoore(endOfJpegBytes);
            int endOfJpeg = bm.Search(fileBytes);

            return(endOfJpeg);
        }
    public int FindCategoryBM(TwitterStatus tweet, List <StringPattern> Final)
    {
        int    kategori           = 0;
        String TField             = tweet.Text.ToLower();
        List <StringPattern> Find = new List <StringPattern>();

        foreach (var item in Final)
        {
            if (item.Next == null)
            {
                BoyerMoore bm = new BoyerMoore(item.Data.ToLower());
                if (bm.Search(TField) != -1)
                {
                    Find.Add(item);
                }
            }
            else
            {
                StringPattern P = new StringPattern();
                P = item;
                bool valid = true;
                while (P != null)
                {
                    BoyerMoore bm = new BoyerMoore(P.Data.ToLower());
                    if (bm.Search(TField) == -1)
                    {
                        valid = false;
                        break;
                    }
                    P = P.Next;
                }
                if (valid == true)
                {
                    Find.Add(item);
                }
            }
        }
        int min = 999;

        foreach (var item in Find)
        {
            BoyerMoore bm = new BoyerMoore(item.Data.ToLower());
            if (bm.Search(TField) < min)
            {
                min = bm.Search(TField);
            }
        }
        foreach (var item in Find)
        {
            BoyerMoore bm = new BoyerMoore(item.Data.ToLower());
            if (bm.Search(TField) == min)
            {
                kategori = item.Kategori;
            }
        }
        return(kategori);
    }
Exemple #12
0
        // FUNGSI UTAMA
        // Mengklasifikasikan 'tweet' berdasarkan 'keyword' ke dalam dinas yang tepat pada dinasList
        public int classify(string tweet_initial)
        {
            int    index = -1, iDinas = -1, i = 0;
            int    min   = -1;
            string str   = null;
            string tweet = corrector.Corrected(tweet_initial);

            // Search keyword in tweet using KMP
            foreach (string[] dinas in keyword)
            {
                foreach (string key in dinas)
                {
                    if (!useBm)
                    {
                        index = KnuthMorrisPratt.KMPSearch(tweet, key);
                    }
                    else
                    {
                        index = BoyerMoore.BMSearch(tweet, key);
                    }

                    if (index != -1)
                    {
                        if (min == -1)
                        {
                            min    = index;
                            str    = key;
                            iDinas = i;
                        }
                        else
                        {
                            if (index < min)
                            {
                                min    = index;
                                str    = key;
                                iDinas = i;
                            }
                        }
                    }
                }
                i++;
            }
            Console.WriteLine();
            if (min != -1)
            {
                Console.WriteLine("Found {0} in index {1}\nDisposisi \"{2}\" ke dinas {3}", str, min, tweet, this.dinasList [iDinas]);
                data.Add(iDinas);
                return(iDinas);
            }
            else
            {
                Console.WriteLine("Couldn't find any keyword in tweet\nDisposisi \"{0}\" ke dinas {1}", tweet, this.dinasList [dinasList.Count - 1]);
                data.Add(dinasList.Count - 1);
                return(dinasList.Count - 1);
            }
        }
Exemple #13
0
        public void Find_SearchNonexistentSubstring_EmptyListReturned()
        {
            string text    = "abcde";
            string pattern = "ghf";

            var expected = new List <int>();
            var actual   = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
        public void ShouldAbortOnFirstOccurence()
        {
            const string text    = "That is my text with the word text 3 times. That is why text again";
            const string pattern = "Text";

            var occurrences = BoyerMoore.FindAll(text, pattern, true, true).ToList();

            Assert.Single(occurrences);
            Assert.Equal(11, occurrences[0]);
        }
Exemple #15
0
        public void Find_DifferentCases_EmptyListReturned()
        {
            string text    = "abd Hello world adt";
            string pattern = "hello world";

            var expected = new List <int>();
            var actual   = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
Exemple #16
0
        private static int GetEndOfJpeg(byte[] fileBytes, int indexOfMp4, out BoyerMoore bm)
        {
            var endOfJpegBytes = MovingPhotoExtraction.ToBytes("FF D9".Split(' '));

            bm = new BoyerMoore(endOfJpegBytes);
            var subBytes      = fileBytes.Take(indexOfMp4).ToArray();
            var endOfJpegList = bm.SearchAll(subBytes);

            return(endOfJpegList.LastOrDefault());
        }
Exemple #17
0
        public Cheatbox(string processName)
        {
            Process[] processList = Process.GetProcessesByName(processName);
            Process   p           = processList.OrderByDescending(process => process.PrivateMemorySize64).First();

            _processHandle = OpenProcess((uint)Access.AllAccess, false, (uint)p.Id);

            Inspect   = new Inspector(_processHandle);
            BoyerScan = new BoyerMoore(_processHandle);
            Editor    = new Editor(_processHandle);
        }
Exemple #18
0
        /// <summary>
        /// Finds the list of string that matches any of the patterns with the indices of each occurrence in sequence.
        /// </summary>
        /// <param name="patterns">List of patterns that needs to be searched in Sequence.</param>
        /// <param name="startIndex">Minimum index in Sequence at which match has to start.</param>
        /// <param name="ignoreCase">
        /// if true ignore character casing while match.
        /// <remarks>
        /// Note that symbols in Sequence are always Upper case.
        /// </remarks>
        /// </param>
        /// <returns></returns>
        public IDictionary <string, IList <int> > FindMatches(IList <string> patterns, int startIndex = 0, bool ignoreCase = true)
        {
            if (PatternFinder == null)
            {
                PatternFinder = new BoyerMoore();
            }

            return(PatternFinder.FindMatch(
                       this,
                       PatternConverter.GetInstanace(this.Alphabet).Convert(patterns).Values.SelectMany(pattern => pattern).ToList()));
        }
Exemple #19
0
        public void SimpleFindOneOutputPatternTest()
        {
            ISequence      sequence      = new Sequence(DnaAlphabet.Instance, "AGCT");
            IPatternFinder patternFinder = new BoyerMoore();
            IList <int>    actual        = patternFinder.FindMatch(sequence, "AGCT");

            HashSet <int> expected = new HashSet <int>();

            expected.Add(0);

            Assert.IsTrue(Compare(expected, actual));
        }
Exemple #20
0
        public void MatchWildcardPatternMiddle()
        {
            ISequence      sequence      = new Sequence(DnaAlphabet.Instance, "AGCTAGGTAGCTCAAAAAABCD");
            IPatternFinder patternFinder = new BoyerMoore();
            IList <int>    actual        = patternFinder.FindMatch(sequence, "AGCTAGGTAGCTCA*BCD");

            HashSet <int> expected = new HashSet <int>();

            expected.Add(0);

            Assert.IsTrue(Compare(expected, actual));
        }
        public void ShouldFindAllOccurrences()
        {
            const string text    = "That is my text with the word text 3 times. That is why text again";
            const string pattern = "Text";

            var occurrences = BoyerMoore.FindAll(text, pattern, true).ToList();

            Assert.Equal(3, occurrences.Count);
            Assert.Equal(11, occurrences[0]);
            Assert.Equal(30, occurrences[1]);
            Assert.Equal(56, occurrences[2]);
        }
Exemple #22
0
        internal override void OnFiles(List <string> aFiles, POINT aPos)
        {
            var goodFiles = aFiles.Where(x => {
                var ext = Path.GetExtension(x).ToLower();
                return(ext == ".png");
            });

            if (goodFiles.Count() == 0)
            {
                Logger.LogMessage("No files to handle");
                return;
            }

            if (CardHandlerMethods.GetActiveCardHandler(out var cardHandler))
            {
                foreach (var file in goodFiles)
                {
                    var bytes = File.ReadAllBytes(file);

                    if (BoyerMoore.ContainsSequence(bytes, CharaToken, out var index))
                    {
                        var sex = new BoyerMoore(SexToken).Search(bytes, index)
                                  .Select(i => bytes[i + SexToken.Length])
                                  .First(b => b == 0 || b == 1);
                        cardHandler.Character_Load(file, aPos, sex);
                    }
                    else if (BoyerMoore.ContainsSequence(bytes, KoiCharaToken, out index))
                    {
                        var sex = new BoyerMoore(SexToken).Search(bytes, index)
                                  .Select(i => bytes[i + SexToken.Length])
                                  .First(b => b == 0 || b == 1);
                        cardHandler.CharacterConvert_Load(file, aPos, sex);
                    }
                    else if (BoyerMoore.ContainsSequence(bytes, CoordinateToken))
                    {
                        cardHandler.Coordinate_Load(file, aPos);
                    }
                    else if (BoyerMoore.ContainsSequence(bytes, KoiCoordinateToken))
                    {
                        cardHandler.CoordinateConvert_Load(file, aPos);
                    }
                    else
                    {
                        Logger.LogMessage("This file does not contain any EmotionCreators related data");
                    }
                }
            }
            else
            {
                Logger.LogMessage("No handler found for this scene");
            }
        }
Exemple #23
0
        public void Find_MultiplePatternOccurrences_3PositionsReturned()
        {
            string text    = "hi adb hi 48 hiabc";
            string pattern = "hi";

            var expected = new List <int>()
            {
                0, 7, 13
            };
            var actual = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
Exemple #24
0
        public void Find_OnlyIdenticalCharactersInText_4PositionsReturned()
        {
            string text    = "aaaa";
            string pattern = "a";

            var expected = new List <int>()
            {
                0, 1, 2, 3
            };
            var actual = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
Exemple #25
0
        public void Find_PatternWithWhiteSpaces_1PositionsReturned()
        {
            string text    = "sd bd de hello world 53 5 sdf";
            string pattern = "hello world";

            var expected = new List <int>()
            {
                9
            };
            var actual = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
Exemple #26
0
        public void Find_OrdinaryPatternAndText_1PositionsReturned()
        {
            string text    = "GCATCGCAGAGAGTATACAGTACG";
            string pattern = "GCAGAGAG";

            var expected = new List <int>()
            {
                5
            };
            var actual = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
        public void TestSearch()
        {
            // Arrange
            var toSearch = "We hold these truths to be self-evident";
            var toFind   = "truth";

            // Act
            var results = new BoyerMoore().Search(toFind, toSearch).ToList();

            // Assert
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(toSearch.IndexOf(toFind, StringComparison.Ordinal), results[0].Start);
        }
Exemple #28
0
        public void ValidateFindMatchList()
        {
            string nodeStr = _utilityObj._xmlUtil.GetTextValue(
                Constants.SimplePatternNode, Constants.SeqFileMatchNode);
            string sequence = _utilityObj._xmlUtil.GetTextValue(
                Constants.SimplePatternNode, Constants.Sequence1);
            string count = _utilityObj._xmlUtil.GetTextValue(
                Constants.SimplePatternNode,
                Constants.FileMatchesExpectedCountNode);
            string value = _utilityObj._xmlUtil.GetTextValue(
                Constants.SimplePatternNode,
                Constants.FileMatchesExpectedValueNode);

            string[] counts   = count.Split(',');
            string[] values   = value.Split(',');
            string[] patterns = nodeStr.Split(',');

            Sequence    seq    = new Sequence(Alphabets.DNA, sequence);
            IList <int> result = null;

            IList <string> lstStr = new List <string>();

            foreach (string pattern in patterns)
            {
                lstStr.Add(pattern);
            }

            int i = 0;

            foreach (string pattern in patterns)
            {
                result = new BoyerMoore().FindMatch(seq, pattern);
                if (result.Count != 0)
                {
                    Assert.AreEqual(counts[i].ToString(),
                                    result.Count.ToString((IFormatProvider)null));
                    string[] strValues = values[i].Split(':');
                    for (int j = 0; j < result.Count; j++)
                    {
                        Assert.AreEqual(strValues[j],
                                        result[j].ToString((IFormatProvider)null));
                    }
                    ++i;
                }
            }

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Sequence BVT : Successfully validated the expected result"));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "Sequence BVT : Successfully validated the expected result"));
        }
        public void TestSearchIpsum()
        {
            // Arrange
            var toSearch =
                "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
            var toFind = "of";

            // Act
            var results = new BoyerMoore().Search(toFind, toSearch).ToList();

            // Assert
            Assert.AreEqual(5, results.Count);
            Assert.AreEqual(toSearch.IndexOf(toFind, StringComparison.Ordinal), results[0].Start);
        }
Exemple #30
0
        public void BoyerMooreAlignDnaSequenceWith1000BP()
        {
            var    boyerMoore         = new BoyerMoore();
            string boyerMooreSequence =
                utilityObj.xmlUtil.GetTextValue(Constants.BoyerMooreSequence, Constants.SequenceNode);
            string referenceSequence =
                utilityObj.xmlUtil.GetTextValue(Constants.BoyerMooreSequence, Constants.SearchSequenceNode);
            string expectedMatch =
                utilityObj.xmlUtil.GetTextValue(Constants.BoyerMooreSequence, Constants.ExpectedMatch);
            ISequence boyerMooreSeq = new Sequence(Alphabets.DNA, boyerMooreSequence);

            IList <int> indexList = boyerMoore.FindMatch(boyerMooreSeq,
                                                         referenceSequence);

            Assert.AreEqual(expectedMatch, indexList[0].ToString((IFormatProvider)null));
        }
        public static void Main()
        {
            var trie = new BoyerMoore("lorem");
            string text = File.ReadAllText("../../largeTextFile.txt");
            int count = 0;
            int nextIndex = 0;
            while (true)
            {
                nextIndex = trie.Search(text, nextIndex + 1);
                if (nextIndex == -1)
                {
                    break;
                }

                count += 1;
            }

            Console.WriteLine(count);
        }