1 | <?php |
---|
2 | class QuestionRDFWriter |
---|
3 | { |
---|
4 | protected $model; |
---|
5 | |
---|
6 | protected $filePath = 'data/questions/'; |
---|
7 | |
---|
8 | public function __construct() |
---|
9 | { |
---|
10 | // Create empty MemModel |
---|
11 | $factory = new ModelFactory(); |
---|
12 | $this->model = $factory->getDefaultModel(); |
---|
13 | |
---|
14 | if (!is_dir($this->filePath)) |
---|
15 | mkdir($this->filePath); |
---|
16 | |
---|
17 | if(file_exists($this->filePath.'questions.rdf')) |
---|
18 | $this->model->load($this->filePath.'questions.rdf'); |
---|
19 | } |
---|
20 | |
---|
21 | public function saveQuestions() |
---|
22 | { |
---|
23 | $this->model->saveAs($this->filePath.'questions.rdf','rdf'); |
---|
24 | } |
---|
25 | |
---|
26 | public function createQuestion($qTitle,$qDescription,$qType,$qID,$qCode,$qCategory,$qAnswers) |
---|
27 | { |
---|
28 | $resourceQuestion = new Resource(QUESTION.'/'.$qID); |
---|
29 | |
---|
30 | $resourceQuestionType = new Resource(QUESTION); |
---|
31 | $predicateRType = new Resource(RTYPE); |
---|
32 | $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType)); |
---|
33 | |
---|
34 | $predicateTitle = new Resource(TITLE); |
---|
35 | $questionTitle = new Literal($qTitle); |
---|
36 | $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle)); |
---|
37 | |
---|
38 | $predicateDescription = new Resource(DESCRIPTION); |
---|
39 | $questionDescription = new Literal($qDescription); |
---|
40 | $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription)); |
---|
41 | |
---|
42 | $predicateQType = new Resource(QTYPE); |
---|
43 | $resourceQuestionType = new Literal($qType); |
---|
44 | $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType)); |
---|
45 | |
---|
46 | $predicateUniqueID = new Resource(UID); |
---|
47 | $questionUID = new Literal($qID); |
---|
48 | $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID)); |
---|
49 | |
---|
50 | $predicateQCode = new Resource(QCODE); |
---|
51 | $questionQCode = new Literal($qCode); |
---|
52 | $this->model->add(new Statement($resourceQuestion,$predicateQCode,$questionQCode)); |
---|
53 | |
---|
54 | $predicateQCategory = new Resource(QCATEGORY); |
---|
55 | $questionQCategory = new Literal($qCategory); |
---|
56 | $this->model->add(new Statement($resourceQuestion,$predicateQCategory,$questionQCategory)); |
---|
57 | |
---|
58 | foreach($qAnswers as $answer) |
---|
59 | { |
---|
60 | $answerID = md5( uniqid(rand(), true) ); |
---|
61 | $resourceAnswer = new Resource(ANSWER.'/'.$answerID); |
---|
62 | |
---|
63 | $resourceAnswerType = new Resource(ANSWER); |
---|
64 | $predicateRType = new Resource(RTYPE); |
---|
65 | $this->model->add(new Statement($resourceAnswer,$predicateRType,$resourceAnswerType)); |
---|
66 | |
---|
67 | $predicateUniqueID = new Resource(UID); |
---|
68 | $answerUID = new Literal($answerID); |
---|
69 | $this->model->add(new Statement($resourceAnswer,$predicateUniqueID,$answerUID)); |
---|
70 | |
---|
71 | $answerTitle = new Literal($answer['Title']); |
---|
72 | $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle)); |
---|
73 | |
---|
74 | $answerDescription = new Literal($answer['Description']); |
---|
75 | $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription)); |
---|
76 | |
---|
77 | $predicateAnswer = new Resource(HAS_ANSWER); |
---|
78 | $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer)); |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | ?> |
---|