|
|
@@ -1,12 +1,16 @@
|
|
|
-<!DOCTYPE html>
|
|
|
+<?php
|
|
|
+require_once '../path.php';
|
|
|
+require_once "../public/_pdo.php";
|
|
|
+?>
|
|
|
+<!DOCTYPE html>
|
|
|
<html>
|
|
|
<head>
|
|
|
</head>
|
|
|
<body>
|
|
|
-<h2>Update Pali Text To single DB</h2>
|
|
|
+<h2>Update Pali Text in single DB</h2>
|
|
|
<p><a href="index.php">Home</a></p>
|
|
|
<?php
|
|
|
-include "../public/_pdo.php";
|
|
|
+
|
|
|
if(isset($_GET["from"])==false){
|
|
|
?>
|
|
|
<form action="db_update_palitext.php" method="get">
|
|
|
@@ -45,15 +49,16 @@ $bookId=$filelist[$from][2];
|
|
|
$vriParNum=0;
|
|
|
$wordOrder=1;
|
|
|
|
|
|
-$dirXmlBase="xml/";
|
|
|
-$dirPaliTextBase="pali-text/";
|
|
|
+$dirXmlBase=_DIR_PALI_CSV_."/";
|
|
|
+$dirPaliTextBase=_DIR_PALI_HTML_."/";
|
|
|
$dirXml=$outputFileNameHead."/";
|
|
|
|
|
|
|
|
|
|
|
|
$xmlfile = $inputFileName;
|
|
|
echo "doing:".$xmlfile."<br>";
|
|
|
-$log=$log."$from,$FileName,open\r\n";
|
|
|
+
|
|
|
+$log=$log.date("Y-m-d h:i:sa").",$from,$FileName,open\r\n";
|
|
|
|
|
|
$arrInserString=array();
|
|
|
|
|
|
@@ -71,16 +76,14 @@ if(($fpPaliText=fopen($dirPaliTextBase.$xmlfile, "r"))!==FALSE){
|
|
|
else{
|
|
|
echo "can not pali text file. filename=".$dirPaliTextBase.$xmlfile;
|
|
|
}
|
|
|
-// 打开text文件并读取数据
|
|
|
+
|
|
|
+// 打开csv文件并读取数据
|
|
|
$inputRow=0;
|
|
|
-if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead."_pali.csv", "r"))!==FALSE){
|
|
|
+if(($fp=fopen(_DIR_PALI_TITLE_."/".($from+1)."_title.csv", "r"))!==FALSE){
|
|
|
while(($data=fgetcsv($fp,0,','))!==FALSE){
|
|
|
if($inputRow>0){
|
|
|
- //if(($inputRow-1)<count($pali_text_array)){
|
|
|
- // $data[6]=$pali_text_array[$inputRow-1];
|
|
|
- //}
|
|
|
- $params=$data;
|
|
|
- array_push($arrInserString,$params);
|
|
|
+ $params=$data;
|
|
|
+ array_push($arrInserString,$params);
|
|
|
}
|
|
|
$inputRow++;
|
|
|
}
|
|
|
@@ -91,57 +94,102 @@ else{
|
|
|
echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
|
|
|
}
|
|
|
|
|
|
-if(($inputRow-1)!=count($pali_text_array)){
|
|
|
-$log=$log."$from, $FileName,error,文件行数不匹配 inputRow=$inputRow pali_text_array=".count($pali_text_array)." \r\n";
|
|
|
+if((count($arrInserString)) != count($pali_text_array)-2){
|
|
|
+ $log=$log."$from, $FileName,error,文件行数不匹配 csv = ".(count($arrInserString)-1) ." pali_text_array=".(count($pali_text_array)-2)." \r\n";
|
|
|
}
|
|
|
|
|
|
$book=$from+1;
|
|
|
-$db_file = "pali_text_new/p{$book}_pali.db3";
|
|
|
-PDO_Connect("sqlite:$db_file");
|
|
|
-$query = "select paragraph,level,text from data where 1";
|
|
|
-echo $query;
|
|
|
-$Fetch_old = PDO_FetchAll($query);
|
|
|
|
|
|
+//计算段落信息,如上一段
|
|
|
+PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
|
|
|
+$query="select * from pali_text where book = '$book' ";
|
|
|
+$title_data = PDO_FetchAll($query);
|
|
|
+echo "Paragraph Count:".count($title_data)."<br>";
|
|
|
+
|
|
|
+$paragraph_count = count($title_data);
|
|
|
|
|
|
-$db_file =_FILE_DB_PALITEXT_;
|
|
|
-PDO_Connect("sqlite:$db_file");
|
|
|
// 开始一个事务,关闭自动提交
|
|
|
$PDO->beginTransaction();
|
|
|
-/*
|
|
|
-$query ="UPDATE pali_text SET text = ? WHERE book=? and paragraph=?";
|
|
|
+$query ="UPDATE pali_text SET level = ? , toc = ? , chapter_len = ? , next_chapter = ?, prev_chapter=? , parent= ? , chapter_strlen = ? WHERE book=? and paragraph=?";
|
|
|
$stmt = $PDO->prepare($query);
|
|
|
-foreach($arrInserString as $oneParam){
|
|
|
- $bookid=substr($oneParam[1],1);
|
|
|
- $newData=array($oneParam[6],
|
|
|
- $bookid,
|
|
|
- $oneParam[2]);
|
|
|
- $stmt->execute($newData);
|
|
|
+
|
|
|
+$paragraph_info = array();
|
|
|
+array_push($paragraph_info,array($from,-1,$paragraph_count,-1,-1,-1));
|
|
|
+for($iPar=0;$iPar < count($title_data); $iPar++){
|
|
|
+ $title_data[$iPar]["level"] = $arrInserString[$iPar][3];
|
|
|
}
|
|
|
-*/
|
|
|
-$query ="UPDATE pali_text SET level = ? , toc = ? WHERE book=? and paragraph=?";
|
|
|
-$stmt = $PDO->prepare($query);
|
|
|
-foreach($Fetch_old as $onePara){
|
|
|
- $level=$onePara["level"];
|
|
|
- if($level==0){
|
|
|
- $level=100;
|
|
|
- }
|
|
|
- if($level==100){
|
|
|
- $maxLen=40;
|
|
|
- if(mb_strlen($onePara["text"],"UTF-8")>$maxLen){
|
|
|
- $toc=ltrim(mb_substr($onePara["text"],0,$maxLen,"UTF-8"))."…";
|
|
|
+
|
|
|
+for($iPar=0;$iPar < count($title_data); $iPar++){
|
|
|
+ $book=$from+1;
|
|
|
+ $paragraph=$title_data[$iPar]["paragraph"];
|
|
|
+
|
|
|
+ if($title_data[$iPar]["level"]==8){
|
|
|
+ $title_data[$iPar]["level"]=100;
|
|
|
+ }
|
|
|
+ $curr_level=$title_data[$iPar]["level"];
|
|
|
+
|
|
|
+
|
|
|
+ $length=-1;
|
|
|
+ for($iPar1=$iPar+1;$iPar1<count($title_data); $iPar1++){
|
|
|
+ if($title_data[$iPar1]["level"]<=$curr_level){
|
|
|
+ $length=$title_data[$iPar1]["paragraph"]-$paragraph;
|
|
|
+ break;
|
|
|
}
|
|
|
- else{
|
|
|
- $toc=ltrim($onePara["text"]);
|
|
|
+ }
|
|
|
+ if($length==-1){
|
|
|
+ $length=$paragraph_count-$paragraph+1;
|
|
|
+ }
|
|
|
+
|
|
|
+ $prev=-1;
|
|
|
+ if($iPar>0){
|
|
|
+ for($iPar1=$iPar-1;$iPar1>=0; $iPar1--){
|
|
|
+ if($title_data[$iPar1]["level"]==$curr_level){
|
|
|
+ $prev=$title_data[$iPar1]["paragraph"];
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- else{
|
|
|
- $toc=ltrim($onePara["text"]);
|
|
|
+
|
|
|
+ $next=-1;
|
|
|
+ if($iPar<count($title_data)-1){
|
|
|
+ for($iPar1=$iPar+1;$iPar1<count($title_data); $iPar1++){
|
|
|
+ if($title_data[$iPar1]["level"]==$curr_level){
|
|
|
+ $next=$title_data[$iPar1]["paragraph"];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $parent=-1;
|
|
|
+ if($iPar>0){
|
|
|
+ for($iPar1=$iPar-1;$iPar1>=0; $iPar1--){
|
|
|
+ if($title_data[$iPar1]["level"]<$curr_level){
|
|
|
+ $parent=$title_data[$iPar1]["paragraph"];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算章节包含总字符数
|
|
|
+ $iChapter_strlen = 0;
|
|
|
+ for($i = $iPar ; $i < $iPar+$length; $i++ ){
|
|
|
+ $iChapter_strlen += $title_data[$i]["lenght"];
|
|
|
}
|
|
|
- $newData=array($level,
|
|
|
- $toc,
|
|
|
- $book,
|
|
|
- $onePara["paragraph"]);
|
|
|
+ $newData=array(
|
|
|
+ $arrInserString[$iPar][3],
|
|
|
+ $arrInserString[$iPar][5],
|
|
|
+ $length,
|
|
|
+ $next,
|
|
|
+ $prev,
|
|
|
+ $parent,
|
|
|
+ $iChapter_strlen,
|
|
|
+ $book,
|
|
|
+ $paragraph
|
|
|
+ );
|
|
|
$stmt->execute($newData);
|
|
|
+
|
|
|
+ if($curr_level>0 && $curr_level<8){
|
|
|
+ array_push($paragraph_info,array($book,$paragraph,$length,$prev,$next,$parent));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 提交更改
|
|
|
@@ -153,15 +201,17 @@ if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
|
|
|
$log=$log."$from, $FileName, error, $error[2] \r\n";
|
|
|
}
|
|
|
else{
|
|
|
- $count=count($arrInserString);
|
|
|
- echo "updata $count recorders.";
|
|
|
+ $count=count($title_data);
|
|
|
+ echo "updata $count paragraph info recorders.<br>";
|
|
|
+ echo count($paragraph_info)." Heading<br>";
|
|
|
}
|
|
|
+//段落信息结束
|
|
|
|
|
|
|
|
|
-
|
|
|
- $myLogFile = fopen($dirLog."db_insert_palitext.log", "a");
|
|
|
+ $myLogFile = fopen(_DIR_LOG_."/db_update_palitext.log", "a");
|
|
|
fwrite($myLogFile, $log);
|
|
|
fclose($myLogFile);
|
|
|
+
|
|
|
?>
|
|
|
|
|
|
|