Example #1
0
 /// <summary>
 /// Reads the regular expressions and weights that form the handler.
 /// </summary>
 /// <param name="reader">Data source being processed.</param>
 /// <param name="handler">Handler being created.</param>
 private static void ReadRegexSegmentHandler(BinaryReader reader, RegexSegmentHandler handler)
 {
     int count = reader.ReadInt16();
     for (int i = 0; i < count; i++)
     {
         handler.Segments.Add(new RegexSegmentHandler.RegexSegment(
             reader.ReadString(), reader.ReadInt32()));
     }
 }
Example #2
0
 /// <summary>
 /// Adds the segments to the regular expression handler.
 /// </summary>
 /// <param name="handler">Regular expression handler.</param>
 /// <param name="reader">The XML stream reader.</param>
 private static void ProcessRegexSegments(RegexSegmentHandler handler, XmlReader reader)
 {
     while (reader.Read())
     {
         if (reader.Depth > 0)
         {
             string pattern = reader.GetAttribute("pattern");
             int weight = 0;
             if (String.IsNullOrEmpty(pattern) == false &&
                 int.TryParse(reader.GetAttribute("weight"), out weight))
                 handler.AddSegment(pattern, weight);
         }
     }
 }
Example #3
0
        /// <summary>
        /// Creates the handler for the current provider.
        /// </summary>
        /// <param name="reader">Data source being processed.</param>
        /// <param name="provider">Provider the new handler should be assigned to.</param>
        /// <returns>An instance of the new handler.</returns>
        private static Handler CreateHandler(BinaryReader reader, Provider provider)
        {
            HandlerTypes type = (HandlerTypes)reader.ReadByte();
            byte confidence = reader.ReadByte();
            string name = reader.ReadString();
            bool checkUAProfs = reader.ReadBoolean();
            string defaultDeviceId = String.Empty;

            switch (type)
            {
                case HandlerTypes.EditDistance:
                    return new Handlers.EditDistanceHandler(
                        provider, name, defaultDeviceId, confidence, checkUAProfs);
                case HandlerTypes.ReducedInitialString:
                    return new Handlers.ReducedInitialStringHandler(
                        provider, name, defaultDeviceId, confidence, checkUAProfs, reader.ReadString());
                case HandlerTypes.RegexSegment:
                    var handler = new Handlers.RegexSegmentHandler(
                        provider, name, defaultDeviceId, confidence, checkUAProfs);
                    ReadRegexSegmentHandler(reader, handler);
                    return handler;
            }

            throw new BinaryException(String.Format("Type '{0}' is not a recognised handler.", type));
        }