public void MapInput(Input input, IntermediateInput intermediate) { ReadOnlyMemory <char> text = ReadOnlyMemoryUtils.TrimWhiteSpace(input.Text); // Handle comments, if any. If no comments are present, the value for that column // in this row will be empty. if (!ReadOnlyMemoryUtils.SplitOne(text, '#', out var left, out var right)) { right = ReadOnlyMemory <char> .Empty; } intermediate.Comment = right; var ator = ReadOnlyMemoryUtils.Split(left, _seps).GetEnumerator(); // Empty lines are filtered in the Input.MapComment step. var notEmpty = ator.MoveNext(); Contracts.Assert(notEmpty); ReadOnlyMemory <char> token = ator.Current; // Parse the label. if (_tryFloatParse(in token, out intermediate.Label)) { intermediate.Weight = 1; // Default weight is of course 1. }
#pragma warning restore 0649 public static void MapComment(Input input, CommentIndicator output) { // We expand a bit on the SVM-light comment strategy. In SVM-light, a comment line // must have the # as the first character, and a totally whitespace or empty line // is considered a parse error. However, for the purpose of detecting comments, // we detect # after trimming whitespace, and also consider totally blank lines // "comments" instead of whitespace. ReadOnlyMemory <char> text = ReadOnlyMemoryUtils.TrimWhiteSpace(input.Text); if (text.IsEmpty || text.Span[0] == '#') { output.IsComment = float.NaN; } else { output.IsComment = 0; } }