<commit_before>/*
 * basex-script
 * https://github.com/alxarch/basex-script
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

module.exports = (function () {

var _ = require('lodash'),
	_path = require('path'),
	read = require('fs').readFileSync,
	commands = JSON.parse(read(__dirname+'/commands.json')),
	Script = function Script () {
		this.queue = [];
		this.modules = [];
		this.bindings = {};
		this.db = null;
	},
	format = require('util').format,
	attr = function (v, k) {
		return format('%s=%s', k, v); 
	};

Script.prototype = {
	requires: function () {
		var that = this;
		_(arguments)
			.toArray()
			.flatten()
			.compact()
			.each(function (m) {
				that.modules.push(m);
			});
		return this;
	},
	xquery: function (xquery) {
		return this.command('xquery', xquery);
	},
	command: function (name, input, params) {

		if(_.isPlainObject(input)){
			params = input;
			input = undefined;
		}

		params = params || {};

		switch(name){
			case 'xquery':
				input = format('<![CDATA[%s]]>', input || '()');
				break;
			case 'open':
			case 'create-db':
				this.db = params.name;
				break;
			case 'check':
				this.db = params.input;
				break;
			case 'close':
				this.db = null;
				break;
			case 'drop-db':
				if (params.name === this.db) {
					this.db = null;
				}
				break;
		}

		var cmd = _.extend({}, params, {__cmd__: name, __input__: input});

		// validate.command(cmd);

		this.queue.push(cmd);

		return this;
	},
	check: function (dbname) {
		return this.command('check', {input: dbname});
	},
	createdb: function (dbname, input) {
		return this.command('create-db', input, {name: dbname});
	},
	dropdb: function (dbname) {
		return this.command('drop-db', {name: dbname});
	},<commit_msg>Adds optimize() method<commit_after>/*
 * basex-script
 * https://github.com/alxarch/basex-script
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

module.exports = (function () {

var _ = require('lodash'),
	_path = require('path'),
	read = require('fs').readFileSync,
	commands = JSON.parse(read(__dirname+'/commands.json')),
	Script = function Script () {
		this.queue = [];
		this.modules = [];
		this.bindings = {};
		this.db = null;
	},
	format = require('util').format,
	attr = function (v, k) {
		return format('%s=%s', k, v); 
	};

Script.prototype = {
	requires: function () {
		var that = this;
		_(arguments)
			.toArray()
			.flatten()
			.compact()
			.each(function (m) {
				that.modules.push(m);
			});
		return this;
	},
	xquery: function (xquery) {
		return this.command('xquery', xquery);
	},
	command: function (name, input, params) {

		if(_.isPlainObject(input)){
			params = input;
			input = undefined;
		}

		params = params || {};

		switch(name){
			case 'xquery':
				input = format('<![CDATA[%s]]>', input || '()');
				break;
			case 'open':
			case 'create-db':
				this.db = params.name;
				break;
			case 'check':
				this.db = params.input;
				break;
			case 'close':
				this.db = null;
				break;
			case 'drop-db':
				if (params.name === this.db) {
					this.db = null;
				}
				break;
		}

		var cmd = _.extend({}, params, {__cmd__: name, __input__: input});

		// validate.command(cmd);

		this.queue.push(cmd);

		return this;
	},
	check: function (dbname) {
		return this.command('check', {input: dbname});
	},
	createdb: function (dbname, input) {
		return this.command('create-db', input, {name: dbname});
	},
	optimize: function(all){
		return this.command(all ? 'optimize-all' : 'optimize');
	},
	dropdb: function (dbname) {
		return this.command('drop-db', {name: dbname});
	},
{'fraction_non_alphanumeric': 0.19130195430773467, 'fraction_numerical': 0.002202036884117809, 'mean_word_length': 3.1484018264840183, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3581571', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1296, 'n_words': 292}