Mercurial > hg > extraction-interface
annotate search/search_function.php @ 0:b12c99b7c3f0
commit for previous development
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 19 Jan 2015 17:13:49 +0100 |
parents | |
children |
rev | line source |
---|---|
0
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1 <?php |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
2 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
3 include_once('../interface/Lib_mb_utf8.php'); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
4 include_once('../interface/config.php'); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
5 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
6 set_time_limit(0); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
7 ini_set('memory_limit', '-1'); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
8 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
9 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
10 mysql_query("SET NAMES utf8"); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
11 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
12 if (!$link_mysql) { |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
13 die('Could not connect: ' . mysql_error()); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
14 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
15 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
16 $db_selected = mysql_select_db($mysql_database, $link_mysql); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
17 if (!$db_selected) { |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
18 die ('Can\'t use foo : ' . mysql_error()); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
19 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
20 function trimKeyword($keywords){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
21 $token=strtok($keywords,","); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
22 while($token!=false){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
23 $token=trim($token); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
24 $keywordArray[]=$token; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
25 $token=strtok(","); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
26 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
27 return $keywordArray; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
28 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
29 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
30 function search($keywordArray){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
31 $condition=""; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
32 foreach($keywordArray as $i=>$keyword){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
33 if($i!=0){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
34 $condition.=" OR "; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
35 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
36 $condition.=" contents.content LIKE '%".$keyword."%' "; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
37 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
38 //books.name AS book_name, books.level1, books.level2, books.period, contents.books_id, contents.line, contents.content |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
39 $query="SELECT books.level1 AS LEVEL1, books.level2 AS LEVEL2, |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
40 books.name AS Name, books.period AS PERIOD, |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
41 books.start_year AS 'TimeSpan:begin', books.end_year AS 'TimeSpan:end', |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
42 books.id AS BOOK_ID, contents.line AS PAGE, contents.content AS CONTENT, |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
43 info.volume AS VOLUME, info.author AS AUTHOR, info.edition AS EDITION |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
44 FROM contents |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
45 JOIN books ON contents.books_id = books.id |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
46 JOIN books_info info ON contents.books_id=info.books_id |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
47 WHERE ".$condition." |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
48 ORDER BY contents.books_id, contents.line"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
49 //WHERE contents.content LIKE '%".$keyword."%' |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
50 $result = mysql_query($query); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
51 //echo "result length: ".mysql_num_rows($result)."<br>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
52 while ($row = mysql_fetch_assoc($result)) { //Find the section(s) where the page belongs to |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
53 //$resultArray[$i]=$row; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
54 $subQuery="SELECT id, name, start_page, end_page |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
55 FROM sections |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
56 WHERE books_id=".$row['BOOK_ID']." AND start_page<=".$row['PAGE']." AND end_page>=".$row['PAGE']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
57 $subResult=mysql_query($subQuery); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
58 $sectionArray=array(); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
59 while($subRow=mysql_fetch_assoc($subResult)){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
60 $sectionArray[]=$subRow; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
61 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
62 $row['SECTION']=$sectionArray; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
63 $resultArray[]=$row; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
64 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
65 //echo "array length: ".sizeof($resultArray)."<br>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
66 return $resultArray; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
67 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
68 $NO_TAG=0; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
69 $LOCUST_TEMPLE=1; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
70 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
71 function printTable($array,$keywordArray,$filename,$tag){ //print HTML |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
72 global $NO_TAG, $LOCUST_TEMPLE; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
73 $header='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
74 <html> |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
75 <head> |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
76 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
77 <link href="../search.css" type="text/css" rel="stylesheet"/> |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
78 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
79 <script src="../search.js" charset="utf-8"></script> |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
80 </head> |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
81 <body>'; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
82 $keywordStr=""; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
83 foreach($keywordArray as $i=>$keyword){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
84 if($i!=0){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
85 $keywordStr.=", "; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
86 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
87 $keywordStr.=$keyword; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
88 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
89 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
90 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
91 $fp=fopen("search_results/".$filename.".html","w"); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
92 fwrite($fp,$header); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
93 //$str="<a href='http://".$_SERVER['HTTP_HOST']."/map/map.php?mode=1&file=".$filename.".csv&name=".$keywordStr."' target='_blank'>view the distribution on the map</a><br><br>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
94 $str="<a href='http://".$_SERVER['HTTP_HOST']."/map/get_coordinates_for_listed_books.php?file=".$filename.".csv&name=".$keywordStr."' target='_blank'>view the distribution on the map</a><br><br>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
95 fwrite($fp,$str); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
96 $str.="<a href='http://".$_SERVER['HTTP_HOST']."/search/search_results/".$filename.".html' target='_blank'>html version</a><br><br>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
97 echo $str; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
98 echo sizeof($array)." result(s) of \"".$keywordStr."\" "; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
99 fwrite($fp,sizeof($array)." result(s) of \"".$keywordStr."\"<br>"); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
100 $str="<table>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
101 $str.="<tr>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
102 $str.="<td class='sequence'>#<td class='bookId'>book id<td class='bookName'>book name<td class='level1'>level1<td class='level2'>level2<td class='period'>period<td class='sectionName'>section info<td class='page'>page<td class='content'>content"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
103 fwrite($fp,$str); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
104 echo $str; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
105 $i=1; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
106 foreach($array as $row){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
107 $str="<tr>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
108 $str.="<td>".$i; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
109 $str.="<td>".$row['BOOK_ID']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
110 $str.="<td>".$row['Name']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
111 $str.="<td>".$row['LEVEL1']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
112 $str.="<td>".$row['LEVEL2']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
113 $str.="<td>".$row['PERIOD']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
114 $str.="<td>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
115 fwrite($fp,$str); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
116 echo $str; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
117 foreach($row['SECTION'] as $section){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
118 $str="<div class='section'><a href='/interface/tagging_text.php?id=".$section['id']."' target='_blank'>".$section['name']."</a>p".$section['start_page']."-".$section['end_page']."</div>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
119 echo $str; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
120 $str="<div class='section'><a href='/interface/tagging_text.php?id=".$section['id']."' target='_blank'>".$section['name']."</a>p".$section['start_page']."-".$section['end_page']."</div>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
121 fwrite($fp,$str); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
122 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
123 $str="<td>".$row['PAGE']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
124 if($tag==$NO_TAG){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
125 $str.="<td>".$row['CONTENT']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
126 }else if($tag==$LOCUST_TEMPLE){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
127 $str.="<td>".findLocustTempleDescription($row['CONTENT'],$keywordArray,0); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
128 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
129 fwrite($fp,$str); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
130 echo $str; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
131 $i++; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
132 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
133 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
134 echo "</table>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
135 fwrite($fp,"</table></body></html>"); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
136 fclose($fp); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
137 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
138 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
139 function findLocustTempleDescription($str,$keywordArray,$findUnknownTemple){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
140 $result=""; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
141 $pattern[0]="/(.*)("; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
142 foreach($keywordArray as $i=>$keyword){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
143 $pattern[0].=$keyword; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
144 if($i!=sizeof($keywordArray)-1){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
145 $pattern[0].="|"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
146 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
147 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
148 $pattern[0].=")(.*)/u"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
149 //0=whole,1=text,2=locust temple,3=description |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
150 $pattern[1]="/(.*\s+)(\S{1,5}[廟寺祠])(.*)/u"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
151 //0=whole,1=descripption,2=unknown temple,3=text |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
152 $success=preg_match($pattern[$findUnknownTemple],$str,$match); //note that preg_match only matches the last match! |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
153 if($findUnknownTemple==0){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
154 if($success==1){//find string "locust temple" |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
155 $result=findLocustTempleDescription($match[1],$keywordArray,0); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
156 $result.="<keyword>".$match[2]."</keyword>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
157 $result.=findLocustTempleDescription($match[3],$keywordArray,1); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
158 return $result; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
159 }else{//no string "locust temple" |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
160 return "<irrelevant>".$str."</irrelevant>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
161 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
162 }else{ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
163 if($success==1){//find the pattern "locust temple......unknown temple" |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
164 $result=findLocustTempleDescription($match[1],$keywordArray,1); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
165 $result.="<irrelevant>".$match[2].$match[3]."</irrelevant>"; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
166 //$result.="<keyword>".$match[2]."</keyword>".$match[3]; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
167 return $result; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
168 }else{//can't find the pattern |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
169 return $str; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
170 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
171 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
172 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
173 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
174 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
175 function writeCsvFile($array,$fileName){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
176 $columnNameArray=['BOOK_ID','LEVEL1','LEVEL2', |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
177 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','PAGE','SECTION','CONTENT', |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
178 'Description']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
179 $fp=fopen("./csv_files/".$fileName.".csv","w"); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
180 fputcsv($fp,$columnNameArray); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
181 foreach($array as $row){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
182 $book=array(); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
183 $row['Description']=''; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
184 foreach($columnNameArray as $column){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
185 $book[$column]=$row[$column]; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
186 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
187 $book['Name']="(".$row['PERIOD'].") ".$row['Name']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
188 $row['AUTHOR']=str_replace("(","(",$row['AUTHOR']); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
189 $row['AUTHOR']=str_replace(")",") ",$row['AUTHOR']); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
190 $book['Description']=$row['VOLUME']." ╱ ".$row['AUTHOR']." ╱ ".$row['EDITION']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
191 $book['SECTION']=''; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
192 foreach($row['SECTION'] as $idx=>$section){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
193 $book['SECTION'].=$section['name']." ".$section['start_page']."-".$section['end_page']; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
194 if($idx!=sizeof($row['SECTION'])){ |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
195 $book['SECTION'].=" ╱ "; |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
196 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
197 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
198 fputcsv($fp,$book); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
199 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
200 fclose($fp); |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
201 } |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
202 |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
203 ?> |
b12c99b7c3f0
commit for previous development
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
204 |