public void Validate(string[] lines, List <VowpalWabbitExample> examples, IVowpalWabbitLabelComparator labelComparator = null) { VowpalWabbitExample[] strExamples = new VowpalWabbitExample[lines.Count()]; try { for (int i = 0; i < lines.Length; i++) { strExamples[i] = this.vw.ParseLine(lines[i]); } for (int i = 0; i < strExamples.Length; i++) { var diff = strExamples[i].Diff(this.vw, examples[i], labelComparator); Assert.IsNull(diff, diff + " generated string: '" + strExamples[i].VowpalWabbitString + "'"); } } finally { foreach (var ex in strExamples) { if (ex != null) { ex.Dispose(); } } } }
public void Validate(IEnumerable <string> lines, TExample example, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null) { // natively parsed string example compared against: // (1) natively build example // (2) string serialized & natively parsed string example var strExamples = lines.Select(l => this.vw.Native.ParseLine(l)).ToArray(); using (var nativeExampleWithString = (VowpalWabbitMultiLineExampleCollection)this.factorySerializer.Serialize(example, label)) { var examplesToCompare = new List <VowpalWabbitExample>(); if (nativeExampleWithString.SharedExample != null) { examplesToCompare.Add(nativeExampleWithString.SharedExample); } examplesToCompare.AddRange(nativeExampleWithString.Examples); examplesToCompare = examplesToCompare.Where(e => !e.IsNewLine).ToList(); Assert.AreEqual(strExamples.Length, examplesToCompare.Count); for (int i = 0; i < strExamples.Length; i++) { var diff = strExamples[i].Diff(this.vw.Native, examplesToCompare[i], labelComparator); Assert.IsNull(diff, diff + " generated string: '" + examplesToCompare[i].VowpalWabbitString + "'"); } } foreach (var ex in strExamples) { ex.Dispose(); } }
public void Validate(string line, string json, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null) { using (var jsonSerializer = new VowpalWabbitJsonSerializer(this.vw)) using (var jsonExample = jsonSerializer.ParseAndCreate(json, label)) { this.Validate(line, jsonExample, labelComparator, label); } }
public void Validate(string line, string json, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null) { using (var jsonSerializer = new VowpalWabbitJsonSerializer(this.vw)) using (var jsonExample = jsonSerializer.ParseAndCreate(json, label)) { this.Validate(line, jsonExample, labelComparator, label); } }
public void Validate(string[] lines, JsonReader jsonReader, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null, int?index = null, VowpalWabbitJsonExtension extension = null) { VowpalWabbitExample[] strExamples = new VowpalWabbitExample[lines.Count()]; try { for (int i = 0; i < lines.Length; i++) { strExamples[i] = this.vw.ParseLine(lines[i]); } using (var jsonSerializer = new VowpalWabbitJsonSerializer(this.vw)) { if (extension != null) { jsonSerializer.RegisterExtension(extension); // extension are not supported with native JSON parsing } using (var jsonExample = (VowpalWabbitMultiLineExampleCollection)jsonSerializer.ParseAndCreate(jsonReader, label, index)) { var jsonExamples = new List <VowpalWabbitExample>(); if (jsonExample.SharedExample != null) { jsonExamples.Add(jsonExample.SharedExample); } jsonExamples.AddRange(jsonExample.Examples); Assert.AreEqual(strExamples.Length, jsonExamples.Count); for (int i = 0; i < strExamples.Length; i++) { using (var strJsonExample = this.vw.ParseLine(jsonExamples[i].VowpalWabbitString)) { var diff = strExamples[i].Diff(this.vw, jsonExamples[i], labelComparator); Assert.IsNull(diff, diff + " generated string: '" + jsonExamples[i].VowpalWabbitString + "'"); diff = strExamples[i].Diff(this.vw, strJsonExample, labelComparator); Assert.IsNull(diff, diff); } } } } } finally { foreach (var ex in strExamples) { if (ex != null) { ex.Dispose(); } } } }
internal static void Validate(string line, VowpalWabbitExample ex, IVowpalWabbitLabelComparator comparator, string args = null) { using (var vw = new VowpalWabbit(args)) using (var strExample = vw.ParseLine(line)) { var diff = strExample.Diff(vw, ex, comparator); Assert.IsNull(diff, diff + " generated string: '" + ex.VowpalWabbitString + "'"); } }
internal static void Validate(string line, VowpalWabbitExample ex, IVowpalWabbitLabelComparator comparator, string args = null) { using (var vw = new VowpalWabbit(args)) using (var strExample = vw.ParseLine(line)) { var diff = strExample.Diff(vw, ex, comparator); Assert.IsNull(diff, diff + " generated string: '" + ex.VowpalWabbitString + "'"); } }
public void Validate(string line, string json, IVowpalWabbitLabelComparator labelComparator = null) { using (var strExample = this.vw.ParseLine(line)) using (var jsonExample = this.jsonSerializer.Parse(json)) using (var strJsonExample = this.vw.ParseLine(jsonExample.VowpalWabbitString)) { var diff = strExample.Diff(this.vw, jsonExample, labelComparator); Assert.IsNull(diff, diff + " generated string: '" + jsonExample.VowpalWabbitString + "'"); diff = strExample.Diff(this.vw, strJsonExample, labelComparator); Assert.IsNull(diff, diff); } }
public void Validate(string line, string json, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null) { using (var strExample = this.vw.ParseLine(line)) using (var jsonSerializer = new VowpalWabbitJsonSerializer(this.vw)) using (var jsonExample = (VowpalWabbitSingleLineExampleCollection)jsonSerializer.ParseAndCreate(json, label)) using (var strJsonExample = this.vw.ParseLine(jsonExample.Example.VowpalWabbitString)) { var diff = strExample.Diff(this.vw, jsonExample.Example, labelComparator); Assert.IsNull(diff, diff + " generated string: '" + jsonExample.Example.VowpalWabbitString + "'"); diff = strExample.Diff(this.vw, strJsonExample, labelComparator); Assert.IsNull(diff, diff); } }
public void Validate(string line, string json, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null) { using (var strExample = this.vw.ParseLine(line)) using (var jsonSerializer = new VowpalWabbitJsonSerializer(this.vw)) using (var jsonExample = (VowpalWabbitSingleLineExampleCollection)jsonSerializer.ParseAndCreate(json, label)) using (var strJsonExample = this.vw.ParseLine(jsonExample.Example.VowpalWabbitString)) { var diff = strExample.Diff(this.vw, jsonExample.Example, labelComparator); Assert.IsNull(diff, diff + " generated string: '" + jsonExample.VowpalWabbitString + "'"); diff = strExample.Diff(this.vw, strJsonExample, labelComparator); Assert.IsNull(diff, diff); } }
public void Validate(string[] lines, string json, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null, int? index = null, VowpalWabbitJsonExtension extension = null) { VowpalWabbitExample[] strExamples = new VowpalWabbitExample[lines.Count()]; try { for (int i = 0; i < lines.Length; i++) strExamples[i] = this.vw.ParseLine(lines[i]); using (var jsonSerializer = new VowpalWabbitJsonSerializer(this.vw)) { if (extension != null) jsonSerializer.RegisterExtension(extension); using (var jsonExample = (VowpalWabbitMultiLineExampleCollection)jsonSerializer.ParseAndCreate(json, label, index)) { var jsonExamples = new List<VowpalWabbitExample>(); if (jsonExample.SharedExample != null) jsonExamples.Add(jsonExample.SharedExample); jsonExamples.AddRange(jsonExample.Examples); Assert.AreEqual(strExamples.Length, jsonExamples.Count); for (int i = 0; i < strExamples.Length; i++) { using (var strJsonExample = this.vw.ParseLine(jsonExamples[i].VowpalWabbitString)) { var diff = strExamples[i].Diff(this.vw, jsonExamples[i], labelComparator); Assert.IsNull(diff, diff + " generated string: '" + jsonExamples[i].VowpalWabbitString + "'"); diff = strExamples[i].Diff(this.vw, strJsonExample, labelComparator); Assert.IsNull(diff, diff); } } } } } finally { foreach (var ex in strExamples) if (ex != null) ex.Dispose(); } }
public void Validate(string line, VowpalWabbitExampleCollection example, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null) { Assert.IsNotNull(example); var jsonExample = example as VowpalWabbitSingleLineExampleCollection; Assert.IsNotNull(jsonExample); using (var strExample = this.vw.ParseLine(line)) using (var strJsonExample = this.vw.ParseLine(jsonExample.Example.VowpalWabbitString)) { var diff = strExample.Diff(this.vw, jsonExample.Example, labelComparator); Assert.IsNull(diff, diff + " generated string: '" + jsonExample.VowpalWabbitString + "'"); diff = strExample.Diff(this.vw, strJsonExample, labelComparator); Assert.IsNull(diff, diff); } }
public void Validate(string line, VowpalWabbitExampleCollection example, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null) { Assert.IsNotNull(example); var jsonExample = example as VowpalWabbitSingleLineExampleCollection; Assert.IsNotNull(jsonExample); using (var strExample = this.vw.ParseLine(line)) using (var strJsonExample = this.vw.ParseLine(jsonExample.Example.VowpalWabbitString)) { var diff = strExample.Diff(this.vw, jsonExample.Example, labelComparator); Assert.IsNull(diff, diff + " generated string: '" + jsonExample.VowpalWabbitString + "'"); diff = strExample.Diff(this.vw, strJsonExample, labelComparator); Assert.IsNull(diff, diff); } }
public void Validate(string line, string json, IVowpalWabbitLabelComparator labelComparator = null, ILabel label = null, bool enableNativeJsonValidation = true) { using (var jsonSerializer = new VowpalWabbitJsonSerializer(this.vw)) using (var jsonExample = jsonSerializer.ParseAndCreate(json, label)) { this.Validate(line, jsonExample, labelComparator, label); if (enableNativeJsonValidation) { var examples = this.vw.ParseJson(json); Assert.AreEqual(1, examples.Count); using (var jsonNativeExample = new VowpalWabbitSingleLineExampleCollection(this.vw, examples[0])) { this.Validate(line, jsonNativeExample, labelComparator, label, validateVowpalWabbitString: false); } } } }