我正在尝试检查某些术语是否出现在哈希键中,如果我用哈希值标记它们。我的代码识别出完全匹配但对于略有不同的术语失败。同样对于完全匹配,代码用所有值而不是相关值标记匹配的术语。
%Drugs = ('tamoxifen' => tablet,
'docotaxel' => capsule,
'5-hydroxycin' => IDK,);
$sentence="tamoxifen 4-hydroxytamoxifen tamoxifen-incoded pre-docotaxel Drugs";
@sentence=split/ /,$sentence;
@array=();
foreach $word(@sentence)
{
chomp $word;
for $keys(keys %Drugs)
{
if($Drugs{$word})
{
$term="<$Drugs{$keys}>$word<$Drugs{$keys}>";
push(@array,$term);
}
elsif($word=~/.*$Drugs{$keys}$/i)
{
$term="<$Drugs{$keys}>$word<$Drugs{$keys}>";
push(@array,$term);
}
}
foreach $Bio(@array)
{
print "$Bio\n";
}
我想要输出句子:
<tablet>tamoxifen</tablet> <tablet>4-hydroxytamoxifen</tablet> <tablet>tamoxifen-incoded<tablet> <capsule>pre-docotaxel<capsule> Drugs.(Here Drugs didn't match and hence it is left untagged)