source: php/trunk/unittest/rdftestcases/rdftestcases.php@ 65

Last change on this file since 65 was 65, checked in by cla, 14 years ago

rdfint

  • added execution of positive parser tests
  • added exception list
  • Property svn:eol-style set to native
File size: 6.0 KB
Line 
1<?PHP
2
3/* RDFInt.php - RDF Interfaces for PHP
4 * Copyright 2011 netlabs.org
5 * Author: Christian Langanke, Adrian Gschwend
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20// load library setup
21define( 'RDFINT', getenv( 'PHP_LIBROOT_RDFINT'));
22require_once( RDFINT.'/rdfa.php');
23
24class RDFTestCasesManifest {
25
26 private $rdfDataManifest;
27 private $exceptions;
28
29 // --------------------------------------------------------
30
31 public function __construct() {
32
33 $remoteManifest = 'http://www.w3.org/2000/10/rdf-tests/rdfcore/Manifest.rdf';
34 $localManifest = getenv('tmp').'/RDFTestcases_Manifest.rdf';
35
36 $aNamespace = array( 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
37 'test' => 'http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#',
38 'case' => 'http://www.w3.org/2000/10/rdf-tests/rdfcore/');
39
40 // cache manifest file first
41 if (!file_exists( $localManifest)) {
42 $data = file_get_contents( $remoteManifest);
43 file_put_contents( $localManifest, $data );
44 }
45
46 // load RDF data
47 $this->rdfDataManifest = new \rdfa\Data();
48 foreach ( $aNamespace as $prefix => $uriNamespace) {
49 $this->rdfDataManifest->setMapping( $prefix, $uriNamespace);
50 }
51 $result = $this->rdfDataManifest->parse( $localManifest);
52
53 // load exception list
54 $this->exceptions = explode( "\r\n", file_get_contents( 'exception.lst'));
55
56 } // public function __construct
57
58 // --------------------------------------------------------
59
60 private function _caseNameFromSubject( $uriTestcase) {
61 $nameParts = explode( ':', $uriTestcase);
62 $name = str_replace( 'Manifest.rdf#', '', $nameParts[1]);
63 return $name;
64
65 } // private function _caseNameFromSubject
66
67 // --------------------------------------------------------
68
69 // helper: get projections on approved testcases
70 private function _searchApprovedTestcases( $category) {
71
72 // determine data
73 $templateTestcase = array( 'input' => 'test:inputDocument',
74 'output' => 'test:outputDocument',
75 'conclusion' => 'test:conclusionDocument');
76
77 // assemble query and search
78 $query[ 'test:status'] = 'APPROVED';
79 $query[ 'rdf:type'] = "test:$category";
80 $testcases = $this->rdfDataManifest->query( $query, $templateTestcase);
81
82 // create name attribute from URI
83 // unshring URI values
84 foreach ($testcases as $testcase) {
85 $testcase->name = $this->_caseNameFromSubject( $testcase->getSubject());
86 $testcase->input = $this->rdfDataManifest->_resolve( $testcase->input);
87 $testcase->output = $this->rdfDataManifest->_resolve( $testcase->output);
88 $testcase->conclusion = $this->rdfDataManifest->_resolve( $testcase->conclusion);
89 }
90
91 return $testcases;
92
93 } // private function _searchApprovedTestcases
94
95 // --------------------------------------------------------
96
97 // helper: determine names or count of approved testcases for category
98 // NOTE: for better performance we use getSubjects() instead of query(),
99 // and check for approval in a further step
100
101 // helper: get subjects of approved testcases
102 private function _getApprovedTestcaseSubjects( $category) {
103
104 $uriTestcases = $this->rdfDataManifest->getSubjects( 'rdf:type', "test:$category");
105 $count = 0;
106 $testcases = array();
107 foreach ( $uriTestcases as $uriTestcase) {
108
109 // don't execute if in exception list
110 if (array_search( $this->_caseNameFromSubject( $uriTestcase), $this->exceptions) !== false)
111 continue;
112
113
114 if ($this->rdfDataManifest->_getFirstValue( $uriTestcase, 'test:status') == 'APPROVED')
115 $testcases[] = $uriTestcase;
116 }
117
118 return $testcases;
119
120 } // private function _getApprovedTestcaseSubjects
121
122
123 private function _countApprovedTestcases( $category) {
124
125 return count( $this->_getApprovedTestcaseSubjects( $category));
126
127 } // private function _countApprovedTestcases
128
129 // --------------------------------------------------------
130
131 public function getParserTests( $category) {
132
133 return $this->_searchApprovedTestcases( $category);
134
135 } // public function getParserTests
136
137 // --------------------------------------------------------
138
139 public function getCategories() {
140
141 // all categories - for later use
142 $validTpes = array( 'PositiveParserTest',
143 'NegativeParserTest',
144 'PositiveEntailmentTest',
145 'NegativeEntailmentTest',
146 'MiscellaneousTest');
147
148 $validTpes = array( 'PositiveParserTest');
149
150 return $validTpes;
151
152 } // public function getCategories
153
154 // --------------------------------------------------------
155
156 public function listCases( $category = Null, $verbose = false) {
157
158 // use all categories by default
159 if (($category == Null) || ($category == ''))
160 $categories = $this->getCategories();
161 else
162 $categories = array( $category);
163
164 // now list cases
165 echo "Categories of RDF Test Cases:\n";
166 foreach ($categories as $category) {
167 if ($verbose) {
168 echo " $category\n";
169 $uriTestcases = $this->_getApprovedTestcaseSubjects( $category);
170 $count = count( $uriTestcases);
171 foreach ($uriTestcases as $uriTestcase) {
172 echo " " . $this->_caseNameFromSubject( $uriTestcase) . "\n";
173 }
174 echo "$count cases for: $category\n\n";
175 } else {
176 $count = $this->_countApprovedTestcases( $category);
177 echo " $category $count cases\n";
178 }
179 }
180
181 } // public function listCases
182
183} // class UnitTest
184
185
Note: See TracBrowser for help on using the repository browser.