调整
This commit is contained in:
@@ -129,7 +129,7 @@ class Aireview extends Base
|
|||||||
$aFile = empty($aFile['data']) ? [] : $aFile['data'];
|
$aFile = empty($aFile['data']) ? [] : $aFile['data'];
|
||||||
$aArticleMain = empty($aFile['mains']) ? [] : $aFile['mains'];
|
$aArticleMain = empty($aFile['mains']) ? [] : $aFile['mains'];
|
||||||
}
|
}
|
||||||
$sContent = empty($aArticleMain) ? '' : implode("", array_unique($aArticleMain));
|
$sContent = empty($aArticleMain) ? '' : implode("\n", array_unique($aArticleMain));
|
||||||
if(empty($sContent)){
|
if(empty($sContent)){
|
||||||
return json_encode(array('status' => 4,'msg' => 'No article content found:'.$sQuestionFields));
|
return json_encode(array('status' => 4,'msg' => 'No article content found:'.$sQuestionFields));
|
||||||
}
|
}
|
||||||
@@ -140,6 +140,7 @@ class Aireview extends Base
|
|||||||
$sContent = $oHelperFunction->filterAllTags($sContent);
|
$sContent = $oHelperFunction->filterAllTags($sContent);
|
||||||
//将文章内容拆分参考文献
|
//将文章内容拆分参考文献
|
||||||
$aDealContent = $this->dealContent($sContent);
|
$aDealContent = $this->dealContent($sContent);
|
||||||
|
|
||||||
$sBefore= empty($aDealContent['before']) ? '' : $aDealContent['before'];
|
$sBefore= empty($aDealContent['before']) ? '' : $aDealContent['before'];
|
||||||
$sReference = empty($aDealContent['after']) ? '' : $aDealContent['after'];
|
$sReference = empty($aDealContent['after']) ? '' : $aDealContent['after'];
|
||||||
if(in_array($sQuestionFields, ['attribute'])){//科学性和创新性
|
if(in_array($sQuestionFields, ['attribute'])){//科学性和创新性
|
||||||
@@ -191,26 +192,67 @@ class Aireview extends Base
|
|||||||
* @title 将文章内容拆分参考文献
|
* @title 将文章内容拆分参考文献
|
||||||
* @param sContent 文章内容
|
* @param sContent 文章内容
|
||||||
*/
|
*/
|
||||||
private function dealContent($sContent = ''){
|
private function dealContent($sContent = '',$regex = null){
|
||||||
if(empty($sContent)){
|
if(empty($sContent)){
|
||||||
return [];
|
return ['before' => '', 'after' => ''];
|
||||||
}
|
}
|
||||||
|
|
||||||
//拆分字符串
|
// 1. 限制匹配范围(末尾30%)
|
||||||
$lastPos = strrpos($sContent, 'Reference');
|
$contentLength = strlen($sContent);
|
||||||
if ($lastPos === false) {
|
$searchStart = $contentLength > 5000 ? (int)($contentLength * 0.7) : 0;
|
||||||
$lastPos = strrpos($sContent, 'REFERENCE');
|
$searchContent = substr($sContent, $searchStart);
|
||||||
if($lastPos === false){
|
|
||||||
// 未找到 "Reference",返回原字符串和空
|
// 2. 正则模式优化
|
||||||
return ['before' => $sContent, 'after' => ''];
|
if ($regex === null) {
|
||||||
}
|
$keywords = [
|
||||||
|
'references?', 'bibliograph(?:y|ies)',
|
||||||
|
'works? cited', 'citation(?:s)?'
|
||||||
|
];
|
||||||
|
$pattern = sprintf(
|
||||||
|
'/(?:^|\s)\s*#*\s*(%s)\s*[:\-–]?\s*(?:$|\s)/i',
|
||||||
|
implode('|', $keywords)
|
||||||
|
);
|
||||||
|
$regex = $pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拆分:关键词之前的内容
|
// 3. 匹配并处理结果
|
||||||
$before = substr($sContent, 0, $lastPos);
|
if (preg_match_all($regex, $searchContent, $matches, PREG_OFFSET_CAPTURE)) {
|
||||||
// 关键词及之后的内容(包含关键词本身)
|
$lastMatch = end($matches[0]);
|
||||||
$after = substr($sContent, $lastPos);
|
$refPosition = $searchStart + $lastMatch[1];
|
||||||
return ['before' => $before,'after' => $after];
|
|
||||||
|
// 4. 合并字符串处理
|
||||||
|
$before = substr($sContent, 0, $refPosition);
|
||||||
|
$after = substr($sContent, $refPosition);
|
||||||
|
|
||||||
|
// 一次性处理空白和换行
|
||||||
|
$process = function($str) {
|
||||||
|
return str_replace("\n", '', trim($str));
|
||||||
|
};
|
||||||
|
return [
|
||||||
|
'before' => $process($before),
|
||||||
|
'after' => $process($after)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 未匹配时处理
|
||||||
|
return [
|
||||||
|
'before' => str_replace("\n", '', trim($sContent)),
|
||||||
|
'after' => ''
|
||||||
|
];
|
||||||
|
// $lastPos = strrpos($sContent, 'Reference');
|
||||||
|
// if ($lastPos === false) {
|
||||||
|
// $lastPos = strrpos($sContent, 'REFERENCE');
|
||||||
|
// if($lastPos === false){
|
||||||
|
// // 未找到 "Reference",返回原字符串和空
|
||||||
|
// return ['before' => $sContent, 'after' => ''];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 拆分:关键词之前的内容
|
||||||
|
// $before = substr($sContent, 0, $lastPos);
|
||||||
|
// // 关键词及之后的内容(包含关键词本身)
|
||||||
|
// $after = substr($sContent, $lastPos);
|
||||||
|
// return ['before' => $before,'after' => $after];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user