<?php
class CONSTITUENT_ACCEPT {
	function instructions() {
	?>
		<TR><TD VALIGN=TOP>Instructions: <BR>Decide if the <FONT style='BACKGROUND-COLOR: yellow'><b>highlighted part</b></FONT> of each translation is acceptable, given the reference. This should not be a relative judgement against the other system translations.<BR>
		<I>Please note that segments are selected automatically, and they should be taken as an approximate guide.  They might include extra words, or miss words on either end that are not in the actual alignment.</I></TD><TD>
		&nbsp;
		</TD><TD>
		
		
	<?php
	}
	
	function min_item_number() {
		return get_task_property('min_constituent_number');
	}
	
	function max_item_number() {
		return get_task_property('max_constituent_number');	
	}
	
	
	function head_text() {
		return "Yes/No Judgements of Segments";
	}
	
	
	//return judgement string, null if no judgements scored
	function process_judgement() {
		$translation_ids = get_task_property('translation_id');
		$success = false;

		$ranks = array();
		$systems = array();
		
		while (list($key, $value) = each($_POST)) {
			if (preg_match("/C_ACCEPT_(.+)/",$key,$reg)) {
				//at least one judgement is present, mark as a successful attempt
				$success = true;
				$ranks[] = $translation_ids[$reg[1]].":".$value;
			}
		}
		
		if ($success) {
			return join(" ",$ranks);
		} else {
			return null;
		}
	}
	
	
	function is_numerical_score() {
		return true;
	}

	function process_statistics($system_score_list,$score_total) {
		//we get system->string. We return system->{score_name->value}
		
		$processed_scores = array();
			
		foreach ($system_score_list as $system => $score) {
			if ($score == 1) $score = 1;
			if ($score == 2) $score = 0;
			if ($score == 3) continue;
			$processed_scores[$system]["CONSTITUENT_ACCEPT"] = $score;	
		}
		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);

		$constituent_file = get_task_property('constituent');

		$constituent_info_string = display_one_line($constituent_file,$assignment_number);
		
		list($sentence_number,$constituent_type) = split(" \|\|\| ",$constituent_info_string);
		
		//FIXED: the sentence numbers stored in the constituent file start at 1, not 0
		#$sentence_number--;
		
		$constituent_map = load_constituent_locations($system_id_list,$constituent_info_string);
	
		//print_r($constituent_map);
		
		print "<B>Source:</B> ".display_one_phrase(get_task_property('source'),$sentence_number,$constituent_map["src"]["start_word"],$constituent_map["src"]["end_word"]);
	
		//for($i=0;$i<count($reference);$i++) {
		//	print "<P><B>Reference:</B> <FONT COLOR=#008000>".display_one_phrase($reference[$i],$assignment_number)."</FONT>\n";
		//}
		$reference = get_task_property('reference');

		//only 1 ref for constituents
		print "<P><B>Reference:</B> <FONT COLOR=#008000>".display_one_phrase($reference[0],$sentence_number,$constituent_map["ref"]["start_word"],$constituent_map["ref"]["end_word"])."</FONT>\n";
	
		$translation_ids = get_task_property('translation_id');
		$translation_files = get_task_property('translation_file');
		?>
		<TABLE BORDER=1>
		<TR><TD><B>Translation</B></TD><TD><B>Acceptable?</B></TD></TR>
		<?php
		foreach($system_id_list as $system_id) {
			$system_name = $translation_ids[$system_id];
			if (file_exists($translation_files[$system_id]) && array_key_exists($system_name,$constituent_map)) {
				print "<TR BGCOLOR=#F0F0FF><TD><FONT COLOR=#000080>".display_one_phrase($translation_files[$system_id],$sentence_number,$constituent_map[$system_name]["start_word"],$constituent_map[$system_name]["end_word"]);
				//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<=3;$j++) {
					print "<TD WIDTH=75 ALIGN=CENTER><INPUT TYPE=RADIO NAME=C_ACCEPT_$system_id VALUE=$j></TD>\n";
				}
				print "</TR>\n<TR>";
				for($j=1;$j<=3;$j++) {
					print "<TD TD WIDTH=75 VALIGN=TOP ALIGN=CENTER>";
					if ($j==1) print"<BR>Yes";
					if ($j==2) print"<BR>No";
					if ($j==3) print"<BR><i>Not Sure</i>";
					print "</TD>\n";
				}
				?>
				</TR></TABLE>
				</TD>
				</TD></TR>
				<?php
			}
		}

	}
	
}
?>