Skip to content

Instantly share code, notes, and snippets.

@dimchansky
Last active August 29, 2015 14:17
Show Gist options
  • Save dimchansky/b54b05182d0c458e3caf to your computer and use it in GitHub Desktop.
Save dimchansky/b54b05182d0c458e3caf to your computer and use it in GitHub Desktop.
Converts plain text request rules to JSON format
// 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