Complex classes like ARC2_TurtleParser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ARC2_TurtleParser, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class ARC2_TurtleParser extends ARC2_RDFParser { |
||
| 15 | |||
| 16 | function __construct($a = '', &$caller) { |
||
| 19 | |||
| 20 | function ARC2_TurtleParser($a = '', &$caller) { |
||
| 23 | |||
| 24 | function __init() {/* reader */ |
||
| 25 | parent::__init(); |
||
| 26 | $this->state = 0; |
||
| 27 | $this->xml = 'http://www.w3.org/XML/1998/namespace'; |
||
| 28 | $this->rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; |
||
| 29 | $this->xsd = 'http://www.w3.org/2001/XMLSchema#'; |
||
| 30 | $this->nsp = array($this->xml => 'xml', $this->rdf => 'rdf', $this->xsd => 'xsd'); |
||
| 31 | $this->unparsed_code = ''; |
||
| 32 | $this->max_parsing_loops = $this->v('turtle_max_parsing_loops', 500, $this->a); |
||
| 33 | } |
||
| 34 | |||
| 35 | /* */ |
||
| 36 | |||
| 37 | function x($re, $v, $options = 'si') { |
||
| 38 | $v = preg_replace('/^[\xA0\xC2]+/', ' ', $v); |
||
| 39 | while (preg_match('/^\s*(\#[^\xd\xa]*)(.*)$/si', $v, $m)) {/* comment removal */ |
||
| 40 | $v = $m[2]; |
||
| 41 | } |
||
| 42 | return ARC2::x($re, $v, $options); |
||
| 43 | //$this->unparsed_code = ($sub_r && count($sub_r)) ? $sub_r[count($sub_r) - 1] : ''; |
||
| 44 | } |
||
| 45 | |||
| 46 | function createBnodeID(){ |
||
| 50 | |||
| 51 | /* */ |
||
| 52 | |||
| 53 | function addT($t) { |
||
| 54 | if ($this->skip_dupes) { |
||
| 55 | $h = md5(serialize($t)); |
||
| 56 | if (!isset($this->added_triples[$h])) { |
||
| 57 | $this->triples[$this->t_count] = $t; |
||
| 58 | $this->t_count++; |
||
| 59 | $this->added_triples[$h] = true; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | else { |
||
| 63 | $this->triples[$this->t_count] = $t; |
||
| 64 | $this->t_count++; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | /* */ |
||
| 69 | |||
| 70 | function getTriples() { |
||
| 73 | |||
| 74 | function countTriples() { |
||
| 77 | |||
| 78 | /* */ |
||
| 79 | |||
| 80 | function getUnparsedCode() { |
||
| 83 | |||
| 84 | /* */ |
||
| 85 | |||
| 86 | function setDefaultPrefixes() { |
||
| 87 | $this->prefixes = array( |
||
| 88 | 'rdf:' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
||
| 89 | 'rdfs:' => 'http://www.w3.org/2000/01/rdf-schema#', |
||
| 90 | 'owl:' => 'http://www.w3.org/2002/07/owl#', |
||
| 91 | 'xsd:' => 'http://www.w3.org/2001/XMLSchema#', |
||
| 92 | ); |
||
| 93 | if ($ns = $this->v('ns', array(), $this->a)) { |
||
| 94 | foreach ($ns as $p => $u) $this->prefixes[$p . ':'] = $u; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | |||
| 99 | function parse($path, $data = '', $iso_fallback = false) { |
||
| 100 | $this->setDefaultPrefixes(); |
||
| 101 | /* reader */ |
||
| 102 | if (!$this->v('reader')) { |
||
| 103 | ARC2::inc('Reader'); |
||
| 104 | $this->reader = & new ARC2_Reader($this->a, $this); |
||
| 105 | } |
||
| 106 | $this->reader->setAcceptHeader('Accept: application/x-turtle; q=0.9, */*; q=0.1'); |
||
| 107 | $this->reader->activate($path, $data); |
||
| 108 | $this->base = $this->v1('base', $this->reader->base, $this->a); |
||
| 109 | $this->r = array('vars' => array()); |
||
| 110 | /* parse */ |
||
| 111 | $buffer = ''; |
||
| 112 | $more_triples = array(); |
||
| 113 | $sub_v = ''; |
||
| 114 | $sub_v2 = ''; |
||
| 115 | $loops = 0; |
||
| 116 | $prologue_done = 0; |
||
| 117 | while ($d = $this->reader->readStream(0)) { |
||
| 118 | $buffer .= $d; |
||
| 119 | $sub_v = $buffer; |
||
| 120 | do { |
||
| 121 | $proceed = 0; |
||
| 122 | if (!$prologue_done) { |
||
| 123 | $proceed = 1; |
||
| 124 | if ((list($sub_r, $sub_v) = $this->xPrologue($sub_v)) && $sub_r) { |
||
| 125 | $loops = 0; |
||
| 126 | $sub_v .= $this->reader->readStream(0, 128); |
||
| 127 | /* we might have missed the final DOT in the previous prologue loop */ |
||
| 128 | if ($sub_r = $this->x('\.', $sub_v)) $sub_v = $sub_r[1]; |
||
| 129 | if ($this->x("\@?(base|prefix)", $sub_v)) {/* more prologue to come, use outer loop */ |
||
| 130 | $proceed = 0; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | else { |
||
| 134 | $prologue_done = 1; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | if ($prologue_done && (list($sub_r, $sub_v, $more_triples, $sub_v2) = $this->xTriplesBlock($sub_v)) && is_array($sub_r)) { |
||
| 138 | $proceed = 1; |
||
| 139 | $loops = 0; |
||
| 140 | foreach ($sub_r as $t) { |
||
| 141 | $this->addT($t); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } while ($proceed); |
||
| 145 | $loops++; |
||
| 146 | $buffer = $sub_v; |
||
| 147 | if ($loops > $this->max_parsing_loops) {/* most probably a parser or code bug, might also be a huge object value, though */ |
||
| 148 | $this->addError('too many loops: ' . $loops . '. Could not parse "' . substr($buffer, 0, 200) . '..."'); |
||
| 149 | break; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | foreach ($more_triples as $t) { |
||
| 153 | $this->addT($t); |
||
| 154 | } |
||
| 155 | $sub_v = count($more_triples) ? $sub_v2 : $sub_v; |
||
| 156 | $buffer = $sub_v; |
||
| 157 | $this->unparsed_code = $buffer; |
||
| 158 | $this->reader->closeStream(); |
||
| 159 | unset($this->reader); |
||
| 160 | /* remove trailing comments */ |
||
| 161 | while (preg_match('/^\s*(\#[^\xd\xa]*)(.*)$/si', $this->unparsed_code, $m)) $this->unparsed_code = $m[2]; |
||
| 162 | if ($this->unparsed_code && !$this->getErrors()) { |
||
| 163 | $rest = preg_replace('/[\x0a|\x0d]/i', ' ', substr($this->unparsed_code, 0, 30)); |
||
| 164 | if (trim($rest)) $this->addError('Could not parse "' . $rest . '"'); |
||
| 165 | } |
||
| 166 | return $this->done(); |
||
| 167 | } |
||
| 168 | |||
| 169 | function xPrologue($v) { |
||
| 170 | $r = 0; |
||
| 171 | if (!$this->t_count) { |
||
| 172 | if ((list($sub_r, $v) = $this->xBaseDecl($v)) && $sub_r) { |
||
| 173 | $this->base = $sub_r; |
||
| 174 | $r = 1; |
||
| 175 | } |
||
| 176 | while ((list($sub_r, $v) = $this->xPrefixDecl($v)) && $sub_r) { |
||
| 177 | $this->prefixes[$sub_r['prefix']] = $sub_r['uri']; |
||
| 178 | $r = 1; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | return array($r, $v); |
||
| 182 | } |
||
| 183 | |||
| 184 | /* 3 */ |
||
| 185 | |||
| 186 | function xBaseDecl($v) { |
||
| 187 | if ($r = $this->x("\@?base\s+", $v)) { |
||
| 188 | if ((list($r, $sub_v) = $this->xIRI_REF($r[1])) && $r) { |
||
| 189 | if ($sub_r = $this->x('\.', $sub_v)) { |
||
| 190 | $sub_v = $sub_r[1]; |
||
| 191 | } |
||
| 192 | return array($r, $sub_v); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | return array(0, $v); |
||
| 196 | } |
||
| 197 | |||
| 198 | /* 4 */ |
||
| 199 | |||
| 200 | function xPrefixDecl($v) { |
||
| 201 | if ($r = $this->x("\@?prefix\s+", $v)) { |
||
| 202 | if ((list($r, $sub_v) = $this->xPNAME_NS($r[1])) && $r) { |
||
| 203 | $prefix = $r; |
||
| 204 | if((list($r, $sub_v) = $this->xIRI_REF($sub_v)) && $r) { |
||
| 205 | $uri = $this->calcURI($r, $this->base); |
||
| 206 | if ($sub_r = $this->x('\.', $sub_v)) { |
||
| 207 | $sub_v = $sub_r[1]; |
||
| 208 | } |
||
| 209 | return array(array('prefix' => $prefix, 'uri_ref' => $r, 'uri' => $uri), $sub_v); |
||
| 210 | } |
||
| 211 | } |
||
| 212 | } |
||
| 213 | return array(0, $v); |
||
| 214 | } |
||
| 215 | |||
| 216 | /* 21.., 32.. */ |
||
| 217 | |||
| 218 | function xTriplesBlock($v) { |
||
| 347 | |||
| 348 | /* 39.. */ |
||
| 349 | |||
| 350 | function xBlankNodePropertyList($v) { |
||
| 430 | |||
| 431 | /* 40.. */ |
||
| 432 | |||
| 433 | function xCollection($v) { |
||
| 434 | if ($sub_r = $this->x('\(', $v)) { |
||
| 435 | $sub_v = $sub_r[1]; |
||
| 436 | $s = $this->createBnodeID(); |
||
| 437 | $r = array('id' => $s, 'type' => 'bnode', 'triples' => array()); |
||
| 438 | $closed = 0; |
||
| 439 | do { |
||
| 440 | $proceed = 0; |
||
| 441 | if ((list($sub_r, $sub_v) = $this->xVarOrTerm($sub_v)) && $sub_r) { |
||
| 442 | $r['triples'][] = array('type' => 'triple', 's' => $s, 'p' => $this->rdf . 'first', 'o' => $sub_r['value'], 's_type' => 'bnode', 'p_type' => 'uri', 'o_type' => $sub_r['type'], 'o_lang' => $this->v('lang', '', $sub_r), 'o_datatype' => $this->v('datatype', '', $sub_r)); |
||
| 443 | $proceed = 1; |
||
| 444 | } |
||
| 445 | elseif ((list($sub_r, $sub_v) = $this->xCollection($sub_v)) && $sub_r) { |
||
| 446 | $r['triples'][] = array('type' => 'triple', 's' => $s, 'p' => $this->rdf . 'first', 'o' => $sub_r['id'], 's_type' => 'bnode', 'p_type' => 'uri', 'o_type' => $sub_r['type'], 'o_lang' => '', 'o_datatype' => ''); |
||
| 447 | $r['triples'] = array_merge($r['triples'], $sub_r['triples']); |
||
| 448 | $proceed = 1; |
||
| 449 | } |
||
| 450 | elseif((list($sub_r, $sub_v) = $this->xBlankNodePropertyList($sub_v)) && $sub_r) { |
||
| 451 | $r['triples'][] = array('type' => 'triple', 's' => $s, 'p' => $this->rdf . 'first', 'o' => $sub_r['id'], 's_type' => 'bnode', 'p_type' => 'uri', 'o_type' => $sub_r['type'], 'o_lang' => '', 'o_datatype' => ''); |
||
| 452 | $r['triples'] = array_merge($r['triples'], $sub_r['triples']); |
||
| 453 | $proceed = 1; |
||
| 454 | } |
||
| 455 | if ($proceed) { |
||
| 456 | if ($sub_r = $this->x('\)', $sub_v)) { |
||
| 457 | $sub_v = $sub_r[1]; |
||
| 458 | $r['triples'][] = array('type' => 'triple', 's' => $s, 'p' => $this->rdf . 'rest', 'o' => $this->rdf . 'nil', 's_type' => 'bnode', 'p_type' => 'uri', 'o_type' => 'uri', 'o_lang' => '', 'o_datatype' => ''); |
||
| 459 | $closed = 1; |
||
| 460 | $proceed = 0; |
||
| 461 | } |
||
| 462 | else { |
||
| 463 | $next_s = $this->createBnodeID(); |
||
| 464 | $r['triples'][] = array('type' => 'triple', 's' => $s, 'p' => $this->rdf . 'rest', 'o' => $next_s, 's_type' => 'bnode', 'p_type' => 'uri', 'o_type' => 'bnode', 'o_lang' => '', 'o_datatype' => ''); |
||
| 465 | $s = $next_s; |
||
| 466 | } |
||
| 467 | } |
||
| 468 | } while ($proceed); |
||
| 469 | if ($closed) { |
||
| 470 | return array($r, $sub_v); |
||
| 471 | } |
||
| 472 | } |
||
| 473 | return array (0, $v); |
||
| 474 | } |
||
| 475 | |||
| 476 | /* 42 */ |
||
| 477 | |||
| 478 | function xVarOrTerm($v) { |
||
| 479 | if ((list($sub_r, $sub_v) = $this->xVar($v)) && $sub_r) { |
||
| 480 | return array($sub_r, $sub_v); |
||
| 481 | } |
||
| 482 | elseif ((list($sub_r, $sub_v) = $this->xGraphTerm($v)) && $sub_r) { |
||
| 483 | return array($sub_r, $sub_v); |
||
| 484 | } |
||
| 485 | return array(0, $v); |
||
| 486 | } |
||
| 487 | |||
| 488 | /* 44, 74.., 75.. */ |
||
| 489 | |||
| 490 | function xVar($v) { |
||
| 491 | if ($r = $this->x('(\?|\$)([^\s]+)', $v)) { |
||
| 492 | if ((list($sub_r, $sub_v) = $this->xVARNAME($r[2])) && $sub_r) { |
||
| 493 | if (!in_array($sub_r, $this->r['vars'])) { |
||
| 494 | $this->r['vars'][] = $sub_r; |
||
| 495 | } |
||
| 496 | return array(array('value' => $sub_r, 'type' => 'var'), $sub_v . $r[3]); |
||
| 497 | } |
||
| 498 | } |
||
| 499 | return array(0, $v); |
||
| 500 | } |
||
| 501 | |||
| 502 | /* 45 */ |
||
| 503 | |||
| 504 | function xGraphTerm($v) { |
||
| 505 | foreach (array( |
||
| 506 | 'IRIref' => 'uri', |
||
| 507 | 'RDFLiteral' => 'literal', |
||
| 508 | 'NumericLiteral' => 'literal', |
||
| 509 | 'BooleanLiteral' => 'literal', |
||
| 510 | 'BlankNode' => 'bnode', |
||
| 511 | 'NIL' => 'uri', |
||
| 512 | 'Placeholder' => 'placeholder' |
||
| 513 | ) as $term => $type) { |
||
| 514 | $m = 'x' . $term; |
||
| 515 | if ((list($sub_r, $sub_v) = $this->$m($v)) && $sub_r) { |
||
| 516 | if (!is_array($sub_r)) { |
||
| 517 | $sub_r = array('value' => $sub_r); |
||
| 518 | } |
||
| 519 | $sub_r['type'] = $this->v1('type', $type, $sub_r); |
||
| 520 | return array($sub_r, $sub_v); |
||
| 521 | } |
||
| 522 | } |
||
| 523 | return array(0, $v); |
||
| 524 | } |
||
| 525 | |||
| 526 | /* 60 */ |
||
| 527 | |||
| 528 | function xRDFLiteral($v) { |
||
| 529 | if ((list($sub_r, $sub_v) = $this->xString($v)) && $sub_r) { |
||
| 530 | $sub_r['value'] = $this->unescapeNtripleUTF($sub_r['value']); |
||
| 531 | $r = $sub_r; |
||
| 532 | if ((list($sub_r, $sub_v) = $this->xLANGTAG($sub_v)) && $sub_r) { |
||
| 533 | $r['lang'] = $sub_r; |
||
| 534 | } |
||
| 535 | elseif (!$this->x('\s', $sub_v) && ($sub_r = $this->x('\^\^', $sub_v)) && (list($sub_r, $sub_v) = $this->xIRIref($sub_r[1])) && $sub_r[1]) { |
||
| 536 | $r['datatype'] = $sub_r; |
||
| 537 | } |
||
| 538 | return array($r, $sub_v); |
||
| 539 | } |
||
| 540 | return array(0, $v); |
||
| 541 | } |
||
| 542 | |||
| 543 | /* 61.., 62.., 63.., 64.. */ |
||
| 544 | |||
| 545 | function xNumericLiteral($v) { |
||
| 558 | |||
| 559 | /* 65.. */ |
||
| 560 | |||
| 561 | function xBooleanLiteral($v) { |
||
| 562 | if ($r = $this->x('(true|false)', $v)) { |
||
| 563 | return array($r[1], $r[2]); |
||
| 564 | } |
||
| 565 | return array(0, $v); |
||
| 566 | } |
||
| 567 | |||
| 568 | /* 66.., 87.., 88.., 89.., 90.., 91.. */ |
||
| 569 | |||
| 570 | function xString($v) {/* largely simplified, may need some tweaks in following revisions */ |
||
| 571 | $sub_v = $v; |
||
| 572 | if (!preg_match('/^\s*([\']{3}|\'|[\"]{3}|\")(.*)$/s', $sub_v, $m)) return array(0, $v); |
||
| 573 | $delim = $m[1]; |
||
| 574 | $rest = $m[2]; |
||
| 575 | $sub_types = array("'''" => 'literal_long1', '"""' => 'literal_long2', "'" => 'literal1', '"' => 'literal2'); |
||
| 576 | $sub_type = $sub_types[$delim]; |
||
| 577 | $pos = 0; |
||
| 578 | $r = false; |
||
| 579 | do { |
||
| 580 | $proceed = 0; |
||
| 581 | $delim_pos = strpos($rest, $delim, $pos); |
||
| 582 | if ($delim_pos === false) break; |
||
| 583 | $new_rest = substr($rest, $delim_pos + strlen($delim)); |
||
| 584 | $r = substr($rest, 0, $delim_pos); |
||
| 585 | if (!preg_match('/([\x5c]+)$/s', $r, $m) || !(strlen($m[1]) % 2)) { |
||
| 586 | $rest = $new_rest; |
||
| 587 | } |
||
| 588 | else { |
||
| 589 | $r = false; |
||
| 590 | $pos = $delim_pos + 1; |
||
| 591 | $proceed = 1; |
||
| 592 | } |
||
| 593 | } while ($proceed); |
||
| 594 | if ($r !== false) { |
||
| 595 | return array(array('value' => $this->toUTF8($r) , 'type' => 'literal', 'sub_type' => $sub_type), $rest); |
||
| 596 | } |
||
| 597 | return array(0, $v); |
||
| 598 | } |
||
| 599 | |||
| 600 | /* 67 */ |
||
| 601 | |||
| 602 | function xIRIref($v) { |
||
| 603 | if ((list($r, $v) = $this->xIRI_REF($v)) && $r) { |
||
| 604 | return array($this->calcURI($r, $this->base), $v); |
||
| 605 | } |
||
| 606 | elseif ((list($r, $v) = $this->xPrefixedName($v)) && $r) { |
||
| 607 | return array($r, $v); |
||
| 608 | } |
||
| 609 | return array(0, $v); |
||
| 610 | } |
||
| 611 | |||
| 612 | /* 68 */ |
||
| 613 | |||
| 614 | function xPrefixedName($v) { |
||
| 615 | if ((list($r, $v) = $this->xPNAME_LN($v)) && $r) { |
||
| 616 | return array($r, $v); |
||
| 617 | } |
||
| 618 | elseif ((list($r, $sub_v) = $this->xPNAME_NS($v)) && $r) { |
||
| 619 | return isset($this->prefixes[$r]) ? array($this->prefixes[$r], $sub_v) : array(0, $v); |
||
| 620 | } |
||
| 621 | return array(0, $v); |
||
| 622 | } |
||
| 623 | |||
| 624 | /* 69.., 73.., 93, 94.. */ |
||
| 625 | |||
| 626 | function xBlankNode($v) { |
||
| 627 | if (($r = $this->x('\_\:', $v)) && (list($r, $sub_v) = $this->xPN_LOCAL($r[1])) && $r) { |
||
| 628 | return array(array('type' => 'bnode', 'value' => '_:' . $r), $sub_v); |
||
| 629 | } |
||
| 630 | if ($r = $this->x('\[[\x20\x9\xd\xa]*\]', $v)) { |
||
| 631 | return array(array('type' => 'bnode', 'value' => $this->createBnodeID()), $r[1]); |
||
| 632 | } |
||
| 633 | return array(0, $v); |
||
| 634 | } |
||
| 635 | |||
| 636 | /* 70.. @@sync with SPARQLParser */ |
||
| 637 | |||
| 638 | function xIRI_REF($v) { |
||
| 639 | //if ($r = $this->x('\<([^\<\>\"\{\}\|\^\'[:space:]]*)\>', $v)) { |
||
| 640 | if (($r = $this->x('\<(\$\{[^\>]*\})\>', $v)) && ($sub_r = $this->xPlaceholder($r[1]))) { |
||
| 641 | return array($r[1], $r[2]); |
||
| 642 | } |
||
| 643 | elseif ($r = $this->x('\<\>', $v)) { |
||
| 644 | return array(true, $r[1]); |
||
| 645 | } |
||
| 646 | elseif ($r = $this->x('\<([^\s][^\<\>]*)\>', $v)) { |
||
| 647 | return array($r[1] ? $r[1] : true, $r[2]); |
||
| 648 | } |
||
| 649 | return array(0, $v); |
||
| 650 | } |
||
| 651 | |||
| 652 | /* 71 */ |
||
| 653 | |||
| 654 | function xPNAME_NS($v) { |
||
| 655 | list($r, $sub_v) = $this->xPN_PREFIX($v); |
||
| 656 | $prefix = $r ? $r : ''; |
||
| 657 | return ($r = $this->x("\:", $sub_v)) ? array($prefix . ':', $r[1]) : array(0, $v); |
||
| 658 | } |
||
| 659 | |||
| 660 | /* 72 */ |
||
| 661 | |||
| 662 | function xPNAME_LN($v) { |
||
| 663 | if ((list($r, $sub_v) = $this->xPNAME_NS($v)) && $r) { |
||
| 664 | if (!$this->x('\s', $sub_v) && (list($sub_r, $sub_v) = $this->xPN_LOCAL($sub_v)) && $sub_r) { |
||
| 665 | if (!isset($this->prefixes[$r])) { |
||
| 666 | return array(0, $v); |
||
| 667 | } |
||
| 668 | return array($this->prefixes[$r] . $sub_r, $sub_v); |
||
| 669 | } |
||
| 670 | } |
||
| 671 | return array(0, $v); |
||
| 672 | } |
||
| 673 | |||
| 674 | /* 76 */ |
||
| 675 | |||
| 676 | function xLANGTAG($v) { |
||
| 677 | if (!$this->x('\s', $v) && ($r = $this->x('\@([a-z]+(\-[a-z0-9]+)*)', $v))) { |
||
| 678 | return array($r[1], $r[3]); |
||
| 679 | } |
||
| 680 | return array(0, $v); |
||
| 681 | } |
||
| 682 | |||
| 683 | /* 77.. */ |
||
| 684 | |||
| 685 | function xINTEGER($v) { |
||
| 686 | if ($r = $this->x('([0-9]+)', $v)) { |
||
| 687 | return array($r[1], $r[2]); |
||
| 688 | } |
||
| 689 | return array(false, $v); |
||
| 690 | } |
||
| 691 | |||
| 692 | /* 78.. */ |
||
| 693 | |||
| 694 | function xDECIMAL($v) { |
||
| 695 | if ($r = $this->x('([0-9]+\.[0-9]*)', $v)) { |
||
| 696 | return array($r[1], $r[2]); |
||
| 697 | } |
||
| 698 | if ($r = $this->x('(\.[0-9]+)', $v)) { |
||
| 699 | return array($r[1], $r[2]); |
||
| 700 | } |
||
| 701 | return array(false, $v); |
||
| 702 | } |
||
| 703 | |||
| 704 | /* 79.., 86.. */ |
||
| 705 | |||
| 706 | function xDOUBLE($v) { |
||
| 718 | |||
| 719 | /* 92 */ |
||
| 720 | |||
| 721 | function xNIL($v) { |
||
| 722 | if ($r = $this->x('\([\x20\x9\xd\xa]*\)', $v)) { |
||
| 723 | return array(array('type' => 'uri', 'value' => $this->rdf . 'nil'), $r[1]); |
||
| 724 | } |
||
| 725 | return array(0, $v); |
||
| 726 | } |
||
| 727 | |||
| 728 | /* 95.. */ |
||
| 729 | |||
| 730 | function xPN_CHARS_BASE($v) { |
||
| 731 | if ($r = $this->x("([a-z]+|\\\u[0-9a-f]{1,4})", $v)) { |
||
| 732 | return array($r[1], $r[2]); |
||
| 733 | } |
||
| 734 | return array(0, $v); |
||
| 735 | } |
||
| 736 | |||
| 737 | /* 96 */ |
||
| 738 | |||
| 739 | function xPN_CHARS_U($v) { |
||
| 748 | |||
| 749 | /* 97.. */ |
||
| 750 | |||
| 751 | function xVARNAME($v) { |
||
| 752 | $r = ''; |
||
| 753 | do { |
||
| 754 | $proceed = 0; |
||
| 755 | if ($sub_r = $this->x('([0-9]+)', $v)) { |
||
| 756 | $r .= $sub_r[1]; |
||
| 757 | $v = $sub_r[2]; |
||
| 758 | $proceed = 1; |
||
| 759 | } |
||
| 760 | elseif ((list($sub_r, $sub_v) = $this->xPN_CHARS_U($v)) && $sub_r) { |
||
| 761 | $r .= $sub_r; |
||
| 762 | $v = $sub_v; |
||
| 763 | $proceed = 1; |
||
| 764 | } |
||
| 765 | elseif ($r && ($sub_r = $this->x('([\xb7\x300-\x36f]+)', $v))) { |
||
| 766 | $r .= $sub_r[1]; |
||
| 767 | $v = $sub_r[2]; |
||
| 768 | $proceed = 1; |
||
| 769 | } |
||
| 770 | } while ($proceed); |
||
| 771 | return array($r, $v); |
||
| 772 | } |
||
| 773 | |||
| 774 | /* 98.. */ |
||
| 775 | |||
| 776 | function xPN_CHARS($v) { |
||
| 785 | |||
| 786 | /* 99 */ |
||
| 787 | |||
| 788 | function xPN_PREFIX($v) { |
||
| 789 | if ($sub_r = $this->x("([^\s\:\(\)\{\}\;\,]+)", $v, 's')) {/* accelerator */ |
||
| 790 | return array($sub_r[1], $sub_r[2]);/* @@testing */ |
||
| 791 | } |
||
| 792 | if ((list($r, $sub_v) = $this->xPN_CHARS_BASE($v)) && $r) { |
||
| 793 | do { |
||
| 794 | $proceed = 0; |
||
| 795 | list($sub_r, $sub_v) = $this->xPN_CHARS($sub_v); |
||
| 796 | if ($sub_r !== false) { |
||
| 797 | $r .= $sub_r; |
||
| 798 | $proceed = 1; |
||
| 799 | } |
||
| 800 | elseif ($sub_r = $this->x("\.", $sub_v)) { |
||
| 801 | $r .= '.'; |
||
| 802 | $sub_v = $sub_r[1]; |
||
| 803 | $proceed = 1; |
||
| 804 | } |
||
| 805 | } while ($proceed); |
||
| 806 | list($sub_r, $sub_v) = $this->xPN_CHARS($sub_v); |
||
| 807 | $r .= $sub_r ? $sub_r : ''; |
||
| 808 | } |
||
| 809 | return array($r, $sub_v); |
||
| 810 | } |
||
| 811 | |||
| 812 | /* 100 */ |
||
| 813 | |||
| 814 | function xPN_LOCAL($v) { |
||
| 847 | |||
| 848 | /* */ |
||
| 849 | |||
| 850 | function unescapeNtripleUTF($v) { |
||
| 868 | |||
| 869 | /* */ |
||
| 870 | |||
| 871 | function xPlaceholder($v) { |
||
| 884 | |||
| 885 | /* */ |
||
| 886 | } |
||
| 887 |