Estoy tratando de encontrar una manera de negar oraciones basadas en el etiquetado POS. Por favor tener en cuenta:Omitir oraciones usando POS-etiquetado
include_once 'class.postagger.php';
function negate($sentence) {
$tagger = new PosTagger('includes/lexicon.txt');
$tags = $tagger->tag($sentence);
foreach ($tags as $t) {
$input[] = trim($t['token']) . "/" . trim($t['tag']) . " ";
}
$sentence = implode(" ", $input);
$postagged = $sentence;
// Concatenate "not" to every JJ, RB or VB
// Todo: ignore negative words (not, never, neither)
$sentence = preg_replace("/(\w+)\/(JJ|MD|RB|VB|VBD|VBN)\b/", "not$1/$2", $sentence);
// Remove all POS tags
$sentence = preg_replace("/\/[A-Z$]+/", "", $sentence);
return "$postagged<br>$sentence";
}
Por cierto: En este ejemplo, estoy usando el POS-tagging implementation y lexicon de Ian Barber. Un ejemplo de este código en ejecución sería:
echo negate("I will never go to their place again");
I/NN will/MD never/RB go/VB to/TO their/PRP$ place/NN again/RB
I notwill notnever notgo to their place notagain
Como se puede ver, (y este problema también se comenta en el código), negando las palabras mismas están siendo negados como wel: never
se convierte en notnever
, lo que obviamente shouldn' t sucede. Dado que mis habilidades de expresión regular no son todo eso, ¿hay alguna manera de excluir estas palabras de la expresión regular utilizada?
[editar] Además, me gustaría mucho recibir otros comentarios/críticas que pueda tener en esta implementación negación, ya que estoy seguro de que es (todavía) bastante deficiente :-)
http://stackoverflow.com/questions/2633353/algorithm-for-negating-sentences –