sportGroup = $sportGroup;
$this->sport = $sport;
}
function setSportsLevel($sportLevel)
{
$this->sportLevel = $sportLevel;
}
function getSportsRound()
{
return $this->sportLevel;
}
function getHeaders()
{
return $this->header;
}
function getMatrix()
{
return $this->matrix;
}
function getReportLines()
{
return $this->reportLines;
}
function isUsable()
{
return $this->usable;
}
function getProblem()
{
return $this->problem;
}
function setDecoratorLength($decoratorLen)
{
$this->decoratorLen = $decoratorLen;
}
function parseHeaders($line)
{
$this->reportLines[] = $line;
$hAnalysis = new Lexicon($line);
$hAnalysis->preAnalyse();
$dictionary = Lexicon::getDictionary();
$words = ParserUtility::getWords($line);
$count = 1;
foreach($words as $word)
{
//echo '
~'.$word.'~IN~'.implode("#",$dictionary['HEADER-COL']) ;
if(ParserUtility::in_array_i($dictionary['HEADER-COL'], $word)===false)
{
$this->usable = false;
$this->problem = "Unknown Header ".$word;
$this->__resetObj();
return;
}
$this->header[$count] = $word;
$count++;
}
$this->headerCount = count($this->header);
$previousHead = "SL";
$this->headerPositions[$previousHead]['INDEX'] = 0;
$this->headerPositions[$previousHead]['POSITION-START'] = 0;
$this->headerPositions[$previousHead]['TEXT-END'] = strlen($previousHead);
$this->headerPositions[$previousHead]['TEXT-LENGTH'] = strlen($previousHead);
foreach($this->header as $head)
{
if($this->debug) echo "
Header - Parsing '".$head."' IN -> ".$line;
$stEnd = ParserUtility::get_start_end_pos($line, $head);
$startEnd = $stEnd[0];
//if($this->debug) { echo "
POSITION - "; print_r($startEnd); }
$this->headerPositions[$previousHead]['POSITION-END'] = $startEnd['START-POSITION']-1;
$this->headerPositions[$previousHead]['POSITION-LENGTH'] = ($this->headerPositions[$previousHead]['POSITION-END'] - $this->headerPositions[$previousHead]['POSITION-START'])+1;
$this->headerPositions[$head]['INDEX'] = $this->headerPositions[$previousHead]['INDEX']+1;
$this->headerPositions[$head]['POSITION-START'] = $startEnd['START-POSITION'];
$this->headerPositions[$head]['TEXT-END'] = $startEnd['END-POSITION'];
$this->headerPositions[$head]['TEXT-LENGTH'] = $startEnd['LENGTH'];
$previousHead = $head;
if($this->debug) echo "
Header - Set position data of '".$head."' ";
if($this->debug) echo "
:::::::::::::::::::::::::::::
";
}
$this->headerPositions[$previousHead]['POSITION-END'] = $this->decoratorLen;
}
function parseData($line)
{
$this->reportLines[] = $line;
if($this->usable)
{
$hAnalysis = new Lexicon($line);
$hAnalysis->analyse();
$words = ParserUtility::getWords($line);
if($this->debug) echo "
Line - Operating on '".$line."' which is >>".$hAnalysis->getGeneralContext();
if($hAnalysis->getGeneralContext() == 'SPORTS-ROUND')
{
$this->sportLevel = $hAnalysis->getSportsRound();
if($this->debug) echo "
SETTING SPORTS-ROUND >> '".$hAnalysis->getSportsRound()."'";
if($this->debug) echo "
---------------------------------
";
}
else
{
$headerIndex = 0;
$incrementRow = true;
$hasSL = false;
$wordStEnd = ParserUtility::get_start_end_pos($line, $words[0]);
if(@$wordStEnd[0]['END-POSITION']<=@$this->headerPositions['SL']['POSITION-END']
&& @$wordStEnd[0]['END-POSITION']>@$this->headerPositions['SL']['POSITION-START'])
{
$hasSL = true;
}
foreach($words as $indx=>$wrd)
{
$word = ' '.$wrd.' ';
if($this->debug) echo "
Line - Parsing '".$word."' IN -> ".$line." for ".$this->sportGroup;
switch($this->sportGroup)
{
case ParserUtility::$_RUNNING_ :
case ParserUtility::$_RELAY_ :
if($hasSL===true)
{
$headerIndex = $this->__processRowFor_jump($indx, $word, $line, $headerIndex);
if($headerIndex<0)
{
$this->__processRowFor_addnlData($indx, $word, $line, $headerIndex);
$incrementRow = false;
}
}
else
{
$this->__processRowFor_addnlData($indx, $word, $line, $headerIndex);
$incrementRow = false;
}
break;
case ParserUtility::$_JUMPING_ :
case ParserUtility::$_JUMPING_TEAM_ :
if($hasSL===true)
{
$headerIndex = $this->__processRowFor_jump($indx, $word, $line, $headerIndex);
if($headerIndex<0)
{
$this->__processRowFor_addnlData($indx, $word, $line, $headerIndex);
$incrementRow = false;
}
}
else
{
$this->__processRowFor_addnlData($indx, $word, $line, $headerIndex);
$incrementRow = false;
}
break;
case ParserUtility::$_THROWING_ :
case ParserUtility::$_THROWING_TEAM_ :
if($hasSL===true)
{
$headerIndex = $this->__processRowFor_throw($indx, $word, $line, $headerIndex);
if($headerIndex<0)
{
$this->__processRowFor_addnlData($indx, $word, $line, $headerIndex);
$incrementRow = false;
}
}
else
{
$this->__processRowFor_addnlData($indx, $word, $line, $headerIndex);
$incrementRow = false;
}
break;
default :
$this->usable = false;
$this->problem = "PARSER NOT IMPLEMENTED";
$this->__resetObj();
break;
}
}
$this->__processCombinatorData();
$this->prc = $this->rowCounter;
$this->rowCounter++;
}
if($this->debug) echo "
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
";
}
}
function __processRowFor_addnlData($indx, $word, $line, $hIndex)
{
$this->matrix[$this->prc]['ADDTIONAL-DATA'][$line]['COMBINATOR'][] = $word;
}
function __processRowFor_run($indx, $word, $line, $hIndex)
{
return $this->__pattern1($indx, $word, $line, $hIndex);
}
function __processRowFor_jump($indx, $word, $line, $hIndex)
{
return $this->__pattern1($indx, $word, $line, $hIndex);
}
function __processRowFor_throw($indx, $word, $line, $hIndex)
{
return $this->__pattern1($indx, $word, $line, $hIndex);
}
function __pattern1($indx, $word, $line, $hIndex)
{
$wordStEnd = ParserUtility::get_start_end_pos($line, $word);
if(sizeof($wordStEnd)==0)
{
$wordStEnd = ParserUtility::get_start_end_pos($line, ' '.trim($word));
}
if(sizeof($wordStEnd)==0)
{
$wordStEnd = ParserUtility::get_start_end_pos($line, trim($word).' ');
}
$headerIndex = -1;
if($this->debug) { echo "
POSITION - "; print_r($wordStEnd); }
if($this->debug) { echo "
HEADER - "; print_r($this->headerPositions); }
if($indx==0
&& @$wordStEnd[0]['END-POSITION']<=$this->headerPositions['SL']['POSITION-END']
&& @$wordStEnd[0]['END-POSITION']>$this->headerPositions['SL']['POSITION-START'])//&& is_numeric(trim($word))===true
{
$this->matrix[$this->rowCounter]['RAW-LINE']["COMBINATOR"][0] = trim($line);
$this->matrix[$this->rowCounter]['ROUND']["COMBINATOR"][0] = $this->getSportsRound();
$this->matrix[$this->rowCounter]["SL"]["COMBINATOR"][0] = trim($word);
if($this->debug) echo "
Putting '".$word."' AT -> SL";
if($this->debug) echo "
---------------------------------
";
}
else if(isset($this->matrix[$this->rowCounter]['SL']))
{
foreach($wordStEnd as $wordStartEnd)
{
if($wordStartEnd['END-POSITION']<=$this->decoratorLen)
{
$headerIndex = 0;
foreach($this->headerPositions as $header=>$headerPos)
{
if($this->debug) echo "
Matching end 'w-".$wordStartEnd['END-POSITION']."' between 'h-".$headerPos['POSITION-START']."' and 'h-".$headerPos['POSITION-END']."' @ ".$header.' HAVING hIndex=>'.$hIndex;
if($wordStartEnd['END-POSITION']<=$headerPos['POSITION-END']
&& $wordStartEnd['END-POSITION']>$headerPos['POSITION-START']
&& $headerIndex >= $hIndex)
{
if($this->debug) echo "
-- Success Matching 'w-".$wordStartEnd['END-POSITION']."' with 'h-".$headerPos['POSITION-END']."' and 'w-".$wordStartEnd['END-POSITION']."' with 'h-".$headerPos['POSITION-START']."' @ ".$header.' HAVING hIndex=>'.$hIndex.'';
$this->matrix[$this->rowCounter][$header]['COMBINATOR'][] = trim($word);
if($this->debug) echo "
Line - Putting '".$word."' AT -> ".$header;
if($this->debug) echo "
---------------------------------
";
if(count($wordStEnd)>1)
{
$headerIndex++;
}
return $headerIndex;
}
elseif(($wordStartEnd['END-POSITION']-$headerPos['POSITION-END'])==1)
{
if($this->debug) echo "
-- Force Matching 'w-".$wordStartEnd['END-POSITION']."' with 'h-".$headerPos['POSITION-END']."' and 'w-".$wordStartEnd['END-POSITION']."' with 'h-".$headerPos['POSITION-START']."' @ ".$header.'';
$this->matrix[$this->rowCounter][$header]['COMBINATOR'][] = trim($word);
if($this->debug) echo "
Line - Putting '".$word."' AT -> ".$header;
if($this->debug) echo "
---------------------------------
";
return $headerIndex;
}
$headerIndex++;
}
}
else
{
//echo "IN~".$word.' >> '.$line;
$this->matrix[$this->rowCounter]['REMARKS']['COMBINATOR'][] = trim($word);
}
}
}
return $headerIndex;
}
function __processCombinatorData()
{
if(is_array($this->matrix) && sizeof($this->matrix) > 0)
{
if(is_array(@$this->matrix[$this->rowCounter]))
{
foreach($this->matrix[$this->rowCounter] as $header=>$rowData)
{
if($header==='ADDTIONAL-DATA')
{
$toDelete = array();
$cntr = 0;
foreach($this->matrix[$this->rowCounter]['ADDTIONAL-DATA'] as $lnn=>$addlnRec)
{
$this->matrix[$this->rowCounter]['ADDTIONAL-DATA'][$cntr]["COMBINATOR"] = $addlnRec['COMBINATOR'];
$this->matrix[$this->rowCounter]['ADDTIONAL-DATA'][$cntr]["COMBINED"] = implode(" ",$addlnRec['COMBINATOR']);
$cntr++;
$toDelete[] = $lnn;
}
foreach($toDelete as $lndl)
{
unset($this->matrix[$this->rowCounter]['ADDTIONAL-DATA'][$lndl]);
}
}
else
{
if(is_array(@$rowData['COMBINATOR']))
{
$this->matrix[$this->rowCounter][$header]["COMBINED"] = implode(" ",$rowData['COMBINATOR']);
if(strtolower($header)==='name')
{
$analysis = new Lexicon(implode(" ",$rowData['COMBINATOR']));
$nameAnalysis = $analysis->getAnalysisForNames();
$this->matrix[$this->rowCounter][$header]["COMBINED"] = @$nameAnalysis['FULL-NAME'];
$this->matrix[$this->rowCounter][$header]["ROLL-NO"] = @$nameAnalysis['ROLL-NO'];
$this->matrix[$this->rowCounter][$header]["FIRST-NAME"] = @$nameAnalysis['FIRST-NAME'];
$this->matrix[$this->rowCounter][$header]["LAST-NAME"] = @$nameAnalysis['LAST-NAME'];
}
}
}
}
}
switch($this->sportGroup)
{
case ParserUtility::$_RUNNING_ :
case ParserUtility::$_RELAY_ :
$this->__processDataFor_run();
break;
case ParserUtility::$_JUMPING_ :
case ParserUtility::$_JUMPING_TEAM_ :
$this->__processDataFor_jump();
break;
case ParserUtility::$_THROWING_ :
case ParserUtility::$_THROWING_TEAM_ :
$this->__processDataFor_throw();
break;
default :
break;
}
}
}
function __processDataFor_run()
{
if(is_array(@$this->matrix[$this->rowCounter]))
{
foreach($this->matrix[$this->rowCounter] as $header=>$rowData)
{
$rec = @ParserUtility::$terms_reportHeader_dType[$header];
switch($rec)
{
case "string":
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
break;
case "int":
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false)
{
$this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED";
}
$this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']);
break;
case "float":
if(trim( $rowData['COMBINED'])!=='')
{
if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false)
{
$this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED";
}
$this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']);
if(strpos($rowData['COMBINED'],":"))
{
$calcData = ParserUtility::numerizeTime($rowData['COMBINED']);
$this->matrix[$this->rowCounter][$header]["DATA"] = $calcData;
}
else
{
$this->matrix[$this->rowCounter][$header]["DATA"] = floatval($rowData['COMBINED']);
}
}
break;
default:
if($header!=='ADDTIONAL-DATA')
{
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
}
break;
}
}
}
}
function __processDataFor_jump()
{
if(is_array(@$this->matrix[$this->rowCounter]))
{
foreach($this->matrix[$this->rowCounter] as $header=>$rowData)
{
$rec = @ParserUtility::$terms_reportHeader_dType[$header];
switch($rec)
{
case "string":
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
break;
case "int":
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false)
{
$this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED";
}
$this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']);
break;
case "float":
if(trim( $rowData['COMBINED'])!=='')
{
if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false)
{
$this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED";
}
$theData = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']);
$this->matrix[$this->rowCounter][$header]["COMBINED"] = $theData ;
if(strpos($theData,"-"))
{
$calcData = ParserUtility::numerizeLength($theData);
$this->matrix[$this->rowCounter][$header]["DATA"] = $calcData;
}
else
{
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
}
}
break;
default:
if($header!=='ADDTIONAL-DATA')
{
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
}
break;
}
}
}
}
function __processDataFor_throw()
{
if(is_array(@$this->matrix[$this->rowCounter]))
{
foreach($this->matrix[$this->rowCounter] as $header=>$rowData)
{
$rec = @ParserUtility::$terms_reportHeader_dType[$header];
switch($rec)
{
case "string":
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
break;
case "int":
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false)
{
$this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED";
}
$this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']);
break;
case "float":
if(trim( $rowData['COMBINED'])!=='')
{
if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false)
{
$this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED";
}
$this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']);
if(strpos($rowData['COMBINED'],"-"))
{
$calcData = ParserUtility::numerizeLength($rowData['COMBINED']);
$this->matrix[$this->rowCounter][$header]["DATA"] = $calcData;
}
else
{
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
}
}
break;
default:
if($header==='ADDTIONAL-DATA')
{
}
else
{
$this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED'];
}
break;
}
}
}
}
function __resetObj()
{
$this->decoratorLen = 0;
$this->header = array();
$this->headerCount = 0;
$this->headerPositions = array();
$this->matrix = array();
$this->rowCounter = 0;
}
}
?>