UNPKG

pcfg-generator

Version:

A module to convert JSON-formated treebank data into a Stochastic Context-Free Grammar

31 lines (27 loc) 1.23 kB
var assert = require('assert') , fs = require('fs') , pcfg = require(__dirname + '/../') ; describe('pcfg-generator', function() { describe('generate', function() { it('should generate a Stochastic Context Free Grammar from the input', function() { var test_json = JSON.parse(fs.readFileSync(__dirname + '/test.json', 'utf8')); var test_pcfg = JSON.parse(fs.readFileSync(__dirname + '/test.pcfg', 'utf8')); assert.deepEqual(pcfg.generate(test_json), test_pcfg); }); }); describe('toCNF', function() { it('should generate a valid CNF grammar from a pcfg', function() { var test_json = JSON.parse(fs.readFileSync(__dirname + '/test.json', 'utf8')); var test_cnf = fs.readFileSync(__dirname + '/test.cnf', 'utf8'); assert.strictEqual(pcfg.toCNF(pcfg.generate(test_json)), test_cnf); }); }); describe('finalize', function() { it('should output the CNF in a format suited for a parser', function() { var test_pcfg = JSON.parse(fs.readFileSync(__dirname + '/test.pcfg', 'utf8')); var test_final = JSON.parse(fs.readFileSync(__dirname + '/test.final', 'utf8')); assert.deepEqual(pcfg.finalize(test_pcfg), test_final); }); }); });