<?php

require_once dirname(__FILE__) . "/GenerateModel.php";
$GenerateModel = new GenerateModel($_POST['TraceURI'], $_POST['ModelName']);
$Model = new TraceModel($GenerateModel->BaseURI, $GenerateModel->ModelName);
$GenerateModel->PutModel();
echo $Model->getData();
/* if (!$Model->exist())
   
        {$GenerateModel->PutModel();}
     else 
        {echo ($Model->getData());}*/
 function sparql()
 {
     if ($this->hasMethod == 'sparql') {
         $tr = $this->hasSource[0];
         if ($this->model_uri == null) {
             $this->model_uri = $tr->getModel();
         }
         $this->hasParameter[] = '"model=' . $this->model_uri . '"';
         $prefixes[] = "@prefix : <http://liris.cnrs.fr/silex/2009/ktbs#> .";
         $statements[] = "<> :contains <" . $this->name . "> .";
         $statements[] = "<" . $this->name . "> a :ComputedTrace ;";
         $statements[] = ":hasMethod :sparql ;";
         $statements[] = ":hasSource " . $this->listSources() . " ;";
         $statements[] = ':hasParameter ' . implode(',', $this->hasParameter) . ' .';
         $this->script = implode("\n", $prefixes) . "\n" . implode("\n", $statements);
         $this->result = RestfulHelper::post($this->base_uri, $this->script);
         if ($this->model_uri != $tr->getModel()) {
             $model = new TraceModel($this->model_uri);
             $Gene = new GenerateModel($this->uri, $model->getName());
             $Gene->PutModel();
         }
     }
 }