UNPKG

treebank-parser

Version:

A simple parser for treebanks stored in S-Expressions

44 lines (37 loc) 1.74 kB
var assert = require('assert') , fs = require('fs') , json_utils = require(__dirname+'/../lib/json-utils') ; describe('lib/json-utils', function() { var test_tree = null; beforeEach(function() { test_tree = JSON.parse(fs.readFileSync(__dirname + '/test.json', 'utf8')); }); describe('get_node', function() { it('should return the correct node from the inputted tree', function() { var test_properties = ['ROOT_0', 'S_0', 'VP_0', 'NP_0'], test_node = {'NNS_0': 'coins'}; assert.deepEqual(json_utils.get_node(test_tree, test_properties), test_node); }); }); describe('set_tree_value', function() { it('should set the value of the specified node to the inputted value', function() { var test_properties = ['ROOT_0', 'S_0', 'VP_0', 'VB_0'], test_value = 'Drop'; var test_compare_tree = JSON.parse(fs.readFileSync(__dirname + '/test.json', 'utf8')); test_compare_tree['ROOT_0']['S_0']['VP_0']['VB_0'] = test_value; json_utils.set_tree_value(test_tree, test_properties, test_value); assert.deepEqual(test_tree, test_compare_tree); }); }); describe('get_property_name_for_duplicate', function() { it('should retrieve an unused version of the property name', function() { var test_properties = ['ROOT_0', 'S_0', 'VP_0']; var test_node = json_utils.get_node(test_tree, test_properties); assert.strictEqual(json_utils.get_property_name_for_duplicate(test_node, 'VB'), 'VB_1'); }); }); describe('strip_duplicate_indicator', function() { it('should strip the duplicate indicator from a property name', function() { assert.strictEqual(json_utils.strip_duplicate_indicator('VB_0'), 'VB'); }); }); });