<?php
class NIST {
	function instructions() {
	?>
		<TR><TD VALIGN=TOP>Instructions</TD><TD>
		5= All Meaning<BR>
		4= Most Meaning<BR>
		3= Much Meaning<BR>
		2= Little Meaning<BR>
		1= None
		</TD><TD>
		5= Flawless English<BR>
		4= Good English<BR>
		3= Non-native English<BR>
		2= Disfluent English<BR>
		1= Incomprehensible
		</TD></TR>	
		
	<?php
	}
	
	function min_item_number() {
		return get_task_property('min_sentence_number');
	}
	
	function max_item_number() {
		return get_task_property('max_sentence_number');	
	}
	
	function head_text() {
		return "Judge Sentences";
	}
	
	//return judgement string, null if no judgements scored
	function process_judgement() {
		$translation_ids = get_task_property('translation_id');
		$success = false;
		
		$types = array("ADEQUACY","FLUENCY");
		$score_hash = array();
		while (list($key, $value) = each($_POST)) {
			foreach ($types as $type) {
				if (preg_match("/${type}_(.+)/",$key,$reg)) {
					//at least one judgement is present, mark as a successful attempt
					$success = true;
					$score_hash[$translation_ids[$reg[1]]][$type]=$value;
				}
			}
		}
		$nist_scores = array();
		foreach($score_hash as $system => $score_list) {
			$nist_scores[] = $system.":".($score_list["ADEQUACY"] ? $score_list["ADEQUACY"] : "-").",".($score_list["FLUENCY"] ? $score_list["FLUENCY"] : "-");
		}	
		if ($success) {
			return join(" ",$nist_scores);
		} else {
			return null;
		}
	}
	
	function is_numerical_score() {
		return false;
	}

	function process_statistics($system_score_list) {
		//we get system->string. We return system->{score_name->value}
		$processed_scores = array();
	
		foreach ($system_score_list as $system => $score) {
			
			list($adequacy,$fluency) = split(",",$score);
			
			
			if ($adequacy != "-") {
				$processed_scores[$system]["NIST_ADEQUACY"] = $adequacy;
			}
			if ($fluency != "-") {
				$processed_scores[$system]["NIST_FLUENCY"] = $fluency;
			}
		}
		return $processed_scores;
	
	}

	function test_info($assignment_id) {	

		list($test_type_id,$assignment_number,$assignment_info_string) = split("-",$assignment_id);			
		$system_id_list = split(",",$assignment_info_string);
		$translation_file = get_task_property('translation_file');
	
		print "<B>Source:</B> ".display_one_line(get_task_property('source'),$assignment_number);
		$reference = get_task_property('reference');
		for($i=0;$i<count($reference);$i++) {
			print "<P><B>Reference:</B> <FONT COLOR=#008000>".display_one_line($reference[$i],$assignment_number)."</FONT>\n";
		}
		
		?>
		<TABLE BORDER=1>
		<TR><TD><B>Translation</B></TD><TD><B>Adequacy</B></TD><TD><B>Fluency</B></TD></TR>
		<?php
		foreach($system_id_list as $system_id) {
			if (file_exists($translation_file[$system_id])) {
				print "<TR BGCOLOR=#F0F0FF><TD><FONT COLOR=#000080>".display_one_line($translation_file[$system_id],$assignment_number);
				//print ($GLOBALS["translation_file"][$system_id]." ".$GLOBALS["translation_id"][$system_id]);
				?>
				</FONT></TD><TD NOWRAP>
				<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR>
				<?php
				for($j=1;$j<=5;$j++) {
					print "<TD><INPUT TYPE=RADIO NAME=ADEQUACY_$system_id VALUE=$j></TD>\n";
				}
				print "</TR>\n<TR>";
				for($j=1;$j<=5;$j++) {
					print "<TD ALIGN=CENTER>$j</TD>\n";
				}
				?>
				</TR></TABLE>
				</TD><TD NOWRAP>
				<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR>
				<?php
				for($j=1;$j<=5;$j++) {
					print "<TD><INPUT TYPE=RADIO NAME=FLUENCY_$system_id VALUE=$j></TD>\n";
				}
				?>
				</TR>
				<TR>
				<?php
				for($j=1;$j<=5;$j++) {
					print "<TD ALIGN=CENTER>$j</TD>\n";
				}
				?>
				</TR></TABLE>
				</TD></TR>
				<?php
			}
		}
		
	}
	
}
?>