你能否就这个问题给我建议?
输出
word no 0 My =
word no 1 brother =
word no 2 see = Predicate
word no 3 the =
word no 4 moon =
我的问题是如何签名单词,如果它在谓词之前调用主语并且在谓词之后是对象
word no 0 My is Subject
word no 1 brother is Subject
word no 2 see is Predicate
word no 3 the is Object
word no 4 moon is Object
这是我的代码
<?php
$a = "My brother see the moon";
$b = explode(" ",preg_replace("/(\.|\"|,|;|\(|\)|'|)+?/i","",$a));
for($ulangKata=0;$ulangKata<count($b);$ulangKata++)
{
$kata_kerja = 'see';
$huruf_kecil = strtolower($a);
$fungsi_replace = preg_replace("/(\.|\"|,|;|\(|\)|'|)+?/i","",$huruf_kecil);
$pecah_untuk_kata = explode(" ",$fungsi_replace);
$pecah_kata = $pecah_untuk_kata[$ulangKata];
echo "kata ke - ".$ulangKata." ".$b[$ulangKata]."<br>";
}
echo "<br>";
for($ulangKata=0;$ulangKata<count($b);$ulangKata++)
{
echo $b[$ulangKata]."<br>";
}
echo "<br>";
for($ulangKata=0;$ulangKata<count($b);$ulangKata++)
{
$tmp = $ulangKata;
if($b[$ulangKata]==$kata_kerja)
{
$name = 'Predicate';
echo "word no-> ".$ulangKata." -> ".$b[$ulangKata]." = ".$name."<br>";
}
else{echo "word no-> ".$ulangKata." -> ".$b[$ulangKata]." = <br>";}
}
?>
$ text =“你打电话的时候正在学习”
输出如果我有2个谓词
word no-> 0 -> you= Subject
word no-> 1 -> were= Subject
word no-> 2 -> studying= Predicate
word no-> 3 -> when=
word no-> 4 -> she= subject
word no-> 5 -> called= predicate
答案 0 :(得分:0)
输出Subject
直到$b[$ulangKata]==$kata_kerja
然后Object
$name='Subject';
for($ulangKata=0;$ulangKata<count($b);$ulangKata++)
{
if ($name == 'Predicate') $name = 'Object';
elseif($b[$ulangKata]==$kata_kerja) $name = 'Predicate';
echo "word no-> ".$ulangKata." -> ".$b[$ulangKata]." = ".$name."\n";
}
输出
word no-> 0 -> My = Subject
word no-> 1 -> brother = Subject
word no-> 2 -> see = Predicate
word no-> 3 -> the = Object
word no-> 4 -> moon = Object