Mercurial > hg > extraction-interface
view interface/add_dynasty.php @ 20:04db1dd9d10d
update topic_regex_relation table when saving (new) regex file
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 23 Feb 2015 14:34:43 +0100 |
parents | 0e9a7c69f22c |
children |
line wrap: on
line source
<?php include_once('Lib_mb_utf8.php'); include_once('config.php'); set_time_limit(0); ini_set('memory_limit', '-1'); $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); mysql_query("SET NAMES utf8"); if (!$link_mysql) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($mysql_database, $link_mysql); if (!$db_selected) { die ('Can\'t use foo : ' . mysql_error()); } function add_dynasty($dynasty_info){ $dynasty = $dynasty_info[0]; $start_year = $dynasty_info[1]; $end_year = $dynasty_info[2]; $dir_path = "dynasty_period_list/"; $myfile = fopen($dir_path.$dynasty.".txt", "r") or die("Unable to open file!"); // Output one line until end-of-file while(!feof($myfile)) { $line = fgets($myfile); $splited_line = preg_split('/\r\n|\r|\n/', $line); $matched_period = $splited_line[0]; $query="SELECT id, period, start_year FROM books WHERE period='".$matched_period."'"; $result=mysql_query($query); if(!$result){ echo json_encode("Failed during querying books records."); return; } while($row=mysql_fetch_assoc($result)){ echo $row['id']." ".$row['period']."<br>"; if ($row['start_year'] > ($start_year-10) && $row['start_year'] < ($end_year+10)) { // write $dynasty into record $query="UPDATE books SET dynasty='".$dynasty."' WHERE id='".$row['id']."'"; $res=mysql_query($query); if(!$res){ echo json_encode("Failed during querying records."); return; } } } echo "----------".$matched_period." books number: ".mysql_num_rows($result)."<br>"; } fclose($myfile); } // $dynasty array contains (dynasty, start_year, end_year) $dynasty = array("漢",-140,200); add_dynasty($dynasty); $dynasty = array("三國",220,280); add_dynasty($dynasty); $dynasty = array("晉",265,420); add_dynasty($dynasty); $dynasty = array("南北朝",386,589); add_dynasty($dynasty); $dynasty = array("隋",581,618); add_dynasty($dynasty); $dynasty = array("唐",618,907); add_dynasty($dynasty); $dynasty = array("五代",907,959); add_dynasty($dynasty); $dynasty = array("宋",960,1279); add_dynasty($dynasty); $dynasty = array("遼",916,1125); add_dynasty($dynasty); $dynasty = array("金",1115,1234); add_dynasty($dynasty); $dynasty = array("元",1260,1367); add_dynasty($dynasty); $dynasty = array("西夏",1032,1227); add_dynasty($dynasty); $dynasty = array("明",1368,1644); add_dynasty($dynasty); $dynasty = array("清",1616,1911); add_dynasty($dynasty); $dynasty = array("民國",1911,9999); add_dynasty($dynasty); // dynasty list ref: http://dict.revised.moe.edu.tw/htm/fulu/nh.htm ?>