Example #1
0
        private static List <string> GetWords(Graph.Graph graph, Trie.Trie trie)
        {
            ISet <string> results = new HashSet <string>();

            for (int i = 0; i < graph.Vertices.Count; i++)
            {
                string content = graph.Vertices[i].Content;
                bool[] visited = new bool[graph.Vertices.Count];
                visited[i] = true;
                DepthFirstSearch(graph, i, trie, content, visited, results);
            }

            return(results.ToList());
        }
Example #2
0
 private static void DepthFirstSearch(Graph.Graph graph, int vertexIndex, Trie.Trie trie, string content, bool[] visited, ISet <string> results)
 {
     if (trie.Contains(content) && content.Length >= 3)
     {
         results.Add(content);
     }
     foreach (int edgeIndex in graph.Vertices[vertexIndex].Edges)
     {
         if (!visited[edgeIndex])
         {
             string        newContent = content + graph.Vertices[edgeIndex].Content;
             Trie.TrieNode node       = trie.GetNode(newContent);
             if (node != null)
             {
                 visited[edgeIndex] = true;
                 DepthFirstSearch(graph, edgeIndex, trie, newContent, visited, results);
                 visited[edgeIndex] = false;
             }
         }
     }
 }
Example #3
0
        public MainWindow()
        {
            InitializeComponent();

            _wordList = new WordList.WordList();
            //wordList.ReadLexique3(@"D:\Projects\Personal\Lexique\WordList\Lexique3.txt");
            //wordList.ReadWordList(@"D:\Projects\Personal\Lexique\WordList\liste.de.mots.francais.frgut.txt");
            //wordList.ReadWordList(@"D:\Projects\Personal\Lexique\WordList\liste_francais.txt");
            //wordList.ReadWordList(@"D:\Projects\Personal\Lexique\WordList\ods4.txt");
            _wordList.ReadWordList(@"D:\GitHub\Lexique\WordList\ODS5.txt");
            //wordList.ReadWordList(@"D:\Projects\Personal\Lexique\WordList\pli07.txt");
            //wordList.ReadCSV(@"D:\Projects\Personal\Lexique\WordList\DicFra.csv");
            //wordList.ReadTxt(@"D:\Projects\Personal\Lexique\WordList\dict.xmatiere.com.16.csvtxt");
            //wordList.ReadWordList(@"D:\Projects\Personal\Lexique\WordList\liste16.txt");
            _wordList.Distinct();

            _trie = new Trie.Trie();
            foreach (string word in _wordList.Words)
            {
                _trie.Add(word);
            }

            //
            string[,] table = new string[4, 4];
            table[0, 0]     = "G";
            table[0, 1]     = "I";
            table[0, 2]     = "R";
            table[0, 3]     = "I";
            table[1, 0]     = "I";
            table[1, 1]     = "A";
            table[1, 2]     = "A";
            table[1, 3]     = "S";
            table[2, 0]     = "R";
            table[2, 1]     = "N";
            table[2, 2]     = "E";
            table[2, 3]     = "T";
            table[3, 0]     = "N";
            table[3, 1]     = "O";
            table[3, 2]     = "O";
            table[3, 3]     = "S";

            for (int column = 0; column < gridInput.ColumnDefinitions.Count; column++)
            {
                for (int row = 0; row < gridInput.RowDefinitions.Count; row++)
                {
                    TextBox input = gridInput.Children.OfType <TextBox>().First(x => Grid.GetRow(x) == row && Grid.GetColumn(x) == column);
                    if (input != null)
                    {
                        input.Text = table[row, column];
                    }
                }
            }

            //for (int y = 0; y < 4; y++)
            //    for (int x = 0; x < 4; x++)
            //    {
            //        Label lbl = new Label
            //        {
            //            Content = table[x, y],
            //            Width = 40,
            //            Height = 40,
            //            HorizontalContentAlignment = HorizontalAlignment.Center,
            //            VerticalContentAlignment = VerticalAlignment.Center,
            //            Background = new SolidColorBrush(Colors.CadetBlue),
            //            Tag = null
            //        };
            //        Canvas.SetLeft(lbl, x * (40 + 10) + 100);
            //        Canvas.SetTop(lbl, y * (40 + 10) + 100);
            //        Panel.SetZIndex(lbl, 10);
            //        canvasPaint.Children.Add(lbl);
            //    }

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    Label lbl = new Label
                    {
                        Content = table[x, y],
                        Width   = 40,
                        Height  = 40,
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment   = VerticalAlignment.Center,
                        Background = new SolidColorBrush(Colors.CadetBlue),
                        Tag        = null
                    };
                    Canvas.SetLeft(lbl, x * 40 + 100);
                    Canvas.SetTop(lbl, y * 40 + 100);
                    Panel.SetZIndex(lbl, 10);
                    canvasPaint.Children.Add(lbl);
                }
            }

            //for (int y = 0; y < 4; y++)
            //    for (int x = 0; x < 4; x++)
            //    {
            //        Label lbl = new Label
            //            {
            //                Content = table[x, y],
            //                Width = 40,
            //                Height = 40,
            //                HorizontalContentAlignment = HorizontalAlignment.Center,
            //                VerticalContentAlignment = VerticalAlignment.Center,
            //                Background = new SolidColorBrush(Colors.CadetBlue),
            //                Tag = null
            //            };
            //        Canvas.SetLeft(lbl, x * 40 + 100);
            //        Canvas.SetTop(lbl, y * 40 + 100);
            //        Panel.SetZIndex(lbl, 0);
            //        canvasPaint.Children.Add(lbl);

            //        Ellipse ellipse = new Ellipse
            //        {
            //            Width = 40,
            //            Height = 40,
            //            Tag = lbl,
            //            Fill = new SolidColorBrush(Color.FromArgb(128, 255, 0, 0))
            //        };
            //        Canvas.SetLeft(ellipse, x * 40 + 100);
            //        Canvas.SetTop(ellipse, y * 40 + 100);
            //        Panel.SetZIndex(ellipse, 10);
            //        canvasPaint.Children.Add(ellipse);
            //    }
        }