Mercurial > hg > extraction-interface
annotate interface/add_dynasty.php @ 5:cbbb7ef22394
Change urls from "localmonographs" to "localgazetteers".
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 30 Jan 2015 10:17:44 +0100 |
parents | 883ad980a43b |
children | 0e9a7c69f22c |
rev | line source |
---|---|
4
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1 <?php |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
2 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
3 include_once('Lib_mb_utf8.php'); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
4 include_once('config.php'); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
5 set_time_limit(0); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
6 ini_set('memory_limit', '-1'); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
7 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
8 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
9 mysql_query("SET NAMES utf8"); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
10 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
11 if (!$link_mysql) { |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
12 die('Could not connect: ' . mysql_error()); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
13 } |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
14 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
15 $db_selected = mysql_select_db($mysql_database, $link_mysql); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
16 if (!$db_selected) { |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
17 die ('Can\'t use foo : ' . mysql_error()); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
18 } |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
19 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
20 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
21 function add_dynasty($dynasty_info){ |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
22 $dynasty = $dynasty_info[0]; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
23 $start_year = $dynasty_info[1]; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
24 $end_year = $dynasty_info[2]; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
25 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
26 $dir_path = "dynasty_period_list/"; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
27 $myfile = fopen($dir_path.$dynasty.".txt", "r") or die("Unable to open file!"); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
28 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
29 // Output one line until end-of-file |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
30 while(!feof($myfile)) { |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
31 $line = fgets($myfile); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
32 $splited_line = preg_split('/\r\n|\r|\n/', $line); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
33 $matched_period = $splited_line[0]; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
34 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
35 $query="SELECT id, period, start_year FROM books WHERE period='".$matched_period."'"; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
36 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
37 $result=mysql_query($query); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
38 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
39 if(!$result){ |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
40 echo json_encode("Failed during querying records."); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
41 return; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
42 } |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
43 while($row=mysql_fetch_assoc($result)){ |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
44 echo $row['id']." ".$row['period']."<br>"; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
45 if ($row['start_year'] > ($start_year-10) && $row['start_year'] < ($end_year+10)) { |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
46 // write $dynasty into record |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
47 $query="UPDATE books SET dynasty='".$dynasty."' WHERE id='".$row['id']."'"; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
48 $res=mysql_query($query); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
49 if(!$res){ |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
50 echo json_encode("Failed during querying records."); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
51 return; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
52 } |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
53 } |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
54 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
55 } |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
56 echo "----------".$matched_period." books number: ".mysql_num_rows($result)."<br>"; |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
57 } |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
58 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
59 fclose($myfile); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
60 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
61 } |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
62 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
63 |
5
cbbb7ef22394
Change urls from "localmonographs" to "localgazetteers".
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
4
diff
changeset
|
64 // $dynasty array contains (dynasty, start_year, end_year) |
4
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
65 $dynasty = array("漢",-140,200); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
66 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
67 $dynasty = array("三國",220,280); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
68 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
69 $dynasty = array("晉",265,420); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
70 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
71 $dynasty = array("南北朝",386,589); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
72 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
73 $dynasty = array("隋",581,618); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
74 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
75 $dynasty = array("唐",618,907); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
76 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
77 $dynasty = array("五代",907,959); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
78 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
79 $dynasty = array("宋",960,1279); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
80 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
81 $dynasty = array("遼",916,1125); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
82 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
83 $dynasty = array("金",1115,1234); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
84 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
85 $dynasty = array("元",1260,1367); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
86 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
87 $dynasty = array("西夏",1032,1227); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
88 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
89 $dynasty = array("明",1368,1644); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
90 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
91 $dynasty = array("清",1616,1911); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
92 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
93 $dynasty = array("民國",1911,9999); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
94 add_dynasty($dynasty); |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
95 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
96 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
97 // dynasty list ref: http://dict.revised.moe.edu.tw/htm/fulu/nh.htm |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
98 |
883ad980a43b
add dynasty column to table books
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
99 ?> |