source: Dev/trunk/classes/SurveyRDFWriter.php @ 16

Last change on this file since 16 was 16, checked in by basvannuland, 14 years ago

little work on the ontology

File size: 2.5 KB
Line 
1<?php
2
3class SurveyRDFWriter
4{
5        var $model;
6               
7        var $resourceSurvey;
8    /**
9    * Use SurveyRDFWriter::getInstance() instead of this
10    * constructor.
11    */
12    public function __construct()
13    {
14        // Create empty MemModel
15                $factory = new ModelFactory();
16                $this->model = $factory->getDefaultModel();
17               
18                $this->initResources();
19    }
20
21        function initResources()
22        {
23               
24                $this->resourceSurvey = new Resource(SURVEY);
25        }
26       
27        public function createSurvey($sTitle, $sDescription)
28        {               
29               
30                $predicateTitle = new Resource(TITLE);         
31                $surveyTitle = new Literal($sTitle);
32                $this->model->add(new Statement($this->resourceSurvey,$predicateTitle,$surveyTitle));           
33               
34                $predicateDescription = new Resource(DESCRIPTION);
35                $surveyDescription = new Literal($sDescription);
36                $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription));               
37        }
38       
39        public function addQuestion($qTitle,$qDescription,$qType,$qAnswers)
40        {
41                $resourceQuestion = new Resource(QUESTION);
42                $predicateQuestion = new Resource(HAS_QUESTION);
43                $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));
44               
45                $predicateTitle = new Resource(TITLE);         
46                $questionTitle = new Literal($qTitle);
47                $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle));     
48               
49                $predicateDescription = new Resource(DESCRIPTION);
50                $questionDescription = new Literal($qDescription);
51                $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription));         
52               
53                $predicateType = new Resource(TYPE);
54                $resourceQuestionType = new Resource(QUESTION_TYPE);
55                $this->model->add(new Statement($resourceQuestion,$predicateType,$resourceQuestionType));
56               
57                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);
64                        $answerTitle = new Literal($answer['Title']);
65                        $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle));
66                       
67                        $predicateDescription = new Resource(DESCRIPTION);
68                        $answerDescription = new Literal($answer['Description']);
69                        $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription));
70                       
71                }
72               
73               
74        }
75       
76        public function saveSurvey($sTitle)
77        {
78                $this->model->saveAs('surveys/'.$sTitle.'.rdf','rdf');
79               
80                return true;
81        }
82
83}
84
85?>
Note: See TracBrowser for help on using the repository browser.