<?php
/**
* gonx_grammar class :
*
* @package GONX
* @author Ben Yacoub Hatem <hide@address.com>
* @copyright Copyright (c) 2004
* @version $Id: grammar.class.php,v 1.4 2004/11/08 05:45:58 hatemben Exp $ - 2004-10-25 11:34:41 - grammar.class.php
* @generator dtd2php version 1.0.1
* @access public
**/
class gonx_grammar{
/**
* Constructor
* @access protected
*/
function gonx_grammar(){
$this->_document = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}
var $_document;
/*
* Open grammar tag.
*
* @param tag_format
* @param xml_base
* @param version this variable is required
* @param xml_lang
* @param xmlns_xsi
* @param xsi_schemaLocation
* @param root
* @param mode
*/
function start_grammar($tag_format = "", $xml_base = "", $version = "", $xml_lang = "", $xmlns_xsi = "", $xsi_schemaLocation = "", $root = "", $mode = "")
{
$resu = ("<grammar");
if ((isset($tag_format)) and ($tag_format!=="")){
$resu .= ' tag-format="'.$tag_format.'"';
}
if ((isset($xml_base)) and ($xml_base!=="")){
$resu .= ' xml:base="'.$xml_base.'"';
}
if ((isset($version)) and ($version!=="")){
$resu .= ' version="'.$version.'"';
} else {
$resu .= ' <!-- Error occured in grammar. Need to pass "version"=... -->';
}
if ((isset($xml_lang)) and ($xml_lang!=="")){
$resu .= ' xml:lang="'.$xml_lang.'"';
}
$resu .= ' xmlns = \'http://www.w3.org/2001/06/grammar\' ';
if ((isset($xmlns_xsi)) and ($xmlns_xsi!=="")){
$resu .= ' xmlns:xsi="'.$xmlns_xsi.'"';
}
if ((isset($xsi_schemaLocation)) and ($xsi_schemaLocation!=="")){
$resu .= ' xsi:schemaLocation="'.$xsi_schemaLocation.'"';
}
if ((isset($root)) and ($root!=="")){
$resu .= ' root="'.$root.'"';
}
if ((isset($mode)) and ($mode!=="")){
$resu .= ' mode="'.$mode.'"';
}
$resu .= (">\n ");
$this->_document .= $resu;
}
/*
* Close grammar tag.
*
*/
function end_grammar()
{
$this->_document .= "</grammar>\n";
}
/*
* Open ruleref tag.
*
* @param uri
* @param type
* @param special
*/
function start_ruleref($uri = "", $type = "", $special = "")
{
$resu = '<ruleref';
if ((isset($uri)) and ($uri!=="")){
$resu .= ' uri="'.$uri.'"';
}
if ((isset($type)) and ($type!=="")){
$resu .= ' type="'.$type.'"';
}
if ((isset($special)) and ($special!=="")){
$resu .= ' special="'.$special.'"';
}
$resu .= ">\n ";
$this->_document .= $resu;
}
/*
* Close ruleref tag.
*
*/
function end_ruleref()
{
$this->_document .= "</ruleref>\n";
}
/*
* Open token tag.
*
* @param xml_lang
*/
function start_token($xml_lang = "")
{
$resu = ("<token");
if ((isset($xml_lang)) and ($xml_lang!=="")){
$resu .= ' xml:lang="'.$xml_lang.'"';
}
$resu .= (">\n ");
$this->_document .= $resu;
}
/*
* Close token tag.
*
*/
function end_token()
{
$this->_document .= "</token>\n";
}
/*
* Open tag tag.
*/
function start_tag()
{
$this->_document .= "<tag>\n";
}
/*
* Close tag tag.
*
*/
function end_tag()
{
$this->_document .= "</tag>\n";
}
/*
* Open one_of tag.
*
* @param xml_lang
*/
function start_one_of($xml_lang = "")
{
$resu = ("<one-of");
if ((isset($xml_lang)) and ($xml_lang!=="")){
$resu .= ' xml:lang="'.$xml_lang.'"';
}
$resu .= (">\n ");
$this->_document .= $resu;
}
/*
* Close one_of tag.
*
*/
function end_one_of()
{
$this->_document .= "</one-of>\n";
}
/*
* Open item tag.
*
* @param repeat
* @param repeat_prob
* @param weight
* @param xml_lang
* @param tag NOTE : this is an optional tag added 8/11/2004, to be checked on the W3C recommandation
*/
function start_item($repeat = "", $repeat_prob = "", $weight = "", $xml_lang = "", $tag = "")
{
$resu = ("<item");
if ((isset($repeat)) and ($repeat!=="")){
$resu .= ' repeat="'.$repeat.'"';
}
if ((isset($repeat_prob)) and ($repeat_prob!=="")){
$resu .= ' repeat-prob="'.$repeat_prob.'"';
}
if ((isset($weight)) and ($weight!=="")){
$resu .= ' weight="'.$weight.'"';
}
if ((isset($xml_lang)) and ($xml_lang!=="")){
$resu .= ' xml:lang="'.$xml_lang.'"';
}
if ((isset($tag)) and ($tag!=="")){
$resu .= ' tag="'.$tag.'"';
}
$resu .= (">\n ");
$this->_document .= $resu;
}
/*
* Close item tag.
*
*/
function end_item()
{
$this->_document .= "</item>\n";
}
/*
* Open rule tag.
*
* @param id this variable is required
* @param scope
*/
function start_rule($id = "", $scope = "")
{
$resu = ("<rule");
if ((isset($id)) and ($id!=="")){
$resu .= ' id="'.$id.'"';
} else {
$resu .= ' <!-- Error occured in rule. Need to pass "id"=... -->';
}
if ((isset($scope)) and ($scope!=="")){
$resu .= ' scope="'.$scope.'"';
}
$resu .= (">\n ");
$this->_document .= $resu;
}
/*
* Close rule tag.
*
*/
function end_rule()
{
$this->_document .= "</rule>\n";
}
/*
* Open example tag.
*/
function start_example()
{
$this->_document .= "<example>\n";
}
/*
* Close example tag.
*
*/
function end_example()
{
$this->_document .= "</example>\n";
}
/*
* Open lexicon tag.
*
* @param uri this variable is required
* @param type
*/
function start_lexicon($uri = "", $type = "")
{
$resu = '<lexicon';
if ((isset($uri)) and ($uri!=="")){
$resu .= ' uri="'.$uri.'"';
} else {
$resu .= ' <!-- Error occured in lexicon. Need to pass "uri"=... -->';
}
if ((isset($type)) and ($type!=="")){
$resu .= ' type="'.$type.'"';
}
$resu .= ">\n ";
$this->_document .= $resu;
}
/*
* Close lexicon tag.
*
*/
function end_lexicon()
{
$this->_document .= "</lexicon>\n";
}
/*
* Open meta tag.
*
* @param name
* @param content this variable is required
* @param http_equiv
*/
function start_meta($name = "", $content = "", $http_equiv = "")
{
$resu = '<meta';
if ((isset($name)) and ($name!=="")){
$resu .= ' name="'.$name.'"';
}
if ((isset($content)) and ($content!=="")){
$resu .= ' content="'.$content.'"';
} else {
$resu .= ' <!-- Error occured in meta. Need to pass "content"=... -->';
}
if ((isset($http_equiv)) and ($http_equiv!=="")){
$resu .= ' http-equiv="'.$http_equiv.'"';
}
$resu .= ">\n ";
$this->_document .= $resu;
}
/*
* Close meta tag.
*
*/
function end_meta()
{
$this->_document .= "</meta>\n";
}
/*
*
* Load a grammar Module to extends class funtionnalities.
*
*/
function load($module,$params = "")
{
if (ereg('::',$module)) {
$d = explode('::',$module);
$module = $d[0];
$method = $d[1];
}
// Usage of absolute path to library
if (ereg('WIN',PHP_OS)) {
$path = explode('\\', __FILE__);
} else $path = explode('/', __FILE__);
array_pop($path) ;
$path = implode('/',$path);
if (is_file("$path/grammar_mods/{$module}.class.php")) {
require_once("$path/grammar_mods/$module.class.php");
$m = new $module($this,$params);
if (isset($method)) {
$m->$method($params);
}
}
}
/*
*
* Place content between grammar tags.
*
* @param text text to display
*/
function write($text = "")
{
$this->_document .= ' '.$text."\n".' ';
}
/*
*
* Echo generated grammar application to user.
*
*/
function generate()
{
echo $this->_document;
}
}
?>