@@ -59,6 +59,7 @@ |
||
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Normalize email |
| 62 | + * @param string $value |
|
| 62 | 63 | */ |
| 63 | 64 | static function FILTER_SANITIZE_EMAIL($value) |
| 64 | 65 | { |
@@ -7,82 +7,82 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Filters { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * uppercase, no trailing and ending blancs, no multiple spaces, no "strange" strings, no blanks after dot., a single blanc after comma |
|
| 12 | - */ |
|
| 13 | - static function FILTER_SANITIZE_ADDRESS($value) |
|
| 14 | - { |
|
| 15 | - //$value = filter_var($value, FILTER_SANITIZE_STRING); // no "strange" strings |
|
| 16 | - $value = preg_replace('/\s*([,;])/', '$1 ', $value); // a single blanc after comma and semicolon, no space before |
|
| 17 | - $value = preg_replace('/\-/', ' - ', $value); // a single blanc after and before dash |
|
| 18 | - $value = preg_replace('/\s*\.\s*/', '.', $value); // no blanks before and after dot |
|
| 19 | - $value = preg_replace('/[\s]{1,}/', ' ', $value); // no multiple spaces, |
|
| 20 | - $value = preg_replace('/,\s,\s/', ', ', $value); // remove multiple comma |
|
| 21 | - $value = preg_replace('/;\s;\s/', '; ', $value); // remove multiple semicolon |
|
| 22 | - $value = preg_replace('/\-\s\-\s/', '- ', $value); // remove multiple dash |
|
| 23 | - $value = preg_replace('/^\s*[\,\;]/', '', $value); // remove comma and semicolon at start |
|
| 24 | - $value = trim($value); // no trailing and ending blancs |
|
| 10 | + /** |
|
| 11 | + * uppercase, no trailing and ending blancs, no multiple spaces, no "strange" strings, no blanks after dot., a single blanc after comma |
|
| 12 | + */ |
|
| 13 | + static function FILTER_SANITIZE_ADDRESS($value) |
|
| 14 | + { |
|
| 15 | + //$value = filter_var($value, FILTER_SANITIZE_STRING); // no "strange" strings |
|
| 16 | + $value = preg_replace('/\s*([,;])/', '$1 ', $value); // a single blanc after comma and semicolon, no space before |
|
| 17 | + $value = preg_replace('/\-/', ' - ', $value); // a single blanc after and before dash |
|
| 18 | + $value = preg_replace('/\s*\.\s*/', '.', $value); // no blanks before and after dot |
|
| 19 | + $value = preg_replace('/[\s]{1,}/', ' ', $value); // no multiple spaces, |
|
| 20 | + $value = preg_replace('/,\s,\s/', ', ', $value); // remove multiple comma |
|
| 21 | + $value = preg_replace('/;\s;\s/', '; ', $value); // remove multiple semicolon |
|
| 22 | + $value = preg_replace('/\-\s\-\s/', '- ', $value); // remove multiple dash |
|
| 23 | + $value = preg_replace('/^\s*[\,\;]/', '', $value); // remove comma and semicolon at start |
|
| 24 | + $value = trim($value); // no trailing and ending blancs |
|
| 25 | 25 | |
| 26 | - return $value?mb_strtoupper($value,'UTF-8'):false; // uppercase |
|
| 27 | - } |
|
| 26 | + return $value?mb_strtoupper($value,'UTF-8'):false; // uppercase |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - static function FILTER_SANITIZE_TOKEN($value) |
|
| 31 | - { |
|
| 32 | - $value = preg_replace('/[^\w]/', '', $value); |
|
| 33 | - return $value?strtoupper($value):false; |
|
| 34 | - } |
|
| 30 | + static function FILTER_SANITIZE_TOKEN($value) |
|
| 31 | + { |
|
| 32 | + $value = preg_replace('/[^\w]/', '', $value); |
|
| 33 | + return $value?strtoupper($value):false; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Normalize an italian telephone number |
|
| 39 | - */ |
|
| 40 | - static function FILTER_SANITIZE_TELEPHONE($value) |
|
| 41 | - { |
|
| 42 | - $value = preg_replace('/^[^0-9\+]+/', '', $value); // remove all from beginning execept numbers and + |
|
| 43 | - $value = preg_replace('/^\+39/', '', $value); // remove +39 prefix |
|
| 44 | - $value = preg_replace('/^0039/', '', $value); // remove 0039 prefix |
|
| 45 | - $value = preg_replace('/[\s\(\)]+/', '', $value); // remove all blanks and parenthesis |
|
| 37 | + /** |
|
| 38 | + * Normalize an italian telephone number |
|
| 39 | + */ |
|
| 40 | + static function FILTER_SANITIZE_TELEPHONE($value) |
|
| 41 | + { |
|
| 42 | + $value = preg_replace('/^[^0-9\+]+/', '', $value); // remove all from beginning execept numbers and + |
|
| 43 | + $value = preg_replace('/^\+39/', '', $value); // remove +39 prefix |
|
| 44 | + $value = preg_replace('/^0039/', '', $value); // remove 0039 prefix |
|
| 45 | + $value = preg_replace('/[\s\(\)]+/', '', $value); // remove all blanks and parenthesis |
|
| 46 | 46 | |
| 47 | - // separate number from extensions (if any) |
|
| 48 | - if( preg_match('/([0-9]+)(.*)/', $value, $matches)){ |
|
| 49 | - $value = $matches[1]; |
|
| 50 | - $extension = preg_replace('/[^0-9]/', '', $matches[2]);; |
|
| 51 | - if($extension){ |
|
| 52 | - $value .= " [$extension]"; |
|
| 53 | - } |
|
| 54 | - } |
|
| 47 | + // separate number from extensions (if any) |
|
| 48 | + if( preg_match('/([0-9]+)(.*)/', $value, $matches)){ |
|
| 49 | + $value = $matches[1]; |
|
| 50 | + $extension = preg_replace('/[^0-9]/', '', $matches[2]);; |
|
| 51 | + if($extension){ |
|
| 52 | + $value .= " [$extension]"; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $value?:false; |
|
| 57 | - } |
|
| 56 | + return $value?:false; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Normalize email |
|
| 62 | - */ |
|
| 63 | - static function FILTER_SANITIZE_EMAIL($value) |
|
| 64 | - { |
|
| 65 | - $value = filter_var($value, FILTER_VALIDATE_EMAIL); |
|
| 66 | - return $value?strtoupper($value):false; |
|
| 67 | - } |
|
| 60 | + /** |
|
| 61 | + * Normalize email |
|
| 62 | + */ |
|
| 63 | + static function FILTER_SANITIZE_EMAIL($value) |
|
| 64 | + { |
|
| 65 | + $value = filter_var($value, FILTER_VALIDATE_EMAIL); |
|
| 66 | + return $value?strtoupper($value):false; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | - static function FILTER_SANITIZE_ID($value) |
|
| 71 | - { |
|
| 72 | - $value = strtolower($value); |
|
| 73 | - $value = preg_replace('/[^a-z0-9]+/', ' ', $value); |
|
| 74 | - $value = preg_replace('/[^a-z0-9]+/', ' ', $value); |
|
| 75 | - $value = preg_replace('/[\s]{1,}/', '_', trim($value)); |
|
| 76 | - return $value?:false; |
|
| 77 | - } |
|
| 70 | + static function FILTER_SANITIZE_ID($value) |
|
| 71 | + { |
|
| 72 | + $value = strtolower($value); |
|
| 73 | + $value = preg_replace('/[^a-z0-9]+/', ' ', $value); |
|
| 74 | + $value = preg_replace('/[^a-z0-9]+/', ' ', $value); |
|
| 75 | + $value = preg_replace('/[\s]{1,}/', '_', trim($value)); |
|
| 76 | + return $value?:false; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | |
| 80 | - static function FILTER_SANITIZE_LAT_LONG($value) |
|
| 81 | - { |
|
| 82 | - // http://www.regexlib.com/REDetails.aspx?regexp_id=2728 |
|
| 83 | - $value = preg_replace('/,/', '.', $value); |
|
| 84 | - $value = sprintf('%01.6f',floatval($value)); |
|
| 85 | - return preg_match('/^-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/', $value)?$value:false; |
|
| 86 | - } |
|
| 80 | + static function FILTER_SANITIZE_LAT_LONG($value) |
|
| 81 | + { |
|
| 82 | + // http://www.regexlib.com/REDetails.aspx?regexp_id=2728 |
|
| 83 | + $value = preg_replace('/,/', '.', $value); |
|
| 84 | + $value = sprintf('%01.6f',floatval($value)); |
|
| 85 | + return preg_match('/^-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/', $value)?$value:false; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | \ No newline at end of file |
@@ -13,24 +13,24 @@ discard block |
||
| 13 | 13 | static function FILTER_SANITIZE_ADDRESS($value) |
| 14 | 14 | { |
| 15 | 15 | //$value = filter_var($value, FILTER_SANITIZE_STRING); // no "strange" strings |
| 16 | - $value = preg_replace('/\s*([,;])/', '$1 ', $value); // a single blanc after comma and semicolon, no space before |
|
| 17 | - $value = preg_replace('/\-/', ' - ', $value); // a single blanc after and before dash |
|
| 18 | - $value = preg_replace('/\s*\.\s*/', '.', $value); // no blanks before and after dot |
|
| 19 | - $value = preg_replace('/[\s]{1,}/', ' ', $value); // no multiple spaces, |
|
| 20 | - $value = preg_replace('/,\s,\s/', ', ', $value); // remove multiple comma |
|
| 21 | - $value = preg_replace('/;\s;\s/', '; ', $value); // remove multiple semicolon |
|
| 22 | - $value = preg_replace('/\-\s\-\s/', '- ', $value); // remove multiple dash |
|
| 23 | - $value = preg_replace('/^\s*[\,\;]/', '', $value); // remove comma and semicolon at start |
|
| 24 | - $value = trim($value); // no trailing and ending blancs |
|
| 16 | + $value = preg_replace('/\s*([,;])/', '$1 ', $value); // a single blanc after comma and semicolon, no space before |
|
| 17 | + $value = preg_replace('/\-/', ' - ', $value); // a single blanc after and before dash |
|
| 18 | + $value = preg_replace('/\s*\.\s*/', '.', $value); // no blanks before and after dot |
|
| 19 | + $value = preg_replace('/[\s]{1,}/', ' ', $value); // no multiple spaces, |
|
| 20 | + $value = preg_replace('/,\s,\s/', ', ', $value); // remove multiple comma |
|
| 21 | + $value = preg_replace('/;\s;\s/', '; ', $value); // remove multiple semicolon |
|
| 22 | + $value = preg_replace('/\-\s\-\s/', '- ', $value); // remove multiple dash |
|
| 23 | + $value = preg_replace('/^\s*[\,\;]/', '', $value); // remove comma and semicolon at start |
|
| 24 | + $value = trim($value); // no trailing and ending blancs |
|
| 25 | 25 | |
| 26 | - return $value?mb_strtoupper($value,'UTF-8'):false; // uppercase |
|
| 26 | + return $value ? mb_strtoupper($value, 'UTF-8') : false; // uppercase |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
| 30 | 30 | static function FILTER_SANITIZE_TOKEN($value) |
| 31 | 31 | { |
| 32 | 32 | $value = preg_replace('/[^\w]/', '', $value); |
| 33 | - return $value?strtoupper($value):false; |
|
| 33 | + return $value ? strtoupper($value) : false; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | static function FILTER_SANITIZE_TELEPHONE($value) |
| 41 | 41 | { |
| 42 | - $value = preg_replace('/^[^0-9\+]+/', '', $value); // remove all from beginning execept numbers and + |
|
| 43 | - $value = preg_replace('/^\+39/', '', $value); // remove +39 prefix |
|
| 44 | - $value = preg_replace('/^0039/', '', $value); // remove 0039 prefix |
|
| 45 | - $value = preg_replace('/[\s\(\)]+/', '', $value); // remove all blanks and parenthesis |
|
| 42 | + $value = preg_replace('/^[^0-9\+]+/', '', $value); // remove all from beginning execept numbers and + |
|
| 43 | + $value = preg_replace('/^\+39/', '', $value); // remove +39 prefix |
|
| 44 | + $value = preg_replace('/^0039/', '', $value); // remove 0039 prefix |
|
| 45 | + $value = preg_replace('/[\s\(\)]+/', '', $value); // remove all blanks and parenthesis |
|
| 46 | 46 | |
| 47 | 47 | // separate number from extensions (if any) |
| 48 | - if( preg_match('/([0-9]+)(.*)/', $value, $matches)){ |
|
| 48 | + if (preg_match('/([0-9]+)(.*)/', $value, $matches)) { |
|
| 49 | 49 | $value = $matches[1]; |
| 50 | - $extension = preg_replace('/[^0-9]/', '', $matches[2]);; |
|
| 51 | - if($extension){ |
|
| 50 | + $extension = preg_replace('/[^0-9]/', '', $matches[2]); ; |
|
| 51 | + if ($extension) { |
|
| 52 | 52 | $value .= " [$extension]"; |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - return $value?:false; |
|
| 56 | + return $value ?: false; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | static function FILTER_SANITIZE_EMAIL($value) |
| 64 | 64 | { |
| 65 | - $value = filter_var($value, FILTER_VALIDATE_EMAIL); |
|
| 66 | - return $value?strtoupper($value):false; |
|
| 65 | + $value = filter_var($value, FILTER_VALIDATE_EMAIL); |
|
| 66 | + return $value ? strtoupper($value) : false; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | $value = preg_replace('/[^a-z0-9]+/', ' ', $value); |
| 74 | 74 | $value = preg_replace('/[^a-z0-9]+/', ' ', $value); |
| 75 | 75 | $value = preg_replace('/[\s]{1,}/', '_', trim($value)); |
| 76 | - return $value?:false; |
|
| 76 | + return $value ?: false; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | // http://www.regexlib.com/REDetails.aspx?regexp_id=2728 |
| 83 | 83 | $value = preg_replace('/,/', '.', $value); |
| 84 | - $value = sprintf('%01.6f',floatval($value)); |
|
| 85 | - return preg_match('/^-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/', $value)?$value:false; |
|
| 84 | + $value = sprintf('%01.6f', floatval($value)); |
|
| 85 | + return preg_match('/^-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/', $value) ? $value : false; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | \ No newline at end of file |
@@ -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"; |
@@ -7,195 +7,195 @@ |
||
| 7 | 7 | abstract class AbstractModel |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * |
|
| 12 | - * MUST be redefined by concrete class with the model schema |
|
| 13 | - * Each array element is composed by a propery name and and property options. |
|
| 14 | - * Property option is an array with following (optional) fields: |
|
| 15 | - * 'default' a value to be used for the propery |
|
| 16 | - * 'filter' a php filter |
|
| 17 | - * 'options' php filter options |
|
| 18 | - * 'flags' php filter flags |
|
| 19 | - * |
|
| 20 | - * Example:array ( |
|
| 21 | - * 'legalName' => array( |
|
| 22 | - * 'filter' => FILTER_CALLBACK, |
|
| 23 | - * 'options' => '\BOTK\Filters::FILTER_NORMALIZZE_ADDRESS', |
|
| 24 | - * ), |
|
| 25 | - * 'alternateName' => array( |
|
| 10 | + /** |
|
| 11 | + * |
|
| 12 | + * MUST be redefined by concrete class with the model schema |
|
| 13 | + * Each array element is composed by a propery name and and property options. |
|
| 14 | + * Property option is an array with following (optional) fields: |
|
| 15 | + * 'default' a value to be used for the propery |
|
| 16 | + * 'filter' a php filter |
|
| 17 | + * 'options' php filter options |
|
| 18 | + * 'flags' php filter flags |
|
| 19 | + * |
|
| 20 | + * Example:array ( |
|
| 21 | + * 'legalName' => array( |
|
| 22 | + * 'filter' => FILTER_CALLBACK, |
|
| 23 | + * 'options' => '\BOTK\Filters::FILTER_NORMALIZZE_ADDRESS', |
|
| 24 | + * ), |
|
| 25 | + * 'alternateName' => array( |
|
| 26 | 26 | 'flags' => FILTER_FORCE_ARRAY, |
| 27 | - * ), |
|
| 28 | - * 'postalCode' => array( // italian rules |
|
| 29 | - * 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 30 | - * 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 31 | - * 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 32 | - * ), |
|
| 33 | - * ) |
|
| 34 | - */ |
|
| 35 | - protected static $DEFAULT_OPTIONS = array( |
|
| 36 | - 'base' => array( |
|
| 37 | - 'default' => 'http://linkeddata.center/botk/resource/', |
|
| 38 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 39 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 40 | - ), |
|
| 41 | - 'uri' => array( |
|
| 42 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 43 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 44 | - ), |
|
| 45 | - 'lang' => array( |
|
| 46 | - 'default' => 'it', |
|
| 47 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 48 | - 'options' => array('regexp'=>'/^[a-z]{2}$/'), |
|
| 49 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 50 | - ), |
|
| 51 | - 'id' => array( |
|
| 52 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 53 | - 'options' => array('regexp'=>'/^\w+$/'), |
|
| 54 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 55 | - ), |
|
| 56 | - ); |
|
| 27 | + * ), |
|
| 28 | + * 'postalCode' => array( // italian rules |
|
| 29 | + * 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 30 | + * 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 31 | + * 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 32 | + * ), |
|
| 33 | + * ) |
|
| 34 | + */ |
|
| 35 | + protected static $DEFAULT_OPTIONS = array( |
|
| 36 | + 'base' => array( |
|
| 37 | + 'default' => 'http://linkeddata.center/botk/resource/', |
|
| 38 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 39 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 40 | + ), |
|
| 41 | + 'uri' => array( |
|
| 42 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 43 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 44 | + ), |
|
| 45 | + 'lang' => array( |
|
| 46 | + 'default' => 'it', |
|
| 47 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 48 | + 'options' => array('regexp'=>'/^[a-z]{2}$/'), |
|
| 49 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 50 | + ), |
|
| 51 | + 'id' => array( |
|
| 52 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 53 | + 'options' => array('regexp'=>'/^\w+$/'), |
|
| 54 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 55 | + ), |
|
| 56 | + ); |
|
| 57 | 57 | |
| 58 | - protected $options ; |
|
| 59 | - protected $vocabulary = array( |
|
| 60 | - 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 61 | - 'schema' => 'http://schema.org/', |
|
| 62 | - 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 63 | - 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 64 | - 'dct' => 'http://purl.org/dc/terms/', |
|
| 65 | - 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 66 | - ); |
|
| 67 | - protected $data; |
|
| 68 | - protected $rdf =null; //lazy created |
|
| 69 | - protected $tripleCount=0; //lazy created |
|
| 70 | - protected $uniqueIdGenerator=null; // dependency injections |
|
| 58 | + protected $options ; |
|
| 59 | + protected $vocabulary = array( |
|
| 60 | + 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 61 | + 'schema' => 'http://schema.org/', |
|
| 62 | + 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 63 | + 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 64 | + 'dct' => 'http://purl.org/dc/terms/', |
|
| 65 | + 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 66 | + ); |
|
| 67 | + protected $data; |
|
| 68 | + protected $rdf =null; //lazy created |
|
| 69 | + protected $tripleCount=0; //lazy created |
|
| 70 | + protected $uniqueIdGenerator=null; // dependency injections |
|
| 71 | 71 | |
| 72 | - abstract public function asTurtle(); |
|
| 72 | + abstract public function asTurtle(); |
|
| 73 | 73 | |
| 74 | - protected function mergeOptions( array $options1, array $options2 ) |
|
| 75 | - { |
|
| 76 | - foreach($options2 as $property=>$option){ |
|
| 77 | - assert(is_array($option)); |
|
| 74 | + protected function mergeOptions( array $options1, array $options2 ) |
|
| 75 | + { |
|
| 76 | + foreach($options2 as $property=>$option){ |
|
| 77 | + assert(is_array($option)); |
|
| 78 | 78 | |
| 79 | - $options1[$property]=isset($options1[$property]) |
|
| 80 | - ?array_merge($options1[$property], $option) |
|
| 81 | - :$option; |
|
| 82 | - } |
|
| 79 | + $options1[$property]=isset($options1[$property]) |
|
| 80 | + ?array_merge($options1[$property], $option) |
|
| 81 | + :$option; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - return $options1; |
|
| 85 | - } |
|
| 84 | + return $options1; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | public function __construct(array $data = array(), array $customOptions = array()) |
| 88 | 88 | { |
| 89 | - $options = $this->mergeOptions(self::$DEFAULT_OPTIONS,$customOptions); |
|
| 89 | + $options = $this->mergeOptions(self::$DEFAULT_OPTIONS,$customOptions); |
|
| 90 | 90 | |
| 91 | - // set default values |
|
| 92 | - foreach( $options as $property=>$option){ |
|
| 93 | - if(empty($data[$property]) && isset($option['default'])){ |
|
| 94 | - $data[$property] = $option['default']; |
|
| 95 | - } |
|
| 96 | - } |
|
| 91 | + // set default values |
|
| 92 | + foreach( $options as $property=>$option){ |
|
| 93 | + if(empty($data[$property]) && isset($option['default'])){ |
|
| 94 | + $data[$property] = $option['default']; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - // ensure data are sanitized and validated |
|
| 99 | - $sanitizedData = array_filter( filter_var_array($data, $options), function($value,$property) use($data,$options){ |
|
| 100 | - if ($value===false && isset($data[$property]) && $data[$property]!==false){ |
|
| 101 | - $id = empty($data['id'])?'unknown':$data['id']; |
|
| 102 | - throw new DataModelException("failed validation of '$property' property of subject with id '$id'. Record dropped."); |
|
| 103 | - } |
|
| 104 | - return !is_null($value); |
|
| 105 | - } , ARRAY_FILTER_USE_BOTH); |
|
| 98 | + // ensure data are sanitized and validated |
|
| 99 | + $sanitizedData = array_filter( filter_var_array($data, $options), function($value,$property) use($data,$options){ |
|
| 100 | + if ($value===false && isset($data[$property]) && $data[$property]!==false){ |
|
| 101 | + $id = empty($data['id'])?'unknown':$data['id']; |
|
| 102 | + throw new DataModelException("failed validation of '$property' property of subject with id '$id'. Record dropped."); |
|
| 103 | + } |
|
| 104 | + return !is_null($value); |
|
| 105 | + } , ARRAY_FILTER_USE_BOTH); |
|
| 106 | 106 | |
| 107 | - $this->options = $options; |
|
| 108 | - $this->data = $sanitizedData; |
|
| 109 | - $this->setIdGenerator(function($data){return uniqid();}); |
|
| 107 | + $this->options = $options; |
|
| 108 | + $this->data = $sanitizedData; |
|
| 109 | + $this->setIdGenerator(function($data){return uniqid();}); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * dependecy injection setter |
|
| 115 | - */ |
|
| 116 | - public function setIdGenerator($generator) |
|
| 117 | - { |
|
| 118 | - assert( is_callable($generator)); |
|
| 119 | - $this->uniqueIdGenerator = $generator; |
|
| 113 | + /** |
|
| 114 | + * dependecy injection setter |
|
| 115 | + */ |
|
| 116 | + public function setIdGenerator($generator) |
|
| 117 | + { |
|
| 118 | + assert( is_callable($generator)); |
|
| 119 | + $this->uniqueIdGenerator = $generator; |
|
| 120 | 120 | |
| 121 | - return $this; |
|
| 122 | - } |
|
| 121 | + return $this; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * a generic implementation that use uri, base and id property (all optionals) |
|
| 127 | - */ |
|
| 128 | - public function getUri() |
|
| 129 | - { |
|
| 130 | - if(!empty($this->data['uri'])){ |
|
| 131 | - $uri = $this->data['uri']; |
|
| 132 | - } elseif(!empty($this->data['base'])) { |
|
| 133 | - $idGenerator=$this->uniqueIdGenerator; |
|
| 134 | - $uri = $this->data['base']; |
|
| 135 | - $uri.=empty($this->data['id'])?$idGenerator($this->data):$this->data['id']; |
|
| 136 | - } else{ |
|
| 137 | - $idGenerator=$this->uniqueIdGenerator; |
|
| 138 | - $uri = 'urn:local:botk:'.$idGenerator($this->data); |
|
| 139 | - } |
|
| 125 | + /** |
|
| 126 | + * a generic implementation that use uri, base and id property (all optionals) |
|
| 127 | + */ |
|
| 128 | + public function getUri() |
|
| 129 | + { |
|
| 130 | + if(!empty($this->data['uri'])){ |
|
| 131 | + $uri = $this->data['uri']; |
|
| 132 | + } elseif(!empty($this->data['base'])) { |
|
| 133 | + $idGenerator=$this->uniqueIdGenerator; |
|
| 134 | + $uri = $this->data['base']; |
|
| 135 | + $uri.=empty($this->data['id'])?$idGenerator($this->data):$this->data['id']; |
|
| 136 | + } else{ |
|
| 137 | + $idGenerator=$this->uniqueIdGenerator; |
|
| 138 | + $uri = 'urn:local:botk:'.$idGenerator($this->data); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - return $uri; |
|
| 142 | - } |
|
| 141 | + return $uri; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | |
| 145 | - public function asArray() |
|
| 146 | - { |
|
| 147 | - return $this->data; |
|
| 148 | - } |
|
| 145 | + public function asArray() |
|
| 146 | + { |
|
| 147 | + return $this->data; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | 150 | |
| 151 | - public function getOptions() |
|
| 152 | - { |
|
| 153 | - return $this->options; |
|
| 154 | - } |
|
| 151 | + public function getOptions() |
|
| 152 | + { |
|
| 153 | + return $this->options; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | |
| 157 | - public function getVocabulary() |
|
| 158 | - { |
|
| 159 | - return $this->vocabulary; |
|
| 160 | - } |
|
| 157 | + public function getVocabulary() |
|
| 158 | + { |
|
| 159 | + return $this->vocabulary; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | - public function setVocabulary($prefix,$ns) |
|
| 164 | - { |
|
| 165 | - $this->vocabulary[$prefix] = $ns; |
|
| 166 | - } |
|
| 163 | + public function setVocabulary($prefix,$ns) |
|
| 164 | + { |
|
| 165 | + $this->vocabulary[$prefix] = $ns; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | 168 | |
| 169 | - public function unsetVocabulary($prefix) |
|
| 170 | - { |
|
| 171 | - unset($this->vocabulary[$prefix]); |
|
| 172 | - } |
|
| 169 | + public function unsetVocabulary($prefix) |
|
| 170 | + { |
|
| 171 | + unset($this->vocabulary[$prefix]); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | |
| 175 | - public function getTurtleHeader($base=null) |
|
| 176 | - { |
|
| 177 | - $header = empty($base)?'': "@base <$base> .\n"; |
|
| 178 | - foreach( $this->vocabulary as $prefix=>$ns ){ |
|
| 179 | - $header.="@prefix $prefix: <$ns> .\n"; |
|
| 180 | - } |
|
| 175 | + public function getTurtleHeader($base=null) |
|
| 176 | + { |
|
| 177 | + $header = empty($base)?'': "@base <$base> .\n"; |
|
| 178 | + foreach( $this->vocabulary as $prefix=>$ns ){ |
|
| 179 | + $header.="@prefix $prefix: <$ns> .\n"; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - return $header; |
|
| 183 | - } |
|
| 182 | + return $header; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | 185 | |
| 186 | - public function getTripleCount() |
|
| 187 | - { |
|
| 188 | - // triple count is computed during rdf creation |
|
| 189 | - if (is_null($this->rdf)){ |
|
| 190 | - $this->asTurtle(); |
|
| 191 | - } |
|
| 186 | + public function getTripleCount() |
|
| 187 | + { |
|
| 188 | + // triple count is computed during rdf creation |
|
| 189 | + if (is_null($this->rdf)){ |
|
| 190 | + $this->asTurtle(); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - return $this->tripleCount; |
|
| 194 | - } |
|
| 193 | + return $this->tripleCount; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | 196 | |
| 197 | - public function __toString() |
|
| 198 | - { |
|
| 199 | - return $this->getTurtleHeader() ."\n". $this->asTurtle(); |
|
| 200 | - } |
|
| 197 | + public function __toString() |
|
| 198 | + { |
|
| 199 | + return $this->getTurtleHeader() ."\n". $this->asTurtle(); |
|
| 200 | + } |
|
| 201 | 201 | } |
| 202 | 202 | \ No newline at end of file |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * ), |
| 33 | 33 | * ) |
| 34 | 34 | */ |
| 35 | - protected static $DEFAULT_OPTIONS = array( |
|
| 35 | + protected static $DEFAULT_OPTIONS = array( |
|
| 36 | 36 | 'base' => array( |
| 37 | 37 | 'default' => 'http://linkeddata.center/botk/resource/', |
| 38 | 38 | 'filter' => FILTER_SANITIZE_URL, |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | ), |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - protected $options ; |
|
| 58 | + protected $options; |
|
| 59 | 59 | protected $vocabulary = array( |
| 60 | 60 | 'botk' => 'http://http://linkeddata.center/botk/v1#', |
| 61 | 61 | 'schema' => 'http://schema.org/', |
@@ -65,19 +65,19 @@ discard block |
||
| 65 | 65 | 'foaf' => 'http://xmlns.com/foaf/0.1/', |
| 66 | 66 | ); |
| 67 | 67 | protected $data; |
| 68 | - protected $rdf =null; //lazy created |
|
| 69 | - protected $tripleCount=0; //lazy created |
|
| 70 | - protected $uniqueIdGenerator=null; // dependency injections |
|
| 68 | + protected $rdf = null; //lazy created |
|
| 69 | + protected $tripleCount = 0; //lazy created |
|
| 70 | + protected $uniqueIdGenerator = null; // dependency injections |
|
| 71 | 71 | |
| 72 | 72 | abstract public function asTurtle(); |
| 73 | 73 | |
| 74 | - protected function mergeOptions( array $options1, array $options2 ) |
|
| 74 | + protected function mergeOptions(array $options1, array $options2) |
|
| 75 | 75 | { |
| 76 | - foreach($options2 as $property=>$option){ |
|
| 76 | + foreach ($options2 as $property=>$option) { |
|
| 77 | 77 | assert(is_array($option)); |
| 78 | 78 | |
| 79 | - $options1[$property]=isset($options1[$property]) |
|
| 80 | - ?array_merge($options1[$property], $option) |
|
| 79 | + $options1[$property] = isset($options1[$property]) |
|
| 80 | + ? array_merge($options1[$property], $option) |
|
| 81 | 81 | :$option; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -86,19 +86,19 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | public function __construct(array $data = array(), array $customOptions = array()) |
| 88 | 88 | { |
| 89 | - $options = $this->mergeOptions(self::$DEFAULT_OPTIONS,$customOptions); |
|
| 89 | + $options = $this->mergeOptions(self::$DEFAULT_OPTIONS, $customOptions); |
|
| 90 | 90 | |
| 91 | 91 | // set default values |
| 92 | - foreach( $options as $property=>$option){ |
|
| 93 | - if(empty($data[$property]) && isset($option['default'])){ |
|
| 92 | + foreach ($options as $property=>$option) { |
|
| 93 | + if (empty($data[$property]) && isset($option['default'])) { |
|
| 94 | 94 | $data[$property] = $option['default']; |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // ensure data are sanitized and validated |
| 99 | - $sanitizedData = array_filter( filter_var_array($data, $options), function($value,$property) use($data,$options){ |
|
| 100 | - if ($value===false && isset($data[$property]) && $data[$property]!==false){ |
|
| 101 | - $id = empty($data['id'])?'unknown':$data['id']; |
|
| 99 | + $sanitizedData = array_filter(filter_var_array($data, $options), function($value, $property) use($data, $options){ |
|
| 100 | + if ($value === false && isset($data[$property]) && $data[$property] !== false) { |
|
| 101 | + $id = empty($data['id']) ? 'unknown' : $data['id']; |
|
| 102 | 102 | throw new DataModelException("failed validation of '$property' property of subject with id '$id'. Record dropped."); |
| 103 | 103 | } |
| 104 | 104 | return !is_null($value); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | $this->options = $options; |
| 108 | 108 | $this->data = $sanitizedData; |
| 109 | - $this->setIdGenerator(function($data){return uniqid();}); |
|
| 109 | + $this->setIdGenerator(function($data) {return uniqid(); }); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function setIdGenerator($generator) |
| 117 | 117 | { |
| 118 | - assert( is_callable($generator)); |
|
| 118 | + assert(is_callable($generator)); |
|
| 119 | 119 | $this->uniqueIdGenerator = $generator; |
| 120 | 120 | |
| 121 | 121 | return $this; |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function getUri() |
| 129 | 129 | { |
| 130 | - if(!empty($this->data['uri'])){ |
|
| 131 | - $uri = $this->data['uri']; |
|
| 132 | - } elseif(!empty($this->data['base'])) { |
|
| 133 | - $idGenerator=$this->uniqueIdGenerator; |
|
| 130 | + if (!empty($this->data['uri'])) { |
|
| 131 | + $uri = $this->data['uri']; |
|
| 132 | + } elseif (!empty($this->data['base'])) { |
|
| 133 | + $idGenerator = $this->uniqueIdGenerator; |
|
| 134 | 134 | $uri = $this->data['base']; |
| 135 | - $uri.=empty($this->data['id'])?$idGenerator($this->data):$this->data['id']; |
|
| 136 | - } else{ |
|
| 137 | - $idGenerator=$this->uniqueIdGenerator; |
|
| 135 | + $uri .= empty($this->data['id']) ? $idGenerator($this->data) : $this->data['id']; |
|
| 136 | + } else { |
|
| 137 | + $idGenerator = $this->uniqueIdGenerator; |
|
| 138 | 138 | $uri = 'urn:local:botk:'.$idGenerator($this->data); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | |
| 163 | - public function setVocabulary($prefix,$ns) |
|
| 163 | + public function setVocabulary($prefix, $ns) |
|
| 164 | 164 | { |
| 165 | 165 | $this->vocabulary[$prefix] = $ns; |
| 166 | 166 | } |
@@ -172,11 +172,11 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
| 175 | - public function getTurtleHeader($base=null) |
|
| 175 | + public function getTurtleHeader($base = null) |
|
| 176 | 176 | { |
| 177 | - $header = empty($base)?'': "@base <$base> .\n"; |
|
| 178 | - foreach( $this->vocabulary as $prefix=>$ns ){ |
|
| 179 | - $header.="@prefix $prefix: <$ns> .\n"; |
|
| 177 | + $header = empty($base) ? '' : "@base <$base> .\n"; |
|
| 178 | + foreach ($this->vocabulary as $prefix=>$ns) { |
|
| 179 | + $header .= "@prefix $prefix: <$ns> .\n"; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | return $header; |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | public function getTripleCount() |
| 187 | 187 | { |
| 188 | 188 | // triple count is computed during rdf creation |
| 189 | - if (is_null($this->rdf)){ |
|
| 189 | + if (is_null($this->rdf)) { |
|
| 190 | 190 | $this->asTurtle(); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -196,6 +196,6 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | public function __toString() |
| 198 | 198 | { |
| 199 | - return $this->getTurtleHeader() ."\n". $this->asTurtle(); |
|
| 199 | + return $this->getTurtleHeader()."\n".$this->asTurtle(); |
|
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | \ No newline at end of file |
@@ -5,72 +5,72 @@ |
||
| 5 | 5 | /** |
| 6 | 6 | * @dataProvider telephones |
| 7 | 7 | */ |
| 8 | - public function testItTelephoneFilter($data, $expectedData) |
|
| 9 | - { |
|
| 10 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TELEPHONE($data)); |
|
| 11 | - } |
|
| 8 | + public function testItTelephoneFilter($data, $expectedData) |
|
| 9 | + { |
|
| 10 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TELEPHONE($data)); |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public function telephones() |
|
| 13 | + public function telephones() |
|
| 14 | 14 | { |
| 15 | - return array( |
|
| 16 | - array( '+39 0341 2333991', '03412333991'), |
|
| 17 | - array( ' +39 0341 2333991 ', '03412333991'), |
|
| 18 | - array( '03412333991', '03412333991'), |
|
| 19 | - array( '003903412333991', '03412333991'), |
|
| 20 | - array( '00390341 23 33991', '03412333991'), |
|
| 21 | - array( '+39 0341 2333991', '03412333991'), |
|
| 22 | - array( '+39 03412333991', '03412333991'), |
|
| 23 | - array( '+39 0341 23 33 991', '03412333991'), |
|
| 24 | - array( '+39 (0341) 2333991', '03412333991'), |
|
| 25 | - array( '+39 (0341) 2333991 ext. 1234', '03412333991 [1234]'), |
|
| 26 | - array( '+39 (0341) 2333991 {1234]', '03412333991 [1234]'), |
|
| 27 | - array( ' apdas 0341 2333991sfsd12sdfsf 34', '03412333991 [1234]'), |
|
| 28 | - array( ' apdassdfs',''), |
|
| 29 | - ); |
|
| 30 | - } |
|
| 15 | + return array( |
|
| 16 | + array( '+39 0341 2333991', '03412333991'), |
|
| 17 | + array( ' +39 0341 2333991 ', '03412333991'), |
|
| 18 | + array( '03412333991', '03412333991'), |
|
| 19 | + array( '003903412333991', '03412333991'), |
|
| 20 | + array( '00390341 23 33991', '03412333991'), |
|
| 21 | + array( '+39 0341 2333991', '03412333991'), |
|
| 22 | + array( '+39 03412333991', '03412333991'), |
|
| 23 | + array( '+39 0341 23 33 991', '03412333991'), |
|
| 24 | + array( '+39 (0341) 2333991', '03412333991'), |
|
| 25 | + array( '+39 (0341) 2333991 ext. 1234', '03412333991 [1234]'), |
|
| 26 | + array( '+39 (0341) 2333991 {1234]', '03412333991 [1234]'), |
|
| 27 | + array( ' apdas 0341 2333991sfsd12sdfsf 34', '03412333991 [1234]'), |
|
| 28 | + array( ' apdassdfs',''), |
|
| 29 | + ); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function testEmailFilter() |
|
| 33 | - { |
|
| 34 | - $this->assertEquals('[email protected]', BOTK\Filters::FILTER_SANITIZE_EMAIL('[email protected]')); |
|
| 35 | - $this->assertTrue(empty(BOTK\Filters::FILTER_SANITIZE_EMAIL('invalid email'))); |
|
| 36 | - } |
|
| 32 | + public function testEmailFilter() |
|
| 33 | + { |
|
| 34 | + $this->assertEquals('[email protected]', BOTK\Filters::FILTER_SANITIZE_EMAIL('[email protected]')); |
|
| 35 | + $this->assertTrue(empty(BOTK\Filters::FILTER_SANITIZE_EMAIL('invalid email'))); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * @dataProvider tokens |
| 40 | 40 | */ |
| 41 | - public function testTokenFilter($data, $expectedData) |
|
| 42 | - { |
|
| 43 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TOKEN($data)); |
|
| 44 | - } |
|
| 41 | + public function testTokenFilter($data, $expectedData) |
|
| 42 | + { |
|
| 43 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_TOKEN($data)); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function tokens() |
|
| 46 | + public function tokens() |
|
| 47 | 47 | { |
| 48 | - return array( |
|
| 49 | - array( 'abc d e #1', 'ABCDE1'), |
|
| 50 | - array( 'abcde1', 'ABCDE1'), |
|
| 51 | - array( 'ABCDE1', 'ABCDE1'), |
|
| 52 | - array( ' ABC_DE-1 ', 'ABC_DE1'), |
|
| 53 | - array( ' ABC_DE:1 ', 'ABC_DE1'), |
|
| 54 | - ); |
|
| 55 | - } |
|
| 48 | + return array( |
|
| 49 | + array( 'abc d e #1', 'ABCDE1'), |
|
| 50 | + array( 'abcde1', 'ABCDE1'), |
|
| 51 | + array( 'ABCDE1', 'ABCDE1'), |
|
| 52 | + array( ' ABC_DE-1 ', 'ABC_DE1'), |
|
| 53 | + array( ' ABC_DE:1 ', 'ABC_DE1'), |
|
| 54 | + ); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * @dataProvider adresses |
| 59 | 59 | */ |
| 60 | - public function testAddressFilter($data, $expectedData) |
|
| 61 | - { |
|
| 62 | - $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_ADDRESS($data)); |
|
| 63 | - } |
|
| 60 | + public function testAddressFilter($data, $expectedData) |
|
| 61 | + { |
|
| 62 | + $this->assertEquals($expectedData, BOTK\Filters::FILTER_SANITIZE_ADDRESS($data)); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function adresses() |
|
| 65 | + public function adresses() |
|
| 66 | 66 | { |
| 67 | - return array( |
|
| 68 | - array( 'Lungolario Luigi Cadorna, 1, 23900 Lecco LC, Italy', 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO LC, ITALY'), |
|
| 69 | - array( 'Lungolario Luigi Cadorna 1-23900 Lecco LC - Italy', 'LUNGOLARIO LUIGI CADORNA 1 - 23900 LECCO LC - ITALY'), |
|
| 70 | - array( 'Lungolario Luigi Cadorna 1 Lecco LC - -Italy', 'LUNGOLARIO LUIGI CADORNA 1 LECCO LC - ITALY'), |
|
| 71 | - array( ',,test;;', 'TEST;'), |
|
| 72 | - ); |
|
| 73 | - } |
|
| 67 | + return array( |
|
| 68 | + array( 'Lungolario Luigi Cadorna, 1, 23900 Lecco LC, Italy', 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO LC, ITALY'), |
|
| 69 | + array( 'Lungolario Luigi Cadorna 1-23900 Lecco LC - Italy', 'LUNGOLARIO LUIGI CADORNA 1 - 23900 LECCO LC - ITALY'), |
|
| 70 | + array( 'Lungolario Luigi Cadorna 1 Lecco LC - -Italy', 'LUNGOLARIO LUIGI CADORNA 1 LECCO LC - ITALY'), |
|
| 71 | + array( ',,test;;', 'TEST;'), |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | } |
| 76 | 76 | |
@@ -2,115 +2,115 @@ |
||
| 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 | - 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 12 | - 'schema' => 'http://schema.org/', |
|
| 13 | - 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 14 | - 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 15 | - 'dct' => 'http://purl.org/dc/terms/', |
|
| 16 | - 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 17 | - ); |
|
| 10 | + protected $vocabulary = array( |
|
| 11 | + 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 12 | + 'schema' => 'http://schema.org/', |
|
| 13 | + 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 14 | + 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 15 | + 'dct' => 'http://purl.org/dc/terms/', |
|
| 16 | + 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 17 | + ); |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - public function testGetVocabulary() |
|
| 21 | - { |
|
| 22 | - $vocabulary = array( |
|
| 23 | - 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 24 | - 'schema' => 'http://schema.org/', |
|
| 25 | - 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 26 | - 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 27 | - 'dct' => 'http://purl.org/dc/terms/', |
|
| 28 | - 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 29 | - ); |
|
| 20 | + public function testGetVocabulary() |
|
| 21 | + { |
|
| 22 | + $vocabulary = array( |
|
| 23 | + 'botk' => 'http://http://linkeddata.center/botk/v1#', |
|
| 24 | + 'schema' => 'http://schema.org/', |
|
| 25 | + 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 26 | + 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 27 | + 'dct' => 'http://purl.org/dc/terms/', |
|
| 28 | + 'foaf' => 'http://xmlns.com/foaf/0.1/', |
|
| 29 | + ); |
|
| 30 | 30 | |
| 31 | - $obj = new DummyModel(array()); |
|
| 31 | + $obj = new DummyModel(array()); |
|
| 32 | 32 | |
| 33 | - $this->assertEquals($this->vocabulary, $obj->getVocabulary()); |
|
| 34 | - } |
|
| 33 | + $this->assertEquals($this->vocabulary, $obj->getVocabulary()); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - public function testSetVocabulary() |
|
| 38 | - { |
|
| 39 | - $vocabulary = $this->vocabulary; |
|
| 40 | - $vocabulary['my'] = 'urn:test:'; |
|
| 37 | + public function testSetVocabulary() |
|
| 38 | + { |
|
| 39 | + $vocabulary = $this->vocabulary; |
|
| 40 | + $vocabulary['my'] = 'urn:test:'; |
|
| 41 | 41 | |
| 42 | - $obj = new DummyModel(array()); |
|
| 43 | - $obj->setVocabulary('my','urn:test:'); |
|
| 42 | + $obj = new DummyModel(array()); |
|
| 43 | + $obj->setVocabulary('my','urn:test:'); |
|
| 44 | 44 | |
| 45 | - $this->assertEquals($vocabulary, $obj->getVocabulary()); |
|
| 46 | - } |
|
| 45 | + $this->assertEquals($vocabulary, $obj->getVocabulary()); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - public function testUnsetVocabulary() |
|
| 50 | - { |
|
| 51 | - $vocabulary = $this->vocabulary; |
|
| 52 | - unset($vocabulary['foaf']); |
|
| 49 | + public function testUnsetVocabulary() |
|
| 50 | + { |
|
| 51 | + $vocabulary = $this->vocabulary; |
|
| 52 | + unset($vocabulary['foaf']); |
|
| 53 | 53 | |
| 54 | - $obj = new DummyModel(array()); |
|
| 55 | - $obj->unsetVocabulary('foaf'); |
|
| 54 | + $obj = new DummyModel(array()); |
|
| 55 | + $obj->unsetVocabulary('foaf'); |
|
| 56 | 56 | |
| 57 | - $this->assertEquals($vocabulary, $obj->getVocabulary()); |
|
| 58 | - } |
|
| 57 | + $this->assertEquals($vocabulary, $obj->getVocabulary()); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * @dataProvider uris |
| 63 | 63 | */ |
| 64 | - public function testGetUri($data, $expectedData) |
|
| 65 | - { |
|
| 66 | - $obj = new DummyModel($data); |
|
| 67 | - $obj->setIdGenerator(function($d){return'abc';}); |
|
| 68 | - $this->assertEquals($expectedData, $obj->getUri()); |
|
| 69 | - } |
|
| 64 | + public function testGetUri($data, $expectedData) |
|
| 65 | + { |
|
| 66 | + $obj = new DummyModel($data); |
|
| 67 | + $obj->setIdGenerator(function($d){return'abc';}); |
|
| 68 | + $this->assertEquals($expectedData, $obj->getUri()); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - public function uris() |
|
| 72 | + public function uris() |
|
| 73 | 73 | { |
| 74 | - return array( |
|
| 75 | - array( array(), 'http://linkeddata.center/botk/resource/abc'), |
|
| 76 | - array( array('base'=>'http://example.com/resource/'), 'http://example.com/resource/abc'), |
|
| 77 | - array( array('base'=>'http://example.com/resource/', 'id'=>'efg'), 'http://example.com/resource/efg'), |
|
| 78 | - array( array('uri'=>'http://example.com/resource/ijk'), 'http://example.com/resource/ijk'), |
|
| 79 | - ); |
|
| 80 | - } |
|
| 74 | + return array( |
|
| 75 | + array( array(), 'http://linkeddata.center/botk/resource/abc'), |
|
| 76 | + array( array('base'=>'http://example.com/resource/'), 'http://example.com/resource/abc'), |
|
| 77 | + array( array('base'=>'http://example.com/resource/', 'id'=>'efg'), 'http://example.com/resource/efg'), |
|
| 78 | + array( array('uri'=>'http://example.com/resource/ijk'), 'http://example.com/resource/ijk'), |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function testTurtleHeader() |
|
| 83 | - { |
|
| 84 | - $obj = new DummyModel(array()); |
|
| 85 | - $s =""; |
|
| 86 | - foreach( $this->vocabulary as $p=>$v){ |
|
| 87 | - $s.= "@prefix $p: <$v> .\n"; |
|
| 88 | - } |
|
| 82 | + public function testTurtleHeader() |
|
| 83 | + { |
|
| 84 | + $obj = new DummyModel(array()); |
|
| 85 | + $s =""; |
|
| 86 | + foreach( $this->vocabulary as $p=>$v){ |
|
| 87 | + $s.= "@prefix $p: <$v> .\n"; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $this->assertEquals($s, $obj->getTurtleHeader()); |
|
| 91 | - } |
|
| 90 | + $this->assertEquals($s, $obj->getTurtleHeader()); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - public function testTurtleHeaderWithBase() |
|
| 95 | - { |
|
| 96 | - $obj = new DummyModel(array()); |
|
| 97 | - $s ="@base <urn:a:b> .\n"; |
|
| 98 | - foreach( $this->vocabulary as $p=>$v){ |
|
| 99 | - $s.= "@prefix $p: <$v> .\n"; |
|
| 100 | - } |
|
| 94 | + public function testTurtleHeaderWithBase() |
|
| 95 | + { |
|
| 96 | + $obj = new DummyModel(array()); |
|
| 97 | + $s ="@base <urn:a:b> .\n"; |
|
| 98 | + foreach( $this->vocabulary as $p=>$v){ |
|
| 99 | + $s.= "@prefix $p: <$v> .\n"; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - $this->assertEquals($s, $obj->getTurtleHeader('urn:a:b')); |
|
| 103 | - } |
|
| 102 | + $this->assertEquals($s, $obj->getTurtleHeader('urn:a:b')); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | |
| 106 | 106 | |
| 107 | - public function testasString() |
|
| 108 | - { |
|
| 109 | - $obj = new DummyModel(array()); |
|
| 110 | - $s= $obj->getTurtleHeader() ."\n<urn:a:b> owl:sameAs <urn:a:b> ."; |
|
| 107 | + public function testasString() |
|
| 108 | + { |
|
| 109 | + $obj = new DummyModel(array()); |
|
| 110 | + $s= $obj->getTurtleHeader() ."\n<urn:a:b> owl:sameAs <urn:a:b> ."; |
|
| 111 | 111 | |
| 112 | - $this->assertEquals($s, (string)$obj); |
|
| 113 | - } |
|
| 112 | + $this->assertEquals($s, (string)$obj); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | |
@@ -2,7 +2,7 @@ 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 |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $obj = new DummyModel(array()); |
| 32 | 32 | |
| 33 | - $this->assertEquals($this->vocabulary, $obj->getVocabulary()); |
|
| 33 | + $this->assertEquals($this->vocabulary, $obj->getVocabulary()); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | $vocabulary['my'] = 'urn:test:'; |
| 41 | 41 | |
| 42 | 42 | $obj = new DummyModel(array()); |
| 43 | - $obj->setVocabulary('my','urn:test:'); |
|
| 43 | + $obj->setVocabulary('my', 'urn:test:'); |
|
| 44 | 44 | |
| 45 | - $this->assertEquals($vocabulary, $obj->getVocabulary()); |
|
| 45 | + $this->assertEquals($vocabulary, $obj->getVocabulary()); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $obj = new DummyModel(array()); |
| 55 | 55 | $obj->unsetVocabulary('foaf'); |
| 56 | 56 | |
| 57 | - $this->assertEquals($vocabulary, $obj->getVocabulary()); |
|
| 57 | + $this->assertEquals($vocabulary, $obj->getVocabulary()); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | public function testGetUri($data, $expectedData) |
| 65 | 65 | { |
| 66 | 66 | $obj = new DummyModel($data); |
| 67 | - $obj->setIdGenerator(function($d){return'abc';}); |
|
| 67 | + $obj->setIdGenerator(function($d) {return'abc'; }); |
|
| 68 | 68 | $this->assertEquals($expectedData, $obj->getUri()); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -72,34 +72,34 @@ discard block |
||
| 72 | 72 | public function uris() |
| 73 | 73 | { |
| 74 | 74 | return array( |
| 75 | - array( array(), 'http://linkeddata.center/botk/resource/abc'), |
|
| 76 | - array( array('base'=>'http://example.com/resource/'), 'http://example.com/resource/abc'), |
|
| 77 | - array( array('base'=>'http://example.com/resource/', 'id'=>'efg'), 'http://example.com/resource/efg'), |
|
| 78 | - array( array('uri'=>'http://example.com/resource/ijk'), 'http://example.com/resource/ijk'), |
|
| 75 | + array(array(), 'http://linkeddata.center/botk/resource/abc'), |
|
| 76 | + array(array('base'=>'http://example.com/resource/'), 'http://example.com/resource/abc'), |
|
| 77 | + array(array('base'=>'http://example.com/resource/', 'id'=>'efg'), 'http://example.com/resource/efg'), |
|
| 78 | + array(array('uri'=>'http://example.com/resource/ijk'), 'http://example.com/resource/ijk'), |
|
| 79 | 79 | ); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | public function testTurtleHeader() |
| 83 | 83 | { |
| 84 | 84 | $obj = new DummyModel(array()); |
| 85 | - $s =""; |
|
| 86 | - foreach( $this->vocabulary as $p=>$v){ |
|
| 87 | - $s.= "@prefix $p: <$v> .\n"; |
|
| 85 | + $s = ""; |
|
| 86 | + foreach ($this->vocabulary as $p=>$v) { |
|
| 87 | + $s .= "@prefix $p: <$v> .\n"; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $this->assertEquals($s, $obj->getTurtleHeader()); |
|
| 90 | + $this->assertEquals($s, $obj->getTurtleHeader()); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | public function testTurtleHeaderWithBase() |
| 95 | 95 | { |
| 96 | 96 | $obj = new DummyModel(array()); |
| 97 | - $s ="@base <urn:a:b> .\n"; |
|
| 98 | - foreach( $this->vocabulary as $p=>$v){ |
|
| 99 | - $s.= "@prefix $p: <$v> .\n"; |
|
| 97 | + $s = "@base <urn:a:b> .\n"; |
|
| 98 | + foreach ($this->vocabulary as $p=>$v) { |
|
| 99 | + $s .= "@prefix $p: <$v> .\n"; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $this->assertEquals($s, $obj->getTurtleHeader('urn:a:b')); |
|
| 102 | + $this->assertEquals($s, $obj->getTurtleHeader('urn:a:b')); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | public function testasString() |
| 108 | 108 | { |
| 109 | 109 | $obj = new DummyModel(array()); |
| 110 | - $s= $obj->getTurtleHeader() ."\n<urn:a:b> owl:sameAs <urn:a:b> ."; |
|
| 110 | + $s = $obj->getTurtleHeader()."\n<urn:a:b> owl:sameAs <urn:a:b> ."; |
|
| 111 | 111 | |
| 112 | - $this->assertEquals($s, (string)$obj); |
|
| 112 | + $this->assertEquals($s, (string) $obj); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
@@ -5,364 +5,364 @@ |
||
| 5 | 5 | /** |
| 6 | 6 | * @dataProvider goodLocalBusiness |
| 7 | 7 | */ |
| 8 | - public function testDataFilteringWithValidDataAndDefaultOptions($data, $expectedData) |
|
| 9 | - { |
|
| 10 | - $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 11 | - $this->assertEquals($expectedData, $localBusiness->asArray()); |
|
| 12 | - } |
|
| 8 | + public function testDataFilteringWithValidDataAndDefaultOptions($data, $expectedData) |
|
| 9 | + { |
|
| 10 | + $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 11 | + $this->assertEquals($expectedData, $localBusiness->asArray()); |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - public function goodLocalBusiness() |
|
| 14 | + public function goodLocalBusiness() |
|
| 15 | 15 | { |
| 16 | - return array( |
|
| 17 | - array( |
|
| 18 | - array(), |
|
| 19 | - array( |
|
| 20 | - 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 21 | - 'lang' => 'it', |
|
| 22 | - 'addressCountry' => 'IT', |
|
| 23 | - ), |
|
| 24 | - ), |
|
| 16 | + return array( |
|
| 17 | + array( |
|
| 18 | + array(), |
|
| 19 | + array( |
|
| 20 | + 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 21 | + 'lang' => 'it', |
|
| 22 | + 'addressCountry' => 'IT', |
|
| 23 | + ), |
|
| 24 | + ), |
|
| 25 | 25 | |
| 26 | - array( |
|
| 27 | - array( |
|
| 28 | - 'base' => 'http://linkeddata.center/botk/resource#', |
|
| 29 | - 'lang' => 'en', |
|
| 30 | - 'addressCountry' => 'US', |
|
| 31 | - ), |
|
| 32 | - array( |
|
| 33 | - 'base' => 'http://linkeddata.center/botk/resource#', |
|
| 34 | - 'lang' => 'en', |
|
| 35 | - 'addressCountry' => 'US', |
|
| 36 | - ), |
|
| 37 | - ), |
|
| 26 | + array( |
|
| 27 | + array( |
|
| 28 | + 'base' => 'http://linkeddata.center/botk/resource#', |
|
| 29 | + 'lang' => 'en', |
|
| 30 | + 'addressCountry' => 'US', |
|
| 31 | + ), |
|
| 32 | + array( |
|
| 33 | + 'base' => 'http://linkeddata.center/botk/resource#', |
|
| 34 | + 'lang' => 'en', |
|
| 35 | + 'addressCountry' => 'US', |
|
| 36 | + ), |
|
| 37 | + ), |
|
| 38 | 38 | |
| 39 | - array( |
|
| 40 | - array( |
|
| 41 | - 'id' => '1234567890', |
|
| 42 | - 'taxID' => 'fgn nrc 63S0 6F205 A', |
|
| 43 | - 'vatID' => '01234567890', |
|
| 44 | - 'legalName' => 'Test soc srl', |
|
| 45 | - 'businessName' => 'Test soc srl', |
|
| 46 | - 'businessType' => 'schema:MedicalOrganization', |
|
| 47 | - 'addressCountry' => 'IT', |
|
| 48 | - 'addressLocality' => 'LECCO', |
|
| 49 | - 'addressRegion' => 'LC', |
|
| 50 | - 'streetAddress' => 'Via F. Valsecchi,124', |
|
| 51 | - 'postalCode' => '23900', |
|
| 52 | - 'page' => 'http://linkeddata.center/', |
|
| 53 | - 'telephone' => '+39 3356382949', |
|
| 54 | - 'faxNumber' => '+39 3356382949', |
|
| 55 | - 'email' => array('[email protected]'), |
|
| 56 | - 'geoDescription' => array('Via F. Valsecchi,124-23900 Lecco (LC)'), |
|
| 57 | - 'lat' => '1.12345', |
|
| 58 | - 'long' => '2.123456', |
|
| 59 | - ), |
|
| 60 | - array( |
|
| 61 | - 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 62 | - 'lang' => 'it', |
|
| 63 | - 'id' => '1234567890', |
|
| 64 | - 'businessType' => array('schema:MedicalOrganization'), |
|
| 65 | - 'taxID' => 'FGNNRC63S06F205A', |
|
| 66 | - 'vatID' => '01234567890', |
|
| 67 | - 'legalName' => 'TEST SOC SRL', |
|
| 68 | - 'businessName' => array('Test soc srl'), |
|
| 69 | - 'addressCountry' => 'IT', |
|
| 70 | - 'addressLocality' => 'LECCO', |
|
| 71 | - 'addressRegion' => 'LC', |
|
| 72 | - 'streetAddress' => 'VIA F.VALSECCHI, 124', |
|
| 73 | - 'postalCode' => '23900', |
|
| 74 | - 'page' => array('http://linkeddata.center/'), |
|
| 75 | - 'telephone' => '3356382949', |
|
| 76 | - 'faxNumber' => '3356382949', |
|
| 77 | - 'email' => array('[email protected]'), |
|
| 78 | - 'geoDescription' => array('VIA F.VALSECCHI, 124 - 23900 LECCO (LC)'), |
|
| 79 | - 'lat' => '1.12345', |
|
| 80 | - 'long' => '2.123456', |
|
| 81 | - ), |
|
| 82 | - ), |
|
| 83 | - array( |
|
| 84 | - array( |
|
| 85 | - 'id' => '1234567890', |
|
| 86 | - 'addressCountry' => null, |
|
| 87 | - ), |
|
| 88 | - array( |
|
| 89 | - 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 90 | - 'lang' => 'it', |
|
| 91 | - 'id' => '1234567890', |
|
| 92 | - 'addressCountry' => 'IT', |
|
| 93 | - ), |
|
| 94 | - ), |
|
| 95 | - ); |
|
| 96 | - } |
|
| 39 | + array( |
|
| 40 | + array( |
|
| 41 | + 'id' => '1234567890', |
|
| 42 | + 'taxID' => 'fgn nrc 63S0 6F205 A', |
|
| 43 | + 'vatID' => '01234567890', |
|
| 44 | + 'legalName' => 'Test soc srl', |
|
| 45 | + 'businessName' => 'Test soc srl', |
|
| 46 | + 'businessType' => 'schema:MedicalOrganization', |
|
| 47 | + 'addressCountry' => 'IT', |
|
| 48 | + 'addressLocality' => 'LECCO', |
|
| 49 | + 'addressRegion' => 'LC', |
|
| 50 | + 'streetAddress' => 'Via F. Valsecchi,124', |
|
| 51 | + 'postalCode' => '23900', |
|
| 52 | + 'page' => 'http://linkeddata.center/', |
|
| 53 | + 'telephone' => '+39 3356382949', |
|
| 54 | + 'faxNumber' => '+39 3356382949', |
|
| 55 | + 'email' => array('[email protected]'), |
|
| 56 | + 'geoDescription' => array('Via F. Valsecchi,124-23900 Lecco (LC)'), |
|
| 57 | + 'lat' => '1.12345', |
|
| 58 | + 'long' => '2.123456', |
|
| 59 | + ), |
|
| 60 | + array( |
|
| 61 | + 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 62 | + 'lang' => 'it', |
|
| 63 | + 'id' => '1234567890', |
|
| 64 | + 'businessType' => array('schema:MedicalOrganization'), |
|
| 65 | + 'taxID' => 'FGNNRC63S06F205A', |
|
| 66 | + 'vatID' => '01234567890', |
|
| 67 | + 'legalName' => 'TEST SOC SRL', |
|
| 68 | + 'businessName' => array('Test soc srl'), |
|
| 69 | + 'addressCountry' => 'IT', |
|
| 70 | + 'addressLocality' => 'LECCO', |
|
| 71 | + 'addressRegion' => 'LC', |
|
| 72 | + 'streetAddress' => 'VIA F.VALSECCHI, 124', |
|
| 73 | + 'postalCode' => '23900', |
|
| 74 | + 'page' => array('http://linkeddata.center/'), |
|
| 75 | + 'telephone' => '3356382949', |
|
| 76 | + 'faxNumber' => '3356382949', |
|
| 77 | + 'email' => array('[email protected]'), |
|
| 78 | + 'geoDescription' => array('VIA F.VALSECCHI, 124 - 23900 LECCO (LC)'), |
|
| 79 | + 'lat' => '1.12345', |
|
| 80 | + 'long' => '2.123456', |
|
| 81 | + ), |
|
| 82 | + ), |
|
| 83 | + array( |
|
| 84 | + array( |
|
| 85 | + 'id' => '1234567890', |
|
| 86 | + 'addressCountry' => null, |
|
| 87 | + ), |
|
| 88 | + array( |
|
| 89 | + 'base' => 'http://linkeddata.center/botk/resource/', |
|
| 90 | + 'lang' => 'it', |
|
| 91 | + 'id' => '1234567890', |
|
| 92 | + 'addressCountry' => 'IT', |
|
| 93 | + ), |
|
| 94 | + ), |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - public function testGetDefaultOptions() |
|
| 99 | - { |
|
| 100 | - $expectedOptions = array ( |
|
| 101 | - 'base' => array( |
|
| 102 | - 'default' => 'http://linkeddata.center/botk/resource/', |
|
| 103 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 104 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 105 | - ), |
|
| 106 | - 'uri' => array( |
|
| 107 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 108 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 109 | - ), |
|
| 110 | - 'lang' => array( |
|
| 111 | - 'default' => 'it', |
|
| 112 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 113 | - 'options' => array('regexp'=>'/^[a-z]{2}$/'), |
|
| 114 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 115 | - ), |
|
| 116 | - 'id' => array( |
|
| 117 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 118 | - 'options' => array('regexp'=>'/^\w+$/'), |
|
| 119 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 120 | - ), |
|
| 121 | - 'businessType' => array( |
|
| 122 | - // additional types as extension of schema:LocalBusiness |
|
| 123 | - 'filter' => FILTER_DEFAULT, |
|
| 124 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 125 | - ), |
|
| 126 | - 'taxID' => array( |
|
| 127 | - 'filter' => FILTER_CALLBACK, |
|
| 128 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_TOKEN', |
|
| 129 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 130 | - ), |
|
| 131 | - 'vatID' => array( // italian rules |
|
| 132 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 133 | - 'options' => array('regexp'=>'/^[0-9]{11}$/'), |
|
| 134 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 135 | - ), |
|
| 136 | - 'legalName' => array( |
|
| 137 | - 'filter' => FILTER_CALLBACK, |
|
| 138 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 139 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 140 | - ), |
|
| 141 | - 'businessName' => array( |
|
| 142 | - // a schema:alternateName for schema:PostalAddress |
|
| 143 | - 'filter' => FILTER_DEFAULT, |
|
| 144 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 145 | - ), |
|
| 146 | - 'addressCountry' => array( |
|
| 147 | - 'default' => 'IT', |
|
| 148 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 149 | - 'options' => array('regexp'=>'/^[A-Z]{2}$/'), |
|
| 150 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 151 | - ), |
|
| 152 | - 'addressLocality' => array( |
|
| 153 | - 'filter' => FILTER_CALLBACK, |
|
| 154 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 155 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 156 | - ), |
|
| 157 | - 'addressRegion' => array( |
|
| 158 | - 'filter' => FILTER_CALLBACK, |
|
| 159 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 160 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 161 | - ), |
|
| 162 | - 'streetAddress' => array( |
|
| 163 | - 'filter' => FILTER_CALLBACK, |
|
| 164 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 165 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 166 | - ), |
|
| 167 | - 'postalCode' => array( // italian rules |
|
| 168 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 169 | - 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 170 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 171 | - ), |
|
| 172 | - 'page' => array( |
|
| 173 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 174 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 175 | - ), |
|
| 176 | - 'telephone' => array( |
|
| 177 | - 'filter' => FILTER_CALLBACK, |
|
| 178 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 179 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 180 | - ), |
|
| 181 | - 'faxNumber' => array( |
|
| 182 | - 'filter' => FILTER_CALLBACK, |
|
| 183 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 184 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 185 | - ), |
|
| 186 | - 'email' => array( |
|
| 187 | - 'filter' => FILTER_CALLBACK, |
|
| 188 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_EMAIL', |
|
| 189 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 190 | - ), |
|
| 191 | - 'geoDescription' => array( |
|
| 192 | - // a schema:alternateName for schema:GeoCoordinates |
|
| 193 | - 'filter' => FILTER_CALLBACK, |
|
| 194 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 195 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 196 | - ), |
|
| 197 | - 'lat' => array( |
|
| 198 | - 'filter' => FILTER_CALLBACK, |
|
| 199 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
| 200 | - ), |
|
| 201 | - 'long' => array( |
|
| 202 | - 'filter' => FILTER_CALLBACK, |
|
| 203 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
| 204 | - ), |
|
| 205 | - ); |
|
| 98 | + public function testGetDefaultOptions() |
|
| 99 | + { |
|
| 100 | + $expectedOptions = array ( |
|
| 101 | + 'base' => array( |
|
| 102 | + 'default' => 'http://linkeddata.center/botk/resource/', |
|
| 103 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 104 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 105 | + ), |
|
| 106 | + 'uri' => array( |
|
| 107 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 108 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 109 | + ), |
|
| 110 | + 'lang' => array( |
|
| 111 | + 'default' => 'it', |
|
| 112 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 113 | + 'options' => array('regexp'=>'/^[a-z]{2}$/'), |
|
| 114 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 115 | + ), |
|
| 116 | + 'id' => array( |
|
| 117 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 118 | + 'options' => array('regexp'=>'/^\w+$/'), |
|
| 119 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 120 | + ), |
|
| 121 | + 'businessType' => array( |
|
| 122 | + // additional types as extension of schema:LocalBusiness |
|
| 123 | + 'filter' => FILTER_DEFAULT, |
|
| 124 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 125 | + ), |
|
| 126 | + 'taxID' => array( |
|
| 127 | + 'filter' => FILTER_CALLBACK, |
|
| 128 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_TOKEN', |
|
| 129 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 130 | + ), |
|
| 131 | + 'vatID' => array( // italian rules |
|
| 132 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 133 | + 'options' => array('regexp'=>'/^[0-9]{11}$/'), |
|
| 134 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 135 | + ), |
|
| 136 | + 'legalName' => array( |
|
| 137 | + 'filter' => FILTER_CALLBACK, |
|
| 138 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 139 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 140 | + ), |
|
| 141 | + 'businessName' => array( |
|
| 142 | + // a schema:alternateName for schema:PostalAddress |
|
| 143 | + 'filter' => FILTER_DEFAULT, |
|
| 144 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 145 | + ), |
|
| 146 | + 'addressCountry' => array( |
|
| 147 | + 'default' => 'IT', |
|
| 148 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 149 | + 'options' => array('regexp'=>'/^[A-Z]{2}$/'), |
|
| 150 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 151 | + ), |
|
| 152 | + 'addressLocality' => array( |
|
| 153 | + 'filter' => FILTER_CALLBACK, |
|
| 154 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 155 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 156 | + ), |
|
| 157 | + 'addressRegion' => array( |
|
| 158 | + 'filter' => FILTER_CALLBACK, |
|
| 159 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 160 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 161 | + ), |
|
| 162 | + 'streetAddress' => array( |
|
| 163 | + 'filter' => FILTER_CALLBACK, |
|
| 164 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 165 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 166 | + ), |
|
| 167 | + 'postalCode' => array( // italian rules |
|
| 168 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 169 | + 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 170 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 171 | + ), |
|
| 172 | + 'page' => array( |
|
| 173 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 174 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 175 | + ), |
|
| 176 | + 'telephone' => array( |
|
| 177 | + 'filter' => FILTER_CALLBACK, |
|
| 178 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 179 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 180 | + ), |
|
| 181 | + 'faxNumber' => array( |
|
| 182 | + 'filter' => FILTER_CALLBACK, |
|
| 183 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 184 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 185 | + ), |
|
| 186 | + 'email' => array( |
|
| 187 | + 'filter' => FILTER_CALLBACK, |
|
| 188 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_EMAIL', |
|
| 189 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 190 | + ), |
|
| 191 | + 'geoDescription' => array( |
|
| 192 | + // a schema:alternateName for schema:GeoCoordinates |
|
| 193 | + 'filter' => FILTER_CALLBACK, |
|
| 194 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 195 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 196 | + ), |
|
| 197 | + 'lat' => array( |
|
| 198 | + 'filter' => FILTER_CALLBACK, |
|
| 199 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
| 200 | + ), |
|
| 201 | + 'long' => array( |
|
| 202 | + 'filter' => FILTER_CALLBACK, |
|
| 203 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
| 204 | + ), |
|
| 205 | + ); |
|
| 206 | 206 | |
| 207 | - $localBusiness = new BOTK\Model\LocalBusiness(array()); |
|
| 208 | - $this->assertEquals($expectedOptions, $localBusiness->getOptions()); |
|
| 209 | - } |
|
| 207 | + $localBusiness = new BOTK\Model\LocalBusiness(array()); |
|
| 208 | + $this->assertEquals($expectedOptions, $localBusiness->getOptions()); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | |
| 212 | 212 | |
| 213 | - public function testChangeDefaultOptions() |
|
| 214 | - { |
|
| 215 | - $localBusiness = new BOTK\Model\LocalBusiness(array(), array ( |
|
| 216 | - 'lang' => array('default' => 'en'), |
|
| 217 | - 'vatID' => array('options' => array('regexp'=>'/^IT[0-9]{11}$/')), |
|
| 218 | - )); |
|
| 219 | - $options = $localBusiness->getOptions(); |
|
| 220 | - $this->assertEquals( |
|
| 221 | - array( |
|
| 222 | - 'default' => 'en', |
|
| 223 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 224 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 225 | - 'options' => array('regexp'=>'/^[a-z]{2}$/') |
|
| 226 | - ), |
|
| 227 | - $options['lang'] |
|
| 228 | - ); |
|
| 229 | - $this->assertEquals( |
|
| 230 | - array( |
|
| 231 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 232 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 233 | - 'options' => array('regexp'=>'/^IT[0-9]{11}$/') |
|
| 234 | - ), |
|
| 235 | - $options['vatID'] |
|
| 236 | - ); |
|
| 237 | - } |
|
| 213 | + public function testChangeDefaultOptions() |
|
| 214 | + { |
|
| 215 | + $localBusiness = new BOTK\Model\LocalBusiness(array(), array ( |
|
| 216 | + 'lang' => array('default' => 'en'), |
|
| 217 | + 'vatID' => array('options' => array('regexp'=>'/^IT[0-9]{11}$/')), |
|
| 218 | + )); |
|
| 219 | + $options = $localBusiness->getOptions(); |
|
| 220 | + $this->assertEquals( |
|
| 221 | + array( |
|
| 222 | + 'default' => 'en', |
|
| 223 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 224 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 225 | + 'options' => array('regexp'=>'/^[a-z]{2}$/') |
|
| 226 | + ), |
|
| 227 | + $options['lang'] |
|
| 228 | + ); |
|
| 229 | + $this->assertEquals( |
|
| 230 | + array( |
|
| 231 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 232 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 233 | + 'options' => array('regexp'=>'/^IT[0-9]{11}$/') |
|
| 234 | + ), |
|
| 235 | + $options['vatID'] |
|
| 236 | + ); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | |
| 240 | 240 | /** |
| 241 | 241 | * @dataProvider goodRdf |
| 242 | 242 | */ |
| 243 | - public function testRdfGeneration($data, $rdf, $tripleCount) |
|
| 244 | - { |
|
| 245 | - $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 246 | - $this->assertEquals($rdf, $localBusiness->asTurtle()); |
|
| 247 | - $this->assertEquals($tripleCount, $localBusiness->getTripleCount()); |
|
| 248 | - } |
|
| 243 | + public function testRdfGeneration($data, $rdf, $tripleCount) |
|
| 244 | + { |
|
| 245 | + $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 246 | + $this->assertEquals($rdf, $localBusiness->asTurtle()); |
|
| 247 | + $this->assertEquals($tripleCount, $localBusiness->getTripleCount()); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - public function goodRdf() |
|
| 250 | + public function goodRdf() |
|
| 251 | 251 | { |
| 252 | - return array( |
|
| 253 | - array( |
|
| 254 | - array(), |
|
| 255 | - '', |
|
| 256 | - 0, |
|
| 257 | - ), |
|
| 258 | - array( |
|
| 259 | - array( |
|
| 260 | - 'base' => 'urn:', |
|
| 261 | - 'id' => 'abc', |
|
| 262 | - 'vatID' => '01234567890', |
|
| 263 | - 'legalName' => 'Calenda chiodi snc', |
|
| 264 | - ), |
|
| 265 | - '<urn:abc> a schema:Organization;dct:identifier "abc";schema:vatID "01234567890"@it;schema:legalName """CALENDA CHIODI SNC"""@it; . ', |
|
| 266 | - 4, |
|
| 267 | - ), |
|
| 252 | + return array( |
|
| 253 | + array( |
|
| 254 | + array(), |
|
| 255 | + '', |
|
| 256 | + 0, |
|
| 257 | + ), |
|
| 258 | + array( |
|
| 259 | + array( |
|
| 260 | + 'base' => 'urn:', |
|
| 261 | + 'id' => 'abc', |
|
| 262 | + 'vatID' => '01234567890', |
|
| 263 | + 'legalName' => 'Calenda chiodi snc', |
|
| 264 | + ), |
|
| 265 | + '<urn:abc> a schema:Organization;dct:identifier "abc";schema:vatID "01234567890"@it;schema:legalName """CALENDA CHIODI SNC"""@it; . ', |
|
| 266 | + 4, |
|
| 267 | + ), |
|
| 268 | 268 | |
| 269 | - array( |
|
| 270 | - array( |
|
| 271 | - 'uri' => 'urn:abc', |
|
| 272 | - 'vatID' => '01234567890', |
|
| 273 | - 'legalName' => 'Calenda chiodi snc', |
|
| 274 | - ), |
|
| 275 | - '<urn:abc> a schema:Organization;schema:vatID "01234567890"@it;schema:legalName """CALENDA CHIODI SNC"""@it; . ', |
|
| 276 | - 3, |
|
| 277 | - ), |
|
| 269 | + array( |
|
| 270 | + array( |
|
| 271 | + 'uri' => 'urn:abc', |
|
| 272 | + 'vatID' => '01234567890', |
|
| 273 | + 'legalName' => 'Calenda chiodi snc', |
|
| 274 | + ), |
|
| 275 | + '<urn:abc> a schema:Organization;schema:vatID "01234567890"@it;schema:legalName """CALENDA CHIODI SNC"""@it; . ', |
|
| 276 | + 3, |
|
| 277 | + ), |
|
| 278 | 278 | |
| 279 | - array( |
|
| 280 | - array( |
|
| 281 | - 'uri' => 'urn:abc', |
|
| 282 | - 'lat' => '43.23456', |
|
| 283 | - 'long' => '35.23444', |
|
| 284 | - ), |
|
| 285 | - '<urn:abc> a schema:Organization;schema:location <urn:abc_place>; . <geo:43.234560,35.234440> a schema:GeoCoordinates;wgs:lat 43.234560 ;wgs:long 35.234440 ; . <urn:abc_place> a schema:LocalBusiness;schema:geo <geo:43.234560,35.234440>; . ', |
|
| 286 | - 7, |
|
| 287 | - ), |
|
| 288 | - ); |
|
| 289 | - } |
|
| 279 | + array( |
|
| 280 | + array( |
|
| 281 | + 'uri' => 'urn:abc', |
|
| 282 | + 'lat' => '43.23456', |
|
| 283 | + 'long' => '35.23444', |
|
| 284 | + ), |
|
| 285 | + '<urn:abc> a schema:Organization;schema:location <urn:abc_place>; . <geo:43.234560,35.234440> a schema:GeoCoordinates;wgs:lat 43.234560 ;wgs:long 35.234440 ; . <urn:abc_place> a schema:LocalBusiness;schema:geo <geo:43.234560,35.234440>; . ', |
|
| 286 | + 7, |
|
| 287 | + ), |
|
| 288 | + ); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | 291 | |
| 292 | 292 | /** |
| 293 | 293 | * @dataProvider structuredAdresses |
| 294 | 294 | */ |
| 295 | - public function testBuildNormalizedAddress($data, $expectedData) |
|
| 296 | - { |
|
| 297 | - $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 298 | - $this->assertEquals($expectedData, $localBusiness->buildNormalizedAddress($data)); |
|
| 299 | - } |
|
| 295 | + public function testBuildNormalizedAddress($data, $expectedData) |
|
| 296 | + { |
|
| 297 | + $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 298 | + $this->assertEquals($expectedData, $localBusiness->buildNormalizedAddress($data)); |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | 301 | |
| 302 | - public function structuredAdresses() |
|
| 302 | + public function structuredAdresses() |
|
| 303 | 303 | { |
| 304 | - return array( |
|
| 305 | - array( |
|
| 306 | - array( |
|
| 307 | - 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 308 | - 'addressLocality' => 'Lecco', |
|
| 309 | - 'addressRegion' => 'LC', |
|
| 310 | - 'addressCountry' => 'IT', |
|
| 311 | - 'postalCode' => '23900', |
|
| 312 | - ), |
|
| 313 | - 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO (LC) - IT' |
|
| 314 | - ), |
|
| 315 | - array( |
|
| 316 | - array( |
|
| 317 | - 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 318 | - 'addressLocality' => 'Lecco', |
|
| 319 | - 'addressCountry' => 'IT', |
|
| 320 | - ), |
|
| 321 | - 'LUNGOLARIO LUIGI CADORNA, 1, LECCO - IT' |
|
| 322 | - ), |
|
| 323 | - array( |
|
| 324 | - array( |
|
| 325 | - 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 326 | - 'addressCountry' => 'IT', |
|
| 327 | - 'postalCode' => '23900', |
|
| 328 | - ), |
|
| 329 | - 'LUNGOLARIO LUIGI CADORNA, 1, 23900 - IT' |
|
| 330 | - ), |
|
| 331 | - array( |
|
| 332 | - array( |
|
| 333 | - 'addressCountry' => 'IT', |
|
| 334 | - 'postalCode' => '23900', |
|
| 335 | - ), |
|
| 336 | - false |
|
| 337 | - ), |
|
| 338 | - ); |
|
| 339 | - } |
|
| 304 | + return array( |
|
| 305 | + array( |
|
| 306 | + array( |
|
| 307 | + 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 308 | + 'addressLocality' => 'Lecco', |
|
| 309 | + 'addressRegion' => 'LC', |
|
| 310 | + 'addressCountry' => 'IT', |
|
| 311 | + 'postalCode' => '23900', |
|
| 312 | + ), |
|
| 313 | + 'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO (LC) - IT' |
|
| 314 | + ), |
|
| 315 | + array( |
|
| 316 | + array( |
|
| 317 | + 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 318 | + 'addressLocality' => 'Lecco', |
|
| 319 | + 'addressCountry' => 'IT', |
|
| 320 | + ), |
|
| 321 | + 'LUNGOLARIO LUIGI CADORNA, 1, LECCO - IT' |
|
| 322 | + ), |
|
| 323 | + array( |
|
| 324 | + array( |
|
| 325 | + 'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
| 326 | + 'addressCountry' => 'IT', |
|
| 327 | + 'postalCode' => '23900', |
|
| 328 | + ), |
|
| 329 | + 'LUNGOLARIO LUIGI CADORNA, 1, 23900 - IT' |
|
| 330 | + ), |
|
| 331 | + array( |
|
| 332 | + array( |
|
| 333 | + 'addressCountry' => 'IT', |
|
| 334 | + 'postalCode' => '23900', |
|
| 335 | + ), |
|
| 336 | + false |
|
| 337 | + ), |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | 341 | |
| 342 | 342 | /** |
| 343 | - * @expectedException \BOTK\Exceptions\DataModelException |
|
| 343 | + * @expectedException \BOTK\Exceptions\DataModelException |
|
| 344 | 344 | * @dataProvider badLocalBusiness |
| 345 | - * |
|
| 345 | + * |
|
| 346 | 346 | */ |
| 347 | 347 | public function testBadLocalBusiness($data) |
| 348 | - { |
|
| 349 | - $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 350 | - } |
|
| 348 | + { |
|
| 349 | + $localBusiness = new BOTK\Model\LocalBusiness($data); |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - public function badLocalBusiness() |
|
| 352 | + public function badLocalBusiness() |
|
| 353 | 353 | { |
| 354 | - return array( |
|
| 355 | - array(array('lang' => 'IT')), |
|
| 356 | - array(array('id' => 'invalid id')), |
|
| 357 | - array(array('vatID' => '012345678901')), //too long |
|
| 358 | - array(array('addressCountry' => 'italy')), //too long |
|
| 359 | - array(array('addressCountry' => 'it')), //lowercase |
|
| 360 | - array(array('postalCode' => '234992')), //toolong |
|
| 361 | - array(array('email' => 'ENRICO')), |
|
| 362 | - array(array('lat' => '90.12345')), //invalid lat |
|
| 363 | - array(array('lat' => '-90.12345')), //invalid lat |
|
| 354 | + return array( |
|
| 355 | + array(array('lang' => 'IT')), |
|
| 356 | + array(array('id' => 'invalid id')), |
|
| 357 | + array(array('vatID' => '012345678901')), //too long |
|
| 358 | + array(array('addressCountry' => 'italy')), //too long |
|
| 359 | + array(array('addressCountry' => 'it')), //lowercase |
|
| 360 | + array(array('postalCode' => '234992')), //toolong |
|
| 361 | + array(array('email' => 'ENRICO')), |
|
| 362 | + array(array('lat' => '90.12345')), //invalid lat |
|
| 363 | + array(array('lat' => '-90.12345')), //invalid lat |
|
| 364 | 364 | |
| 365 | - ); |
|
| 366 | - } |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | 367 | } |
| 368 | 368 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | public function testGetDefaultOptions() |
| 99 | 99 | { |
| 100 | - $expectedOptions = array ( |
|
| 100 | + $expectedOptions = array( |
|
| 101 | 101 | 'base' => array( |
| 102 | 102 | 'default' => 'http://linkeddata.center/botk/resource/', |
| 103 | 103 | 'filter' => FILTER_SANITIZE_URL, |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | public function testChangeDefaultOptions() |
| 214 | 214 | { |
| 215 | - $localBusiness = new BOTK\Model\LocalBusiness(array(), array ( |
|
| 215 | + $localBusiness = new BOTK\Model\LocalBusiness(array(), array( |
|
| 216 | 216 | 'lang' => array('default' => 'en'), |
| 217 | 217 | 'vatID' => array('options' => array('regexp'=>'/^IT[0-9]{11}$/')), |
| 218 | 218 | )); |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | { |
| 245 | 245 | $localBusiness = new BOTK\Model\LocalBusiness($data); |
| 246 | 246 | $this->assertEquals($rdf, $localBusiness->asTurtle()); |
| 247 | - $this->assertEquals($tripleCount, $localBusiness->getTripleCount()); |
|
| 247 | + $this->assertEquals($tripleCount, $localBusiness->getTripleCount()); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | public function goodRdf() |
@@ -354,13 +354,13 @@ discard block |
||
| 354 | 354 | return array( |
| 355 | 355 | array(array('lang' => 'IT')), |
| 356 | 356 | array(array('id' => 'invalid id')), |
| 357 | - array(array('vatID' => '012345678901')), //too long |
|
| 358 | - array(array('addressCountry' => 'italy')), //too long |
|
| 359 | - array(array('addressCountry' => 'it')), //lowercase |
|
| 360 | - array(array('postalCode' => '234992')), //toolong |
|
| 357 | + array(array('vatID' => '012345678901')), //too long |
|
| 358 | + array(array('addressCountry' => 'italy')), //too long |
|
| 359 | + array(array('addressCountry' => 'it')), //lowercase |
|
| 360 | + array(array('postalCode' => '234992')), //toolong |
|
| 361 | 361 | array(array('email' => 'ENRICO')), |
| 362 | - array(array('lat' => '90.12345')), //invalid lat |
|
| 363 | - array(array('lat' => '-90.12345')), //invalid lat |
|
| 362 | + array(array('lat' => '90.12345')), //invalid lat |
|
| 363 | + array(array('lat' => '-90.12345')), //invalid lat |
|
| 364 | 364 | |
| 365 | 365 | ); |
| 366 | 366 | } |
@@ -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', |
@@ -2,46 +2,46 @@ |
||
| 2 | 2 | require_once __DIR__.'/../vendor/autoload.php'; |
| 3 | 3 | |
| 4 | 4 | $profile = array( |
| 5 | - 'model' => 'LocalBusiness', |
|
| 6 | - 'options' => array( |
|
| 7 | - 'base' => array( 'default'=> 'urn:sample1:') |
|
| 8 | - ), |
|
| 9 | - 'datamapper' => function(array $rawdata){ |
|
| 10 | - $data = array(); |
|
| 11 | - $data['id'] = $rawdata[0]; |
|
| 12 | - $data['businessType'] = 'schema:botk_'.\BOTK\Filters::FILTER_SANITIZE_ID($rawdata[16]); |
|
| 13 | - $data['businessName'][] = trim($rawdata[2] . ' ' . $rawdata[1]); |
|
| 14 | - $data['businessName'][] = $rawdata[2]; |
|
| 15 | - $data['vatID'] = $rawdata[3]; |
|
| 16 | - $data['email'] = $rawdata[4]; |
|
| 17 | - $data['addressLocality'] = $rawdata[5]; |
|
| 18 | - $data['postalCode'] = $rawdata[7]; |
|
| 19 | - $data['addressRegion'] = $rawdata[8]; |
|
| 20 | - $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
|
| 21 | - $data['long'] = $rawdata[14]; |
|
| 22 | - $data['lat'] = $rawdata[15]; |
|
| 5 | + 'model' => 'LocalBusiness', |
|
| 6 | + 'options' => array( |
|
| 7 | + 'base' => array( 'default'=> 'urn:sample1:') |
|
| 8 | + ), |
|
| 9 | + 'datamapper' => function(array $rawdata){ |
|
| 10 | + $data = array(); |
|
| 11 | + $data['id'] = $rawdata[0]; |
|
| 12 | + $data['businessType'] = 'schema:botk_'.\BOTK\Filters::FILTER_SANITIZE_ID($rawdata[16]); |
|
| 13 | + $data['businessName'][] = trim($rawdata[2] . ' ' . $rawdata[1]); |
|
| 14 | + $data['businessName'][] = $rawdata[2]; |
|
| 15 | + $data['vatID'] = $rawdata[3]; |
|
| 16 | + $data['email'] = $rawdata[4]; |
|
| 17 | + $data['addressLocality'] = $rawdata[5]; |
|
| 18 | + $data['postalCode'] = $rawdata[7]; |
|
| 19 | + $data['addressRegion'] = $rawdata[8]; |
|
| 20 | + $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
|
| 21 | + $data['long'] = $rawdata[14]; |
|
| 22 | + $data['lat'] = $rawdata[15]; |
|
| 23 | 23 | |
| 24 | - return $data; |
|
| 25 | - }, |
|
| 24 | + return $data; |
|
| 25 | + }, |
|
| 26 | 26 | ); |
| 27 | 27 | $factsFactory = new \BOTK\FactsFactory($profile); |
| 28 | 28 | |
| 29 | 29 | if (($handle = fopen("sample1.txt", "r")) !== FALSE) { |
| 30 | - //$header = fgets($handle); |
|
| 31 | - echo $factsFactory->generateLinkedDataHeader(); |
|
| 30 | + //$header = fgets($handle); |
|
| 31 | + echo $factsFactory->generateLinkedDataHeader(); |
|
| 32 | 32 | |
| 33 | 33 | while (($rawdata = fgetcsv($handle, 2000, "|")) !== FALSE) { |
| 34 | - try{ |
|
| 35 | - $facts =$factsFactory->factualize($rawdata); |
|
| 36 | - echo $facts->asTurtle(), "\n"; |
|
| 37 | - $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
|
| 38 | - }catch (Exception $e) { |
|
| 39 | - echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
|
| 40 | - $factsFactory->addError($e->getMessage()); |
|
| 41 | - } |
|
| 34 | + try{ |
|
| 35 | + $facts =$factsFactory->factualize($rawdata); |
|
| 36 | + echo $facts->asTurtle(), "\n"; |
|
| 37 | + $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
|
| 38 | + }catch (Exception $e) { |
|
| 39 | + echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
|
| 40 | + $factsFactory->addError($e->getMessage()); |
|
| 41 | + } |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - echo $factsFactory->generateLinkedDataFooter(); |
|
| 44 | + echo $factsFactory->generateLinkedDataFooter(); |
|
| 45 | 45 | |
| 46 | 46 | fclose($handle); |
| 47 | 47 | } |
@@ -4,20 +4,20 @@ discard block |
||
| 4 | 4 | $profile = array( |
| 5 | 5 | 'model' => 'LocalBusiness', |
| 6 | 6 | 'options' => array( |
| 7 | - 'base' => array( 'default'=> 'urn:sample1:') |
|
| 7 | + 'base' => array('default'=> 'urn:sample1:') |
|
| 8 | 8 | ), |
| 9 | - 'datamapper' => function(array $rawdata){ |
|
| 9 | + 'datamapper' => function(array $rawdata) { |
|
| 10 | 10 | $data = array(); |
| 11 | 11 | $data['id'] = $rawdata[0]; |
| 12 | 12 | $data['businessType'] = 'schema:botk_'.\BOTK\Filters::FILTER_SANITIZE_ID($rawdata[16]); |
| 13 | - $data['businessName'][] = trim($rawdata[2] . ' ' . $rawdata[1]); |
|
| 13 | + $data['businessName'][] = trim($rawdata[2].' '.$rawdata[1]); |
|
| 14 | 14 | $data['businessName'][] = $rawdata[2]; |
| 15 | 15 | $data['vatID'] = $rawdata[3]; |
| 16 | 16 | $data['email'] = $rawdata[4]; |
| 17 | 17 | $data['addressLocality'] = $rawdata[5]; |
| 18 | 18 | $data['postalCode'] = $rawdata[7]; |
| 19 | 19 | $data['addressRegion'] = $rawdata[8]; |
| 20 | - $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
|
| 20 | + $data['streetAddress'] = $rawdata[9].' '.$rawdata[10].', '.$rawdata[11]; |
|
| 21 | 21 | $data['long'] = $rawdata[14]; |
| 22 | 22 | $data['lat'] = $rawdata[15]; |
| 23 | 23 | |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | echo $factsFactory->generateLinkedDataHeader(); |
| 32 | 32 | |
| 33 | 33 | while (($rawdata = fgetcsv($handle, 2000, "|")) !== FALSE) { |
| 34 | - try{ |
|
| 35 | - $facts =$factsFactory->factualize($rawdata); |
|
| 34 | + try { |
|
| 35 | + $facts = $factsFactory->factualize($rawdata); |
|
| 36 | 36 | echo $facts->asTurtle(), "\n"; |
| 37 | - $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
|
| 38 | - }catch (Exception $e) { |
|
| 39 | - echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
|
| 37 | + $factsFactory->addToTripleCounter($facts->getTripleCount()); |
|
| 38 | + } catch (Exception $e) { |
|
| 39 | + echo "\n# Caught exception: ", $e->getMessage(), "\n"; |
|
| 40 | 40 | $factsFactory->addError($e->getMessage()); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | $facts =$factsFactory->factualize($rawdata); |
| 36 | 36 | echo $facts->asTurtle(), "\n"; |
| 37 | 37 | $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
| 38 | - }catch (Exception $e) { |
|
| 38 | + } catch (Exception $e) { |
|
| 39 | 39 | echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
| 40 | 40 | $factsFactory->addError($e->getMessage()); |
| 41 | 41 | } |
@@ -2,45 +2,45 @@ |
||
| 2 | 2 | require_once __DIR__.'/../vendor/autoload.php'; |
| 3 | 3 | |
| 4 | 4 | $profile = array( |
| 5 | - 'model' => 'LocalBusiness', |
|
| 6 | - 'source' => 'https://www.dati.lombardia.it/Sanit-/Farmacie/cf6w-iiw9', |
|
| 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 | + 'model' => 'LocalBusiness', |
|
| 6 | + 'source' => 'https://www.dati.lombardia.it/Sanit-/Farmacie/cf6w-iiw9', |
|
| 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 | - }, |
|
| 23 | + return $data; |
|
| 24 | + }, |
|
| 25 | 25 | ); |
| 26 | 26 | $factsFactory = new \BOTK\FactsFactory($profile); |
| 27 | 27 | |
| 28 | 28 | if (($handle = fopen("sample2.csv", "r")) !== FALSE) { |
| 29 | - $header = fgets($handle); |
|
| 30 | - echo $factsFactory->generateLinkedDataHeader(); |
|
| 29 | + $header = fgets($handle); |
|
| 30 | + echo $factsFactory->generateLinkedDataHeader(); |
|
| 31 | 31 | |
| 32 | 32 | while (($rawdata = fgetcsv($handle, 2000, ",")) !== FALSE) { |
| 33 | - try{ |
|
| 34 | - $facts =$factsFactory->factualize($rawdata); |
|
| 35 | - echo $facts->asTurtle(), "\n"; |
|
| 36 | - $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
|
| 37 | - }catch (Exception $e) { |
|
| 38 | - echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
|
| 39 | - $factsFactory->addError($e->getMessage()); |
|
| 40 | - } |
|
| 33 | + try{ |
|
| 34 | + $facts =$factsFactory->factualize($rawdata); |
|
| 35 | + echo $facts->asTurtle(), "\n"; |
|
| 36 | + $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
|
| 37 | + }catch (Exception $e) { |
|
| 38 | + echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
|
| 39 | + $factsFactory->addError($e->getMessage()); |
|
| 40 | + } |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - echo $factsFactory->generateLinkedDataFooter(); |
|
| 43 | + echo $factsFactory->generateLinkedDataFooter(); |
|
| 44 | 44 | |
| 45 | 45 | fclose($handle); |
| 46 | 46 | |
@@ -5,13 +5,13 @@ discard block |
||
| 5 | 5 | 'model' => 'LocalBusiness', |
| 6 | 6 | 'source' => 'https://www.dati.lombardia.it/Sanit-/Farmacie/cf6w-iiw9', |
| 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]; |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | echo $factsFactory->generateLinkedDataHeader(); |
| 31 | 31 | |
| 32 | 32 | while (($rawdata = fgetcsv($handle, 2000, ",")) !== FALSE) { |
| 33 | - try{ |
|
| 34 | - $facts =$factsFactory->factualize($rawdata); |
|
| 33 | + try { |
|
| 34 | + $facts = $factsFactory->factualize($rawdata); |
|
| 35 | 35 | echo $facts->asTurtle(), "\n"; |
| 36 | - $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
|
| 37 | - }catch (Exception $e) { |
|
| 38 | - echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
|
| 36 | + $factsFactory->addToTripleCounter($facts->getTripleCount()); |
|
| 37 | + } catch (Exception $e) { |
|
| 38 | + echo "\n# Caught exception: ", $e->getMessage(), "\n"; |
|
| 39 | 39 | $factsFactory->addError($e->getMessage()); |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | $facts =$factsFactory->factualize($rawdata); |
| 35 | 35 | echo $facts->asTurtle(), "\n"; |
| 36 | 36 | $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
| 37 | - }catch (Exception $e) { |
|
| 37 | + } catch (Exception $e) { |
|
| 38 | 38 | echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
| 39 | 39 | $factsFactory->addError($e->getMessage()); |
| 40 | 40 | } |
@@ -2,47 +2,47 @@ |
||
| 2 | 2 | require_once __DIR__.'/../vendor/autoload.php'; |
| 3 | 3 | |
| 4 | 4 | $profile = array( |
| 5 | - 'model' => 'LocalBusiness', |
|
| 6 | - 'source'=> 'http://www.salute.gov.it/dataset/farmacie.jsp', |
|
| 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'][]= $rawdata[2]; |
|
| 16 | - $data['businessName'][]= 'FARMACIA '.$rawdata[2]; |
|
| 17 | - $data['vatID'] = $rawdata[4]; |
|
| 18 | - $data['postalCode'] = $rawdata[5]; |
|
| 19 | - $data['addressLocality'] = $rawdata[7]; |
|
| 20 | - $data['addressRegion'] = $rawdata[10]; |
|
| 21 | - $data['lat'] = $rawdata[18]; |
|
| 22 | - $data['long'] = $rawdata[19]; |
|
| 5 | + 'model' => 'LocalBusiness', |
|
| 6 | + 'source'=> 'http://www.salute.gov.it/dataset/farmacie.jsp', |
|
| 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'][]= $rawdata[2]; |
|
| 16 | + $data['businessName'][]= 'FARMACIA '.$rawdata[2]; |
|
| 17 | + $data['vatID'] = $rawdata[4]; |
|
| 18 | + $data['postalCode'] = $rawdata[5]; |
|
| 19 | + $data['addressLocality'] = $rawdata[7]; |
|
| 20 | + $data['addressRegion'] = $rawdata[10]; |
|
| 21 | + $data['lat'] = $rawdata[18]; |
|
| 22 | + $data['long'] = $rawdata[19]; |
|
| 23 | 23 | |
| 24 | - return $data; |
|
| 25 | - }, |
|
| 24 | + return $data; |
|
| 25 | + }, |
|
| 26 | 26 | ); |
| 27 | 27 | $factsFactory = new \BOTK\FactsFactory($profile); |
| 28 | 28 | |
| 29 | 29 | if (($handle = fopen("sample3.CSV", "r")) !== FALSE) { |
| 30 | - $header = fgets($handle); |
|
| 31 | - echo $factsFactory->generateLinkedDataHeader(); |
|
| 30 | + $header = fgets($handle); |
|
| 31 | + echo $factsFactory->generateLinkedDataHeader(); |
|
| 32 | 32 | |
| 33 | 33 | while (($rawdata = fgetcsv($handle, 2000, ";")) !== FALSE) { |
| 34 | - if($rawdata[15]!='-') continue; |
|
| 35 | - try{ |
|
| 36 | - $facts =$factsFactory->factualize($rawdata); |
|
| 37 | - echo $facts->asTurtle(), "\n"; |
|
| 38 | - $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
|
| 39 | - }catch (Exception $e) { |
|
| 40 | - echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
|
| 41 | - $factsFactory->addError($e->getMessage()); |
|
| 42 | - } |
|
| 34 | + if($rawdata[15]!='-') continue; |
|
| 35 | + try{ |
|
| 36 | + $facts =$factsFactory->factualize($rawdata); |
|
| 37 | + echo $facts->asTurtle(), "\n"; |
|
| 38 | + $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
|
| 39 | + }catch (Exception $e) { |
|
| 40 | + echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
|
| 41 | + $factsFactory->addError($e->getMessage()); |
|
| 42 | + } |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - echo $factsFactory->generateLinkedDataFooter(); |
|
| 45 | + echo $factsFactory->generateLinkedDataFooter(); |
|
| 46 | 46 | |
| 47 | 47 | fclose($handle); |
| 48 | 48 | |
@@ -5,15 +5,15 @@ discard block |
||
| 5 | 5 | 'model' => 'LocalBusiness', |
| 6 | 6 | 'source'=> 'http://www.salute.gov.it/dataset/farmacie.jsp', |
| 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 | - $data['businessName'][]= $rawdata[2]; |
|
| 16 | - $data['businessName'][]= 'FARMACIA '.$rawdata[2]; |
|
| 15 | + $data['businessName'][] = $rawdata[2]; |
|
| 16 | + $data['businessName'][] = 'FARMACIA '.$rawdata[2]; |
|
| 17 | 17 | $data['vatID'] = $rawdata[4]; |
| 18 | 18 | $data['postalCode'] = $rawdata[5]; |
| 19 | 19 | $data['addressLocality'] = $rawdata[7]; |
@@ -31,13 +31,13 @@ discard block |
||
| 31 | 31 | echo $factsFactory->generateLinkedDataHeader(); |
| 32 | 32 | |
| 33 | 33 | while (($rawdata = fgetcsv($handle, 2000, ";")) !== FALSE) { |
| 34 | - if($rawdata[15]!='-') continue; |
|
| 35 | - try{ |
|
| 36 | - $facts =$factsFactory->factualize($rawdata); |
|
| 34 | + if ($rawdata[15] != '-') continue; |
|
| 35 | + try { |
|
| 36 | + $facts = $factsFactory->factualize($rawdata); |
|
| 37 | 37 | echo $facts->asTurtle(), "\n"; |
| 38 | - $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
|
| 39 | - }catch (Exception $e) { |
|
| 40 | - echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
|
| 38 | + $factsFactory->addToTripleCounter($facts->getTripleCount()); |
|
| 39 | + } catch (Exception $e) { |
|
| 40 | + echo "\n# Caught exception: ", $e->getMessage(), "\n"; |
|
| 41 | 41 | $factsFactory->addError($e->getMessage()); |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -31,12 +31,14 @@ |
||
| 31 | 31 | echo $factsFactory->generateLinkedDataHeader(); |
| 32 | 32 | |
| 33 | 33 | while (($rawdata = fgetcsv($handle, 2000, ";")) !== FALSE) { |
| 34 | - if($rawdata[15]!='-') continue; |
|
| 34 | + if($rawdata[15]!='-') { |
|
| 35 | + continue; |
|
| 36 | + } |
|
| 35 | 37 | try{ |
| 36 | 38 | $facts =$factsFactory->factualize($rawdata); |
| 37 | 39 | echo $facts->asTurtle(), "\n"; |
| 38 | 40 | $factsFactory->addToTripleCounter($facts->getTripleCount()) ; |
| 39 | - }catch (Exception $e) { |
|
| 41 | + } catch (Exception $e) { |
|
| 40 | 42 | echo "\n# Caught exception: " , $e->getMessage(), "\n"; |
| 41 | 43 | $factsFactory->addError($e->getMessage()); |
| 42 | 44 | } |