限制搜索域

Restrict Search Domain

我有一个数据集,我正在搜索某些 IPA symbols。我想根据下面代码中显示的 $where 的值来限制搜索域,但不知道如何。 编辑:$where 是 "onset" "nucleui" 和 "coda." 有人知道如何限制搜索域吗?(下面的代码在 php 中,但该文件链接到一个 HTML 文件,人们可以使用该文件在数据集中搜索 IPA 符号。)编辑:请参阅底部添加的代码。

//set up variables
$words = $table[0]; //row 1 of table
$target = $table[1]; //row 2
$indices = array(); //used to store column numbers
$IPAstr = $_POST["ipa"];
$where = $_POST["where"];

//Find $IPAstr in $target
for($i=1; $i<count($target); $i++)
{
    if (mb_strpos($target[$i],$IPAstr) !== false)
        $indices[] = $i;        
}

//List realizations & count frequency
for($i=0; $i<count($indices); $i++)
{
    $index = $indices[$i];
    $ipalist = array();
    echo "<table border=1><tr><td>".$target[$index]." in " . $words[$index]."</td></tr><td>";
    //output each speaker and count frequency
    for ($j=2; $j<count($table); $j++) {
        echo ($j-1).": ".$table[$j][$index]."<br>";
        $ipalist[$table[$j][$index]]++;
    }
    echo "<br>";
    //output frequency list
    foreach($ipalist as $ipa=>$fre)
        echo "$ipa: $fre<br>";
    echo "</td></tr></table>";
}

//Code to help search for "onset" "nuclei" and "coda"
//list onsets only
echo "Onsets only<br>";
for($col=0; $col<count($table[0]); $col++) {
    $s = $table[0][$col];
    if (whichSyllPart($s) == 'o') echo "$s ";   
}

//list nuclei only
echo "Nuclei only<br>";
for($col=0; $col<count($table[0]); $col++) {
    $s = $table[0][$col];
    if (whichSyllPart($s) == 'n') echo "$s ";   
}

//list codas only
echo "Codas only<br>";
for($col=0; $col<count($table[0]); $col++) {
    $s = $table[0][$col];
    if (whichSyllPart($s) == 'c') echo "$s ";   
}

为了限制搜索域,您需要在代码的“//Find $IPAstr in $target”部分输入以下代码。

//Find $IPAstr in $target
for($i=1; $i<count($target); $i++)
{
    if ($where == whichSyllPart($words[$i])){
        if (mb_strpos($target[$i],$IPAstr) !== false)
            $indices[] = $i;
    }
    else if ($where == "everywhere"){
        if (mb_strpos($target[$i],$IPAstr) !== false)
            $indices[] = $i;
    }
}

为此 运行 你需要一个函数 whichSyllPart()

function whichSyllPart($sy)
{
    $pt = $sy[strlen($sy)-1];
    return($pt);
} 

这会添加一个 if/else if 语句,其中包含根据 $where 的值限制搜索的 whichSyllPart() 函数。