Tryag File Manager
Home
-
Turbo Force
Current Path :
/
home
/
cluster1
/
data
/
bu01
/
1121861
/
html
/
jlex
/
nahuatl
/
php4
/
Upload File :
New :
File
Dir
//home/cluster1/data/bu01/1121861/html/jlex/nahuatl/php4/changer.php4
<? class changer { var $parser; var $out; var $data; var $cur_phrase_set; var $order = array("phrase_n","phrase_d","snd_am","snd_oa","src_p","phrase_e","phrase_s"); var $get_fields; function changer() { $this->get_fields = false; } function rewrite() { $s = ""; foreach($this->order as $field) { if(array_key_exists($field, $this->cur_phrase_set)) { $value = $this->cur_phrase_set[$field]; $s .= "\\$field $value\n"; } } return $s; } function startHandler($xp,$element,$attribs) { $element = strtolower($element); if($element == "phrase_ngroup") { $this->get_fields = true; } } function endHandler($xp,$element) { $element = strtolower($element); if($element != "refgroup") { if($element == "phrase_ngroup") { $s = $this->rewrite(); fwrite($this->out,$s); $this->get_fields = false; $this->cur_phrase_set = array(); } else if($this->get_fields) { $this->cur_phrase_set[$element] = $this->data; } else { if($this->data != "") { fwrite($this->out,"\\$element $this->data\n"); } } } else { fwrite($this->out,"\n"); } $this->data = ""; } function cDataHandler($xp,$data) { $data = trim($data); if($data != "") { $data = ereg_replace("&","&",$data); $data = ereg_replace("<","<",$data); $data = ereg_replace(">",">",$data); //$data = utf8_encode($data); $this->data .= $data; } } function change_phrases($xml,$new_shoebox_name,$fields_file) { $this->parser = xml_parser_create(); xml_set_object($this->parser,$this); xml_set_element_handler($this->parser,"startHandler","endHandler"); xml_set_character_data_handler($this->parser,"cDataHandler"); $in = fopen($xml,"r"); $this->out = fopen($new_shoebox_name,"w"); while($line = fgets($in)) { xml_parse($this->parser,$line,false); } } } $sc = new changer(); $sc->change_phrases("ActiveNahuatl_2005_august_4.xml","fixed_senses.txt","senses_conversion.txt"); ?>