Last active
August 29, 2015 14:17
-
-
Save dimchansky/b54b05182d0c458e3caf to your computer and use it in GitHub Desktop.
Converts plain text request rules to JSON format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add reference: Newtonsoft.Json | |
using System.Globalization; | |
using System.IO; | |
using System.Linq; | |
using Newtonsoft.Json; | |
namespace Rules.Transformation.Json | |
{ | |
internal class Program | |
{ | |
private static void Main() | |
{ | |
const string fileName = @"C:\Work\rules.txt"; | |
const string jsonFileName = @"C:\Work\rules.json"; | |
File.WriteAllText(jsonFileName, JsonConvert.SerializeObject(new | |
{ | |
coefficients = ( | |
from line in File.ReadAllLines(fileName) | |
let cols = line.Split('\t') | |
where cols.Length == 3 | |
group new | |
{ | |
f = cols[1].Split('|'), | |
c = double.Parse(cols[2], CultureInfo.InvariantCulture) | |
} by cols[0] | |
into featuresGroup | |
select featuresGroup | |
).ToDictionary(a => a.Key, a => a) | |
})); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment