Changeset 26
- Timestamp:
- 07/20/11 18:05:04 (14 years ago)
- Location:
- Dev/trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/SurveyRDFReader.php
r16 r26 4 4 { 5 5 var $model; 6 7 public function SurveyRDFReader() 8 { 6 7 var $surveyUID; 8 9 public function __construct($surveyUID) 10 { 9 11 // Create empty MemModel 10 12 $factory = new ModelFactory(); 11 $this->model = $factory->getDefaultModel(); 13 $this->model = $factory->getDefaultModel(); 14 15 $this->surveyUID = $surveyUID; 12 16 } 13 17 14 public function loadSurvey( $sTitle)18 public function loadSurvey() 15 19 { 16 $this->model->load('surveys/'.$ sTitle.'.rdf');20 $this->model->load('surveys/'.$this->surveyUID.'.rdf'); 17 21 } 18 22 19 public function readSurveyTitle() 23 public function getSurveyInfo() 24 { 25 SurveyRDFReader::loadSurvey(); 26 27 $result = array(); 28 $result[] = $this->readSurveyInfo(); 29 $result[] = $this->readSurveyQuestions(); 30 31 return $result; 32 } 33 34 public function readSurveyInfo() 20 35 { 21 36 $querystring = ' 22 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>37 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 23 38 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 24 SELECT ?title 25 WHERE { resources:survey predicates:title ?title }'; 39 SELECT ?title ?description 40 WHERE 41 { 42 _survey predicates:resource_type resources:survey ; 43 predicates:title ?title ; 44 predicates:description ?description 45 }'; 46 47 $result = $this->model->sparqlQuery($querystring); 48 49 return $result; 50 } 51 52 public function readSurveyQuestions() 53 { 54 $result = array(); 55 $result[] = $this->readSurveyQuestionsTitle(); 56 $result[] = $this->readSurveyQuestionsDescription(); 57 $result[] = $this->readSurveyQuestionsType(); 58 $result[] = $this->readSurveyQuestionsID(); 59 60 return $result; 61 } 62 63 public function readSurveyQuestionsTitle() 64 { 65 $querystring = ' 66 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 67 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 68 SELECT ?questionTitle 69 WHERE 70 { 71 _question predicates:resource_type resources:question ; 72 predicates:title ?questionTitle 73 }'; 26 74 27 75 $result = $this->model->sparqlQuery($querystring); … … 30 78 } 31 79 32 public function readSurvey Description()80 public function readSurveyQuestionsDescription() 33 81 { 34 82 $querystring = ' 35 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>83 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 36 84 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 37 SELECT ?description 38 WHERE { resources:survey predicates:description ?description }'; 85 SELECT ?questionDescription 86 WHERE 87 { 88 _question predicates:resource_type resources:question ; 89 predicates:description ?questionDescription 90 }'; 91 92 $result = $this->model->sparqlQuery($querystring); 93 94 return $result; 95 } 96 97 public function readSurveyQuestionsType() 98 { 99 $querystring = ' 100 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 101 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 102 SELECT ?questionType 103 WHERE 104 { 105 _question predicates:resource_type resources:question ; 106 predicates:question_type ?questionType 107 }'; 108 109 $result = $this->model->sparqlQuery($querystring); 110 111 return $result; 112 } 113 114 public function readSurveyQuestionsID() 115 { 116 $querystring = ' 117 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 118 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 119 SELECT ?questionID 120 WHERE 121 { 122 _question predicates:resource_type resources:question ; 123 predicates:uid ?questionID 124 }'; 125 126 $result = $this->model->sparqlQuery($querystring); 127 128 return $result; 129 } 130 131 public function readSurveyAnswers($qID) 132 { 133 $querystring = ' 134 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 135 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 136 SELECT ?answerTitle 137 WHERE 138 { 139 _question predicates:resource_type resources:question ; 140 predicates:uid "' . $qID . '" ; 141 predicates:has_answer _answer . 142 _answer predicates:title ?answerTitle 143 }'; 39 144 40 145 $result = $this->model->sparqlQuery($querystring); -
Dev/trunk/classes/SurveyRDFWriter.php
r16 r26 6 6 7 7 var $resourceSurvey; 8 /** 9 * Use SurveyRDFWriter::getInstance() instead of this 10 * constructor. 11 */ 12 public function __construct() 8 var $surveyUID; 9 10 public function __construct($surveyUID) 13 11 { 14 12 // Create empty MemModel … … 16 14 $this->model = $factory->getDefaultModel(); 17 15 18 $this->initResources(); 16 $this->surveyUID = $surveyUID; 17 19 18 } 20 21 function initResources()22 {23 24 $this->resourceSurvey = new Resource(SURVEY);25 }26 19 27 20 public function createSurvey($sTitle, $sDescription) 28 21 { 22 $this->resourceSurvey = new Resource(SURVEY.'/'.$this->surveyUID); 23 24 $resourceSurveyType = new Resource(SURVEY); 25 $predicateRType = new Resource(RTYPE); 26 $this->model->add(new Statement($this->resourceSurvey,$predicateRType,$resourceSurveyType)); 27 28 $literalSurveyID = new Literal($this->surveyUID); 29 $predicateUniqueID = new Resource(UID); 30 $this->model->add(new Statement($this->resourceSurvey,$predicateUniqueID,$literalSurveyID)); 29 31 30 32 $predicateTitle = new Resource(TITLE); … … 34 36 $predicateDescription = new Resource(DESCRIPTION); 35 37 $surveyDescription = new Literal($sDescription); 36 $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription)); 38 $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription)); 39 37 40 } 38 41 39 42 public function addQuestion($qTitle,$qDescription,$qType,$qAnswers) 40 43 { 41 $resourceQuestion = new Resource(QUESTION); 42 $predicateQuestion = new Resource(HAS_QUESTION); 43 $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion)); 44 44 $questionID = md5( uniqid(rand(), true) ); 45 $resourceQuestion = new Resource(QUESTION.'/'.$questionID); 46 47 $resourceQuestionType = new Resource(QUESTION); 48 $predicateRType = new Resource(RTYPE); 49 $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType)); 50 51 $predicateUniqueID = new Resource(UID); 52 $questionUID = new Literal($questionID); 53 $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID)); 54 45 55 $predicateTitle = new Resource(TITLE); 46 56 $questionTitle = new Literal($qTitle); … … 51 61 $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription)); 52 62 53 $predicate Type = new Resource(TYPE);54 $resourceQuestionType = new Resource(QUESTION_TYPE);55 $this->model->add(new Statement($resourceQuestion,$predicate Type,$resourceQuestionType));63 $predicateQType = new Resource(QTYPE); 64 $resourceQuestionType = new Literal($qType); 65 $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType)); 56 66 57 67 foreach($qAnswers as $answer) 58 { 59 $resourceAnswer = new Resource(ANSWER); 60 $predicateAnswer = new Resource(HAS_ANSWER); 61 $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer)); 62 63 $predicateTitle = new Resource(TITLE); 68 { 69 $answerID = md5( uniqid(rand(), true) ); 70 $resourceAnswer = new Resource(ANSWER.'/'.$answerID); 71 72 $resourceAnswerType = new Resource(ANSWER); 73 $predicateRType = new Resource(RTYPE); 74 $this->model->add(new Statement($resourceAnswer,$predicateRType,$resourceAnswerType)); 75 76 $predicateUniqueID = new Resource(UID); 77 $answerUID = new Literal($answerID); 78 $this->model->add(new Statement($resourceAnswer,$predicateUniqueID,$answerUID)); 79 64 80 $answerTitle = new Literal($answer['Title']); 65 81 $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle)); 66 82 67 $predicateDescription = new Resource(DESCRIPTION);68 83 $answerDescription = new Literal($answer['Description']); 69 84 $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription)); 70 85 86 $predicateAnswer = new Resource(HAS_ANSWER); 87 $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer)); 71 88 } 72 89 90 $predicateQuestion = new Resource(HAS_QUESTION); 91 $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion)); 73 92 74 93 } 75 94 76 public function saveSurvey($sTitle) 77 { 78 $this->model->saveAs('surveys/'.$sTitle.'.rdf','rdf'); 79 80 return true; 95 public function saveSurvey() 96 { 97 $this->model->saveAs('surveys/'.$this->surveyUID.'.rdf','rdf'); 81 98 } 82 99 -
Dev/trunk/rdfConstants.php
r16 r26 16 16 17 17 // Predicates used for RDF triples 18 define('UID',SURVEYTOOL_PREDICATES_NAMESPACE . 'uid'); 18 19 define('CREATOR',SURVEYTOOL_PREDICATES_NAMESPACE . 'creator'); 19 20 define('TITLE',SURVEYTOOL_PREDICATES_NAMESPACE . 'title'); 20 21 define('DESCRIPTION',SURVEYTOOL_PREDICATES_NAMESPACE . 'description'); 21 define('TYPE',SURVEYTOOL_PREDICATES_NAMESPACE . 'type'); 22 define('RTYPE',SURVEYTOOL_PREDICATES_NAMESPACE . 'resource_type'); 23 define('QTYPE',SURVEYTOOL_PREDICATES_NAMESPACE . 'question_type'); 22 24 define('HAS_QUESTION',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_question'); 23 25 define('HAS_ANSWER',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_answer'); -
Dev/trunk/submitsurvey.php
r17 r26 11 11 12 12 $sTitle = $_POST['surveyTitle']; 13 $sDesription = $_POST['surveyDescription']; 13 14 14 $surveyRDFWriter->createSurvey($sTitle,$ _POST['surveyDescription']);15 $surveyRDFWriter->createSurvey($sTitle,$sDesription); 15 16 16 $done = $surveyRDFWriter->saveSurvey($sTitle); 17 $qNumber = 1; 18 do 19 { 20 $qTitle = $_POST['questionTitle'.$qNumber]; 21 $qDescription = $_POST['questionDescription'.$qNumber]; 22 $qType = $_POST['questionType'.$qNumber]; 23 24 if ($qTitle != null) 25 { 26 $qaArray = array(); 27 $aNumber = 1; 28 do 29 { 30 $aTitle = $_POST['q'.$qNumber.'ans'.$aNumber]; 31 if ($aTitle != null) 32 { 33 $aArray = array(); 34 $aArray['Title'] = $aTitle; 35 $aArray['Description'] = 'answerDescription'.$aNumber; 36 $qaArray[] = $aArray; 37 } 38 $aNumber++; 39 } while ($aTitle != null); 40 41 $qNumber++; 42 $surveyRDFWriter->addQuestion($qTitle,$qDescription,$qType,$qaArray); 43 } 44 } while($qTitle != null); 45 46 47 $surveyRDFWriter->saveSurvey($sTitle); 17 48 18 49 echo 'Done<br/><br/>'; … … 27 58 $value = $line['?title']; 28 59 if($value != "") 29 echo $value->toString(). "<br/>";60 echo $value->toString().'<br/>'; 30 61 else 31 echo "undbound<br/>";62 echo 'undbound<br/>'; 32 63 } 33 64 … … 37 68 $value = $line['?description']; 38 69 if($value != "") 39 echo $value->toString(). "<br/>";70 echo $value->toString().'<br/>'; 40 71 else 41 echo "undbound<br/>";72 echo 'undbound<br/>'; 42 73 } 43 74 75 $result3 = $surveyRDFReader->readSurveyQuestions($sTitle); 76 77 if($result3 != null) 78 { 79 var_dump($result3); 80 81 foreach($result3 as $line){ 82 $value = $line['?questionTitle']; 83 if($value != "") 84 echo '<br/>'.'<br/>'.$value->toString().'<br/>'; 85 else 86 echo 'undbound<br/>'; 87 } 88 } else 89 { 90 echo '<"Literal("'.$sTitle.'")"> empty result <br/>'; 91 } 92 echo '<br/>'; 44 93 var_dump($_POST); 45 94 -
Dev/trunk/surveycreation.php
r24 r26 2 2 3 3 if (isset($_POST['timeStamp'])) 4 { 4 5 $timeStamp = $_POST['timeStamp']; 6 7 var_dump($_POST); 8 echo '<br/><br/>'; 9 $surveyDBI = SurveyDatabaseInterface::getInstance(); 10 $surveyDBI->setSurveyInfo($_POST); 11 $info = $surveyDBI->getSurveyInfo(); 12 echo '<br/><br/>'; 13 var_dump($info); 14 } 5 15 else { 6 16 $timeStamp = null; 7 17 } 18 8 19 9 20 ?>
Note: See TracChangeset
for help on using the changeset viewer.