Index: Dev/trunk/classes/SurveyRDFWriter.php
===================================================================
--- Dev/trunk/classes/SurveyRDFWriter.php	(revision 16)
+++ Dev/trunk/classes/SurveyRDFWriter.php	(revision 26)
@@ -6,9 +6,7 @@
 		
 	var $resourceSurvey;
-    /**
-    * Use SurveyRDFWriter::getInstance() instead of this
-    * constructor.
-    */
-    public function __construct()
+	var $surveyUID;
+	
+    public function __construct($surveyUID)
     {
         // Create empty MemModel
@@ -16,15 +14,19 @@
 		$this->model = $factory->getDefaultModel();
 		
-		$this->initResources();
+		$this->surveyUID = $surveyUID;
+		
     }
-
-	function initResources()
-	{
-		
-		$this->resourceSurvey = new Resource(SURVEY);
-	}
 	
 	public function createSurvey($sTitle, $sDescription)
 	{		
+		$this->resourceSurvey = new Resource(SURVEY.'/'.$this->surveyUID);
+		
+		$resourceSurveyType = new Resource(SURVEY);
+		$predicateRType = new Resource(RTYPE);
+		$this->model->add(new Statement($this->resourceSurvey,$predicateRType,$resourceSurveyType));
+		
+		$literalSurveyID = new Literal($this->surveyUID);
+		$predicateUniqueID = new Resource(UID);
+		$this->model->add(new Statement($this->resourceSurvey,$predicateUniqueID,$literalSurveyID));
 		
 		$predicateTitle = new Resource(TITLE);		
@@ -34,13 +36,21 @@
 		$predicateDescription = new Resource(DESCRIPTION);
 		$surveyDescription = new Literal($sDescription);
-		$this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription));		
+		$this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription));
+		
 	}
 	
 	public function addQuestion($qTitle,$qDescription,$qType,$qAnswers)
 	{
-		$resourceQuestion = new Resource(QUESTION);
-		$predicateQuestion = new Resource(HAS_QUESTION);
-		$this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));
-		
+		$questionID = md5( uniqid(rand(), true) );
+		$resourceQuestion = new Resource(QUESTION.'/'.$questionID);
+				
+		$resourceQuestionType = new Resource(QUESTION);
+		$predicateRType = new Resource(RTYPE);
+		$this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType));
+				
+		$predicateUniqueID = new Resource(UID);
+		$questionUID = new Literal($questionID);
+		$this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID));
+				
 		$predicateTitle = new Resource(TITLE);		
 		$questionTitle = new Literal($qTitle);
@@ -51,32 +61,39 @@
 		$this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription));		
 		
-		$predicateType = new Resource(TYPE);
-		$resourceQuestionType = new Resource(QUESTION_TYPE);
-		$this->model->add(new Statement($resourceQuestion,$predicateType,$resourceQuestionType));
+		$predicateQType = new Resource(QTYPE);
+		$resourceQuestionType = new Literal($qType);
+		$this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType));
 		
 		foreach($qAnswers as $answer)
-		{
-			$resourceAnswer = new Resource(ANSWER);
-			$predicateAnswer = new Resource(HAS_ANSWER);	
-			$this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer));
-			
-			$predicateTitle = new Resource(TITLE);
+		{		
+			$answerID = md5( uniqid(rand(), true) );	
+			$resourceAnswer = new Resource(ANSWER.'/'.$answerID);
+				
+			$resourceAnswerType = new Resource(ANSWER);
+			$predicateRType = new Resource(RTYPE);
+			$this->model->add(new Statement($resourceAnswer,$predicateRType,$resourceAnswerType));	
+
+			$predicateUniqueID = new Resource(UID);
+			$answerUID = new Literal($answerID);
+			$this->model->add(new Statement($resourceAnswer,$predicateUniqueID,$answerUID));			
+						
 			$answerTitle = new Literal($answer['Title']);
 			$this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle));
 			
-			$predicateDescription = new Resource(DESCRIPTION);
 			$answerDescription = new Literal($answer['Description']);
 			$this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription));
 			
+			$predicateAnswer = new Resource(HAS_ANSWER);	
+			$this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer));
 		}
 		
+		$predicateQuestion = new Resource(HAS_QUESTION);
+		$this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));
 		
 	}
 	
-	public function saveSurvey($sTitle)
-	{
-		$this->model->saveAs('surveys/'.$sTitle.'.rdf','rdf');
-		
-		return true;
+	public function saveSurvey()
+	{	
+		$this->model->saveAs('surveys/'.$this->surveyUID.'.rdf','rdf');
 	}
 
