DROP TABLE IF EXISTS links;
DROP TABLE IF EXISTS classes;
DROP TABLE IF EXISTS words;
DROP TABLE IF EXISTS substrings;

;SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';

CREATE TABLE IF NOT EXISTS `links` (
	`word` int(10) unsigned NOT NULL,
	`nextword` int(10) unsigned DEFAULT 0 NOT NULL,
	`weight` int(10) unsigned DEFAULT 0 NOT NULL,
	PRIMARY KEY (`word`,`nextword`),
	INDEX `word` (`word`)
) ENGINE=MyISAM DEFAULT CHARACTER SET=latin1;

CREATE TABLE IF NOT EXISTS `classes` (
	`class` int(10) unsigned NOT NULL,
	`startword` int(10) unsigned DEFAULT NULL,
	`weight` int(10) unsigned DEFAULT 0 NOT NULL,
	`endchar` char(1) DEFAULT NULL,
	PRIMARY KEY (`class`,`startword`),
	INDEX `class` (`class`)
) ENGINE=MyISAM DEFAULT CHARACTER SET=latin1;
INSERT INTO `classes` (`class`,`startword`,`weight`,`endchar`) VALUES
	(0, NULL, 0, '.'),
	(1, NULL, 0, '!'),
	(2, NULL, 0, '?'),
	(3, NULL, 0, CHAR(1))
;

CREATE TABLE IF NOT EXISTS `words` (
	`id` int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
	`word` varchar(512) DEFAULT NULL,
	`class` int(10) unsigned NOT NULL DEFAULT 0,
	INDEX `class` (`class`)
) ENGINE=MyISAM DEFAULT CHARACTER SET=latin1;
ALTER TABLE `words` AUTO_INCREMENT = 0;
INSERT INTO `words` (`id`,`word`,`class`) VALUES
	(0, NULL, 0),
        (1, NULL, 0),
	(2, NULL, 0),
	(3, NULL, 0),
	(4, NULL, 0),
	(5, NULL, 0),
	(6, NULL, 0),
	(7, NULL, 0)
;
ALTER TABLE `words` AUTO_INCREMENT = 100;

CREATE TABLE IF NOT EXISTS `substrings` (
	`id` tinyint(2) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
	`startchars` varchar(10) NOT NULL,
	`endchars` varchar(10) NOT NULL
) ENGINE=MyISAM DEFAULT CHARACTER SET=latin1;
ALTER TABLE `substrings` AUTO_INCREMENT=1;
INSERT INTO `substrings` (`id`,`startchars`,`endchars`) VALUES
	(1, '\'', '\''),
	(2, '"', '"'),
	(3, '(', ')'),
	(4, '[', ']'),
	(5, '{', '}'),
	(6, '`', '`'),
	(7, CONCAT(CHAR(1),'ACTION '), CHAR(1))
;

