/** * @dataProvider provideFlagKeywords * @depends testInterface * @return null */ public function testExtractKeywordContraints($str, $notNull, $primary, $new) { $expected = array('is-not-null' => $notNull, 'is-primary-key' => $primary, 'input-string' => $new); $result = $this->parser->extractKeywordConstraints($str); $this->assertFalse($this->parser->isError()); $this->assertEquals($expected, $result); }
/** * Parse the input string and set our elements based on the contents of the * input string. Elements not found in the string will be null. * * @return void * @access private * @since 5/24/05 */ function parse() { preg_match(self::getRegex(), $this->input, $timeMatches); $timeComponent = $timeMatches[0]; // The date is anything before the time $dateComponent = trim(str_replace($timeComponent, '', $this->input)); $timeParser = new TimeStringParser($timeComponent); $dateParser = StringParser::getParserFor($dateComponent); // Merge the two results into our fields if ($dateParser) { $this->setYear($dateParser->year()); $this->setMonth($dateParser->month()); $this->setDay($dateParser->day()); } $this->setHour($timeParser->hour()); $this->setMinute($timeParser->minute()); $this->setSecond($timeParser->second()); if (!is_null($timeParser->offsetHour())) { $this->setOffsetHour($timeParser->offsetHour()); } if (!is_null($timeParser->offsetMinute())) { $this->setOffsetMinute($timeParser->offsetMinute()); } if (!is_null($timeParser->offsetSecond())) { $this->setOffsetSecond($timeParser->offsetSecond()); } }
/** * Returns true if this component (and all child components if applicable) have valid values. * By default, this will just return TRUE. Validate should be called usually before a save event * is handled, to make sure everything went smoothly. * @access public * @return boolean */ function validate() { $parse = StringParser::getParserFor($this->_value); if (!$parse) { $this->_showError = true; return false; } return true; }
/** * @brief Parse the human data and return html * * @param string $data The data to parse * @return string The parsed data */ public function parse($content) { $ret = new StringParser($content); $ret->replace(array('/\\r\\n?/' => '\\n', '/&/' => '&', '/</' => '<', '/>/' => '>')); $ret->replace('/\\n?<blockquote>\\n*(.+?)\\n*<\\/blockquote>/', '<blockquote>$1</blockquote>'); $ret->replaceEach(array('b', 'i', 'em', 'strong', 'u'), '/<($ITEM$)>(.+?)<\\/($ITEM$)>/', '<$1>$2</$1>'); $ret->replace('/<a.+?href\\s*=\\s*[\'"](.+?)["\'].*?>(.+?)<\\/a>/', '<a href="$1">$2</a>'); $ret->replace('/\\n\\n+/', "</p>\n\n<p>"); $ret->replace('/([^\\n]\\n)(?=[^\\n])/', '\\1<br />'); return "<p>" . $ret->get() . "</p>"; }
public function test_constraints() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(1, $diff[0]['diff']); $expected = "\n CREATE TABLE public.products( \"product_no\" numeric(3, 0),\n \"name\" text,\n \"price\" numeric(3, 0),\n CONSTRAINT products_price_check CHECK (price > (0)::numeric) );"; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_new_view() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(2, $diff[0]['diff']); $expected = "\n DROP VIEW public.myview;"; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_table_with_different_colums_databases() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(1, $diff[0]['diff']); $expected = "CREATE TABLE public.testtable(\n \"userid\" character varying NOT NULL,\n \"id\" numeric,\n CONSTRAINT testtable_pkey PRIMARY KEY (\"userid\")\n );\n "; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_new_table() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(1, $diff[0]['diff']); $expected = "\n CREATE TABLE public.testtable(\n \"userid\" character varying NOT NULL,\n \"password\" character varying NOT NULL,\n \"myid\" numeric,\n \"surname\" character varying,\n CONSTRAINT testtable_pkey PRIMARY KEY (\"userid\")\n );"; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_drop_constraints() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(1, $diff[0]['diff']); $expected = "ALTER TABLE public.products DROP CONSTRAINT \"products_price_check\" CASCADE;"; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_new_view() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(2, $diff[0]['diff']); $expected = "\n CREATE OR REPLACE VIEW public.myview AS\n SELECT testtable.userid,\n testtable.password,\n testtable.name,\n testtable.surname\n FROM testtable\n WHERE ((testtable.surname)::text = 'x'::text);"; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_function() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(1, $diff[0]['diff']); $expected = "DROP FUNCTION public.hello(varchar);"; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_new_sequence() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(1, $diff[0]['diff']); $expected = "\n CREATE SEQUENCE public.mysecuence\n INCREMENT 1\n MINVALUE 1\n MAXVALUE 9223372036854775807\n START 342;"; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_function() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(1, $diff[0]['diff']); $expected = "\n CREATE OR REPLACE FUNCTION public.hello(name character varying) RETURNS character varying\n LANGUAGE plpgsql AS \$function\$\n BEGIN\n RETURN 'Hello ' || name;\n END;\n \$function\$\n "; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_constraints() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(1, $diff[0]['diff']); $expected = "\n CREATE TABLE public.products(\n \"product_no_unique\" integer,\n \"name\" text,\n \"price\" numeric,\n CONSTRAINT products_product_no_unique_key UNIQUE (\"product_no_unique\")\n );"; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
public function test_foreing_keys() { $dbVc = new Db(); $dbVc->setMaster(new DbConn($this->conf['devel'])); $dbVc->setSlave(new DbConn($this->conf['devel2'])); $diff = $dbVc->raw('public'); $this->assertCount(1, $diff); $this->assertCount(1, $diff[0]['diff']); $expected = "ALTER TABLE public.weather ADD CONSTRAINT \"weather_city_fkey\" FOREIGN KEY (\"city\") REFERENCES public.cities (city) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION;"; $this->assertEquals(StringParser::trimLines($expected), StringParser::trimLines($diff[0]['diff'][0])); }
/** * Read a Time from the stream in the forms: * - <hour24>:<minute>:<second> * - <hour>:<minute>:<second> <am/pm> * - <minute>, <second> or <am/pm> may be omitted. e.g. 1:59:30 pm; 8AM; 15:30 * * @param string $aString * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object Time * @access public * @static * @since 5/24/05 */ static function fromString($aString, $class = 'Time') { $parser = StringParser::getParserFor($aString); if (!is_string($aString) || !preg_match('/[^\\W]/', $aString) || !$parser) { $null = null; return $null; // die("'".$aString."' is not in a valid format."); } eval('$result = ' . $class . '::withHourMinuteSecond($parser->hour(), $parser->minute(), $parser->second(), $class);'); return $result; }
function isPresent($perm) { if ($this->getString() == 'System_Admin') { return true; } if ($this->getString() == '_a_0_all ') { if ($perm != 'System Admin' && $perm != 'Special Tools') { return true; } else { return false; } } if ($this->getString() != '' && ($perm == 'Patient' || $perm == 'Appointments' || $perm == 'Ambulatory' || $perm == 'Intranet Email' || $perm == 'Special Tools')) { return true; } return StringParser::isPresent($perm); }
function compare_like($value1, $value2) { static $patterns = array(); // Lookup precomputed pattern if (isset($patterns[$value2])) { $pat = $patterns[$value2]; } else { // Calculate pattern $rc = 0; $mod = ""; $prefix = "/^"; $suffix = "\$/"; // quote regular expression characters $str = preg_quote($value2, "/"); // unquote \ $str = str_replace("\\\\", "\\", $str); // Optimize leading/trailing wildcards if (substr($str, 0, 1) == '%') { $str = substr($str, 1); $prefix = "/"; } if (substr($str, -1) == '%' && substr($str, -2, 1) != '\\') { $str = substr($str, 0, -1); $suffix = "/"; } // case sensitive ? if (!LIKE_CASE_SENSITIVE) { $mod = "i"; } // setup a StringParser and replace unescaped '%' with '.*' $sp = new StringParser(); $sp->setConfig(array(), "\\", array()); $sp->setString($str); $str = $sp->replaceCharWithStr("%", ".*"); // replace unescaped '_' with '.' $sp->setString($str); $str = $sp->replaceCharWithStr("_", "."); $pat = $prefix . $str . $suffix . $mod; // Stash precomputed value $patterns[$value2] = $pat; } return preg_match($pat, $value1); }
function executeSingleRecFuncs() { global $g_sqlSingleRecFuncs; global $g_sqlMathOps; debug_printb("[executeSingleRecFuncs] executing singlerec functions...<br>"); for ($i = 0; $i < count($this->colFuncs); ++$i) { if (!$this->colFuncs[$i] || $this->colFuncsExecuted[$i]) { continue; } if (!in_array($this->colFuncs[$i], $g_sqlSingleRecFuncs)) { continue; } debug_print($this->colFuncs[$i] . "(" . $this->colNames[$i] . "): "); // EVAL if ($this->colFuncs[$i] == "EVAL") { $eval_str = $this->colNames[$i]; $out_str = ""; if (has_quotes($eval_str)) { remove_quotes($eval_str); } debug_print("EVAL function, eval String is {$eval_str}!<br>"); $sp = new StringParser(); $sp->specialElements = $g_sqlMathOps; $sp->setString($eval_str); while (!is_empty_str($elem = $sp->parseNextElement())) { debug_print("ELEM: {$elem}\n"); if (is_numeric($elem) || in_array($elem, $g_sqlMathOps)) { $out_str .= $elem . " "; } else { $origColNr = $this->findColNrByAttrs($elem, "", ""); if ($origColNr == NOT_FOUND) { print_error_msg("EVAL: Column '" . $elem . "' not found!"); return false; } $out_str .= "%{$origColNr}%"; } } debug_print("New Eval String: {$out_str}\n"); $val_str = ""; // apply function (use values from the original column as input) $rowCount = count($this->rows); $colCount = count($this->colNames); for ($j = 0; $j < $rowCount; ++$j) { $val_str = $out_str; for ($k = 0; $k < $colCount; ++$k) { if (!is_false(strpos($val_str, "%{$k}%"))) { $val_str = str_replace("%{$k}%", $this->rows[$j]->fields[$k], $val_str); } } debug_print("VAL_STR={$val_str}\n"); $this->rows[$j]->fields[$i] = execFunc($this->colFuncs[$i], $val_str); } $this->colFuncsExecuted[$i] = true; // function with paramater, but the parameter is not a column } else { if ($this->colNames[$i] && !is_empty_str($this->colNames[$i]) && (is_numeric($this->colNames[$i]) || has_quotes($this->colNames[$i]))) { $param = $this->colNames[$i]; if (has_quotes($param)) { remove_quotes($param); } $result = execFunc($this->colFuncs[$i], $param); $rowCount = count($this->rows); debug_print("a function with a non-column parameter! (result={$result})<br>"); for ($j = 0; $j < $rowCount; ++$j) { $this->rows[$j]->fields[$i] = $result; } $this->colFuncsExecuted[$i] = true; // function with parameter? =>execute function with the values form the original column } else { if ($this->colNames[$i]) { debug_print("a function with a column parameter!<br>"); // find original column (without function) $origColNr = $this->findColNrByAttrs($this->colNames[$i], $this->colTables[$i], ""); if ($origColNr == NOT_FOUND) { print_error_msg("Column '" . $this->colNames[$i] . "' not found!"); return false; } // copy some column header data from the original $this->colTables[$i] = $this->colTables[$origColNr]; $this->colTableAliases[$i] = $this->colTableAliases[$origColNr]; // apply function (use values from the original column as input) $rowCount = count($this->rows); for ($j = 0; $j < $rowCount; ++$j) { $this->rows[$j]->fields[$i] = execFunc($this->colFuncs[$i], $this->rows[$j]->fields[$origColNr]); } $this->colFuncsExecuted[$i] = true; // function without parameter: just execute! } else { debug_print("a function with no parameters!<br>"); $result = execFunc($this->colFuncs[$i], ""); $rowCount = count($this->rows); for ($j = 0; $j < $rowCount; ++$j) { $this->rows[$j]->fields[$i] = $result; } $this->colFuncsExecuted[$i] = true; } } } } }
/** * Deals with the arguments "detection" and sets the rigth configs for the method you specify * @param string $method You can use the following: GET, POST, PUT, DELETE * @param array $args * @param string $content_type Should be json or xml, if not, just leave it empty * @return string|array */ public static function call($method, $args, $content_type = null) { if (count($args) == 0) { throw new Exception\InvalidArgsException("You need specify at least the URL to call"); } $method = strtoupper($method); $url = null; $params = null; $callback = null; $data_type = ''; if (!is_string($args[0]) || !filter_var($args[0], FILTER_VALIDATE_URL)) { throw new Exception\InvalidArgsException("The URL you specified is not valid."); } else { $url = \array_shift($args); } //Is there any parameters to add? if (count($args) > 0 && is_array($args[0])) { $params = \array_shift($args); } //Is there any callback function to call? if (count($args) > 0 && is_callable($args[0])) { $callback = \array_shift($args); } //Is there any data type? if (count($args) > 0 && is_string($args[0])) { $data_type = \array_shift($args); } //END of arguments treatment if ($method == 'POST' && $content_type == 'json') { $data = self::curl($method, $url, \reset($params), array(CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_POSTFIELDS => $params)); } else { if ($method == 'POST' && $content_type == 'xml') { $data = self::curl($method, $url, \reset($params), array(CURLOPT_HTTPHEADER => array('Content-Type: text/xml'), CURLOPT_POSTFIELDS => $params)); } else { $data = self::curl($method, $url, $params); } } $data = StringParser::parse($data, $data_type); if (!is_null($callback)) { $data = $callback($data); } return $data; }
public function evaluateNullability() { return $this->internals[$this->S]->nullable === true; } // S is the first public function firstSet() { return array($this->internals[$this->S]); } } // if executing this file directly, run unit tests if (__FILE__ !== $_SERVER["SCRIPT_FILENAME"]) { return; } print "1A\n"; $parser = new StringParser("needle"); var_dump($parser->match("asdfneedle", 4) === array("j" => 10, "value" => "needle")); try { $parser->match("asdfneedle", 0); var_dump(false); } catch (ParseFailureException $e) { var_dump(true); } print "2\n"; # improper anchoring try { $parser = new RegexParser("#boo#"); var_dump(false); } catch (GrammarException $e) { var_dump(true); }
public function parse($value) { return StringParser::parseValue($value, $this->language, null); }
public function parseString($string) { $parser = new StringParser($string); return $parser->parse(); }
/** * Read a month from the stream in any of the forms: * * - July 1998 * * @param string $aString * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object Month * @access public * @since 5/10/05 * @static */ static function fromString($aString, $class = 'Month') { $parser = StringParser::getParserFor($aString); if (!is_string($aString) || !preg_match('/[^\\W]/', $aString) || !$parser) { $null = null; return $null; // die("'".$aString."' is not in a valid format."); } eval('$result = ' . $class . '::withMonthYear($parser->month(), $parser->year(), $class);'); return $result; }
/** * Write an empty POT file containing all strings found * * @param string $file File to write to */ public function writePot($file) { $output = "# Copyright (C) " . date("Y") . " Next Buzz" . PHP_EOL . "msgid \"\"" . PHP_EOL . "msgstr \"\"" . PHP_EOL . "\"Project-Id-Version: buzz-seo\\n\"" . PHP_EOL . "\"POT-Creation-Date: " . date("Y-m-d H:i:sO") . "\\n\"" . PHP_EOL . "\"MIME-Version: 1.0\\n\"" . PHP_EOL . "\"Content-Type: text/plain; charset=UTF-8\\n\"" . PHP_EOL . "\"Content-Transfer-Encoding: 8bit\\n\"" . PHP_EOL . "\"PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\\n\"" . PHP_EOL . "\"Language-Team: Next Buzz, Bas de Kort <*****@*****.**>\\n\"" . PHP_EOL . PHP_EOL; require_once ABSPATH . '/wp-includes/pomo/po.php'; $poifyString = new \PO(); foreach ($this->findings as $translatable => $locations) { $output .= "#:"; foreach ($locations as $line => $location) { $output .= " " . $location . ":" . $line; } $output .= PHP_EOL . "msgid " . $poifyString->poify(StringParser::factory($translatable)->trimMultiline()) . PHP_EOL . "msgstr \"\"" . PHP_EOL . PHP_EOL; } file_put_contents($file, $output); }
/** * Restart parsing after current block * * To achieve this the current top stack object is removed from the * tree. Then the current item * * @access protected * @return bool */ function _reparseAfterCurrentBlock() { if ($this->_status == 2) { // this status will *never* call _reparseAfterCurrentBlock itself // so this is called if the loop ends // therefore, just add the [/ to the text // _savedName should be empty but just in case $this->_cpos -= strlen($this->_savedName); $this->_savedName = ''; $this->_status = 0; $this->_appendText('[/'); return true; } else { return parent::_reparseAfterCurrentBlock(); } }
/** * Answer a new instance represented by a string: * * - '-1199-01-05T20:33:14.321-05:00' * - ' 2002-05-16T17:20:45.00000001+01:01' * - ' 2002-05-16T17:20:45.00000001' * - ' 2002-05-16T17:20' * - ' 2002-05-16T17:20:45' * - ' 2002-05-16T17:20:45+01:57' * - ' 2002-05-16T17:20:45-02:34' * - ' 2002-05-16T17:20:45+00:00' * - ' 1997-04-26T01:02:03+01:02:3' * * @param string $aString The input string. * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object DateAndTime * @access public * @since 5/12/05 * @static */ static function fromString($aString, $class = 'DateAndTime') { $parser = StringParser::getParserFor($aString); if (!is_string($aString) || !preg_match('/[^\\W]/', $aString) || !$parser) { $null = null; return $null; // die("'".$aString."' is not in a valid format."); } if (!is_null($parser->offsetHour())) { eval('$result = ' . $class . '::withYearMonthDayHourMinuteSecondOffset( $parser->year(), $parser->month(), $parser->day(), $parser->hour(), $parser->minute(), $parser->second(), Duration::withDaysHoursMinutesSeconds(0, $parser->offsetHour(), $parser->offsetMinute(), $parser->offsetSecond()), $class);'); } else { if (!is_null($parser->hour())) { eval('$result = ' . $class . '::withYearMonthDayHourMinuteSecond( $parser->year(), $parser->month(), $parser->day(), $parser->hour(), $parser->minute(), $parser->second(), $class);'); } else { eval('$result = ' . $class . '::withYearMonthDay( $parser->year(), $parser->month(), $parser->day(), $class);'); } } return $result; }
function getFilteredResultSet(&$resultSet) { global $g_sqlComparisonOperators; for ($i = 0; $i < $this->getChildCount(); ++$i) { $child = $this->childs[$i]; $this->resultSetsFromChilds[] = $child->getFilteredResultSet($resultSet); } $sp = new StringParser(); //$or_expr=explode_resp_quotes(" OR ",$this->expr_str); $sp->setConfig(array("'", "\""), "\\", array(), array(" OR "), false, false); $sp->setString($this->expr_str); $or_expr = $sp->splitWithSpecialElements(); $andResultSets = array(); for ($i = 0; $i < count($or_expr); ++$i) { $fieldValuePair = array(); $fields = array(); $values = array(); $operators = array(); $childsToInclude = 0; //$and_expr=explode_resp_quotes(" AND ",$or_expr[$i]); $sp->setConfig(array("'", "\""), "\\", array(), array(" AND "), false, false); $sp->setString($or_expr[$i]); $and_expr = $sp->splitWithSpecialElements(); array_walk($and_expr, "array_walk_trim"); for ($j = 0; $j < count($and_expr); ++$j) { if ($and_expr[$j] == "%") { $childsToInclude++; } else { //$operators[]=explode_resp_quotes_multisep($g_sqlComparisonOperators,$and_expr[$j],$fieldValuePair); $usedOps = array(); $sp->setConfig(array("'", "\""), "\\", array(), $g_sqlComparisonOperators, false, false); $sp->setString($and_expr[$j]); $fieldValuePair = $sp->splitWithSpecialElementsRetUsed($usedOps); $operators[] = trim($usedOps[0]); // Remove escape chars (because parseNextElementRaw() was used // to parse Where Statements) list($field, $value) = $fieldValuePair; $fields[] = stripslashes(trim($field)); // like bugfix: don't remove escape chars on the LIKE value if (strtoupper(trim($operators[count($operators) - 1])) == "LIKE") { $values[] = trim($value); } else { $values[] = stripslashes(trim($value)); } } } if (TXTDBAPI_DEBUG) { echo "<br>fields and values to use for AND filter:<br>"; print_r($fields); echo "<br>"; print_r($values); echo "<br>"; print_r($operators); echo "<br>"; echo "childsToInclude: " . $childsToInclude . "<br>"; } $andResultSets[] = $resultSet->filterRowsByAndConditions($fields, $values, $operators); debug_print("filterRowsByAndConditions done<br>"); for ($j = 0; $j < $childsToInclude; ++$j) { $andResultSets[$i]->filterResultSetAndWithAnother($this->resultSetsFromChilds[$this->childResultSetPos++]); } if (TXTDBAPI_DEBUG) { echo "Filtered ResultSet:<br>"; $andResultSets[$i]->dump(); } } $finalResultSet = $andResultSets[0]; for ($i = 1; $i < count($andResultSets); ++$i) { $andResultSets[$i]->reset(); while ($andResultSets[$i]->next()) { $finalResultSet->appendRow($andResultSets[$i]->getCurrentValues(), $andResultSets[$i]->getCurrentRowId()); } } if (TXTDBAPI_DEBUG) { echo "<br><br>FINAL RESULT SET:<br>"; $finalResultSet->dump(); } return $finalResultSet; }
public function extractPage($pageID, $pageTitle, $pageSource) { $mysql = $this->mysql; $result = new ExtractionResult($pageID, $this->language, $this->getExtractorID()); if ($this->decode_title($pageTitle) == NULL) { return $result; } // don't remove tables // 1. some templates are used within templates, e.g. http://en.wikipedia.org/wiki/Plato // 2. the regex sometimes reaches PREG_BACKTRACK_LIMIT_ERROR // $text=preg_replace('~{\|.*\|}~s','',$pageSource); // remove Prettytables $text = $pageSource; $templates = Util::getTemplates($text); foreach ($templates as $template) { $tpl = $template["content"]; //TODO: HIER NICHT "TEMPLATE" HARDCODE, SONDERN SPRACHABHAENGIG $dbpedia_uri = "http://dbpedia.org/resource/Template:" . Util::encodeLocalName($template["name"]); //var_dump($dbpedia_uri); // get template ID from DB $templatequery = "select template_id from template_uri where uri = '{$dbpedia_uri}'"; $templatequeryresult = $mysql->query($templatequery); $tqrow = mysql_fetch_array($templatequeryresult, MYSQL_ASSOC); $template_id = $tqrow['template_id']; if (!isset($template_id)) { continue; } $props = Util::getTemplateProperties($tpl); //TODO: INNER JOIN VERWENDEN STATT NORMALEM JOIN // find ontology class with template id $classquery = "select name, class_id from class, template_class where template_class.template_id = '{$template_id}' and template_class.class_id = class.id"; $classqueryresult = $mysql->query($classquery); $cqrow = mysql_fetch_array($classqueryresult, MYSQL_ASSOC); $class_id = $cqrow['class_id']; $class_name = $cqrow['name']; // get template properties $template_properties = array(); $template_properties_to_merge = array(); // get merging rules for template ID $mergequery = "select ordered_template_property_ids from template_property_merge_rule where template_id = '{$template_id}'"; $mergequeryresult = $mysql->query($mergequery); $i = 0; while ($mergerow = mysql_fetch_array($mergequeryresult, MYSQL_ASSOC)) { $temp = explode(",", $mergerow['ordered_template_property_ids']); $merging_group_count[$i] = 0; foreach ($temp as $tempp) { $template_properties_to_merge[] = $tempp; $merging_group[$tempp] = $i; $merging_group_count[$i]++; } $i++; } $merge_template_sets_done = array(); $main_propid_from_merging_group[] = array(); $main_propvalue_from_merging_group[] = array(); foreach ($props as $keyvalue) { $propkey = mysql_escape_string($keyvalue[1]); $propvalue = $keyvalue[2]; if (trim($propvalue) == "" || $propvalue == null) { continue; } $propquery = "select id from template_property where name = '{$propkey}' and template_id = '{$template_id}'"; $propqueryresult = $mysql->query($propquery); $pqrow = mysql_fetch_array($propqueryresult, MYSQL_ASSOC); $template_property_id = $pqrow['id']; if (!is_null($template_property_id)) { if (!in_array($template_property_id, $template_properties_to_merge)) { $template_properties[$template_property_id] = trim($propvalue); } else { $query = "select class_property_id from template_property_class_property where template_property_id = {$template_property_id}"; $dbresult = $mysql->query($query); $target_unit = null; while ($row = mysql_fetch_array($dbresult, MYSQL_ASSOC)) { $class_property_ids = $row['class_property_id']; $ptrquery = "select * from parser_type_rule where class_property_id = '{$class_property_ids}'"; $ptrresult = $mysql->query($ptrquery); $ptrrow = mysql_fetch_array($ptrresult, MYSQL_ASSOC); $parser_rule = $ptrrow['parser_type']; $unit_type = $ptrrow['unit_type']; $target_unit = $ptrrow['target_unit']; } $unit_exact_type = null; $query1 = "select unit_exact_type from template_parser_type_rule where template_property_id = {$template_property_id}"; $dbresult1 = $mysql->query($query1); while ($row1 = mysql_fetch_array($dbresult1, MYSQL_ASSOC)) { if (strlen($row1['unit_exact_type']) > 0) { $unit_exact_type = $row1['unit_exact_type']; } } if (!in_array($merging_group[$template_property_id], $merge_template_sets_done)) { $merge_template_sets_done[] = $merging_group[$template_property_id]; $propvalue = trim($propvalue); if ($parser_rule == "unit") { if ($unit_type == "Length") { $parseResultArray = UnitValueParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $propkey, UNITTYPE => $unit_type, UNITEXACTTYPE => $unit_exact_type, TARGETUNIT => $target_unit, IGNOREUNIT => true)); if (!is_null($parseResultArray)) { foreach ($parseResultArray as $parseResults) { $propvalue = (string) $parseResults[0] . " {$unit_exact_type}"; } } } } else { if ($parser_rule == "geocoordinates") { if ($merging_group_count[$merging_group[$template_property_id]] == 6 || $merging_group_count[$merging_group[$template_property_id]] == 8) { //{{coord|51|30|29|N|00|07|29|W}} $propvalue = "{{coord|" . $propvalue; $geocoordinatescount = $merging_group_count[$merging_group[$template_property_id]] - 1; } } else { // TODO: new Unit type! } } $template_properties[$template_property_id] = $propvalue; $main_propid_from_merging_group[$merging_group[$template_property_id]] = $template_property_id; $main_propvalue_from_merging_group[$merging_group[$template_property_id]] = $propvalue; } else { $main_propvalue = $main_propvalue_from_merging_group[$merging_group[$template_property_id]]; $main_template_property_id = $main_propid_from_merging_group[$merging_group[$template_property_id]]; if ($parser_rule == "unit") { if ($unit_type == "Length") { $parseResultArray = UnitValueParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $propkey, UNITTYPE => $unit_type, UNITEXACTTYPE => $unit_exact_type, TARGETUNIT => $target_unit)); if (!is_null($parseResultArray)) { foreach ($parseResultArray as $parseResults) { $propvalue = (string) $parseResults[0] . " {$unit_exact_type}"; } } $template_properties[$main_template_property_id] = $main_propvalue . " " . $propvalue; } } else { if ($parser_rule == "geocoordinates") { $geocoordinatescount--; if ($merging_group_count[$merging_group[$template_property_id]] == 6 || $merging_group_count[$merging_group[$template_property_id]] == 8) { //{{coord|51|30|29|N|00|07|29|W}} if ($geocoordinatescount == 0) { $propvalue = $propvalue . "}}"; } $main_propvalue_from_merging_group[$merging_group[$main_template_property_id]] = $main_propvalue . "|" . $propvalue; $template_properties[$main_template_property_id] = $main_propvalue . "|" . $propvalue; } else { $main_propvalue_from_merging_group[$merging_group[$main_template_property_id]] = $main_propvalue . " " . $propvalue; $template_properties[$main_template_property_id] = $main_propvalue . " " . $propvalue; } } else { // TODO: new Unit type! } } unset($template_properties[$template_property_id]); } } } } foreach ($template_properties as $template_property_id => $propvalue) { $query = "select class_property_id from template_property_class_property where template_property_id = {$template_property_id}"; $dbresult = $mysql->query($query); while ($row = mysql_fetch_array($dbresult, MYSQL_ASSOC)) { $class_property_ids = $row['class_property_id']; // foreach template_property_class_property.class_property_id // get parser_type_rule.parser_type $target_unit = null; $ptrquery = "select * from parser_type_rule where class_property_id = '{$class_property_ids}'"; $ptrresult = $mysql->query($ptrquery); $ptrrow = mysql_fetch_array($ptrresult, MYSQL_ASSOC); $parser_rule = $ptrrow['parser_type']; $unit_type = $ptrrow['unit_type']; $target_unit = $ptrrow['target_unit']; $cpquery = "select cp.type, cp.datatype_range, cp.name, c.name as superclass from class_property cp inner join class c on(cp.class_id = c.id) where cp.id = {$class_property_ids}"; $cpresult = $mysql->query($cpquery); $cprow = mysql_fetch_array($cpresult, MYSQL_ASSOC); $property_type = $cprow['type']; $datatype_range = $cprow['datatype_range']; $property_name = $cprow['name']; $ontclass = $cprow['superclass']; //IF PROPERTY IS NOT FROM ONTOLOGY, BUT EXTERNAL, SUCH AS FOAF if (!$cprow) { $cpquery = "select name, uri, class_id from class_property where id = {$class_property_ids}"; $cpresult = $mysql->query($cpquery); $cprow = mysql_fetch_array($cpresult, MYSQL_ASSOC); //TODO: IST DIE CLASS_ID NICHT IMMER NULL IN DIESEM FALL??? $domain_class_id = $cprow['class_id']; if ($domain_class_id == null && $cprow['uri'] == "http://xmlns.com/foaf/0.1/" && $cprow['name'] == "homepage") { try { $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://xmlns.com/foaf/0.1/homepage"), RDFtriple::URI($propvalue)); } catch (Exception $e) { //TODO uncorrect URI } } else { if ($domain_class_id == null && $cprow['uri'] == "http://xmlns.com/foaf/0.1/" && $cprow['name'] == "name") { if (strpos($propvalue, "{{PAGENAME}}") === false) { if (strpos($propvalue, "{{") === false) { $parseResults = StringParser::parseValue($propvalue, $this->language, null); foreach ($parseResults as $mystring) { if ($mystring != "") { $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://xmlns.com/foaf/0.1/name"), RDFtriple::Literal($mystring)); } } } } } } } else { /* if (strpos($propvalue, "[[") !== false) { $propvalue = Util::replaceWikiLinks($propvalue); } */ switch ($property_type) { case 'object': $rangequery = "SELECT c.name as rangeclass FROM class_property_range cpr inner join class c on (cpr.range_class_id = c.id) where property_id = {$class_property_ids}"; $rangeresult = $mysql->query($rangequery); $rowrange = mysql_fetch_array($rangeresult, MYSQL_ASSOC); $rangeclass = $rowrange['rangeclass']; $propvalue = Util::removeWikiEmphasis($propvalue); //TODO:ADD LANGUAGE AS PARAM $parseResults = ObjectTypeParser::parseValue($propvalue, $this->language, $rangeclass); foreach ($parseResults as $r) { $result->addTriple(RDFtriple::page($pageID), RDFtriple::property($ontclass, $property_name, $this->flagNewSchema), RDFtriple::page($r)); } break; case 'datatype': switch ($datatype_range) { case 'string': switch ($parser_rule) { case 'geocoordinates': //TODO: Predicate URIs entweder nur in DB oder nur hardcoden? $propvalue = Util::removeHtmlTags($propvalue); $propvalue = Util::removeHtmlComments($propvalue); $parseResultArray = GeoParser::parseValue($propvalue, $this->language, null); if (!is_null($parseResultArray)) { // http://www.georss.org/georss/point:(NULL) 52.5166666667 13.4166666667 // geo:lat 52.516666 (xsd:float) // geo:long 13.416667 (xsd:float) // $output = array('georss'=>$georss,'lat'=>$lat,'long'=>$long); $georss = $parseResultArray["georss"]; $lat = $parseResultArray["lat"]; $long = $parseResultArray["long"]; if ($georss != null) { $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://www.georss.org/georss/point"), RDFtriple::Literal($georss)); } if ($lat != null) { $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://www.w3.org/2003/01/geo/wgs84_pos#lat"), RDFtriple::Literal($lat, "http://www.w3.org/2001/XMLSchema#float", NULL)); } if ($long != null) { $result->addTriple(RDFtriple::page($pageID), RDFtriple::URI("http://www.w3.org/2003/01/geo/wgs84_pos#long"), RDFtriple::Literal($long, "http://www.w3.org/2001/XMLSchema#float", NULL)); } } else { //TODO: DEBUG LOGFILE FOR UN-PARSED VALUES $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue); } break; default: $parseResults = StringParser::parseValue($propvalue, $this->language, null); foreach ($parseResults as $mystring) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $mystring); } break; } break; case 'integer': if (strpos($propvalue, "{{") !== false) { $propvalue = Util::replaceTemplates($propvalue); } $propvalue = Util::removeHtmlTags($propvalue); $propvalue = Util::removeHtmlComments($propvalue); $propvalue = Util::removeWikiEmphasis($propvalue); /* preg_match_all("/([^0-9]+)[0-9]/", $propvalue, $other_characters, PREG_SET_ORDER); $only_commata_whitespaces_dots = true; foreach ($other_characters as $other_character) { //echo $other_character[1]; if (($other_character[1] != " ") && ($other_character[1] != ",") && ($other_character[1] != ".")) { $only_commata_whitespaces_dots = false; break; } } if ($only_commata_whitespaces_dots) { $propvalue = preg_replace("/[^0-9]*([0-9])/", "$1", $propvalue); } */ $parseResults = NumberParser::parseValue($propvalue, $this->language, array("integer")); if (!is_null($parseResults)) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $parseResults, "http://www.w3.org/2001/XMLSchema#integer"); } else { //TODO: ADD DEGUB LOGFILE FOR UN-PARSED TRIPLES if (!$this->flagStrictExport) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue); } } break; case 'float': if (strpos($propvalue, "{{") !== false) { $propvalue = Util::replaceTemplates($propvalue); } $propvalue = Util::removeHtmlTags($propvalue); $propvalue = Util::removeHtmlComments($propvalue); $propvalue = Util::removeWikiEmphasis($propvalue); $parseResults = NumberParser::parseValue($propvalue, $this->language, array("float")); if (!is_null($parseResults)) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $parseResults, "http://www.w3.org/2001/XMLSchema#float"); } else { //TODO: ADD DEGUB LOGFILE FOR UN-PARSED TRIPLES if (!$this->flagStrictExport) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue); } } break; case 'double': switch ($parser_rule) { case 'currency': $propvalue = Util::removeHtmlTags($propvalue); $propvalue = Util::removeHtmlComments($propvalue); $parseResultArray = UnitValueParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $property_name, UNITTYPE => 'Currency', UNITEXACTTYPE => null, TARGETUNIT => null)); if (!is_null($parseResultArray)) { foreach ($parseResultArray as $parseResults) { $parsedDataType = $parseResults[1]; if ($parsedDataType == "") { $parsedDataType = null; } if ($parseResults[0] != "") { $this->addLiteral($result, $pageID, $ontclass, $property_name, (string) $parseResults[0], $parsedDataType); } } } else { if (!$this->flagStrictExport) { $propvalue = Util::removeTemplates($propvalue); $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue); } } break; case 'unit': $propvalue = Util::replaceWikiLinks($propvalue); //TODO: WARUM NUR IN DIESEM FALL CITE RAUSNEHMEN? preg_match_all("/{{2}cite.*?\\}{2}/i", $propvalue, $matches); foreach ($matches as $match) { $propvalue = str_replace($match[0], Util::replaceTemplates($match[0]), $propvalue); } $propvalue = Util::removeHtmlTags($propvalue); $propvalue = Util::removeHtmlComments($propvalue); // get unit exact type $unit_exact_type = null; // if property is part of merged properties then unit is (probably) already appended, otherwise append unit (here: "exact unit type") if (!in_array($template_property_id, $template_properties_to_merge)) { $query1 = "select unit_exact_type from template_parser_type_rule where template_property_id = {$template_property_id}"; $dbresult1 = $mysql->query($query1); while ($row1 = mysql_fetch_array($dbresult1, MYSQL_ASSOC)) { if (strlen($row1['unit_exact_type']) > 0) { $unit_exact_type = $row1['unit_exact_type']; } } } $parseResultArray = UnitValueParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $property_name, UNITTYPE => $unit_type, UNITEXACTTYPE => $unit_exact_type, TARGETUNIT => $target_unit)); if (!is_null($parseResultArray)) { foreach ($parseResultArray as $parseResults) { $parsedDataType = $parseResults[1]; if ($parsedDataType == "") { $parsedDataType = null; } if ($parseResults[0] != "") { $this->addLiteral($result, $pageID, $ontclass, $property_name, (string) $parseResults[0], $parsedDataType); } } } else { //TODO: GENERATE LOGFILE WITH UNPARSED VALUES if (!$this->flagStrictExport) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue); } } break; default: if (strpos($propvalue, "{{") !== false) { $propvalue = Util::replaceTemplates($propvalue); } $propvalue = Util::removeHtmlTags($propvalue); $propvalue = Util::removeHtmlComments($propvalue); $propvalue = Util::removeWikiEmphasis($propvalue); $parseResults = NumberParser::parseValue($propvalue, $this->language, array("float")); if (!is_null($parseResults)) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $parseResults, "http://www.w3.org/2001/XMLSchema#double"); } else { //TODO: ADD DEGUB LOGFILE FOR UN-PARSED TRIPLES if (!$this->flagStrictExport) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $propvalue); } } break; } break; case 'date': // TODO: when DateTimeParser uses restrictions (start date / end date), pass them as parameter // $parseResults = DateTimeParser::parseValue($propvalue, $this->language, array($unit_type)); $parseResultArray = DateTimeParser::parseValue($propvalue, $this->language, array(PAGEID => $pageID, PROPERTYNAME => $property_name, UNITTYPE => $unit_type, UNITEXACTTYPE => $unit_exact_type, TARGETUNIT => $target_unit)); if (!is_null($parseResultArray)) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $parseResultArray[0], $parseResultArray[1]); } else { if (!$this->flagStrictExport) { $parseResults = StringParser::parseValue($propvalue, $this->language, null); foreach ($parseResults as $mystring) { $this->addLiteral($result, $pageID, $ontclass, $property_name, $mystring); } } } break; default: break; } break; default: break; } } } } } return $result; }