插件3:友好的文本

此插件3接受英文文本作为输入,对其进行修改并转换为更友好的口语化形式,包括替换专业术语、修正语法错误、处理缩写和合同短语等。通过使用一系列预定义的规则,将标准英文文本转换为更符合日常对话风格的文本,提高阅读体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?php // Plug-in 3: Friendly Text

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$speech = "<h3>Winston Churchill: 'We will never surrender'</h3>I have, myself, full confidence that if all do their duty, if nothing is neglected, and if the best arrangements are made, as they are being made, we shall prove ourselves once again able to defend our Island home, to ride out the storm of war, and to outlive the menace of tyranny, if necessary for years, if necessary alone.<br />   At any rate, that is what we are going to try to do. That is the resolve of His Majesty's Government - every man of them. That is the will of Parliament and the nation.<br />   Even though large tracts of Europe and many old and famous States have fallen or may fall into the grip of the Gestapo and all the odious apparatus of Nazi rule, we shall not flag or fail.<br />   We shall go on to the end, we shall fight in France, we shall fight on the seas and oceans, we shall fight with growing confidence and growing strength in the air, we shall defend our Island, whatever the cost may be, we shall fight on the beaches, we shall fight on the landing grounds, we shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender.";

echo PIPHP_FriendlyText($speech, TRUE);

function PIPHP_FriendlyText($text, $emphasis)
{
   // Plug-in 3: Friendly Text
   //
   // This plug-in takes a string variable containing English
   // text, processes it into a 'friendly' form of speech and
   // returns the modified text. It takes these arguments:
   //
   //    $text:     Text to be modified
   //    $emphasis: If TRUE underlines all modifications

   $misc = array("let us", "let's", "i\.e\.", "for example",
      "e\.g\.", "for example", "cannot", "can't", "can not",
      "can't", "shall not", "shan't", "will not", "won't");
   $nots = array("are", "could", "did", "do", "does", "is",
      "had", "has", "have", "might", "must", "should", "was",
      "were", "would");
   $haves = array("could", "might", "must", "should", "would");
   $who = array("he", "here", "how", "I", "it", "she", "that",
      "there", "they", "we", "who", "what", "when", "where",
      "why", "you");
   $what = array("am", "are", "had", "has", "have", "shall",
      "will", "would");
   $contraction = array("m", "re", "d", "s", "ve", "ll", "ll",
      "d");

   for ($j = 0 ; $j < sizeof($misc) ; $j += 2)
   {
      $from = $misc[$j];
      $to   = $misc[$j+1];
      $text = PIPHP_FT_FN1($from, $to, $text, $emphasis);
   }

   for ($j = 0 ; $j < sizeof($nots) ; ++$j)
   {
      $from = $nots[$j] . " not";
      $to   = $nots[$j] . "n't";
      $text = PIPHP_FT_FN1($from, $to, $text, $emphasis);
   }
   
   for ($j = 0 ; $j < sizeof($haves) ; ++$j)
   {
      $from = $haves[$j] . " have";
      $to   = $haves[$j] . "'ve";
      $text = PIPHP_FT_FN1($from, $to, $text, $emphasis);
   }

   for ($j = 0 ; $j < sizeof($who) ; ++$j)
   {
      for ($k = 0 ; $k < sizeof($what) ; ++$k)
      {
         $from = "$who[$j] $what[$k]";
         $to   = "$who[$j]'$contraction[$k]";
         $text = PIPHP_FT_FN1($from, $to, $text, $emphasis);
      }
   }

   $to = "'s";
   $u1 = $u2 = "";

   if ($emphasis)
   {
      $u1 = "<u>";
      $u2 = "</u>";
   }

   return preg_replace("/([\w]*) is([^\w]+)/", "$u1$1$to$u2$2",
      $text);
}

function PIPHP_FT_FN1($f, $t, $s, $e)
{
   $uf = ucfirst($f);
   $ut = ucfirst($t);
   
   if ($e)
   {
      $t  = "<u>$t</u>";
      $ut = "<u>$ut</u>";
   }
   
   $s   = preg_replace("/([^\w]+)$f([^\w]+)/",  "$1$t$2",  $s);
   return preg_replace("/([^\w]+)$uf([^\w]+)/", "$1$ut$2", $s);
}

?>

1. 插件说明:

 插件3接受一个字符串变量,它代表需要转换的英文文本,需要把它转变为比较有好的格式,返回转换后的英文文本。它需要以下参数:

$text 字符串变量,包含需要修改的文本

$empasis 布尔变量,如果实true,则用下划线表示修改过的内容


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值