0

テキストを解析したい。B R I E F I N G S I N B I O I N F O R M A T I C S途中で飛ばしたいみたいな変な文が出てきた。ここにコードがあります

<?php
$text = 'B R I E F I N G S I N B I O I N F O R M A T I C S. Because many biomedical entities have multiple names and abbreviations, it would be advantageous to have an automated means to collect these synonyms and abbreviations to aid users doing literature searches.';

$reg = '/(?<=[.!?]|[.!?][\'"])\s+/';
foreach(preg_split($reg, $text, -1, PREG_SPLIT_NO_EMPTY) as $sentence){
    foreach(preg_split('/\s+/', $sentence) as $words){
       if (count(strlen($words)>1)){
        //I don't know what to do
    }
    }
}
?>

しかし、それはまだ間違っていB R I E F I N G S I N B I O I N F O R M A T I C Sます。ありがとうございました

4

3 に答える 3

1

あなたが示した文から、あなたのテキストの冒頭で、スペースが注入された大文字のみで構成される文を削除します。

echo preg_replace('/^[A-Z](?:\s[A-Z])+\./', '', $text);
于 2012-11-01T10:00:21.450 に答える
1

文字列が毎回同じであれば、これは機能します

<?php
$text = 'B R I E F I N G S I N B I O I N F O R M A T I C S. Because many biomedical entities have multiple names and abbreviations, it would be advantageous to have an automated means to collect these synonyms and abbreviations to aid users doing literature searches.';

$text = str_replace("B R I E F I N G S I N B I O I N F O R M A T I C S. ","",$text); // <--- added this

$reg = '/(?<=[.!?]|[.!?][\'"])\s+/';
foreach(preg_split($reg, $text, -1, PREG_SPLIT_NO_EMPTY) as $sentence){
    foreach(preg_split('/\s+/', $sentence) as $words){
       if (count(strlen($words)>1)){
        //I don't know what to do
    }
    }
}
?>
于 2012-11-01T09:51:43.297 に答える
1

これはどうですか?これは、文中のすべての単語の長さが 1 に等しい場合に機能します。

   <?php
    $text = 'B R I E F I N G S I N B I O I N F O R M A T I C S. Because many biomedical entities have multiple names and abbreviations, it would be advantageous to have an automated means to collect these synonyms and abbreviations to aid users doing literature searches.';

$reg = '/(?<=[.!?]|[.!?][\'"])\s+/';
foreach(preg_split($reg, $text, -1, PREG_SPLIT_NO_EMPTY) as $sentence){
    foreach(preg_split('/\s+/', $sentence) as $words){
       $isStrange = true;
       if (strlen($words)>1){
        $isStrange = false;
    }
    if ($isStrange) echo $sentence.' is very strange!';
    }
}
?>
于 2012-11-01T09:51:10.787 に答える