Changeset 26 for Dev/trunk/classes
- Timestamp:
- 07/20/11 18:05:04 (14 years ago)
- Location:
- Dev/trunk/classes
- Files:
-
- 1 added
- 2 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
Note: See TracChangeset
for help on using the changeset viewer.