- /**
- * Attempt to match header labels with our mapper fields
- *
- * @param header
- * @param mapperFields
- *
- * @return string
- * @access public
- */
- public function defaultFromHeader($header, &$patterns) {
- foreach ($patterns as $key => $re) {
- // Skip empty key/patterns
- if (!$key || !$re || strlen("$re") < 5) {
- continue;
- }
-
- // Scan through the headerPatterns defined in the schema for a match
- if (preg_match($re, $header)) {
- $this->_fieldUsed[$key] = TRUE;
- return $key;
- }
- }
- return '';
- }
-
- /**
- * Guess at the field names given the data and patterns from the schema
- *
- * @param patterns
- * @param index
- *
- * @return string
- * @access public
- */
- public function defaultFromData(&$patterns, $index) {
- $best = '';
- $bestHits = 0;
- $n = count($this->_dataValues);
-
- foreach ($patterns as $key => $re) {
- // Skip empty key/patterns
- if (!$key || !$re || strlen("$re") < 5) {
- continue;
- }
-
- // if ($this->_fieldUsed[$key])
- // continue;
-
- /* Take a vote over the preview data set */
-
- $hits = 0;
- for ($i = 0; $i < $n; $i++) {
- if (preg_match($re, $this->_dataValues[$i][$index])) {
- $hits++;
- }
- }
-
- if ($hits > $bestHits) {
- $bestHits = $hits;
- $best = $key;
- }
- }
-
- if ($best != '') {
- $this->_fieldUsed[$best] = TRUE;
- }
- return $best;
- }