/** * * @param TemplateNode $templateNode * @return bool */ private function catchTemplate($templateNode) { if ($templateNode instanceof TemplateNode) { $children = $templateNode->getChildren(); $templateName = $templateNode->getTitle()->decoded(); foreach ($children as $index => $childNode) { // creates an array of TextNodes from the PropertyNodes of the TemplateNode $childrenTextNodes[$index] = $childNode->getChildren('TextNode'); } //{{coord|latitude|longitude|coordinate parameters|template parameters}} //{{coord|dd|N/S|dd|E/W|coordinate parameters|template parameters}} //{{coord|dd|mm|N/S|dd|mm|E/W|coordinate parameters|template parameters}} //{{coord|dd|mm|ss|N/S|dd|mm|ss|E/W|coordinate parameters|template parameters}} if (preg_match('~coord~i', $templateName)) { $lat = $children[0]; $latMin = new PropertyNode(); $latSec = new PropertyNode(); $latHem = new PropertyNode(); $long = new PropertyNode(); $longMin = new PropertyNode(); $longSec = new PropertyNode(); $longHem = new PropertyNode(); if (isset($childrenTextNodes[1][0]) && preg_match('~^(N|S)$~i', $childrenTextNodes[1][0]->getText())) { $long = $children[2]; } elseif (isset($childrenTextNodes[2][0]) && preg_match('~^(N|S)$~i', $childrenTextNodes[2][0]->getText())) { $latMin = $children[1]; $latHem = $children[2]; $long = $children[3]; $longMin = $children[4]; $longHem = $children[5]; } elseif (isset($childrenTextNodes[3][0]) && preg_match('~^(N|S)$~i', $childrenTextNodes[3][0]->getText())) { $latMin = $children[1]; $latSec = $children[2]; $latHem = $children[3]; $long = $children[4]; $longMin = $children[5]; $longSec = $children[6]; $longHem = $children[7]; } else { $long = $children[1]; } if ($this->acceptOnlyCoordinatesBelongingToArticle) { foreach ($children as $index => $childNode) { if ($childNode->getKey() == 'display') { $display = explode(",", $childrenTextNodes[$index][0]->getText()); if (in_array("title", $display) || in_array("t", $display)) { $this->coordinateBelongsToArticle = true; } } } } $this->geoCoordinate->parseLatitude($lat, $latMin, $latSec, $latHem); $this->geoCoordinate->parseLongitude($long, $longMin, $longSec, $longHem); return array('lat' => $this->geoCoordinate->getLatitude(), 'long' => $this->geoCoordinate->getLongitude()); } elseif (preg_match('~coor\\040(title|at)~i', $templateName)) { return null; } elseif (preg_match('~geolinks~i', $templateName)) { return null; } elseif (preg_match('~mapit~i', $templateName)) { return null; } elseif (preg_match('~koordinate~i', $templateName)) { return null; } elseif (preg_match('~coordinate~i', $templateName)) { return null; } } }
private function createTemplateNode($tableHeader, $rowNode) { //Only accept rows which have the same number of cells than the header) $cellNodes = $rowNode->getChildren(); $cellCount = count($cellNodes); if ($cellCount != count($tableHeader)) { return null; } //Create a new template node $templateNode = new TemplateNode($rowNode->getLine()); //Iterate throw all column definitions of the header definition foreach ($this->headerDefinition as $columnDefinition) { $columnMatchings = array(); //Iterate throw all columns in the header and collect matchings foreach ($tableHeader as $columnIndex => $column) { //Iterate through all alternatives of this columnDefinition foreach ($columnDefinition as $columnAlternative) { //Match this alternativ column definition with the column header $startIndex = null; $endIndex = null; $i = 0; foreach ($columnAlternative as $keyword) { $i = stripos($column, $keyword, $i); if ($i === false) { break; } if ($startIndex === null) { $startIndex = $i; } $endIndex = $i + strlen($keyword); } if ($i !== false) { //Found new column matching $propertyName = implode('&', $columnAlternative); $columnMatchings[] = new ColumnMatching($propertyName, $columnIndex, $startIndex, $endIndex); } } } if (!empty($columnMatchings)) { //Sort all column matchings and select first one usort($columnMatchings, '\\dbpedia\\mapping\\ColumnMatching::compare'); $matching = $columnMatchings[0]; //Create new property node from the best matching and the current row $propertyNode = new PropertyNode($rowNode->getLine()); $propertyNode->setKey($matching->getPropertyName()); foreach ($cellNodes[$matching->getColumnIndex()]->getChildren() as $cellNodeChild) { $propertyNode->addChild($cellNodeChild); } $templateNode->addProperty($propertyNode); } } return $templateNode; }