@@ -112,6 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * dependecy injection setter |
| 115 | + * @param \Closure $generator |
|
| 115 | 116 | */ |
| 116 | 117 | public function setIdGenerator($generator) |
| 117 | 118 | { |
@@ -160,18 +161,28 @@ discard block |
||
| 160 | 161 | } |
| 161 | 162 | |
| 162 | 163 | |
| 164 | + /** |
|
| 165 | + * @param string $prefix |
|
| 166 | + * @param string $ns |
|
| 167 | + */ |
|
| 163 | 168 | public function setVocabulary($prefix,$ns) |
| 164 | 169 | { |
| 165 | 170 | $this->vocabulary[$prefix] = $ns; |
| 166 | 171 | } |
| 167 | 172 | |
| 168 | 173 | |
| 174 | + /** |
|
| 175 | + * @param string $prefix |
|
| 176 | + */ |
|
| 169 | 177 | public function unsetVocabulary($prefix) |
| 170 | 178 | { |
| 171 | 179 | unset($this->vocabulary[$prefix]); |
| 172 | 180 | } |
| 173 | 181 | |
| 174 | 182 | |
| 183 | + /** |
|
| 184 | + * @param string $base |
|
| 185 | + */ |
|
| 175 | 186 | public function getTurtleHeader($base=null) |
| 176 | 187 | { |
| 177 | 188 | $header = empty($base)?'': "@base <$base> .\n"; |
@@ -4,212 +4,212 @@ |
||
| 4 | 4 | abstract class AbstractModel |
| 5 | 5 | { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * |
|
| 9 | - * MUST be redefined by concrete class with the model schema |
|
| 10 | - * Each array element is composed by a propery name and and property options. |
|
| 11 | - * Property option is an array with following (optional) fields: |
|
| 12 | - * 'default' a value to be used for the propery |
|
| 13 | - * 'filter' a php filter |
|
| 14 | - * 'options' php filter options |
|
| 15 | - * 'flags' php filter flags |
|
| 16 | - * |
|
| 17 | - * Example:array ( |
|
| 18 | - * 'legalName' => array( |
|
| 19 | - * 'filter' => FILTER_CALLBACK, |
|
| 20 | - * 'options' => '\BOTK\Filters::FILTER_NORMALIZZE_ADDRESS', |
|
| 21 | - * ), |
|
| 22 | - * 'alternateName' => array( |
|
| 7 | + /** |
|
| 8 | + * |
|
| 9 | + * MUST be redefined by concrete class with the model schema |
|
| 10 | + * Each array element is composed by a propery name and and property options. |
|
| 11 | + * Property option is an array with following (optional) fields: |
|
| 12 | + * 'default' a value to be used for the propery |
|
| 13 | + * 'filter' a php filter |
|
| 14 | + * 'options' php filter options |
|
| 15 | + * 'flags' php filter flags |
|
| 16 | + * |
|
| 17 | + * Example:array ( |
|
| 18 | + * 'legalName' => array( |
|
| 19 | + * 'filter' => FILTER_CALLBACK, |
|
| 20 | + * 'options' => '\BOTK\Filters::FILTER_NORMALIZZE_ADDRESS', |
|
| 21 | + * ), |
|
| 22 | + * 'alternateName' => array( |
|
| 23 | 23 | 'flags' => FILTER_FORCE_ARRAY, |
| 24 | - * ), |
|
| 25 | - * 'postalCode' => array( // italian rules |
|
| 26 | - * 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 27 | - * 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 28 | - * 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 29 | - * ), |
|
| 30 | - * ) |
|
| 31 | - */ |
|
| 32 | - protected static $DEFAULT_OPTIONS = array( |
|
| 33 | - 'uri' => array( |
|
| 34 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 35 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 36 | - ), |
|
| 37 | - 'base' => array( |
|
| 38 | - 'default' => 'http://linkeddata.center/botk/resource/', |
|
| 39 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 40 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 41 | - ), |
|
| 42 | - 'id' => array( |
|
| 43 | - 'filter' => FILTER_CALLBACK, |
|
| 44 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ID', |
|
| 45 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 46 | - ), |
|
| 47 | - 'page' => array( |
|
| 48 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 49 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 50 | - ), |
|
| 51 | - 'homepage' => array( |
|
| 52 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 53 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 54 | - ), |
|
| 55 | - ); |
|
| 56 | - |
|
| 57 | - protected $options ; |
|
| 58 | - protected $vocabulary = array( |
|
| 59 | - 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
|
| 60 | - 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
|
| 61 | - 'owl' => 'http://www.w3.org/2002/07/owl#', |
|
| 62 | - 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 63 | - 'dct' => 'http://purl.org/dc/terms/', |
|
| 64 | - 'void' => 'http://rdfs.org/ns/void#', |
|
| 65 | - 'prov' => 'http://www.w3.org/ns/prov#', |
|
| 66 | - 'schema' => 'http://schema.org/', |
|
| 67 | - 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 68 | - 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 69 | - 'dq' => 'http://purl.org/linked-data/cube#', |
|
| 70 | - 'daq' => 'http://purl.org/eis/vocab/daq#', |
|
| 71 | - 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 72 | - ); |
|
| 73 | - |
|
| 74 | - protected $data; |
|
| 75 | - protected $rdf =null; //lazy created |
|
| 76 | - protected $tripleCount=0; //lazy created |
|
| 77 | - protected $uniqueIdGenerator=null; // dependency injections |
|
| 78 | - protected $droppedFields = array(); |
|
| 79 | - |
|
| 80 | - abstract public function asTurtle(); |
|
| 24 | + * ), |
|
| 25 | + * 'postalCode' => array( // italian rules |
|
| 26 | + * 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 27 | + * 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 28 | + * 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 29 | + * ), |
|
| 30 | + * ) |
|
| 31 | + */ |
|
| 32 | + protected static $DEFAULT_OPTIONS = array( |
|
| 33 | + 'uri' => array( |
|
| 34 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 35 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 36 | + ), |
|
| 37 | + 'base' => array( |
|
| 38 | + 'default' => 'http://linkeddata.center/botk/resource/', |
|
| 39 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 40 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 41 | + ), |
|
| 42 | + 'id' => array( |
|
| 43 | + 'filter' => FILTER_CALLBACK, |
|
| 44 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ID', |
|
| 45 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 46 | + ), |
|
| 47 | + 'page' => array( |
|
| 48 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 49 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 50 | + ), |
|
| 51 | + 'homepage' => array( |
|
| 52 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 53 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 54 | + ), |
|
| 55 | + ); |
|
| 56 | + |
|
| 57 | + protected $options ; |
|
| 58 | + protected $vocabulary = array( |
|
| 59 | + 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
|
| 60 | + 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
|
| 61 | + 'owl' => 'http://www.w3.org/2002/07/owl#', |
|
| 62 | + 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 63 | + 'dct' => 'http://purl.org/dc/terms/', |
|
| 64 | + 'void' => 'http://rdfs.org/ns/void#', |
|
| 65 | + 'prov' => 'http://www.w3.org/ns/prov#', |
|
| 66 | + 'schema' => 'http://schema.org/', |
|
| 67 | + 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 68 | + 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 69 | + 'dq' => 'http://purl.org/linked-data/cube#', |
|
| 70 | + 'daq' => 'http://purl.org/eis/vocab/daq#', |
|
| 71 | + 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 72 | + ); |
|
| 73 | + |
|
| 74 | + protected $data; |
|
| 75 | + protected $rdf =null; //lazy created |
|
| 76 | + protected $tripleCount=0; //lazy created |
|
| 77 | + protected $uniqueIdGenerator=null; // dependency injections |
|
| 78 | + protected $droppedFields = array(); |
|
| 79 | + |
|
| 80 | + abstract public function asTurtle(); |
|
| 81 | 81 | |
| 82 | - protected function mergeOptions( array $options1, array $options2 ) |
|
| 83 | - { |
|
| 84 | - foreach($options2 as $property=>$option){ |
|
| 82 | + protected function mergeOptions( array $options1, array $options2 ) |
|
| 83 | + { |
|
| 84 | + foreach($options2 as $property=>$option){ |
|
| 85 | 85 | |
| 86 | - $options1[$property]=isset($options1[$property]) |
|
| 87 | - ?array_merge($options1[$property], $option) |
|
| 88 | - :$option; |
|
| 89 | - } |
|
| 86 | + $options1[$property]=isset($options1[$property]) |
|
| 87 | + ?array_merge($options1[$property], $option) |
|
| 88 | + :$option; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return $options1; |
|
| 92 | - } |
|
| 91 | + return $options1; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | 94 | public function __construct(array $data = array(), array $customOptions = array()) |
| 95 | 95 | { |
| 96 | - $options = $this->mergeOptions(self::$DEFAULT_OPTIONS,$customOptions); |
|
| 96 | + $options = $this->mergeOptions(self::$DEFAULT_OPTIONS,$customOptions); |
|
| 97 | 97 | |
| 98 | - // set default values |
|
| 99 | - foreach( $options as $property=>$option){ |
|
| 100 | - if(empty($data[$property]) && isset($option['default'])){ |
|
| 101 | - $data[$property] = $option['default']; |
|
| 102 | - } |
|
| 103 | - } |
|
| 98 | + // set default values |
|
| 99 | + foreach( $options as $property=>$option){ |
|
| 100 | + if(empty($data[$property]) && isset($option['default'])){ |
|
| 101 | + $data[$property] = $option['default']; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - // ensure data are sanitized and validated |
|
| 106 | - $sanitizedData = array_filter( filter_var_array($data, $options)); |
|
| 105 | + // ensure data are sanitized and validated |
|
| 106 | + $sanitizedData = array_filter( filter_var_array($data, $options)); |
|
| 107 | 107 | |
| 108 | - // find and register dropped fields |
|
| 109 | - foreach($data as $property=>$value){ |
|
| 110 | - if($value && empty($sanitizedData[$property])){ |
|
| 111 | - $this->droppedFields[]=$property; |
|
| 112 | - } |
|
| 113 | - } |
|
| 108 | + // find and register dropped fields |
|
| 109 | + foreach($data as $property=>$value){ |
|
| 110 | + if($value && empty($sanitizedData[$property])){ |
|
| 111 | + $this->droppedFields[]=$property; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - $this->options = $options; |
|
| 116 | - $this->data = $sanitizedData; |
|
| 117 | - $this->setIdGenerator(function($data){return uniqid();}); |
|
| 115 | + $this->options = $options; |
|
| 116 | + $this->data = $sanitizedData; |
|
| 117 | + $this->setIdGenerator(function($data){return uniqid();}); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
| 121 | - public function getDroppedFields() |
|
| 122 | - { |
|
| 123 | - return $this->droppedFields; |
|
| 124 | - } |
|
| 121 | + public function getDroppedFields() |
|
| 122 | + { |
|
| 123 | + return $this->droppedFields; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * dependecy injection setter |
|
| 129 | - */ |
|
| 130 | - public function setIdGenerator($generator) |
|
| 131 | - { |
|
| 132 | - assert( is_callable($generator)); |
|
| 133 | - $this->uniqueIdGenerator = $generator; |
|
| 127 | + /** |
|
| 128 | + * dependecy injection setter |
|
| 129 | + */ |
|
| 130 | + public function setIdGenerator($generator) |
|
| 131 | + { |
|
| 132 | + assert( is_callable($generator)); |
|
| 133 | + $this->uniqueIdGenerator = $generator; |
|
| 134 | 134 | |
| 135 | - return $this; |
|
| 136 | - } |
|
| 135 | + return $this; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * a generic implementation that use uri, base and id property (all optionals) |
|
| 141 | - */ |
|
| 142 | - public function getUri() |
|
| 143 | - { |
|
| 144 | - if(!empty($this->data['uri'])){ |
|
| 145 | - $uri = $this->data['uri']; |
|
| 146 | - } elseif(!empty($this->data['base'])) { |
|
| 147 | - $idGenerator=$this->uniqueIdGenerator; |
|
| 148 | - $uri = $this->data['base']; |
|
| 149 | - $uri.=empty($this->data['id'])?$idGenerator($this->data):$this->data['id']; |
|
| 150 | - } else{ |
|
| 151 | - $idGenerator=$this->uniqueIdGenerator; |
|
| 152 | - $uri = 'urn:local:botk:'.$idGenerator($this->data); |
|
| 153 | - } |
|
| 139 | + /** |
|
| 140 | + * a generic implementation that use uri, base and id property (all optionals) |
|
| 141 | + */ |
|
| 142 | + public function getUri() |
|
| 143 | + { |
|
| 144 | + if(!empty($this->data['uri'])){ |
|
| 145 | + $uri = $this->data['uri']; |
|
| 146 | + } elseif(!empty($this->data['base'])) { |
|
| 147 | + $idGenerator=$this->uniqueIdGenerator; |
|
| 148 | + $uri = $this->data['base']; |
|
| 149 | + $uri.=empty($this->data['id'])?$idGenerator($this->data):$this->data['id']; |
|
| 150 | + } else{ |
|
| 151 | + $idGenerator=$this->uniqueIdGenerator; |
|
| 152 | + $uri = 'urn:local:botk:'.$idGenerator($this->data); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - return $uri; |
|
| 156 | - } |
|
| 155 | + return $uri; |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | |
| 159 | - public function asArray() |
|
| 160 | - { |
|
| 161 | - return $this->data; |
|
| 162 | - } |
|
| 159 | + public function asArray() |
|
| 160 | + { |
|
| 161 | + return $this->data; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | 164 | |
| 165 | - public function getOptions() |
|
| 166 | - { |
|
| 167 | - return $this->options; |
|
| 168 | - } |
|
| 165 | + public function getOptions() |
|
| 166 | + { |
|
| 167 | + return $this->options; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | 170 | |
| 171 | - public function getVocabularies() |
|
| 172 | - { |
|
| 173 | - return $this->vocabulary; |
|
| 174 | - } |
|
| 171 | + public function getVocabularies() |
|
| 172 | + { |
|
| 173 | + return $this->vocabulary; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - public function setVocabulary($prefix,$ns) |
|
| 178 | - { |
|
| 179 | - $this->vocabulary[$prefix] = $ns; |
|
| 180 | - } |
|
| 177 | + public function setVocabulary($prefix,$ns) |
|
| 178 | + { |
|
| 179 | + $this->vocabulary[$prefix] = $ns; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | 182 | |
| 183 | - public function unsetVocabulary($prefix) |
|
| 184 | - { |
|
| 185 | - unset($this->vocabulary[$prefix]); |
|
| 186 | - } |
|
| 183 | + public function unsetVocabulary($prefix) |
|
| 184 | + { |
|
| 185 | + unset($this->vocabulary[$prefix]); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | - public function getTurtleHeader($base=null) |
|
| 190 | - { |
|
| 191 | - $header = empty($base)?'': "@base <$base> .\n"; |
|
| 192 | - foreach( $this->vocabulary as $prefix=>$ns ){ |
|
| 193 | - $header.="@prefix $prefix: <$ns> .\n"; |
|
| 194 | - } |
|
| 189 | + public function getTurtleHeader($base=null) |
|
| 190 | + { |
|
| 191 | + $header = empty($base)?'': "@base <$base> .\n"; |
|
| 192 | + foreach( $this->vocabulary as $prefix=>$ns ){ |
|
| 193 | + $header.="@prefix $prefix: <$ns> .\n"; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - return $header; |
|
| 197 | - } |
|
| 196 | + return $header; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | |
| 200 | - public function getTripleCount() |
|
| 201 | - { |
|
| 202 | - // triple count is computed during rdf creation |
|
| 203 | - if (is_null($this->rdf)){ |
|
| 204 | - $this->asTurtle(); |
|
| 205 | - } |
|
| 200 | + public function getTripleCount() |
|
| 201 | + { |
|
| 202 | + // triple count is computed during rdf creation |
|
| 203 | + if (is_null($this->rdf)){ |
|
| 204 | + $this->asTurtle(); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return $this->tripleCount; |
|
| 208 | - } |
|
| 207 | + return $this->tripleCount; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | 210 | |
| 211 | - public function __toString() |
|
| 212 | - { |
|
| 213 | - return $this->getTurtleHeader() ."\n". $this->asTurtle(); |
|
| 214 | - } |
|
| 211 | + public function __toString() |
|
| 212 | + { |
|
| 213 | + return $this->getTurtleHeader() ."\n". $this->asTurtle(); |
|
| 214 | + } |
|
| 215 | 215 | } |
| 216 | 216 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * ), |
| 30 | 30 | * ) |
| 31 | 31 | */ |
| 32 | - protected static $DEFAULT_OPTIONS = array( |
|
| 32 | + protected static $DEFAULT_OPTIONS = array( |
|
| 33 | 33 | 'uri' => array( |
| 34 | 34 | 'filter' => FILTER_SANITIZE_URL, |
| 35 | 35 | 'flags' => FILTER_REQUIRE_SCALAR, |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | ), |
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | - protected $options ; |
|
| 57 | + protected $options; |
|
| 58 | 58 | protected $vocabulary = array( |
| 59 | 59 | 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
| 60 | 60 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
@@ -72,19 +72,19 @@ discard block |
||
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | 74 | protected $data; |
| 75 | - protected $rdf =null; //lazy created |
|
| 76 | - protected $tripleCount=0; //lazy created |
|
| 77 | - protected $uniqueIdGenerator=null; // dependency injections |
|
| 75 | + protected $rdf = null; //lazy created |
|
| 76 | + protected $tripleCount = 0; //lazy created |
|
| 77 | + protected $uniqueIdGenerator = null; // dependency injections |
|
| 78 | 78 | protected $droppedFields = array(); |
| 79 | 79 | |
| 80 | 80 | abstract public function asTurtle(); |
| 81 | 81 | |
| 82 | - protected function mergeOptions( array $options1, array $options2 ) |
|
| 82 | + protected function mergeOptions(array $options1, array $options2) |
|
| 83 | 83 | { |
| 84 | - foreach($options2 as $property=>$option){ |
|
| 84 | + foreach ($options2 as $property=>$option) { |
|
| 85 | 85 | |
| 86 | - $options1[$property]=isset($options1[$property]) |
|
| 87 | - ?array_merge($options1[$property], $option) |
|
| 86 | + $options1[$property] = isset($options1[$property]) |
|
| 87 | + ? array_merge($options1[$property], $option) |
|
| 88 | 88 | :$option; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -93,28 +93,28 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | public function __construct(array $data = array(), array $customOptions = array()) |
| 95 | 95 | { |
| 96 | - $options = $this->mergeOptions(self::$DEFAULT_OPTIONS,$customOptions); |
|
| 96 | + $options = $this->mergeOptions(self::$DEFAULT_OPTIONS, $customOptions); |
|
| 97 | 97 | |
| 98 | 98 | // set default values |
| 99 | - foreach( $options as $property=>$option){ |
|
| 100 | - if(empty($data[$property]) && isset($option['default'])){ |
|
| 99 | + foreach ($options as $property=>$option) { |
|
| 100 | + if (empty($data[$property]) && isset($option['default'])) { |
|
| 101 | 101 | $data[$property] = $option['default']; |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // ensure data are sanitized and validated |
| 106 | - $sanitizedData = array_filter( filter_var_array($data, $options)); |
|
| 106 | + $sanitizedData = array_filter(filter_var_array($data, $options)); |
|
| 107 | 107 | |
| 108 | 108 | // find and register dropped fields |
| 109 | - foreach($data as $property=>$value){ |
|
| 110 | - if($value && empty($sanitizedData[$property])){ |
|
| 111 | - $this->droppedFields[]=$property; |
|
| 109 | + foreach ($data as $property=>$value) { |
|
| 110 | + if ($value && empty($sanitizedData[$property])) { |
|
| 111 | + $this->droppedFields[] = $property; |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $this->options = $options; |
| 116 | 116 | $this->data = $sanitizedData; |
| 117 | - $this->setIdGenerator(function($data){return uniqid();}); |
|
| 117 | + $this->setIdGenerator(function($data) {return uniqid(); }); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function setIdGenerator($generator) |
| 131 | 131 | { |
| 132 | - assert( is_callable($generator)); |
|
| 132 | + assert(is_callable($generator)); |
|
| 133 | 133 | $this->uniqueIdGenerator = $generator; |
| 134 | 134 | |
| 135 | 135 | return $this; |
@@ -141,14 +141,14 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function getUri() |
| 143 | 143 | { |
| 144 | - if(!empty($this->data['uri'])){ |
|
| 145 | - $uri = $this->data['uri']; |
|
| 146 | - } elseif(!empty($this->data['base'])) { |
|
| 147 | - $idGenerator=$this->uniqueIdGenerator; |
|
| 144 | + if (!empty($this->data['uri'])) { |
|
| 145 | + $uri = $this->data['uri']; |
|
| 146 | + } elseif (!empty($this->data['base'])) { |
|
| 147 | + $idGenerator = $this->uniqueIdGenerator; |
|
| 148 | 148 | $uri = $this->data['base']; |
| 149 | - $uri.=empty($this->data['id'])?$idGenerator($this->data):$this->data['id']; |
|
| 150 | - } else{ |
|
| 151 | - $idGenerator=$this->uniqueIdGenerator; |
|
| 149 | + $uri .= empty($this->data['id']) ? $idGenerator($this->data) : $this->data['id']; |
|
| 150 | + } else { |
|
| 151 | + $idGenerator = $this->uniqueIdGenerator; |
|
| 152 | 152 | $uri = 'urn:local:botk:'.$idGenerator($this->data); |
| 153 | 153 | } |
| 154 | 154 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
| 177 | - public function setVocabulary($prefix,$ns) |
|
| 177 | + public function setVocabulary($prefix, $ns) |
|
| 178 | 178 | { |
| 179 | 179 | $this->vocabulary[$prefix] = $ns; |
| 180 | 180 | } |
@@ -186,11 +186,11 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
| 189 | - public function getTurtleHeader($base=null) |
|
| 189 | + public function getTurtleHeader($base = null) |
|
| 190 | 190 | { |
| 191 | - $header = empty($base)?'': "@base <$base> .\n"; |
|
| 192 | - foreach( $this->vocabulary as $prefix=>$ns ){ |
|
| 193 | - $header.="@prefix $prefix: <$ns> .\n"; |
|
| 191 | + $header = empty($base) ? '' : "@base <$base> .\n"; |
|
| 192 | + foreach ($this->vocabulary as $prefix=>$ns) { |
|
| 193 | + $header .= "@prefix $prefix: <$ns> .\n"; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | return $header; |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | public function getTripleCount() |
| 201 | 201 | { |
| 202 | 202 | // triple count is computed during rdf creation |
| 203 | - if (is_null($this->rdf)){ |
|
| 203 | + if (is_null($this->rdf)) { |
|
| 204 | 204 | $this->asTurtle(); |
| 205 | 205 | } |
| 206 | 206 | |
@@ -210,6 +210,6 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | public function __toString() |
| 212 | 212 | { |
| 213 | - return $this->getTurtleHeader() ."\n". $this->asTurtle(); |
|
| 213 | + return $this->getTurtleHeader()."\n".$this->asTurtle(); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | \ No newline at end of file |
@@ -3,85 +3,85 @@ |
||
| 3 | 3 | class FactsFactoryTest extends PHPUnit_Framework_TestCase |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - public function testMakeLocalBusiness() |
|
| 7 | - { |
|
| 8 | - $profile = array( |
|
| 9 | - 'model' => 'LocalBusiness', |
|
| 10 | - 'options' => array( |
|
| 11 | - 'base' => array( 'default'=> 'urn:test') |
|
| 12 | - ), |
|
| 13 | - 'datamapper' => function(array $rawdata){ |
|
| 14 | - $data = array(); |
|
| 15 | - $data['id'] = $rawdata[0]; |
|
| 16 | - $data['businessName'][] = $rawdata[2] . ' ' . $rawdata[1]; |
|
| 17 | - $data['businessName'][] = $rawdata[2]; |
|
| 18 | - $data['vatID'] = $rawdata[3]; |
|
| 19 | - $data['email'] = $rawdata[4]; |
|
| 20 | - $data['addressLocality'] = $rawdata[5]; |
|
| 21 | - $data['postalCode'] = $rawdata[7]; |
|
| 22 | - $data['addressRegion'] = $rawdata[8]; |
|
| 23 | - $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
|
| 24 | - $data['long'] = $rawdata[14]; |
|
| 25 | - $data['lat'] = $rawdata[15]; |
|
| 6 | + public function testMakeLocalBusiness() |
|
| 7 | + { |
|
| 8 | + $profile = array( |
|
| 9 | + 'model' => 'LocalBusiness', |
|
| 10 | + 'options' => array( |
|
| 11 | + 'base' => array( 'default'=> 'urn:test') |
|
| 12 | + ), |
|
| 13 | + 'datamapper' => function(array $rawdata){ |
|
| 14 | + $data = array(); |
|
| 15 | + $data['id'] = $rawdata[0]; |
|
| 16 | + $data['businessName'][] = $rawdata[2] . ' ' . $rawdata[1]; |
|
| 17 | + $data['businessName'][] = $rawdata[2]; |
|
| 18 | + $data['vatID'] = $rawdata[3]; |
|
| 19 | + $data['email'] = $rawdata[4]; |
|
| 20 | + $data['addressLocality'] = $rawdata[5]; |
|
| 21 | + $data['postalCode'] = $rawdata[7]; |
|
| 22 | + $data['addressRegion'] = $rawdata[8]; |
|
| 23 | + $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
|
| 24 | + $data['long'] = $rawdata[14]; |
|
| 25 | + $data['lat'] = $rawdata[15]; |
|
| 26 | 26 | |
| 27 | - return $data; |
|
| 28 | - }, |
|
| 29 | - ); |
|
| 30 | - $rawdata = array( |
|
| 31 | - '10042650', |
|
| 32 | - 'ERBORISTERIA I PRATI DI GIOVANNA MONAMI', |
|
| 33 | - '', |
|
| 34 | - '01209991007', |
|
| 35 | - '', |
|
| 36 | - 'ROMA', |
|
| 37 | - 'ROMA', |
|
| 38 | - '00195', |
|
| 39 | - 'RM', |
|
| 40 | - 'VIA', |
|
| 41 | - 'ANTONIO MORDINI', |
|
| 42 | - '3', |
|
| 43 | - '058091', |
|
| 44 | - '0580912017145', |
|
| 45 | - '12.464163', |
|
| 46 | - '41.914001' |
|
| 47 | - ); |
|
| 27 | + return $data; |
|
| 28 | + }, |
|
| 29 | + ); |
|
| 30 | + $rawdata = array( |
|
| 31 | + '10042650', |
|
| 32 | + 'ERBORISTERIA I PRATI DI GIOVANNA MONAMI', |
|
| 33 | + '', |
|
| 34 | + '01209991007', |
|
| 35 | + '', |
|
| 36 | + 'ROMA', |
|
| 37 | + 'ROMA', |
|
| 38 | + '00195', |
|
| 39 | + 'RM', |
|
| 40 | + 'VIA', |
|
| 41 | + 'ANTONIO MORDINI', |
|
| 42 | + '3', |
|
| 43 | + '058091', |
|
| 44 | + '0580912017145', |
|
| 45 | + '12.464163', |
|
| 46 | + '41.914001' |
|
| 47 | + ); |
|
| 48 | 48 | |
| 49 | - $factsFactory = new \BOTK\FactsFactory($profile); |
|
| 50 | - $facts = $factsFactory->factualize($rawdata); |
|
| 51 | - $structuredData = $facts->asArray(); |
|
| 49 | + $factsFactory = new \BOTK\FactsFactory($profile); |
|
| 50 | + $facts = $factsFactory->factualize($rawdata); |
|
| 51 | + $structuredData = $facts->asArray(); |
|
| 52 | 52 | |
| 53 | - $this->assertInstanceOf('\BOTK\Model\LocalBusiness', $facts); |
|
| 54 | - $this->assertEquals(1, count($structuredData['businessName'])); |
|
| 55 | - $this->assertEquals($structuredData['vatID'], '01209991007'); |
|
| 56 | - $this->assertEquals($structuredData['id'], '10042650'); |
|
| 57 | - $this->assertEquals($structuredData['long'], '12.464163'); |
|
| 58 | - $this->assertEquals($structuredData['streetAddress'], 'VIA ANTONIO MORDINI, 3'); |
|
| 59 | - } |
|
| 53 | + $this->assertInstanceOf('\BOTK\Model\LocalBusiness', $facts); |
|
| 54 | + $this->assertEquals(1, count($structuredData['businessName'])); |
|
| 55 | + $this->assertEquals($structuredData['vatID'], '01209991007'); |
|
| 56 | + $this->assertEquals($structuredData['id'], '10042650'); |
|
| 57 | + $this->assertEquals($structuredData['long'], '12.464163'); |
|
| 58 | + $this->assertEquals($structuredData['streetAddress'], 'VIA ANTONIO MORDINI, 3'); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function testRemoveEmpty() |
|
| 62 | - { |
|
| 63 | - $profile = array( |
|
| 64 | - 'model' => 'LocalBusiness', |
|
| 65 | - 'options' => array(), |
|
| 66 | - 'datamapper' => function(array $rawdata){return array();}, |
|
| 67 | - ); |
|
| 68 | - $data = array( |
|
| 69 | - 'one' => 'notempty', |
|
| 70 | - 'two' => null, |
|
| 71 | - 'three' => false, |
|
| 72 | - 'four' => 0, |
|
| 73 | - 'five' => array(), |
|
| 74 | - 'seven' => array(''), |
|
| 75 | - 'eight' => array('notempy'), |
|
| 76 | - 'nine' => array('notempy','',''), |
|
| 77 | - ); |
|
| 78 | - $expectedData = array( |
|
| 79 | - 'one' => 'notempty', |
|
| 80 | - 'eight' => array('notempy'), |
|
| 81 | - 'nine' => array('notempy'), |
|
| 82 | - ); |
|
| 83 | - $factsFactory = new \BOTK\FactsFactory($profile); |
|
| 84 | - $this->assertEquals($expectedData, $factsFactory->removeEmpty($data)); |
|
| 85 | - } |
|
| 61 | + public function testRemoveEmpty() |
|
| 62 | + { |
|
| 63 | + $profile = array( |
|
| 64 | + 'model' => 'LocalBusiness', |
|
| 65 | + 'options' => array(), |
|
| 66 | + 'datamapper' => function(array $rawdata){return array();}, |
|
| 67 | + ); |
|
| 68 | + $data = array( |
|
| 69 | + 'one' => 'notempty', |
|
| 70 | + 'two' => null, |
|
| 71 | + 'three' => false, |
|
| 72 | + 'four' => 0, |
|
| 73 | + 'five' => array(), |
|
| 74 | + 'seven' => array(''), |
|
| 75 | + 'eight' => array('notempy'), |
|
| 76 | + 'nine' => array('notempy','',''), |
|
| 77 | + ); |
|
| 78 | + $expectedData = array( |
|
| 79 | + 'one' => 'notempty', |
|
| 80 | + 'eight' => array('notempy'), |
|
| 81 | + 'nine' => array('notempy'), |
|
| 82 | + ); |
|
| 83 | + $factsFactory = new \BOTK\FactsFactory($profile); |
|
| 84 | + $this->assertEquals($expectedData, $factsFactory->removeEmpty($data)); |
|
| 85 | + } |
|
| 86 | 86 | } |
| 87 | 87 | |
@@ -8,19 +8,19 @@ discard block |
||
| 8 | 8 | $profile = array( |
| 9 | 9 | 'model' => 'LocalBusiness', |
| 10 | 10 | 'options' => array( |
| 11 | - 'base' => array( 'default'=> 'urn:test') |
|
| 11 | + 'base' => array('default'=> 'urn:test') |
|
| 12 | 12 | ), |
| 13 | - 'datamapper' => function(array $rawdata){ |
|
| 13 | + 'datamapper' => function(array $rawdata) { |
|
| 14 | 14 | $data = array(); |
| 15 | 15 | $data['id'] = $rawdata[0]; |
| 16 | - $data['businessName'][] = $rawdata[2] . ' ' . $rawdata[1]; |
|
| 16 | + $data['businessName'][] = $rawdata[2].' '.$rawdata[1]; |
|
| 17 | 17 | $data['businessName'][] = $rawdata[2]; |
| 18 | 18 | $data['vatID'] = $rawdata[3]; |
| 19 | 19 | $data['email'] = $rawdata[4]; |
| 20 | 20 | $data['addressLocality'] = $rawdata[5]; |
| 21 | 21 | $data['postalCode'] = $rawdata[7]; |
| 22 | 22 | $data['addressRegion'] = $rawdata[8]; |
| 23 | - $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
|
| 23 | + $data['streetAddress'] = $rawdata[9].' '.$rawdata[10].', '.$rawdata[11]; |
|
| 24 | 24 | $data['long'] = $rawdata[14]; |
| 25 | 25 | $data['lat'] = $rawdata[15]; |
| 26 | 26 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $profile = array( |
| 64 | 64 | 'model' => 'LocalBusiness', |
| 65 | 65 | 'options' => array(), |
| 66 | - 'datamapper' => function(array $rawdata){return array();}, |
|
| 66 | + 'datamapper' => function(array $rawdata) {return array(); }, |
|
| 67 | 67 | ); |
| 68 | 68 | $data = array( |
| 69 | 69 | 'one' => 'notempty', |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | 'five' => array(), |
| 74 | 74 | 'seven' => array(''), |
| 75 | 75 | 'eight' => array('notempy'), |
| 76 | - 'nine' => array('notempy','',''), |
|
| 76 | + 'nine' => array('notempy', '', ''), |
|
| 77 | 77 | ); |
| 78 | 78 | $expectedData = array( |
| 79 | 79 | 'one' => 'notempty', |
@@ -98,6 +98,9 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | + /** |
|
| 102 | + * @param string $error |
|
| 103 | + */ |
|
| 101 | 104 | public function addError($error) |
| 102 | 105 | { |
| 103 | 106 | $this->errors[]= (string) $error; |
@@ -3,125 +3,125 @@ |
||
| 3 | 3 | |
| 4 | 4 | class FactsFactory implements FactsFactoryInterface { |
| 5 | 5 | |
| 6 | - protected $profile; |
|
| 7 | - protected $tripleCount =0; |
|
| 8 | - protected $errors = array(); |
|
| 9 | - protected $errorCount=0; |
|
| 10 | - protected $unacceptableCount=0; |
|
| 11 | - protected $entityCount=0; |
|
| 12 | - |
|
| 13 | - |
|
| 14 | - public function __construct( array $profile ) |
|
| 15 | - { |
|
| 16 | - assert(!empty($profile['model']) && class_exists('\BOTK\Model\\'.$profile['model'])); |
|
| 17 | - assert(isset($profile['options']) && is_array($profile['options'])); |
|
| 18 | - $defaults = array( |
|
| 19 | - 'source' => null, |
|
| 20 | - 'resilience' => 0.3, |
|
| 21 | - 'datamapper' => function($rawdata){return array();}, |
|
| 22 | - 'rawDataValidationFilter' => function($rawdata){return is_array($rawdata);}, |
|
| 23 | - ); |
|
| 24 | - $this->profile = array_merge($defaults,$profile); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * two level filter array |
|
| 30 | - */ |
|
| 31 | - public function removeEmpty( array $data ) |
|
| 32 | - { |
|
| 33 | - $a = array(); |
|
| 34 | - foreach ($data as $key => $value) { |
|
| 35 | - $a[$key] = is_array($value)?array_filter($value):$value; |
|
| 36 | - } |
|
| 37 | - return array_filter($a); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - public function factualize( array $rawData ) |
|
| 42 | - { |
|
| 43 | - $datamapper = $this->profile['datamapper']; |
|
| 44 | - $class = '\BOTK\Model\\'.$this->profile['model']; |
|
| 45 | - $data =$this->removeEmpty($datamapper($rawData)); |
|
| 6 | + protected $profile; |
|
| 7 | + protected $tripleCount =0; |
|
| 8 | + protected $errors = array(); |
|
| 9 | + protected $errorCount=0; |
|
| 10 | + protected $unacceptableCount=0; |
|
| 11 | + protected $entityCount=0; |
|
| 12 | + |
|
| 13 | + |
|
| 14 | + public function __construct( array $profile ) |
|
| 15 | + { |
|
| 16 | + assert(!empty($profile['model']) && class_exists('\BOTK\Model\\'.$profile['model'])); |
|
| 17 | + assert(isset($profile['options']) && is_array($profile['options'])); |
|
| 18 | + $defaults = array( |
|
| 19 | + 'source' => null, |
|
| 20 | + 'resilience' => 0.3, |
|
| 21 | + 'datamapper' => function($rawdata){return array();}, |
|
| 22 | + 'rawDataValidationFilter' => function($rawdata){return is_array($rawdata);}, |
|
| 23 | + ); |
|
| 24 | + $this->profile = array_merge($defaults,$profile); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * two level filter array |
|
| 30 | + */ |
|
| 31 | + public function removeEmpty( array $data ) |
|
| 32 | + { |
|
| 33 | + $a = array(); |
|
| 34 | + foreach ($data as $key => $value) { |
|
| 35 | + $a[$key] = is_array($value)?array_filter($value):$value; |
|
| 36 | + } |
|
| 37 | + return array_filter($a); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + public function factualize( array $rawData ) |
|
| 42 | + { |
|
| 43 | + $datamapper = $this->profile['datamapper']; |
|
| 44 | + $class = '\BOTK\Model\\'.$this->profile['model']; |
|
| 45 | + $data =$this->removeEmpty($datamapper($rawData)); |
|
| 46 | 46 | |
| 47 | - $facts = new $class($data,$this->profile['options']); |
|
| 48 | - if($facts){ |
|
| 49 | - $this->entityCount++; |
|
| 50 | - $this->tripleCount+=$facts->getTripleCount(); |
|
| 51 | - } |
|
| 52 | - return $facts; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - public function generateLinkedDataHeader() |
|
| 57 | - { |
|
| 58 | - $class = '\BOTK\Model\\'.$this->profile['model']; |
|
| 59 | - $model = new $class(); |
|
| 60 | - return $model->getTurtleHeader(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - public function generateLinkedDataFooter() |
|
| 65 | - { |
|
| 66 | - $now = date('c'); |
|
| 67 | - $rdf = '<> '; |
|
| 68 | - $this->tripleCount += 6; |
|
| 47 | + $facts = new $class($data,$this->profile['options']); |
|
| 48 | + if($facts){ |
|
| 49 | + $this->entityCount++; |
|
| 50 | + $this->tripleCount+=$facts->getTripleCount(); |
|
| 51 | + } |
|
| 52 | + return $facts; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + public function generateLinkedDataHeader() |
|
| 57 | + { |
|
| 58 | + $class = '\BOTK\Model\\'.$this->profile['model']; |
|
| 59 | + $model = new $class(); |
|
| 60 | + return $model->getTurtleHeader(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + public function generateLinkedDataFooter() |
|
| 65 | + { |
|
| 66 | + $now = date('c'); |
|
| 67 | + $rdf = '<> '; |
|
| 68 | + $this->tripleCount += 6; |
|
| 69 | 69 | |
| 70 | - // add provenance info |
|
| 71 | - $verb=$this->tooManyErrors()?'invalidated':'generated'; |
|
| 72 | - $rdf .= "prov:{$verb}AtTime \"$now\"^^xsd:dateTime;"; |
|
| 73 | - if(empty($this->profile['source'])){ |
|
| 74 | - $rdf.= "prov:wasDerivedFrom <{$this->profile['source']}>;"; |
|
| 75 | - $this->tripleCount++; |
|
| 76 | - } |
|
| 70 | + // add provenance info |
|
| 71 | + $verb=$this->tooManyErrors()?'invalidated':'generated'; |
|
| 72 | + $rdf .= "prov:{$verb}AtTime \"$now\"^^xsd:dateTime;"; |
|
| 73 | + if(empty($this->profile['source'])){ |
|
| 74 | + $rdf.= "prov:wasDerivedFrom <{$this->profile['source']}>;"; |
|
| 75 | + $this->tripleCount++; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - // add dataset info |
|
| 79 | - $rdf.= "foaf:primaryTopic [a void:Dataset; void:datadump <>;void:triples {$this->tripleCount} ;void:entities {$this->entityCount}] ;."; |
|
| 78 | + // add dataset info |
|
| 79 | + $rdf.= "foaf:primaryTopic [a void:Dataset; void:datadump <>;void:triples {$this->tripleCount} ;void:entities {$this->entityCount}] ;."; |
|
| 80 | 80 | |
| 81 | - // add human readable comment |
|
| 82 | - $rdf.= "\n\n# File **$verb** with {$this->tripleCount} good triples from {$this->entityCount} entities ({$this->unacceptableCount} ignored), {$this->errorCount} errors\n"; |
|
| 81 | + // add human readable comment |
|
| 82 | + $rdf.= "\n\n# File **$verb** with {$this->tripleCount} good triples from {$this->entityCount} entities ({$this->unacceptableCount} ignored), {$this->errorCount} errors\n"; |
|
| 83 | 83 | |
| 84 | - return $rdf; |
|
| 85 | - } |
|
| 84 | + return $rdf; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - public function addToTripleCounter( $triplesCount) |
|
| 89 | - { |
|
| 90 | - $this->tripleCount += intval($triplesCount); |
|
| 91 | - return $this; |
|
| 92 | - } |
|
| 88 | + public function addToTripleCounter( $triplesCount) |
|
| 89 | + { |
|
| 90 | + $this->tripleCount += intval($triplesCount); |
|
| 91 | + return $this; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | - public function getTripleCount() |
|
| 96 | - { |
|
| 97 | - return $this->tripleCount; |
|
| 98 | - } |
|
| 95 | + public function getTripleCount() |
|
| 96 | + { |
|
| 97 | + return $this->tripleCount; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - public function addError($error) |
|
| 102 | - { |
|
| 103 | - $this->errors[]= (string) $error; |
|
| 104 | - $this->errorCount++; |
|
| 105 | - return $this; |
|
| 106 | - } |
|
| 101 | + public function addError($error) |
|
| 102 | + { |
|
| 103 | + $this->errors[]= (string) $error; |
|
| 104 | + $this->errorCount++; |
|
| 105 | + return $this; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | - public function tooManyErrors() |
|
| 110 | - { |
|
| 111 | - if( $this->entityCount < 100){ return false; } // if less than 100 entity do not check |
|
| 109 | + public function tooManyErrors() |
|
| 110 | + { |
|
| 111 | + if( $this->entityCount < 100){ return false; } // if less than 100 entity do not check |
|
| 112 | 112 | |
| 113 | - return ($this->errorCount/$this->entityCount) > $this->profile['resilience']; |
|
| 114 | - } |
|
| 113 | + return ($this->errorCount/$this->entityCount) > $this->profile['resilience']; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | - public function acceptable( $rawdata) |
|
| 118 | - { |
|
| 119 | - $rawValisdator = $this->profile['rawDataValidationFilter']; |
|
| 117 | + public function acceptable( $rawdata) |
|
| 118 | + { |
|
| 119 | + $rawValisdator = $this->profile['rawDataValidationFilter']; |
|
| 120 | 120 | |
| 121 | - if(!($valid = $rawValisdator($rawdata))){ |
|
| 122 | - $this->unacceptableCount++; |
|
| 123 | - } |
|
| 124 | - return $valid; |
|
| 125 | - } |
|
| 121 | + if(!($valid = $rawValisdator($rawdata))){ |
|
| 122 | + $this->unacceptableCount++; |
|
| 123 | + } |
|
| 124 | + return $valid; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | \ No newline at end of file |
@@ -4,50 +4,50 @@ discard block |
||
| 4 | 4 | class FactsFactory implements FactsFactoryInterface { |
| 5 | 5 | |
| 6 | 6 | protected $profile; |
| 7 | - protected $tripleCount =0; |
|
| 7 | + protected $tripleCount = 0; |
|
| 8 | 8 | protected $errors = array(); |
| 9 | - protected $errorCount=0; |
|
| 10 | - protected $unacceptableCount=0; |
|
| 11 | - protected $entityCount=0; |
|
| 9 | + protected $errorCount = 0; |
|
| 10 | + protected $unacceptableCount = 0; |
|
| 11 | + protected $entityCount = 0; |
|
| 12 | 12 | |
| 13 | 13 | |
| 14 | - public function __construct( array $profile ) |
|
| 14 | + public function __construct(array $profile) |
|
| 15 | 15 | { |
| 16 | 16 | assert(!empty($profile['model']) && class_exists('\BOTK\Model\\'.$profile['model'])); |
| 17 | 17 | assert(isset($profile['options']) && is_array($profile['options'])); |
| 18 | 18 | $defaults = array( |
| 19 | 19 | 'source' => null, |
| 20 | 20 | 'resilience' => 0.3, |
| 21 | - 'datamapper' => function($rawdata){return array();}, |
|
| 22 | - 'rawDataValidationFilter' => function($rawdata){return is_array($rawdata);}, |
|
| 21 | + 'datamapper' => function($rawdata) {return array(); }, |
|
| 22 | + 'rawDataValidationFilter' => function($rawdata) {return is_array($rawdata); }, |
|
| 23 | 23 | ); |
| 24 | - $this->profile = array_merge($defaults,$profile); |
|
| 24 | + $this->profile = array_merge($defaults, $profile); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * two level filter array |
| 30 | 30 | */ |
| 31 | - public function removeEmpty( array $data ) |
|
| 31 | + public function removeEmpty(array $data) |
|
| 32 | 32 | { |
| 33 | 33 | $a = array(); |
| 34 | 34 | foreach ($data as $key => $value) { |
| 35 | - $a[$key] = is_array($value)?array_filter($value):$value; |
|
| 35 | + $a[$key] = is_array($value) ? array_filter($value) : $value; |
|
| 36 | 36 | } |
| 37 | 37 | return array_filter($a); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
| 41 | - public function factualize( array $rawData ) |
|
| 41 | + public function factualize(array $rawData) |
|
| 42 | 42 | { |
| 43 | 43 | $datamapper = $this->profile['datamapper']; |
| 44 | 44 | $class = '\BOTK\Model\\'.$this->profile['model']; |
| 45 | - $data =$this->removeEmpty($datamapper($rawData)); |
|
| 45 | + $data = $this->removeEmpty($datamapper($rawData)); |
|
| 46 | 46 | |
| 47 | - $facts = new $class($data,$this->profile['options']); |
|
| 48 | - if($facts){ |
|
| 47 | + $facts = new $class($data, $this->profile['options']); |
|
| 48 | + if ($facts) { |
|
| 49 | 49 | $this->entityCount++; |
| 50 | - $this->tripleCount+=$facts->getTripleCount(); |
|
| 50 | + $this->tripleCount += $facts->getTripleCount(); |
|
| 51 | 51 | } |
| 52 | 52 | return $facts; |
| 53 | 53 | } |
@@ -68,24 +68,24 @@ discard block |
||
| 68 | 68 | $this->tripleCount += 6; |
| 69 | 69 | |
| 70 | 70 | // add provenance info |
| 71 | - $verb=$this->tooManyErrors()?'invalidated':'generated'; |
|
| 71 | + $verb = $this->tooManyErrors() ? 'invalidated' : 'generated'; |
|
| 72 | 72 | $rdf .= "prov:{$verb}AtTime \"$now\"^^xsd:dateTime;"; |
| 73 | - if(empty($this->profile['source'])){ |
|
| 74 | - $rdf.= "prov:wasDerivedFrom <{$this->profile['source']}>;"; |
|
| 73 | + if (empty($this->profile['source'])) { |
|
| 74 | + $rdf .= "prov:wasDerivedFrom <{$this->profile['source']}>;"; |
|
| 75 | 75 | $this->tripleCount++; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // add dataset info |
| 79 | - $rdf.= "foaf:primaryTopic [a void:Dataset; void:datadump <>;void:triples {$this->tripleCount} ;void:entities {$this->entityCount}] ;."; |
|
| 79 | + $rdf .= "foaf:primaryTopic [a void:Dataset; void:datadump <>;void:triples {$this->tripleCount} ;void:entities {$this->entityCount}] ;."; |
|
| 80 | 80 | |
| 81 | 81 | // add human readable comment |
| 82 | - $rdf.= "\n\n# File **$verb** with {$this->tripleCount} good triples from {$this->entityCount} entities ({$this->unacceptableCount} ignored), {$this->errorCount} errors\n"; |
|
| 82 | + $rdf .= "\n\n# File **$verb** with {$this->tripleCount} good triples from {$this->entityCount} entities ({$this->unacceptableCount} ignored), {$this->errorCount} errors\n"; |
|
| 83 | 83 | |
| 84 | 84 | return $rdf; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | |
| 88 | - public function addToTripleCounter( $triplesCount) |
|
| 88 | + public function addToTripleCounter($triplesCount) |
|
| 89 | 89 | { |
| 90 | 90 | $this->tripleCount += intval($triplesCount); |
| 91 | 91 | return $this; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | public function addError($error) |
| 102 | 102 | { |
| 103 | - $this->errors[]= (string) $error; |
|
| 103 | + $this->errors[] = (string) $error; |
|
| 104 | 104 | $this->errorCount++; |
| 105 | 105 | return $this; |
| 106 | 106 | } |
@@ -108,17 +108,17 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | public function tooManyErrors() |
| 110 | 110 | { |
| 111 | - if( $this->entityCount < 100){ return false; } // if less than 100 entity do not check |
|
| 111 | + if ($this->entityCount < 100) { return false; } // if less than 100 entity do not check |
|
| 112 | 112 | |
| 113 | - return ($this->errorCount/$this->entityCount) > $this->profile['resilience']; |
|
| 113 | + return ($this->errorCount / $this->entityCount) > $this->profile['resilience']; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
| 117 | - public function acceptable( $rawdata) |
|
| 117 | + public function acceptable($rawdata) |
|
| 118 | 118 | { |
| 119 | 119 | $rawValisdator = $this->profile['rawDataValidationFilter']; |
| 120 | 120 | |
| 121 | - if(!($valid = $rawValisdator($rawdata))){ |
|
| 121 | + if (!($valid = $rawValisdator($rawdata))) { |
|
| 122 | 122 | $this->unacceptableCount++; |
| 123 | 123 | } |
| 124 | 124 | return $valid; |
@@ -5,189 +5,189 @@ discard block |
||
| 5 | 5 | /** |
| 6 | 6 | * @dataProvider goodLocalBusiness |
| 7 | 7 | */ |
| 8 | - public function testConstructor($data, $expectedData) |
|
| 9 | - { |
|
| 10 | - $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 11 | - $this->assertEquals($expectedData, $localBusiness->asArray()); |
|
| 12 | - } |
|
| 13 | - public function goodLocalBusiness() |
|
| 8 | + public function testConstructor($data, $expectedData) |
|
| 14 | 9 | { |
| 15 | - return array( |
|
| 16 | - array( |
|
| 17 | - array(), |
|
| 18 | - array( |
|
| 19 | - 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 20 | - 'addressCountry' => 'IT', |
|
| 21 | - ), |
|
| 22 | - ), |
|
| 10 | + $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 11 | + $this->assertEquals($expectedData, $localBusiness->asArray()); |
|
| 12 | + } |
|
| 13 | + public function goodLocalBusiness() |
|
| 14 | + { |
|
| 15 | + return array( |
|
| 16 | + array( |
|
| 17 | + array(), |
|
| 18 | + array( |
|
| 19 | + 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 20 | + 'addressCountry' => 'IT', |
|
| 21 | + ), |
|
| 22 | + ), |
|
| 23 | 23 | |
| 24 | - array( |
|
| 25 | - array( |
|
| 26 | - 'base' => 'urn:a:', |
|
| 27 | - 'addressCountry' => 'US', |
|
| 28 | - ), |
|
| 29 | - array( |
|
| 30 | - 'base' => 'urn:a:', |
|
| 31 | - 'addressCountry' => 'US', |
|
| 32 | - ), |
|
| 33 | - ), |
|
| 24 | + array( |
|
| 25 | + array( |
|
| 26 | + 'base' => 'urn:a:', |
|
| 27 | + 'addressCountry' => 'US', |
|
| 28 | + ), |
|
| 29 | + array( |
|
| 30 | + 'base' => 'urn:a:', |
|
| 31 | + 'addressCountry' => 'US', |
|
| 32 | + ), |
|
| 33 | + ), |
|
| 34 | 34 | |
| 35 | - array( |
|
| 36 | - array( |
|
| 37 | - 'id' => '1234567890', |
|
| 38 | - 'taxID' => 'fgn nrc 63S0 6F205 A', |
|
| 39 | - 'vatID' => '01234567890', |
|
| 40 | - 'legalName' => 'Example srl', |
|
| 41 | - 'businessName' => 'Example', |
|
| 42 | - 'businessType' => 'schema:MedicalOrganization', |
|
| 43 | - 'addressCountry' => 'IT', |
|
| 44 | - 'addressLocality' => 'LECCO', |
|
| 45 | - 'addressRegion' => 'LC', |
|
| 46 | - 'streetAddress' => 'Via Fausto Valsecchi,124', |
|
| 47 | - 'postalCode' => '23900', |
|
| 48 | - 'page' => 'http://linkeddata.center/', |
|
| 49 | - 'telephone' => '+39 3356382949', |
|
| 50 | - 'faxNumber' => '+39 335 63 82 949', |
|
| 51 | - 'email' => array('[email protected]'), |
|
| 52 | - 'addressDescription'=> 'Via F. Valsecchi,124-23900 Lecco (LC)', |
|
| 53 | - 'lat' => '1.12345', |
|
| 54 | - 'long' => '2.123456', |
|
| 55 | - ), |
|
| 56 | - array( |
|
| 57 | - 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 58 | - 'id' => '1234567890', |
|
| 59 | - 'businessType' => array('schema:MedicalOrganization'), |
|
| 60 | - 'taxID' => 'FGNNRC63S06F205A', |
|
| 61 | - 'vatID' => '01234567890', |
|
| 62 | - 'legalName' => 'EXAMPLE SRL', |
|
| 63 | - 'businessName' => array('Example'), |
|
| 64 | - 'addressCountry' => 'IT', |
|
| 65 | - 'addressLocality' => 'LECCO', |
|
| 66 | - 'addressRegion' => 'LC', |
|
| 67 | - 'streetAddress' => 'VIA FAUSTO VALSECCHI, 124', |
|
| 68 | - 'postalCode' => '23900', |
|
| 69 | - 'page' => array('http://linkeddata.center/'), |
|
| 70 | - 'telephone' => '3356382949', |
|
| 71 | - 'faxNumber' => '3356382949', |
|
| 72 | - 'email' => array('[email protected]'), |
|
| 73 | - 'addressDescription'=> 'VIA F.VALSECCHI, 124 - 23900 LECCO (LC)', |
|
| 74 | - 'lat' => '1.12345', |
|
| 75 | - 'long' => '2.123456', |
|
| 76 | - ), |
|
| 77 | - ), |
|
| 78 | - ); |
|
| 79 | - } |
|
| 35 | + array( |
|
| 36 | + array( |
|
| 37 | + 'id' => '1234567890', |
|
| 38 | + 'taxID' => 'fgn nrc 63S0 6F205 A', |
|
| 39 | + 'vatID' => '01234567890', |
|
| 40 | + 'legalName' => 'Example srl', |
|
| 41 | + 'businessName' => 'Example', |
|
| 42 | + 'businessType' => 'schema:MedicalOrganization', |
|
| 43 | + 'addressCountry' => 'IT', |
|
| 44 | + 'addressLocality' => 'LECCO', |
|
| 45 | + 'addressRegion' => 'LC', |
|
| 46 | + 'streetAddress' => 'Via Fausto Valsecchi,124', |
|
| 47 | + 'postalCode' => '23900', |
|
| 48 | + 'page' => 'http://linkeddata.center/', |
|
| 49 | + 'telephone' => '+39 3356382949', |
|
| 50 | + 'faxNumber' => '+39 335 63 82 949', |
|
| 51 | + 'email' => array('[email protected]'), |
|
| 52 | + 'addressDescription'=> 'Via F. Valsecchi,124-23900 Lecco (LC)', |
|
| 53 | + 'lat' => '1.12345', |
|
| 54 | + 'long' => '2.123456', |
|
| 55 | + ), |
|
| 56 | + array( |
|
| 57 | + 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 58 | + 'id' => '1234567890', |
|
| 59 | + 'businessType' => array('schema:MedicalOrganization'), |
|
| 60 | + 'taxID' => 'FGNNRC63S06F205A', |
|
| 61 | + 'vatID' => '01234567890', |
|
| 62 | + 'legalName' => 'EXAMPLE SRL', |
|
| 63 | + 'businessName' => array('Example'), |
|
| 64 | + 'addressCountry' => 'IT', |
|
| 65 | + 'addressLocality' => 'LECCO', |
|
| 66 | + 'addressRegion' => 'LC', |
|
| 67 | + 'streetAddress' => 'VIA FAUSTO VALSECCHI, 124', |
|
| 68 | + 'postalCode' => '23900', |
|
| 69 | + 'page' => array('http://linkeddata.center/'), |
|
| 70 | + 'telephone' => '3356382949', |
|
| 71 | + 'faxNumber' => '3356382949', |
|
| 72 | + 'email' => array('[email protected]'), |
|
| 73 | + 'addressDescription'=> 'VIA F.VALSECCHI, 124 - 23900 LECCO (LC)', |
|
| 74 | + 'lat' => '1.12345', |
|
| 75 | + 'long' => '2.123456', |
|
| 76 | + ), |
|
| 77 | + ), |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - public function testGetDefaultOptions() |
|
| 83 | - { |
|
| 84 | - $expectedOptions = array ( |
|
| 85 | - 'uri' => array( |
|
| 86 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 87 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 88 | - ), |
|
| 89 | - 'base' => array( |
|
| 90 | - 'default' => 'http://linkeddata.center/botk/resource/', |
|
| 91 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 92 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 93 | - ), |
|
| 94 | - 'id' => array( |
|
| 95 | - 'filter' => FILTER_CALLBACK, |
|
| 96 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ID', |
|
| 97 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 98 | - ), |
|
| 99 | - 'page' => array( |
|
| 100 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 101 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 102 | - ), |
|
| 103 | - 'homepage' => array( |
|
| 104 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 105 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 106 | - ), |
|
| 107 | - 'businessType' => array( |
|
| 108 | - // additional types as extension of schema:LocalBusiness |
|
| 109 | - 'filter' => FILTER_DEFAULT, |
|
| 110 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 111 | - ), |
|
| 112 | - 'taxID' => array( |
|
| 113 | - 'filter' => FILTER_CALLBACK, |
|
| 114 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_TOKEN', |
|
| 115 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 116 | - ), |
|
| 117 | - 'vatID' => array( // italian rules |
|
| 118 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 119 | - 'options' => array('regexp'=>'/^[0-9]{11}$/'), |
|
| 120 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 121 | - ), |
|
| 122 | - 'legalName' => array( |
|
| 123 | - 'filter' => FILTER_CALLBACK, |
|
| 124 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 125 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 126 | - ), |
|
| 127 | - 'businessName' => array( |
|
| 128 | - // a schema:alternateName for schema:PostalAddress |
|
| 129 | - 'filter' => FILTER_DEFAULT, |
|
| 130 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 131 | - ), |
|
| 132 | - 'addressDescription'=> array( // |
|
| 133 | - 'filter' => FILTER_CALLBACK, |
|
| 134 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 135 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 136 | - ), |
|
| 137 | - 'addressCountry' => array( |
|
| 138 | - 'default' => 'IT', |
|
| 139 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 140 | - 'options' => array('regexp'=>'/^[A-Z]{2}$/'), |
|
| 141 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 142 | - ), |
|
| 143 | - 'addressLocality' => array( |
|
| 144 | - 'filter' => FILTER_CALLBACK, |
|
| 145 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 146 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 147 | - ), |
|
| 148 | - 'addressRegion' => array( |
|
| 149 | - 'filter' => FILTER_CALLBACK, |
|
| 150 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 151 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 152 | - ), |
|
| 153 | - 'streetAddress' => array( |
|
| 154 | - 'filter' => FILTER_CALLBACK, |
|
| 155 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 156 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 157 | - ), |
|
| 158 | - 'postalCode' => array( // italian rules |
|
| 159 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 160 | - 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 161 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 162 | - ), |
|
| 163 | - 'telephone' => array( |
|
| 164 | - 'filter' => FILTER_CALLBACK, |
|
| 165 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 166 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 167 | - ), |
|
| 168 | - 'faxNumber' => array( |
|
| 169 | - 'filter' => FILTER_CALLBACK, |
|
| 170 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 171 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 172 | - ), |
|
| 173 | - 'email' => array( |
|
| 174 | - 'filter' => FILTER_CALLBACK, |
|
| 175 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_EMAIL', |
|
| 176 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 177 | - ), |
|
| 178 | - 'lat' => array( |
|
| 179 | - 'filter' => FILTER_CALLBACK, |
|
| 180 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_GEO', |
|
| 181 | - ), |
|
| 182 | - 'long' => array( |
|
| 183 | - 'filter' => FILTER_CALLBACK, |
|
| 184 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_GEO', |
|
| 185 | - ), |
|
| 186 | - ); |
|
| 82 | + public function testGetDefaultOptions() |
|
| 83 | + { |
|
| 84 | + $expectedOptions = array ( |
|
| 85 | + 'uri' => array( |
|
| 86 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 87 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 88 | + ), |
|
| 89 | + 'base' => array( |
|
| 90 | + 'default' => 'http://linkeddata.center/botk/resource/', |
|
| 91 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 92 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 93 | + ), |
|
| 94 | + 'id' => array( |
|
| 95 | + 'filter' => FILTER_CALLBACK, |
|
| 96 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ID', |
|
| 97 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 98 | + ), |
|
| 99 | + 'page' => array( |
|
| 100 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 101 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 102 | + ), |
|
| 103 | + 'homepage' => array( |
|
| 104 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 105 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 106 | + ), |
|
| 107 | + 'businessType' => array( |
|
| 108 | + // additional types as extension of schema:LocalBusiness |
|
| 109 | + 'filter' => FILTER_DEFAULT, |
|
| 110 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 111 | + ), |
|
| 112 | + 'taxID' => array( |
|
| 113 | + 'filter' => FILTER_CALLBACK, |
|
| 114 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_TOKEN', |
|
| 115 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 116 | + ), |
|
| 117 | + 'vatID' => array( // italian rules |
|
| 118 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 119 | + 'options' => array('regexp'=>'/^[0-9]{11}$/'), |
|
| 120 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 121 | + ), |
|
| 122 | + 'legalName' => array( |
|
| 123 | + 'filter' => FILTER_CALLBACK, |
|
| 124 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 125 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 126 | + ), |
|
| 127 | + 'businessName' => array( |
|
| 128 | + // a schema:alternateName for schema:PostalAddress |
|
| 129 | + 'filter' => FILTER_DEFAULT, |
|
| 130 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 131 | + ), |
|
| 132 | + 'addressDescription'=> array( // |
|
| 133 | + 'filter' => FILTER_CALLBACK, |
|
| 134 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 135 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 136 | + ), |
|
| 137 | + 'addressCountry' => array( |
|
| 138 | + 'default' => 'IT', |
|
| 139 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 140 | + 'options' => array('regexp'=>'/^[A-Z]{2}$/'), |
|
| 141 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 142 | + ), |
|
| 143 | + 'addressLocality' => array( |
|
| 144 | + 'filter' => FILTER_CALLBACK, |
|
| 145 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 146 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 147 | + ), |
|
| 148 | + 'addressRegion' => array( |
|
| 149 | + 'filter' => FILTER_CALLBACK, |
|
| 150 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 151 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 152 | + ), |
|
| 153 | + 'streetAddress' => array( |
|
| 154 | + 'filter' => FILTER_CALLBACK, |
|
| 155 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 156 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 157 | + ), |
|
| 158 | + 'postalCode' => array( // italian rules |
|
| 159 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 160 | + 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 161 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 162 | + ), |
|
| 163 | + 'telephone' => array( |
|
| 164 | + 'filter' => FILTER_CALLBACK, |
|
| 165 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 166 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 167 | + ), |
|
| 168 | + 'faxNumber' => array( |
|
| 169 | + 'filter' => FILTER_CALLBACK, |
|
| 170 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 171 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 172 | + ), |
|
| 173 | + 'email' => array( |
|
| 174 | + 'filter' => FILTER_CALLBACK, |
|
| 175 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_EMAIL', |
|
| 176 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 177 | + ), |
|
| 178 | + 'lat' => array( |
|
| 179 | + 'filter' => FILTER_CALLBACK, |
|
| 180 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_GEO', |
|
| 181 | + ), |
|
| 182 | + 'long' => array( |
|
| 183 | + 'filter' => FILTER_CALLBACK, |
|
| 184 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_GEO', |
|
| 185 | + ), |
|
| 186 | + ); |
|
| 187 | 187 | |
| 188 | - $localBusiness = new BOTK\Model\LocalBusiness(array()); |
|
| 189 | - $this->assertEquals($expectedOptions, $localBusiness->getOptions()); |
|
| 190 | - } |
|
| 188 | + $localBusiness = new BOTK\Model\LocalBusiness(array()); |
|
| 189 | + $this->assertEquals($expectedOptions, $localBusiness->getOptions()); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | |
| 193 | 193 | |
@@ -195,120 +195,120 @@ discard block |
||
| 195 | 195 | /** |
| 196 | 196 | * @dataProvider goodRdf |
| 197 | 197 | */ |
| 198 | - public function testRdfGeneration($data, $rdf, $tripleCount) |
|
| 199 | - { |
|
| 200 | - $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 201 | - $this->assertEquals($rdf, $localBusiness->asTurtle()); |
|
| 202 | - $this->assertEquals($tripleCount, $localBusiness->getTripleCount()); |
|
| 203 | - } |
|
| 204 | - public function goodRdf() |
|
| 198 | + public function testRdfGeneration($data, $rdf, $tripleCount) |
|
| 199 | + { |
|
| 200 | + $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 201 | + $this->assertEquals($rdf, $localBusiness->asTurtle()); |
|
| 202 | + $this->assertEquals($tripleCount, $localBusiness->getTripleCount()); |
|
| 203 | + } |
|
| 204 | + public function goodRdf() |
|
| 205 | 205 | { |
| 206 | - return array( |
|
| 207 | - array( |
|
| 208 | - array('uri'=>'urn:test:a'), |
|
| 209 | - '<urn:test:a> a schema:LocalBusiness;schema:address <urn:test:a_address>. <urn:test:a_address> a schema:PostalAddress;schema:addressCountry "IT". ', |
|
| 210 | - 4, |
|
| 211 | - ), |
|
| 212 | - array( |
|
| 213 | - array( |
|
| 214 | - 'base' => 'urn:test:', |
|
| 215 | - 'id' => 'b', |
|
| 216 | - 'vatID' => '01234567890', |
|
| 217 | - 'legalName' => 'Calenda chiodi snc', |
|
| 218 | - ), |
|
| 219 | - '<urn:test:b> a schema:LocalBusiness;dct:identifier "b";schema:vatID "01234567890";schema:legalName "CALENDA CHIODI SNC";schema:address <urn:test:b_address>. <urn:test:b_address> a schema:PostalAddress;schema:addressCountry "IT". ', |
|
| 220 | - 7, |
|
| 221 | - ), |
|
| 206 | + return array( |
|
| 207 | + array( |
|
| 208 | + array('uri'=>'urn:test:a'), |
|
| 209 | + '<urn:test:a> a schema:LocalBusiness;schema:address <urn:test:a_address>. <urn:test:a_address> a schema:PostalAddress;schema:addressCountry "IT". ', |
|
| 210 | + 4, |
|
| 211 | + ), |
|
| 212 | + array( |
|
| 213 | + array( |
|
| 214 | + 'base' => 'urn:test:', |
|
| 215 | + 'id' => 'b', |
|
| 216 | + 'vatID' => '01234567890', |
|
| 217 | + 'legalName' => 'Calenda chiodi snc', |
|
| 218 | + ), |
|
| 219 | + '<urn:test:b> a schema:LocalBusiness;dct:identifier "b";schema:vatID "01234567890";schema:legalName "CALENDA CHIODI SNC";schema:address <urn:test:b_address>. <urn:test:b_address> a schema:PostalAddress;schema:addressCountry "IT". ', |
|
| 220 | + 7, |
|
| 221 | + ), |
|
| 222 | 222 | |
| 223 | - array( |
|
| 224 | - array( |
|
| 225 | - 'id' => '1234567890', |
|
| 226 | - 'taxID' => 'fgn nrc 63S0 6F205 A', |
|
| 227 | - 'vatID' => '01234567890', |
|
| 228 | - 'legalName' => 'Example srl', |
|
| 229 | - 'businessName' => 'Example', |
|
| 230 | - 'businessType' => 'schema:MedicalOrganization', |
|
| 231 | - 'addressCountry' => 'IT', |
|
| 232 | - 'addressLocality' => 'LECCO', |
|
| 233 | - 'addressRegion' => 'LC', |
|
| 234 | - 'streetAddress' => 'Via Fausto Valsecchi,124', |
|
| 235 | - 'postalCode' => '23900', |
|
| 236 | - 'page' => 'http://linkeddata.center/', |
|
| 237 | - 'telephone' => '+39 3356382949', |
|
| 238 | - 'faxNumber' => '+39 335 63 82 949', |
|
| 239 | - 'email' => array('[email protected]'), |
|
| 240 | - 'mailbox' => '[email protected]', |
|
| 241 | - 'addressDescription'=> 'Via F. Valsecchi,124-23900 Lecco (LC)', |
|
| 242 | - 'lat' => '1.12345', |
|
| 243 | - 'long' => '2.123456', |
|
| 244 | - ), |
|
| 245 | - '<http://linkeddata.center/botk/resource/1234567890> a schema:LocalBusiness;a schema:MedicalOrganization;dct:identifier "1234567890";schema:vatID "01234567890";schema:legalName "EXAMPLE SRL";schema:alternateName "Example";schema:telephone "3356382949";schema:faxNumber "3356382949";schema:page <http://linkeddata.center/>;schema:email "[email protected]";schema:geo <geo:1.12345,2.123456>;schema:address <http://linkeddata.center/botk/resource/1234567890_address>. <http://linkeddata.center/botk/resource/1234567890_address> a schema:PostalAddress;schema:description "VIA F.VALSECCHI, 124 - 23900 LECCO (LC)";schema:streetAddress "VIA FAUSTO VALSECCHI, 124";schema:postalCode "23900";schema:addressLocality "LECCO";schema:addressRegion "LC";schema:addressCountry "IT". <geo:1.12345,2.123456> a schema:GeoCoordinates;wgs:lat "1.12345"^^xsd:float;wgs:long "2.123456"^^xsd:float . ', |
|
| 246 | - 22, |
|
| 247 | - ), |
|
| 248 | - ); |
|
| 249 | - } |
|
| 223 | + array( |
|
| 224 | + array( |
|
| 225 | + 'id' => '1234567890', |
|
| 226 | + 'taxID' => 'fgn nrc 63S0 6F205 A', |
|
| 227 | + 'vatID' => '01234567890', |
|
| 228 | + 'legalName' => 'Example srl', |
|
| 229 | + 'businessName' => 'Example', |
|
| 230 | + 'businessType' => 'schema:MedicalOrganization', |
|
| 231 | + 'addressCountry' => 'IT', |
|
| 232 | + 'addressLocality' => 'LECCO', |
|
| 233 | + 'addressRegion' => 'LC', |
|
| 234 | + 'streetAddress' => 'Via Fausto Valsecchi,124', |
|
| 235 | + 'postalCode' => '23900', |
|
| 236 | + 'page' => 'http://linkeddata.center/', |
|
| 237 | + 'telephone' => '+39 3356382949', |
|
| 238 | + 'faxNumber' => '+39 335 63 82 949', |
|
| 239 | + 'email' => array('[email protected]'), |
|
| 240 | + 'mailbox' => '[email protected]', |
|
| 241 | + 'addressDescription'=> 'Via F. Valsecchi,124-23900 Lecco (LC)', |
|
| 242 | + 'lat' => '1.12345', |
|
| 243 | + 'long' => '2.123456', |
|
| 244 | + ), |
|
| 245 | + '<http://linkeddata.center/botk/resource/1234567890> a schema:LocalBusiness;a schema:MedicalOrganization;dct:identifier "1234567890";schema:vatID "01234567890";schema:legalName "EXAMPLE SRL";schema:alternateName "Example";schema:telephone "3356382949";schema:faxNumber "3356382949";schema:page <http://linkeddata.center/>;schema:email "[email protected]";schema:geo <geo:1.12345,2.123456>;schema:address <http://linkeddata.center/botk/resource/1234567890_address>. <http://linkeddata.center/botk/resource/1234567890_address> a schema:PostalAddress;schema:description "VIA F.VALSECCHI, 124 - 23900 LECCO (LC)";schema:streetAddress "VIA FAUSTO VALSECCHI, 124";schema:postalCode "23900";schema:addressLocality "LECCO";schema:addressRegion "LC";schema:addressCountry "IT". <geo:1.12345,2.123456> a schema:GeoCoordinates;wgs:lat "1.12345"^^xsd:float;wgs:long "2.123456"^^xsd:float . ', |
|
| 246 | + 22, |
|
| 247 | + ), |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | 251 | |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | 254 | * @dataProvider structuredAdresses |
| 255 | 255 | */ |
| 256 | - public function testBuildNormalizedAddress($rawdata, $expectedData) |
|
| 257 | - { |
|
| 258 | - $localBusiness = new BOTK\Model\LocalBusiness($rawdata); |
|
| 259 | - $data=$localBusiness->asArray(); |
|
| 260 | - $this->assertEquals($expectedData, $data['addressDescription']); |
|
| 261 | - } |
|
| 262 | - public function structuredAdresses() |
|
| 256 | + public function testBuildNormalizedAddress($rawdata, $expectedData) |
|
| 263 | 257 | { |
| 264 | - return array( |
|
| 265 | - array( |
|
| 266 | - array( |
|
| 267 | - 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 268 | - 'addressLocality' => 'Lecco', |
|
| 269 | - 'addressRegion' => 'LC', |
|
| 270 | - 'addressCountry' => 'IT', |
|
| 271 | - 'postalCode' => '23900', |
|
| 272 | - ), |
|
| 273 | - 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO (LC)' |
|
| 274 | - ), |
|
| 275 | - array( |
|
| 276 | - array( |
|
| 277 | - 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 278 | - 'addressLocality' => 'Lecco', |
|
| 279 | - 'addressCountry' => 'IT', |
|
| 280 | - ), |
|
| 281 | - 'LUNGOLARIO LUIGI CADORNA, 1, LECCO' |
|
| 282 | - ), |
|
| 283 | - array( |
|
| 284 | - array( |
|
| 285 | - 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 286 | - 'addressCountry' => 'IT', |
|
| 287 | - 'postalCode' => '23900', |
|
| 288 | - ), |
|
| 289 | - 'LUNGOLARIO LUIGI CADORNA, 1, 23900' |
|
| 290 | - ), |
|
| 291 | - array( |
|
| 292 | - array( |
|
| 293 | - 'addressDescription' => 'test address', |
|
| 294 | - ), |
|
| 295 | - 'TEST ADDRESS' |
|
| 296 | - ), |
|
| 297 | - ); |
|
| 298 | - } |
|
| 258 | + $localBusiness = new BOTK\Model\LocalBusiness($rawdata); |
|
| 259 | + $data=$localBusiness->asArray(); |
|
| 260 | + $this->assertEquals($expectedData, $data['addressDescription']); |
|
| 261 | + } |
|
| 262 | + public function structuredAdresses() |
|
| 263 | + { |
|
| 264 | + return array( |
|
| 265 | + array( |
|
| 266 | + array( |
|
| 267 | + 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 268 | + 'addressLocality' => 'Lecco', |
|
| 269 | + 'addressRegion' => 'LC', |
|
| 270 | + 'addressCountry' => 'IT', |
|
| 271 | + 'postalCode' => '23900', |
|
| 272 | + ), |
|
| 273 | + 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO (LC)' |
|
| 274 | + ), |
|
| 275 | + array( |
|
| 276 | + array( |
|
| 277 | + 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 278 | + 'addressLocality' => 'Lecco', |
|
| 279 | + 'addressCountry' => 'IT', |
|
| 280 | + ), |
|
| 281 | + 'LUNGOLARIO LUIGI CADORNA, 1, LECCO' |
|
| 282 | + ), |
|
| 283 | + array( |
|
| 284 | + array( |
|
| 285 | + 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 286 | + 'addressCountry' => 'IT', |
|
| 287 | + 'postalCode' => '23900', |
|
| 288 | + ), |
|
| 289 | + 'LUNGOLARIO LUIGI CADORNA, 1, 23900' |
|
| 290 | + ), |
|
| 291 | + array( |
|
| 292 | + array( |
|
| 293 | + 'addressDescription' => 'test address', |
|
| 294 | + ), |
|
| 295 | + 'TEST ADDRESS' |
|
| 296 | + ), |
|
| 297 | + ); |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | 300 | |
| 301 | 301 | public function testBadLocalBusiness() |
| 302 | - { |
|
| 303 | - $badData = array( |
|
| 304 | - 'vatID' => 'not a vat', |
|
| 305 | - 'addressCountry' => 'ITALY', // should be a two character ISO country code |
|
| 306 | - 'postalCode' => '234992', // too long |
|
| 307 | - 'email' => 'not an e mail', |
|
| 308 | - ); |
|
| 309 | - $localBusiness = new BOTK\Model\LocalBusiness($badData); |
|
| 310 | - $this->assertEquals(array_keys($badData), $localBusiness->getDroppedFields()); |
|
| 311 | - } |
|
| 302 | + { |
|
| 303 | + $badData = array( |
|
| 304 | + 'vatID' => 'not a vat', |
|
| 305 | + 'addressCountry' => 'ITALY', // should be a two character ISO country code |
|
| 306 | + 'postalCode' => '234992', // too long |
|
| 307 | + 'email' => 'not an e mail', |
|
| 308 | + ); |
|
| 309 | + $localBusiness = new BOTK\Model\LocalBusiness($badData); |
|
| 310 | + $this->assertEquals(array_keys($badData), $localBusiness->getDroppedFields()); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | 313 | } |
| 314 | 314 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | public function testGetDefaultOptions() |
| 83 | 83 | { |
| 84 | - $expectedOptions = array ( |
|
| 84 | + $expectedOptions = array( |
|
| 85 | 85 | 'uri' => array( |
| 86 | 86 | 'filter' => FILTER_SANITIZE_URL, |
| 87 | 87 | 'flags' => FILTER_REQUIRE_SCALAR, |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | public function testBuildNormalizedAddress($rawdata, $expectedData) |
| 257 | 257 | { |
| 258 | 258 | $localBusiness = new BOTK\Model\LocalBusiness($rawdata); |
| 259 | - $data=$localBusiness->asArray(); |
|
| 259 | + $data = $localBusiness->asArray(); |
|
| 260 | 260 | $this->assertEquals($expectedData, $data['addressDescription']); |
| 261 | 261 | } |
| 262 | 262 | public function structuredAdresses() |
@@ -302,8 +302,8 @@ discard block |
||
| 302 | 302 | { |
| 303 | 303 | $badData = array( |
| 304 | 304 | 'vatID' => 'not a vat', |
| 305 | - 'addressCountry' => 'ITALY', // should be a two character ISO country code |
|
| 306 | - 'postalCode' => '234992', // too long |
|
| 305 | + 'addressCountry' => 'ITALY', // should be a two character ISO country code |
|
| 306 | + 'postalCode' => '234992', // too long |
|
| 307 | 307 | 'email' => 'not an e mail', |
| 308 | 308 | ); |
| 309 | 309 | $localBusiness = new BOTK\Model\LocalBusiness($badData); |
@@ -2,147 +2,147 @@ |
||
| 2 | 2 | |
| 3 | 3 | class DummyModel extends BOTK\Model\AbstractModel |
| 4 | 4 | { |
| 5 | - public function asTurtle() { return '<urn:a:b> owl:sameAs <urn:a:b> .';} |
|
| 5 | + public function asTurtle() { return '<urn:a:b> owl:sameAs <urn:a:b> .';} |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | class AbstractModelTest extends PHPUnit_Framework_TestCase |
| 9 | 9 | { |
| 10 | - protected $vocabulary = array( |
|
| 11 | - 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
|
| 12 | - 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
|
| 13 | - 'owl' => 'http://www.w3.org/2002/07/owl#', |
|
| 14 | - 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 15 | - 'dct' => 'http://purl.org/dc/terms/', |
|
| 16 | - 'void' => 'http://rdfs.org/ns/void#', |
|
| 17 | - 'prov' => 'http://www.w3.org/ns/prov#', |
|
| 18 | - 'schema' => 'http://schema.org/', |
|
| 19 | - 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 20 | - 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 21 | - 'dq' => 'http://purl.org/linked-data/cube#', |
|
| 22 | - 'daq' => 'http://purl.org/eis/vocab/daq#', |
|
| 23 | - 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 24 | - ); |
|
| 10 | + protected $vocabulary = array( |
|
| 11 | + 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
|
| 12 | + 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
|
| 13 | + 'owl' => 'http://www.w3.org/2002/07/owl#', |
|
| 14 | + 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 15 | + 'dct' => 'http://purl.org/dc/terms/', |
|
| 16 | + 'void' => 'http://rdfs.org/ns/void#', |
|
| 17 | + 'prov' => 'http://www.w3.org/ns/prov#', |
|
| 18 | + 'schema' => 'http://schema.org/', |
|
| 19 | + 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 20 | + 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 21 | + 'dq' => 'http://purl.org/linked-data/cube#', |
|
| 22 | + 'daq' => 'http://purl.org/eis/vocab/daq#', |
|
| 23 | + 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 24 | + ); |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @dataProvider data |
| 29 | 29 | */ |
| 30 | - public function testConstructor($data, $expectedData) |
|
| 31 | - { |
|
| 32 | - $localBusiness = new DummyModel($data); |
|
| 33 | - $this->assertEquals($expectedData, $localBusiness->asArray()); |
|
| 34 | - } |
|
| 35 | - public function data() |
|
| 30 | + public function testConstructor($data, $expectedData) |
|
| 36 | 31 | { |
| 37 | - return array( |
|
| 38 | - array( array(), array('base'=> 'http://linkeddata.center/botk/resource/'),), |
|
| 39 | - array( array('base' => 'urn:a:','id'=>'x'), array('base'=> 'urn:a:','id'=>'x')), |
|
| 40 | - ); |
|
| 41 | - } |
|
| 32 | + $localBusiness = new DummyModel($data); |
|
| 33 | + $this->assertEquals($expectedData, $localBusiness->asArray()); |
|
| 34 | + } |
|
| 35 | + public function data() |
|
| 36 | + { |
|
| 37 | + return array( |
|
| 38 | + array( array(), array('base'=> 'http://linkeddata.center/botk/resource/'),), |
|
| 39 | + array( array('base' => 'urn:a:','id'=>'x'), array('base'=> 'urn:a:','id'=>'x')), |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - public function testConstructorWithCustomOptions() |
|
| 45 | - { |
|
| 46 | - $localBusiness = new DummyModel(array(), array ( |
|
| 47 | - 'base' => array('default' => 'urn:a:'), |
|
| 48 | - 'lang' => array('default' => 'en'), |
|
| 49 | - )); |
|
| 50 | - $options = $localBusiness->getOptions(); |
|
| 51 | - $this->assertEquals( |
|
| 52 | - array( |
|
| 53 | - 'default' => 'urn:a:', |
|
| 54 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 55 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 56 | - ), |
|
| 57 | - $options['base'] |
|
| 58 | - ); |
|
| 59 | - $this->assertEquals(array('default' => 'en'),$options['lang']); |
|
| 60 | - } |
|
| 44 | + public function testConstructorWithCustomOptions() |
|
| 45 | + { |
|
| 46 | + $localBusiness = new DummyModel(array(), array ( |
|
| 47 | + 'base' => array('default' => 'urn:a:'), |
|
| 48 | + 'lang' => array('default' => 'en'), |
|
| 49 | + )); |
|
| 50 | + $options = $localBusiness->getOptions(); |
|
| 51 | + $this->assertEquals( |
|
| 52 | + array( |
|
| 53 | + 'default' => 'urn:a:', |
|
| 54 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 55 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 56 | + ), |
|
| 57 | + $options['base'] |
|
| 58 | + ); |
|
| 59 | + $this->assertEquals(array('default' => 'en'),$options['lang']); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - public function testgetVocabularies() |
|
| 64 | - { |
|
| 65 | - $obj = new DummyModel(array()); |
|
| 63 | + public function testgetVocabularies() |
|
| 64 | + { |
|
| 65 | + $obj = new DummyModel(array()); |
|
| 66 | 66 | |
| 67 | - $this->assertEquals($this->vocabulary, $obj->getVocabularies()); |
|
| 68 | - } |
|
| 67 | + $this->assertEquals($this->vocabulary, $obj->getVocabularies()); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | - public function testSetVocabulary() |
|
| 72 | - { |
|
| 73 | - $vocabulary = $this->vocabulary; |
|
| 74 | - $vocabulary['my'] = 'urn:test:'; |
|
| 71 | + public function testSetVocabulary() |
|
| 72 | + { |
|
| 73 | + $vocabulary = $this->vocabulary; |
|
| 74 | + $vocabulary['my'] = 'urn:test:'; |
|
| 75 | 75 | |
| 76 | - $obj = new DummyModel(array()); |
|
| 77 | - $obj->setVocabulary('my','urn:test:'); |
|
| 76 | + $obj = new DummyModel(array()); |
|
| 77 | + $obj->setVocabulary('my','urn:test:'); |
|
| 78 | 78 | |
| 79 | - $this->assertEquals($vocabulary, $obj->getVocabularies()); |
|
| 80 | - } |
|
| 79 | + $this->assertEquals($vocabulary, $obj->getVocabularies()); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | |
| 83 | - public function testUnsetVocabulary() |
|
| 84 | - { |
|
| 85 | - $vocabulary = $this->vocabulary; |
|
| 86 | - unset($vocabulary['foaf']); |
|
| 83 | + public function testUnsetVocabulary() |
|
| 84 | + { |
|
| 85 | + $vocabulary = $this->vocabulary; |
|
| 86 | + unset($vocabulary['foaf']); |
|
| 87 | 87 | |
| 88 | - $obj = new DummyModel(array()); |
|
| 89 | - $obj->unsetVocabulary('foaf'); |
|
| 88 | + $obj = new DummyModel(array()); |
|
| 89 | + $obj->unsetVocabulary('foaf'); |
|
| 90 | 90 | |
| 91 | - $this->assertEquals($vocabulary, $obj->getVocabularies()); |
|
| 92 | - } |
|
| 91 | + $this->assertEquals($vocabulary, $obj->getVocabularies()); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * @dataProvider uris |
| 97 | 97 | */ |
| 98 | - public function testGetUri($data, $expectedData) |
|
| 99 | - { |
|
| 100 | - $obj = new DummyModel($data); |
|
| 101 | - $obj->setIdGenerator(function($d){return'abc';}); |
|
| 102 | - $this->assertEquals($expectedData, $obj->getUri()); |
|
| 103 | - } |
|
| 104 | - public function uris() |
|
| 98 | + public function testGetUri($data, $expectedData) |
|
| 99 | + { |
|
| 100 | + $obj = new DummyModel($data); |
|
| 101 | + $obj->setIdGenerator(function($d){return'abc';}); |
|
| 102 | + $this->assertEquals($expectedData, $obj->getUri()); |
|
| 103 | + } |
|
| 104 | + public function uris() |
|
| 105 | 105 | { |
| 106 | - return array( |
|
| 107 | - array( array(), 'http://linkeddata.center/botk/resource/abc'), |
|
| 108 | - array( array('base'=>'http://example.com/resource/'), 'http://example.com/resource/abc'), |
|
| 109 | - array( array('base'=>'http://example.com/resource/', 'id'=>'efg'), 'http://example.com/resource/efg'), |
|
| 110 | - array( array('uri'=>'http://example.com/resource/ijk'), 'http://example.com/resource/ijk'), |
|
| 111 | - ); |
|
| 112 | - } |
|
| 106 | + return array( |
|
| 107 | + array( array(), 'http://linkeddata.center/botk/resource/abc'), |
|
| 108 | + array( array('base'=>'http://example.com/resource/'), 'http://example.com/resource/abc'), |
|
| 109 | + array( array('base'=>'http://example.com/resource/', 'id'=>'efg'), 'http://example.com/resource/efg'), |
|
| 110 | + array( array('uri'=>'http://example.com/resource/ijk'), 'http://example.com/resource/ijk'), |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - public function testTurtleHeader() |
|
| 115 | - { |
|
| 116 | - $obj = new DummyModel(array()); |
|
| 117 | - $s =""; |
|
| 118 | - foreach( $this->vocabulary as $p=>$v){ |
|
| 119 | - $s.= "@prefix $p: <$v> .\n"; |
|
| 120 | - } |
|
| 114 | + public function testTurtleHeader() |
|
| 115 | + { |
|
| 116 | + $obj = new DummyModel(array()); |
|
| 117 | + $s =""; |
|
| 118 | + foreach( $this->vocabulary as $p=>$v){ |
|
| 119 | + $s.= "@prefix $p: <$v> .\n"; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $this->assertEquals($s, $obj->getTurtleHeader()); |
|
| 123 | - } |
|
| 122 | + $this->assertEquals($s, $obj->getTurtleHeader()); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | |
| 126 | - public function testTurtleHeaderWithBase() |
|
| 127 | - { |
|
| 128 | - $obj = new DummyModel(array()); |
|
| 129 | - $s ="@base <urn:a:b> .\n"; |
|
| 130 | - foreach( $this->vocabulary as $p=>$v){ |
|
| 131 | - $s.= "@prefix $p: <$v> .\n"; |
|
| 132 | - } |
|
| 126 | + public function testTurtleHeaderWithBase() |
|
| 127 | + { |
|
| 128 | + $obj = new DummyModel(array()); |
|
| 129 | + $s ="@base <urn:a:b> .\n"; |
|
| 130 | + foreach( $this->vocabulary as $p=>$v){ |
|
| 131 | + $s.= "@prefix $p: <$v> .\n"; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - $this->assertEquals($s, $obj->getTurtleHeader('urn:a:b')); |
|
| 135 | - } |
|
| 134 | + $this->assertEquals($s, $obj->getTurtleHeader('urn:a:b')); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | 137 | |
| 138 | 138 | |
| 139 | - public function testAsString() |
|
| 140 | - { |
|
| 141 | - $obj = new DummyModel(array()); |
|
| 142 | - $s= $obj->getTurtleHeader() ."\n<urn:a:b> owl:sameAs <urn:a:b> ."; |
|
| 139 | + public function testAsString() |
|
| 140 | + { |
|
| 141 | + $obj = new DummyModel(array()); |
|
| 142 | + $s= $obj->getTurtleHeader() ."\n<urn:a:b> owl:sameAs <urn:a:b> ."; |
|
| 143 | 143 | |
| 144 | - $this->assertEquals($s, (string)$obj); |
|
| 145 | - } |
|
| 144 | + $this->assertEquals($s, (string)$obj); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | 147 | } |
| 148 | 148 | |
@@ -2,12 +2,12 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class DummyModel extends BOTK\Model\AbstractModel |
| 4 | 4 | { |
| 5 | - public function asTurtle() { return '<urn:a:b> owl:sameAs <urn:a:b> .';} |
|
| 5 | + public function asTurtle() { return '<urn:a:b> owl:sameAs <urn:a:b> .'; } |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | class AbstractModelTest extends PHPUnit_Framework_TestCase |
| 9 | 9 | { |
| 10 | - protected $vocabulary = array( |
|
| 10 | + protected $vocabulary = array( |
|
| 11 | 11 | 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
| 12 | 12 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
| 13 | 13 | 'owl' => 'http://www.w3.org/2002/07/owl#', |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | public function data() |
| 36 | 36 | { |
| 37 | 37 | return array( |
| 38 | - array( array(), array('base'=> 'http://linkeddata.center/botk/resource/'),), |
|
| 39 | - array( array('base' => 'urn:a:','id'=>'x'), array('base'=> 'urn:a:','id'=>'x')), |
|
| 38 | + array(array(), array('base'=> 'http://linkeddata.center/botk/resource/'),), |
|
| 39 | + array(array('base' => 'urn:a:', 'id'=>'x'), array('base'=> 'urn:a:', 'id'=>'x')), |
|
| 40 | 40 | ); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | public function testConstructorWithCustomOptions() |
| 45 | 45 | { |
| 46 | - $localBusiness = new DummyModel(array(), array ( |
|
| 46 | + $localBusiness = new DummyModel(array(), array( |
|
| 47 | 47 | 'base' => array('default' => 'urn:a:'), |
| 48 | 48 | 'lang' => array('default' => 'en'), |
| 49 | 49 | )); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | ), |
| 57 | 57 | $options['base'] |
| 58 | 58 | ); |
| 59 | - $this->assertEquals(array('default' => 'en'),$options['lang']); |
|
| 59 | + $this->assertEquals(array('default' => 'en'), $options['lang']); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | { |
| 65 | 65 | $obj = new DummyModel(array()); |
| 66 | 66 | |
| 67 | - $this->assertEquals($this->vocabulary, $obj->getVocabularies()); |
|
| 67 | + $this->assertEquals($this->vocabulary, $obj->getVocabularies()); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | $vocabulary['my'] = 'urn:test:'; |
| 75 | 75 | |
| 76 | 76 | $obj = new DummyModel(array()); |
| 77 | - $obj->setVocabulary('my','urn:test:'); |
|
| 77 | + $obj->setVocabulary('my', 'urn:test:'); |
|
| 78 | 78 | |
| 79 | - $this->assertEquals($vocabulary, $obj->getVocabularies()); |
|
| 79 | + $this->assertEquals($vocabulary, $obj->getVocabularies()); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $obj = new DummyModel(array()); |
| 89 | 89 | $obj->unsetVocabulary('foaf'); |
| 90 | 90 | |
| 91 | - $this->assertEquals($vocabulary, $obj->getVocabularies()); |
|
| 91 | + $this->assertEquals($vocabulary, $obj->getVocabularies()); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
@@ -98,40 +98,40 @@ discard block |
||
| 98 | 98 | public function testGetUri($data, $expectedData) |
| 99 | 99 | { |
| 100 | 100 | $obj = new DummyModel($data); |
| 101 | - $obj->setIdGenerator(function($d){return'abc';}); |
|
| 101 | + $obj->setIdGenerator(function($d) {return'abc'; }); |
|
| 102 | 102 | $this->assertEquals($expectedData, $obj->getUri()); |
| 103 | 103 | } |
| 104 | 104 | public function uris() |
| 105 | 105 | { |
| 106 | 106 | return array( |
| 107 | - array( array(), 'http://linkeddata.center/botk/resource/abc'), |
|
| 108 | - array( array('base'=>'http://example.com/resource/'), 'http://example.com/resource/abc'), |
|
| 109 | - array( array('base'=>'http://example.com/resource/', 'id'=>'efg'), 'http://example.com/resource/efg'), |
|
| 110 | - array( array('uri'=>'http://example.com/resource/ijk'), 'http://example.com/resource/ijk'), |
|
| 107 | + array(array(), 'http://linkeddata.center/botk/resource/abc'), |
|
| 108 | + array(array('base'=>'http://example.com/resource/'), 'http://example.com/resource/abc'), |
|
| 109 | + array(array('base'=>'http://example.com/resource/', 'id'=>'efg'), 'http://example.com/resource/efg'), |
|
| 110 | + array(array('uri'=>'http://example.com/resource/ijk'), 'http://example.com/resource/ijk'), |
|
| 111 | 111 | ); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | public function testTurtleHeader() |
| 115 | 115 | { |
| 116 | 116 | $obj = new DummyModel(array()); |
| 117 | - $s =""; |
|
| 118 | - foreach( $this->vocabulary as $p=>$v){ |
|
| 119 | - $s.= "@prefix $p: <$v> .\n"; |
|
| 117 | + $s = ""; |
|
| 118 | + foreach ($this->vocabulary as $p=>$v) { |
|
| 119 | + $s .= "@prefix $p: <$v> .\n"; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $this->assertEquals($s, $obj->getTurtleHeader()); |
|
| 122 | + $this->assertEquals($s, $obj->getTurtleHeader()); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | public function testTurtleHeaderWithBase() |
| 127 | 127 | { |
| 128 | 128 | $obj = new DummyModel(array()); |
| 129 | - $s ="@base <urn:a:b> .\n"; |
|
| 130 | - foreach( $this->vocabulary as $p=>$v){ |
|
| 131 | - $s.= "@prefix $p: <$v> .\n"; |
|
| 129 | + $s = "@base <urn:a:b> .\n"; |
|
| 130 | + foreach ($this->vocabulary as $p=>$v) { |
|
| 131 | + $s .= "@prefix $p: <$v> .\n"; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - $this->assertEquals($s, $obj->getTurtleHeader('urn:a:b')); |
|
| 134 | + $this->assertEquals($s, $obj->getTurtleHeader('urn:a:b')); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -139,9 +139,9 @@ discard block |
||
| 139 | 139 | public function testAsString() |
| 140 | 140 | { |
| 141 | 141 | $obj = new DummyModel(array()); |
| 142 | - $s= $obj->getTurtleHeader() ."\n<urn:a:b> owl:sameAs <urn:a:b> ."; |
|
| 142 | + $s = $obj->getTurtleHeader()."\n<urn:a:b> owl:sameAs <urn:a:b> ."; |
|
| 143 | 143 | |
| 144 | - $this->assertEquals($s, (string)$obj); |
|
| 144 | + $this->assertEquals($s, (string) $obj); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | } |
@@ -7,153 +7,153 @@ |
||
| 7 | 7 | /** |
| 8 | 8 | * @dataProvider adresses |
| 9 | 9 | */ |
| 10 | - public function testAddressFilter($data, $expectedData) |
|
| 11 | - { |
|
| 12 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_ADDRESS($data)); |
|
| 13 | - } |
|
| 14 | - public function adresses() |
|
| 10 | + public function testAddressFilter($data, $expectedData) |
|
| 15 | 11 | { |
| 16 | - return array( |
|
| 17 | - array( 'Lungolario Luigi Cadorna, 1, 23900 Lecco LC, Italy', 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO LC, ITALY'), |
|
| 18 | - array( 'Lungolario Luigi Cadorna 1-23900-Italy', 'LUNGOLARIO LUIGI CADORNA 1 - 23900 - ITALY'), |
|
| 19 | - array( 'Lungolario L. Cadorna 1-23900-Italy', 'LUNGOLARIO L.CADORNA 1 - 23900 - ITALY'), |
|
| 20 | - array( 'Lungolario Luigi Cadorna num 1', 'LUNGOLARIO LUIGI CADORNA, 1'), |
|
| 21 | - array( 'Lungolario Luigi Cadorna n.1, Lecco', 'LUNGOLARIO LUIGI CADORNA, 1, LECCO'), |
|
| 22 | - array( 'Lungolario Luigi Cadorna n. 1, Lecco', 'LUNGOLARIO LUIGI CADORNA, 1, LECCO'), |
|
| 23 | - array( ',,test;;', 'TEST;'), |
|
| 24 | - array( '', null), |
|
| 25 | - ); |
|
| 26 | - } |
|
| 12 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_ADDRESS($data)); |
|
| 13 | + } |
|
| 14 | + public function adresses() |
|
| 15 | + { |
|
| 16 | + return array( |
|
| 17 | + array( 'Lungolario Luigi Cadorna, 1, 23900 Lecco LC, Italy', 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO LC, ITALY'), |
|
| 18 | + array( 'Lungolario Luigi Cadorna 1-23900-Italy', 'LUNGOLARIO LUIGI CADORNA 1 - 23900 - ITALY'), |
|
| 19 | + array( 'Lungolario L. Cadorna 1-23900-Italy', 'LUNGOLARIO L.CADORNA 1 - 23900 - ITALY'), |
|
| 20 | + array( 'Lungolario Luigi Cadorna num 1', 'LUNGOLARIO LUIGI CADORNA, 1'), |
|
| 21 | + array( 'Lungolario Luigi Cadorna n.1, Lecco', 'LUNGOLARIO LUIGI CADORNA, 1, LECCO'), |
|
| 22 | + array( 'Lungolario Luigi Cadorna n. 1, Lecco', 'LUNGOLARIO LUIGI CADORNA, 1, LECCO'), |
|
| 23 | + array( ',,test;;', 'TEST;'), |
|
| 24 | + array( '', null), |
|
| 25 | + ); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @dataProvider tokens |
| 31 | 31 | */ |
| 32 | - public function testTokenFilter($data, $expectedData) |
|
| 33 | - { |
|
| 34 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TOKEN($data)); |
|
| 35 | - } |
|
| 36 | - public function tokens() |
|
| 32 | + public function testTokenFilter($data, $expectedData) |
|
| 33 | + { |
|
| 34 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TOKEN($data)); |
|
| 35 | + } |
|
| 36 | + public function tokens() |
|
| 37 | 37 | { |
| 38 | - return array( |
|
| 39 | - array( 'abc d e #1', 'ABCDE1'), |
|
| 40 | - array( 'abcde1', 'ABCDE1'), |
|
| 41 | - array( 'ABCDE1', 'ABCDE1'), |
|
| 42 | - array( ' ABC_DE-1 ', 'ABC_DE1'), |
|
| 43 | - array( ' ABC_DE:1 ', 'ABC_DE1'), |
|
| 44 | - array( '', false), |
|
| 45 | - ); |
|
| 46 | - } |
|
| 38 | + return array( |
|
| 39 | + array( 'abc d e #1', 'ABCDE1'), |
|
| 40 | + array( 'abcde1', 'ABCDE1'), |
|
| 41 | + array( 'ABCDE1', 'ABCDE1'), |
|
| 42 | + array( ' ABC_DE-1 ', 'ABC_DE1'), |
|
| 43 | + array( ' ABC_DE:1 ', 'ABC_DE1'), |
|
| 44 | + array( '', false), |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @dataProvider telephones |
| 51 | 51 | */ |
| 52 | - public function testItTelephoneFilter($data, $expectedData) |
|
| 53 | - { |
|
| 54 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TELEPHONE($data)); |
|
| 55 | - } |
|
| 56 | - public function telephones() |
|
| 52 | + public function testItTelephoneFilter($data, $expectedData) |
|
| 57 | 53 | { |
| 58 | - return array( |
|
| 59 | - array( '+39 0341 2333991', '03412333991'), |
|
| 60 | - array( ' +39 0341 2333991 ', '03412333991'), |
|
| 61 | - array( '03412333991', '03412333991'), |
|
| 62 | - array( '003903412333991', '03412333991'), |
|
| 63 | - array( '00390341 23 33991', '03412333991'), |
|
| 64 | - array( '+39 0341 2333991', '03412333991'), |
|
| 65 | - array( '+39 03412333991', '03412333991'), |
|
| 66 | - array( '+39 0341 23 33 991', '03412333991'), |
|
| 67 | - array( '+39 (0341) 2333991', '03412333991'), |
|
| 68 | - array( '+39 (0341) 2333991 ext. 1234', '03412333991 [1234]'), |
|
| 69 | - array( '+39 (0341) 2333991 {1234]', '03412333991 [1234]'), |
|
| 70 | - array( ' apdas 0341 2333991sfsd12sdfsf 34', '03412333991 [1234]'), |
|
| 71 | - array( ' apdassdfs', null), |
|
| 72 | - array( '', null), |
|
| 73 | - ); |
|
| 74 | - } |
|
| 54 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TELEPHONE($data)); |
|
| 55 | + } |
|
| 56 | + public function telephones() |
|
| 57 | + { |
|
| 58 | + return array( |
|
| 59 | + array( '+39 0341 2333991', '03412333991'), |
|
| 60 | + array( ' +39 0341 2333991 ', '03412333991'), |
|
| 61 | + array( '03412333991', '03412333991'), |
|
| 62 | + array( '003903412333991', '03412333991'), |
|
| 63 | + array( '00390341 23 33991', '03412333991'), |
|
| 64 | + array( '+39 0341 2333991', '03412333991'), |
|
| 65 | + array( '+39 03412333991', '03412333991'), |
|
| 66 | + array( '+39 0341 23 33 991', '03412333991'), |
|
| 67 | + array( '+39 (0341) 2333991', '03412333991'), |
|
| 68 | + array( '+39 (0341) 2333991 ext. 1234', '03412333991 [1234]'), |
|
| 69 | + array( '+39 (0341) 2333991 {1234]', '03412333991 [1234]'), |
|
| 70 | + array( ' apdas 0341 2333991sfsd12sdfsf 34', '03412333991 [1234]'), |
|
| 71 | + array( ' apdassdfs', null), |
|
| 72 | + array( '', null), |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * @dataProvider emails |
| 79 | 79 | */ |
| 80 | - public function testEmailFilter($data, $expectedData) |
|
| 81 | - { |
|
| 82 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_EMAIL($data)); |
|
| 83 | - } |
|
| 84 | - public function emails() |
|
| 80 | + public function testEmailFilter($data, $expectedData) |
|
| 81 | + { |
|
| 82 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_EMAIL($data)); |
|
| 83 | + } |
|
| 84 | + public function emails() |
|
| 85 | 85 | { |
| 86 | - return array( |
|
| 87 | - array( '[email protected]', '[email protected]'), |
|
| 88 | - array( '[email protected]', '[email protected]'), |
|
| 89 | - array( 'invalid email', null), |
|
| 90 | - ); |
|
| 91 | - } |
|
| 86 | + return array( |
|
| 87 | + array( '[email protected]', '[email protected]'), |
|
| 88 | + array( '[email protected]', '[email protected]'), |
|
| 89 | + array( 'invalid email', null), |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * @dataProvider ids |
| 96 | 96 | */ |
| 97 | - public function testIdFilter($data, $expectedData) |
|
| 98 | - { |
|
| 99 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_ID($data)); |
|
| 100 | - } |
|
| 101 | - public function ids() |
|
| 97 | + public function testIdFilter($data, $expectedData) |
|
| 102 | 98 | { |
| 103 | - return array( |
|
| 104 | - array( '[email protected]', 'abc_example_com'), |
|
| 105 | - array( 'Città di Castello', 'città_di_castello'), |
|
| 106 | - array( 'a-b-1-2-ò', 'a_b_1_2_ò'), |
|
| 107 | - array( 'Gigi d\'Alessio', 'gigi_d_alessio'), |
|
| 108 | - array( 'al "Mangione"', 'al_mangione'), |
|
| 109 | - array( '#125:34', '125_34'), |
|
| 110 | - array( 'http://example.com/test?abc=3&x=1', 'http_example_com_test_abc_3_x_1'), |
|
| 111 | - array( '', false), |
|
| 112 | - ); |
|
| 113 | - } |
|
| 99 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_ID($data)); |
|
| 100 | + } |
|
| 101 | + public function ids() |
|
| 102 | + { |
|
| 103 | + return array( |
|
| 104 | + array( '[email protected]', 'abc_example_com'), |
|
| 105 | + array( 'Città di Castello', 'città_di_castello'), |
|
| 106 | + array( 'a-b-1-2-ò', 'a_b_1_2_ò'), |
|
| 107 | + array( 'Gigi d\'Alessio', 'gigi_d_alessio'), |
|
| 108 | + array( 'al "Mangione"', 'al_mangione'), |
|
| 109 | + array( '#125:34', '125_34'), |
|
| 110 | + array( 'http://example.com/test?abc=3&x=1', 'http_example_com_test_abc_3_x_1'), |
|
| 111 | + array( '', false), |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * @dataProvider geos |
| 118 | 118 | */ |
| 119 | - public function testGeoFilter($data, $expectedData) |
|
| 120 | - { |
|
| 121 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_GEO($data)); |
|
| 122 | - } |
|
| 123 | - public function geos() |
|
| 119 | + public function testGeoFilter($data, $expectedData) |
|
| 120 | + { |
|
| 121 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_GEO($data)); |
|
| 122 | + } |
|
| 123 | + public function geos() |
|
| 124 | 124 | { |
| 125 | - return array( |
|
| 126 | - array( '1.1234567', '1.123456'), |
|
| 127 | - array( '1,123456', '1.123456'), |
|
| 128 | - array( '+1.123456', null), |
|
| 129 | - array( '-1.1234567', '-1.123456'), |
|
| 130 | - array( '90.0', '90.0'), |
|
| 131 | - array( '-90.0', '-90.0'), |
|
| 132 | - array( '90.1', null), |
|
| 133 | - array( '-90.1', null), |
|
| 134 | - array( '', null), |
|
| 135 | - ); |
|
| 136 | - } |
|
| 125 | + return array( |
|
| 126 | + array( '1.1234567', '1.123456'), |
|
| 127 | + array( '1,123456', '1.123456'), |
|
| 128 | + array( '+1.123456', null), |
|
| 129 | + array( '-1.1234567', '-1.123456'), |
|
| 130 | + array( '90.0', '90.0'), |
|
| 131 | + array( '-90.0', '-90.0'), |
|
| 132 | + array( '90.1', null), |
|
| 133 | + array( '-90.1', null), |
|
| 134 | + array( '', null), |
|
| 135 | + ); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | 139 | /** |
| 140 | 140 | * @dataProvider turtle_strings |
| 141 | 141 | */ |
| 142 | - public function testTurtleFilter($data, $expectedData) |
|
| 143 | - { |
|
| 144 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TURTLE_STRING($data)); |
|
| 145 | - } |
|
| 146 | - public function turtle_strings() |
|
| 142 | + public function testTurtleFilter($data, $expectedData) |
|
| 143 | + { |
|
| 144 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TURTLE_STRING($data)); |
|
| 145 | + } |
|
| 146 | + public function turtle_strings() |
|
| 147 | 147 | { |
| 148 | - return array( |
|
| 149 | - array( 'abc', 'abc'), |
|
| 150 | - array( '"la locanda"', '\"la locanda\"'), |
|
| 151 | - array( 'da ""la locanda""', 'da \"\"la locanda\"\"'), |
|
| 152 | - array( 'this is \ backslash', 'this is \\ backslash'), |
|
| 153 | - array( 'this is \\\\ doublebackslash', 'this is \\\\ doublebackslash'), |
|
| 154 | - array( '', null), |
|
| 155 | - ); |
|
| 156 | - } |
|
| 148 | + return array( |
|
| 149 | + array( 'abc', 'abc'), |
|
| 150 | + array( '"la locanda"', '\"la locanda\"'), |
|
| 151 | + array( 'da ""la locanda""', 'da \"\"la locanda\"\"'), |
|
| 152 | + array( 'this is \ backslash', 'this is \\ backslash'), |
|
| 153 | + array( 'this is \\\\ doublebackslash', 'this is \\\\ doublebackslash'), |
|
| 154 | + array( '', null), |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | } |
| 159 | 159 | |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | public function adresses() |
| 15 | 15 | { |
| 16 | 16 | return array( |
| 17 | - array( 'Lungolario Luigi Cadorna, 1, 23900 Lecco LC, Italy', 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO LC, ITALY'), |
|
| 18 | - array( 'Lungolario Luigi Cadorna 1-23900-Italy', 'LUNGOLARIO LUIGI CADORNA 1 - 23900 - ITALY'), |
|
| 19 | - array( 'Lungolario L. Cadorna 1-23900-Italy', 'LUNGOLARIO L.CADORNA 1 - 23900 - ITALY'), |
|
| 20 | - array( 'Lungolario Luigi Cadorna num 1', 'LUNGOLARIO LUIGI CADORNA, 1'), |
|
| 21 | - array( 'Lungolario Luigi Cadorna n.1, Lecco', 'LUNGOLARIO LUIGI CADORNA, 1, LECCO'), |
|
| 22 | - array( 'Lungolario Luigi Cadorna n. 1, Lecco', 'LUNGOLARIO LUIGI CADORNA, 1, LECCO'), |
|
| 23 | - array( ',,test;;', 'TEST;'), |
|
| 24 | - array( '', null), |
|
| 17 | + array('Lungolario Luigi Cadorna, 1, 23900 Lecco LC, Italy', 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO LC, ITALY'), |
|
| 18 | + array('Lungolario Luigi Cadorna 1-23900-Italy', 'LUNGOLARIO LUIGI CADORNA 1 - 23900 - ITALY'), |
|
| 19 | + array('Lungolario L. Cadorna 1-23900-Italy', 'LUNGOLARIO L.CADORNA 1 - 23900 - ITALY'), |
|
| 20 | + array('Lungolario Luigi Cadorna num 1', 'LUNGOLARIO LUIGI CADORNA, 1'), |
|
| 21 | + array('Lungolario Luigi Cadorna n.1, Lecco', 'LUNGOLARIO LUIGI CADORNA, 1, LECCO'), |
|
| 22 | + array('Lungolario Luigi Cadorna n. 1, Lecco', 'LUNGOLARIO LUIGI CADORNA, 1, LECCO'), |
|
| 23 | + array(',,test;;', 'TEST;'), |
|
| 24 | + array('', null), |
|
| 25 | 25 | ); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | public function tokens() |
| 37 | 37 | { |
| 38 | 38 | return array( |
| 39 | - array( 'abc d e #1', 'ABCDE1'), |
|
| 40 | - array( 'abcde1', 'ABCDE1'), |
|
| 41 | - array( 'ABCDE1', 'ABCDE1'), |
|
| 42 | - array( ' ABC_DE-1 ', 'ABC_DE1'), |
|
| 43 | - array( ' ABC_DE:1 ', 'ABC_DE1'), |
|
| 44 | - array( '', false), |
|
| 39 | + array('abc d e #1', 'ABCDE1'), |
|
| 40 | + array('abcde1', 'ABCDE1'), |
|
| 41 | + array('ABCDE1', 'ABCDE1'), |
|
| 42 | + array(' ABC_DE-1 ', 'ABC_DE1'), |
|
| 43 | + array(' ABC_DE:1 ', 'ABC_DE1'), |
|
| 44 | + array('', false), |
|
| 45 | 45 | ); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -56,20 +56,20 @@ discard block |
||
| 56 | 56 | public function telephones() |
| 57 | 57 | { |
| 58 | 58 | return array( |
| 59 | - array( '+39 0341 2333991', '03412333991'), |
|
| 60 | - array( ' +39 0341 2333991 ', '03412333991'), |
|
| 61 | - array( '03412333991', '03412333991'), |
|
| 62 | - array( '003903412333991', '03412333991'), |
|
| 63 | - array( '00390341 23 33991', '03412333991'), |
|
| 64 | - array( '+39 0341 2333991', '03412333991'), |
|
| 65 | - array( '+39 03412333991', '03412333991'), |
|
| 66 | - array( '+39 0341 23 33 991', '03412333991'), |
|
| 67 | - array( '+39 (0341) 2333991', '03412333991'), |
|
| 68 | - array( '+39 (0341) 2333991 ext. 1234', '03412333991 [1234]'), |
|
| 69 | - array( '+39 (0341) 2333991 {1234]', '03412333991 [1234]'), |
|
| 70 | - array( ' apdas 0341 2333991sfsd12sdfsf 34', '03412333991 [1234]'), |
|
| 71 | - array( ' apdassdfs', null), |
|
| 72 | - array( '', null), |
|
| 59 | + array('+39 0341 2333991', '03412333991'), |
|
| 60 | + array(' +39 0341 2333991 ', '03412333991'), |
|
| 61 | + array('03412333991', '03412333991'), |
|
| 62 | + array('003903412333991', '03412333991'), |
|
| 63 | + array('00390341 23 33991', '03412333991'), |
|
| 64 | + array('+39 0341 2333991', '03412333991'), |
|
| 65 | + array('+39 03412333991', '03412333991'), |
|
| 66 | + array('+39 0341 23 33 991', '03412333991'), |
|
| 67 | + array('+39 (0341) 2333991', '03412333991'), |
|
| 68 | + array('+39 (0341) 2333991 ext. 1234', '03412333991 [1234]'), |
|
| 69 | + array('+39 (0341) 2333991 {1234]', '03412333991 [1234]'), |
|
| 70 | + array(' apdas 0341 2333991sfsd12sdfsf 34', '03412333991 [1234]'), |
|
| 71 | + array(' apdassdfs', null), |
|
| 72 | + array('', null), |
|
| 73 | 73 | ); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | public function emails() |
| 85 | 85 | { |
| 86 | 86 | return array( |
| 87 | - array( '[email protected]', '[email protected]'), |
|
| 88 | - array( '[email protected]', '[email protected]'), |
|
| 89 | - array( 'invalid email', null), |
|
| 87 | + array('[email protected]', '[email protected]'), |
|
| 88 | + array('[email protected]', '[email protected]'), |
|
| 89 | + array('invalid email', null), |
|
| 90 | 90 | ); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | public function ids() |
| 102 | 102 | { |
| 103 | 103 | return array( |
| 104 | - array( '[email protected]', 'abc_example_com'), |
|
| 105 | - array( 'Città di Castello', 'città_di_castello'), |
|
| 106 | - array( 'a-b-1-2-ò', 'a_b_1_2_ò'), |
|
| 107 | - array( 'Gigi d\'Alessio', 'gigi_d_alessio'), |
|
| 108 | - array( 'al "Mangione"', 'al_mangione'), |
|
| 109 | - array( '#125:34', '125_34'), |
|
| 110 | - array( 'http://example.com/test?abc=3&x=1', 'http_example_com_test_abc_3_x_1'), |
|
| 111 | - array( '', false), |
|
| 104 | + array('[email protected]', 'abc_example_com'), |
|
| 105 | + array('Città di Castello', 'città_di_castello'), |
|
| 106 | + array('a-b-1-2-ò', 'a_b_1_2_ò'), |
|
| 107 | + array('Gigi d\'Alessio', 'gigi_d_alessio'), |
|
| 108 | + array('al "Mangione"', 'al_mangione'), |
|
| 109 | + array('#125:34', '125_34'), |
|
| 110 | + array('http://example.com/test?abc=3&x=1', 'http_example_com_test_abc_3_x_1'), |
|
| 111 | + array('', false), |
|
| 112 | 112 | ); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | public function geos() |
| 124 | 124 | { |
| 125 | 125 | return array( |
| 126 | - array( '1.1234567', '1.123456'), |
|
| 127 | - array( '1,123456', '1.123456'), |
|
| 128 | - array( '+1.123456', null), |
|
| 129 | - array( '-1.1234567', '-1.123456'), |
|
| 130 | - array( '90.0', '90.0'), |
|
| 131 | - array( '-90.0', '-90.0'), |
|
| 132 | - array( '90.1', null), |
|
| 133 | - array( '-90.1', null), |
|
| 134 | - array( '', null), |
|
| 126 | + array('1.1234567', '1.123456'), |
|
| 127 | + array('1,123456', '1.123456'), |
|
| 128 | + array('+1.123456', null), |
|
| 129 | + array('-1.1234567', '-1.123456'), |
|
| 130 | + array('90.0', '90.0'), |
|
| 131 | + array('-90.0', '-90.0'), |
|
| 132 | + array('90.1', null), |
|
| 133 | + array('-90.1', null), |
|
| 134 | + array('', null), |
|
| 135 | 135 | ); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -146,12 +146,12 @@ discard block |
||
| 146 | 146 | public function turtle_strings() |
| 147 | 147 | { |
| 148 | 148 | return array( |
| 149 | - array( 'abc', 'abc'), |
|
| 150 | - array( '"la locanda"', '\"la locanda\"'), |
|
| 151 | - array( 'da ""la locanda""', 'da \"\"la locanda\"\"'), |
|
| 152 | - array( 'this is \ backslash', 'this is \\ backslash'), |
|
| 153 | - array( 'this is \\\\ doublebackslash', 'this is \\\\ doublebackslash'), |
|
| 154 | - array( '', null), |
|
| 149 | + array('abc', 'abc'), |
|
| 150 | + array('"la locanda"', '\"la locanda\"'), |
|
| 151 | + array('da ""la locanda""', 'da \"\"la locanda\"\"'), |
|
| 152 | + array('this is \ backslash', 'this is \\ backslash'), |
|
| 153 | + array('this is \\\\ doublebackslash', 'this is \\\\ doublebackslash'), |
|
| 154 | + array('', null), |
|
| 155 | 155 | ); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -2,27 +2,27 @@ |
||
| 2 | 2 | require_once __DIR__.'/../vendor/autoload.php'; |
| 3 | 3 | |
| 4 | 4 | $options = array( |
| 5 | - 'factsProfile' => array( |
|
| 6 | - 'model' => 'LocalBusiness', |
|
| 7 | - 'options' => array( |
|
| 8 | - 'base' => array( 'default'=> 'http://salute.gov.it/resource/farmacie#') |
|
| 9 | - ), |
|
| 10 | - 'datamapper' => function(array $rawdata){ |
|
| 11 | - $data = array(); |
|
| 12 | - $data['id'] = $rawdata[2]; |
|
| 13 | - $data['businessType']= 'schema:botk_farmacie'; |
|
| 14 | - $data['businessName']= $rawdata[4]; |
|
| 15 | - $data['streetAddress'] = $rawdata[5]; |
|
| 16 | - $data['addressLocality'] = $rawdata[6]; |
|
| 17 | - $data['telephone'] = $rawdata[7]; |
|
| 18 | - $data['faxNumber'] = $rawdata[8]; |
|
| 19 | - $data['email'] = $rawdata[9]; |
|
| 20 | - $data['long'] = $rawdata[14]; |
|
| 21 | - $data['lat'] = $rawdata[13]; |
|
| 5 | + 'factsProfile' => array( |
|
| 6 | + 'model' => 'LocalBusiness', |
|
| 7 | + 'options' => array( |
|
| 8 | + 'base' => array( 'default'=> 'http://salute.gov.it/resource/farmacie#') |
|
| 9 | + ), |
|
| 10 | + 'datamapper' => function(array $rawdata){ |
|
| 11 | + $data = array(); |
|
| 12 | + $data['id'] = $rawdata[2]; |
|
| 13 | + $data['businessType']= 'schema:botk_farmacie'; |
|
| 14 | + $data['businessName']= $rawdata[4]; |
|
| 15 | + $data['streetAddress'] = $rawdata[5]; |
|
| 16 | + $data['addressLocality'] = $rawdata[6]; |
|
| 17 | + $data['telephone'] = $rawdata[7]; |
|
| 18 | + $data['faxNumber'] = $rawdata[8]; |
|
| 19 | + $data['email'] = $rawdata[9]; |
|
| 20 | + $data['long'] = $rawdata[14]; |
|
| 21 | + $data['lat'] = $rawdata[13]; |
|
| 22 | 22 | |
| 23 | - return $data; |
|
| 24 | - }, |
|
| 25 | - ), |
|
| 23 | + return $data; |
|
| 24 | + }, |
|
| 25 | + ), |
|
| 26 | 26 | ); |
| 27 | 27 | |
| 28 | 28 | BOTK\SimpleCsvGateway::factory($options)->run(); |
| 29 | 29 | \ No newline at end of file |
@@ -5,13 +5,13 @@ |
||
| 5 | 5 | 'factsProfile' => array( |
| 6 | 6 | 'model' => 'LocalBusiness', |
| 7 | 7 | 'options' => array( |
| 8 | - 'base' => array( 'default'=> 'http://salute.gov.it/resource/farmacie#') |
|
| 8 | + 'base' => array('default'=> 'http://salute.gov.it/resource/farmacie#') |
|
| 9 | 9 | ), |
| 10 | - 'datamapper' => function(array $rawdata){ |
|
| 10 | + 'datamapper' => function(array $rawdata) { |
|
| 11 | 11 | $data = array(); |
| 12 | 12 | $data['id'] = $rawdata[2]; |
| 13 | - $data['businessType']= 'schema:botk_farmacie'; |
|
| 14 | - $data['businessName']= $rawdata[4]; |
|
| 13 | + $data['businessType'] = 'schema:botk_farmacie'; |
|
| 14 | + $data['businessName'] = $rawdata[4]; |
|
| 15 | 15 | $data['streetAddress'] = $rawdata[5]; |
| 16 | 16 | $data['addressLocality'] = $rawdata[6]; |
| 17 | 17 | $data['telephone'] = $rawdata[7]; |
@@ -2,32 +2,32 @@ |
||
| 2 | 2 | require_once __DIR__.'/../vendor/autoload.php'; |
| 3 | 3 | |
| 4 | 4 | $options = array( |
| 5 | - 'factsProfile' => array( |
|
| 6 | - 'model' => 'LocalBusiness', |
|
| 7 | - 'options' => array( |
|
| 8 | - 'base' => array( 'default'=> 'http://salute.gov.it/resource/farmacie#') |
|
| 9 | - ), |
|
| 10 | - 'datamapper' => function(array $rawdata){ |
|
| 11 | - $data = array(); |
|
| 12 | - $data['businessType']= 'schema:botk_farmacie'; |
|
| 13 | - $data['id'] = $rawdata[0]; |
|
| 14 | - $data['streetAddress'] = $rawdata[2]; |
|
| 15 | - $data['businessName'] = 'FARMACIA '.$rawdata[3]; |
|
| 16 | - $data['vatID'] = $rawdata[4]; |
|
| 17 | - $data['postalCode'] = $rawdata[5]; |
|
| 18 | - $data['addressLocality'] = $rawdata[7]; |
|
| 19 | - $data['addressRegion'] = $rawdata[10]; |
|
| 20 | - $data['lat'] = $rawdata[18]; |
|
| 21 | - $data['long'] = $rawdata[19]; |
|
| 5 | + 'factsProfile' => array( |
|
| 6 | + 'model' => 'LocalBusiness', |
|
| 7 | + 'options' => array( |
|
| 8 | + 'base' => array( 'default'=> 'http://salute.gov.it/resource/farmacie#') |
|
| 9 | + ), |
|
| 10 | + 'datamapper' => function(array $rawdata){ |
|
| 11 | + $data = array(); |
|
| 12 | + $data['businessType']= 'schema:botk_farmacie'; |
|
| 13 | + $data['id'] = $rawdata[0]; |
|
| 14 | + $data['streetAddress'] = $rawdata[2]; |
|
| 15 | + $data['businessName'] = 'FARMACIA '.$rawdata[3]; |
|
| 16 | + $data['vatID'] = $rawdata[4]; |
|
| 17 | + $data['postalCode'] = $rawdata[5]; |
|
| 18 | + $data['addressLocality'] = $rawdata[7]; |
|
| 19 | + $data['addressRegion'] = $rawdata[10]; |
|
| 20 | + $data['lat'] = $rawdata[18]; |
|
| 21 | + $data['long'] = $rawdata[19]; |
|
| 22 | 22 | |
| 23 | - return $data; |
|
| 24 | - }, |
|
| 25 | - 'rawDataValidationFilter' => function( $rawdata){ |
|
| 26 | - // salta le farmacie non attive |
|
| 27 | - return (!empty($rawdata[15]) && ($rawdata[15]=='-')); |
|
| 28 | - }, |
|
| 29 | - ), |
|
| 30 | - 'fieldDelimiter' => ';' |
|
| 23 | + return $data; |
|
| 24 | + }, |
|
| 25 | + 'rawDataValidationFilter' => function( $rawdata){ |
|
| 26 | + // salta le farmacie non attive |
|
| 27 | + return (!empty($rawdata[15]) && ($rawdata[15]=='-')); |
|
| 28 | + }, |
|
| 29 | + ), |
|
| 30 | + 'fieldDelimiter' => ';' |
|
| 31 | 31 | ); |
| 32 | 32 | |
| 33 | 33 | BOTK\SimpleCsvGateway::factory($options)->run(); |
@@ -5,11 +5,11 @@ discard block |
||
| 5 | 5 | 'factsProfile' => array( |
| 6 | 6 | 'model' => 'LocalBusiness', |
| 7 | 7 | 'options' => array( |
| 8 | - 'base' => array( 'default'=> 'http://salute.gov.it/resource/farmacie#') |
|
| 8 | + 'base' => array('default'=> 'http://salute.gov.it/resource/farmacie#') |
|
| 9 | 9 | ), |
| 10 | - 'datamapper' => function(array $rawdata){ |
|
| 10 | + 'datamapper' => function(array $rawdata) { |
|
| 11 | 11 | $data = array(); |
| 12 | - $data['businessType']= 'schema:botk_farmacie'; |
|
| 12 | + $data['businessType'] = 'schema:botk_farmacie'; |
|
| 13 | 13 | $data['id'] = $rawdata[0]; |
| 14 | 14 | $data['streetAddress'] = $rawdata[2]; |
| 15 | 15 | $data['businessName'] = 'FARMACIA '.$rawdata[3]; |
@@ -22,9 +22,9 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | return $data; |
| 24 | 24 | }, |
| 25 | - 'rawDataValidationFilter' => function( $rawdata){ |
|
| 25 | + 'rawDataValidationFilter' => function($rawdata) { |
|
| 26 | 26 | // salta le farmacie non attive |
| 27 | - return (!empty($rawdata[15]) && ($rawdata[15]=='-')); |
|
| 27 | + return (!empty($rawdata[15]) && ($rawdata[15] == '-')); |
|
| 28 | 28 | }, |
| 29 | 29 | ), |
| 30 | 30 | 'fieldDelimiter' => ';' |
@@ -2,34 +2,34 @@ |
||
| 2 | 2 | require_once __DIR__.'/../vendor/autoload.php'; |
| 3 | 3 | |
| 4 | 4 | $options = array( |
| 5 | - 'factsProfile' => array( |
|
| 6 | - 'model' => 'LocalBusiness', |
|
| 7 | - 'options' => array( |
|
| 8 | - 'base' => array( 'default'=> 'urn:sample1:') |
|
| 9 | - ), |
|
| 10 | - 'datamapper' => function($rawdata){ |
|
| 11 | - $data = array(); |
|
| 12 | - $data['id'] = $rawdata[0]; |
|
| 13 | - $data['businessType'] = 'schema:'.\BOTK\Filters::FILTER_SANITIZE_ID($rawdata[16]); |
|
| 14 | - $data['businessName'][] = $rawdata[1]; |
|
| 15 | - $data['businessName'][] = $rawdata[2]; |
|
| 16 | - $data['vatID'] = $rawdata[3]; |
|
| 17 | - $data['email'] = $rawdata[4]; |
|
| 18 | - $data['addressLocality'] = $rawdata[5]; |
|
| 19 | - $data['postalCode'] = $rawdata[7]; |
|
| 20 | - $data['addressRegion'] = $rawdata[8]; |
|
| 21 | - $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
|
| 22 | - $data['long'] = $rawdata[14]; |
|
| 23 | - $data['lat'] = $rawdata[15]; |
|
| 5 | + 'factsProfile' => array( |
|
| 6 | + 'model' => 'LocalBusiness', |
|
| 7 | + 'options' => array( |
|
| 8 | + 'base' => array( 'default'=> 'urn:sample1:') |
|
| 9 | + ), |
|
| 10 | + 'datamapper' => function($rawdata){ |
|
| 11 | + $data = array(); |
|
| 12 | + $data['id'] = $rawdata[0]; |
|
| 13 | + $data['businessType'] = 'schema:'.\BOTK\Filters::FILTER_SANITIZE_ID($rawdata[16]); |
|
| 14 | + $data['businessName'][] = $rawdata[1]; |
|
| 15 | + $data['businessName'][] = $rawdata[2]; |
|
| 16 | + $data['vatID'] = $rawdata[3]; |
|
| 17 | + $data['email'] = $rawdata[4]; |
|
| 18 | + $data['addressLocality'] = $rawdata[5]; |
|
| 19 | + $data['postalCode'] = $rawdata[7]; |
|
| 20 | + $data['addressRegion'] = $rawdata[8]; |
|
| 21 | + $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
|
| 22 | + $data['long'] = $rawdata[14]; |
|
| 23 | + $data['lat'] = $rawdata[15]; |
|
| 24 | 24 | |
| 25 | - return $data; |
|
| 26 | - }, |
|
| 27 | - 'rawDataValidationFilter' => function( $rawdata){ |
|
| 28 | - return !empty($rawdata['16']); |
|
| 29 | - }, |
|
| 30 | - ), |
|
| 31 | - 'skippFirstLine' => false, |
|
| 32 | - 'fieldDelimiter' => '|' |
|
| 25 | + return $data; |
|
| 26 | + }, |
|
| 27 | + 'rawDataValidationFilter' => function( $rawdata){ |
|
| 28 | + return !empty($rawdata['16']); |
|
| 29 | + }, |
|
| 30 | + ), |
|
| 31 | + 'skippFirstLine' => false, |
|
| 32 | + 'fieldDelimiter' => '|' |
|
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | 35 | BOTK\SimpleCsvGateway::factory($options)->run(); |
@@ -5,9 +5,9 @@ discard block |
||
| 5 | 5 | 'factsProfile' => array( |
| 6 | 6 | 'model' => 'LocalBusiness', |
| 7 | 7 | 'options' => array( |
| 8 | - 'base' => array( 'default'=> 'urn:sample1:') |
|
| 8 | + 'base' => array('default'=> 'urn:sample1:') |
|
| 9 | 9 | ), |
| 10 | - 'datamapper' => function($rawdata){ |
|
| 10 | + 'datamapper' => function($rawdata) { |
|
| 11 | 11 | $data = array(); |
| 12 | 12 | $data['id'] = $rawdata[0]; |
| 13 | 13 | $data['businessType'] = 'schema:'.\BOTK\Filters::FILTER_SANITIZE_ID($rawdata[16]); |
@@ -18,13 +18,13 @@ discard block |
||
| 18 | 18 | $data['addressLocality'] = $rawdata[5]; |
| 19 | 19 | $data['postalCode'] = $rawdata[7]; |
| 20 | 20 | $data['addressRegion'] = $rawdata[8]; |
| 21 | - $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
|
| 21 | + $data['streetAddress'] = $rawdata[9].' '.$rawdata[10].', '.$rawdata[11]; |
|
| 22 | 22 | $data['long'] = $rawdata[14]; |
| 23 | 23 | $data['lat'] = $rawdata[15]; |
| 24 | 24 | |
| 25 | 25 | return $data; |
| 26 | 26 | }, |
| 27 | - 'rawDataValidationFilter' => function( $rawdata){ |
|
| 27 | + 'rawDataValidationFilter' => function($rawdata) { |
|
| 28 | 28 | return !empty($rawdata['16']); |
| 29 | 29 | }, |
| 30 | 30 | ), |