Ejemplo n.º 1
0
 /// <summary>
 /// Learns a new token, but doesn't actually link it to anything.
 /// </summary>
 /// <param name="s"></param>
 public Token LearnToken(string s)
 {
     if (!Lexicon.Contains(s))
     {
         var t = new Token(s);
         Lexicon.Add(t);
         return(t);
     }
     return(Lexicon[s]);
 }
Ejemplo n.º 2
0
            public void Visit(AbstractSyntaxTreeNode node)
            {
                var words = _splitter.Split(node.Value);

                foreach (var word in words)
                {
                    Content += " " + word + " ";
                    if (!Lexicon.Contains(word))
                    {
                        Lexicon.Add(word);
                    }
                }
            }
Ejemplo n.º 3
0
        private bool TryRead(out double[][] coordinates, out string label, out string comment)
        {
            coordinates = null;
            label       = null;
            comment     = null;

            buffer.Clear();

            string line;

            do // Find the next ".SEGMENT" region
            {
                try
                {
                    line = reader.ReadLine();
                }
                catch
                {
                    line = null; // TODO: This try-catch block is only necessary because of the
                    // current version of SharpZipLib being used. This block can be removed after
                    // SharpZipLib NuGet's package is finally updated.
                }

                if (line == null)
                {
                    return(false);
                }
            } while (!line.StartsWith(".SEGMENT"));

            // Get the label
            label = line.Split('?').Last().Trim().TrimStart('"').TrimEnd('"');
            if (!Lexicon.Contains(label))
            {
                return(false);
            }

            // Read .COMMENT line
            comment = reader.ReadLine().Replace(".COMMENT", "").Trim();

            // Read .PEN_DOWN
            line = reader.ReadLine();
            if (line != ".PEN_DOWN")
            {
                return(false);
            }

            do // Read until empty line
            {
                line = reader.ReadLine();

                if (line == ".PEN_UP")
                {
                    continue;
                }

                if (line == ".PEN_DOWN")
                {
                    continue;
                }

                if (line.StartsWith(".DT"))
                {
                    break;
                }

                string[] parts = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length != 2)
                {
                    return(false);
                }

                double x = double.Parse(parts[0]);
                double y = double.Parse(parts[1]);

                buffer.Add(new[] { x, y });
#if NET35
            } while (!StringEx.IsNullOrWhiteSpace(line));
#else
            } while (!String.IsNullOrWhiteSpace(line));
Ejemplo n.º 4
0
        private bool TryRead(out double[][] coordinates, out string label, out string comment)
        {
            coordinates = null;
            label       = null;
            comment     = null;

            buffer.Clear();

            string line;

            do // Find the next ".SEGMENT" region
            {
                line = reader.ReadLine();
                if (line == null)
                {
                    return(false);
                }
            } while (!line.StartsWith(".SEGMENT"));

            // Get the label
            label = line.Split('?').Last().Trim().TrimStart('"').TrimEnd('"');
            if (!Lexicon.Contains(label))
            {
                return(false);
            }

            // Read .COMMENT line
            comment = reader.ReadLine().Replace(".COMMENT", "").Trim();

            // Read .PEN_DOWN
            line = reader.ReadLine();
            if (line != ".PEN_DOWN")
            {
                return(false);
            }

            do // Read until empty line
            {
                line = reader.ReadLine();

                if (line == ".PEN_UP")
                {
                    continue;
                }

                if (line == ".PEN_DOWN")
                {
                    continue;
                }

                if (line.StartsWith(".DT"))
                {
                    break;
                }

                string[] parts = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length != 2)
                {
                    return(false);
                }

                double x = double.Parse(parts[0]);
                double y = double.Parse(parts[1]);

                buffer.Add(new[] { x, y });
#if NET35
            } while (line != null && String.IsNullOrEmpty(line.Trim()));
#else
            } while (!String.IsNullOrWhiteSpace(line));