php - 在斯坦福 NER 中标记全名

标签 php named-entity-recognition

我正在尝试将全名标记为完整标签(一个人)而不是单个标签。这是一个例子。

http://nlp.stanford.edu:8080/ner/process (斯坦福NER在线)

例句:穆罕默德·阿里是一位伟大的拳击手。阿里最大的对手是乔·弗雷泽。这个名字也可以写成 M. Ali 和 J. Frazier。

这是我现有的 PHP 代码`

$text = "Muhammad Ali was a great boxer. Ali's greatest rival was Joe Frazier. The name can also   be written as M. Ali and J. Frazier";

$pos = new \StanfordNLP\NERTagger(
          'XPATH/NER/StanfordNLP/stanford-ner-2013-11-12/classifiers/english.conll.4class.distsim.crf.ser.gz',
          'XPATH/NER/StanfordNLP/stanford-ner-2013-11-12/stanford-ner.jar'
);
$result = $pos->tag(explode(' ', " $text")); 

foreach ($result as $eType)
{

    if(!(strcmp($eType[1], 'PERSON')))
    {
         echo "Word ".$eType[0]." of Stanford entity type PERSON</br>";                   
    }
}`

最佳答案

没关系,我自己就能解决这个问题。基本上,如果前一个单词也是实体类型 person,我会专注于组合单词。这是我想出的代码

<?php
        ini_set('max_execution_time', 300); //300 seconds = 5 minutes
        require "./php_aho_corasick-master/AhoCorasickPHP-master/AhoCorasick.php";
        require "./php_aho_corasick-master/AhoCorasickPHP-master/TreeNodes.php";
        include_once('AlchemyAPI/alchemyapi.php');
        include_once('TextStatistics/TextStatistics.php');

        require './NER/StanfordNLP/Base.php';
        require './NER/StanfordNLP/Exception.php';
        require './NER/StanfordNLP/Parser.php';
        require './NER/StanfordNLP/StanfordTagger.php';
        require './NER/StanfordNLP/NERTagger.php';
        $text= "Muhammad Ali was a great boxer, Ali's greatest rival was Joe Frazier, The name can also be written as M. Ali and J. Frazier.";
        $pos = new \StanfordNLP\NERTagger(
          'C:/wamp/www/GoogleResultsParserTopK/NER/StanfordNLP/stanford-ner-2013-11-12/classifiers/english.conll.4class.distsim.crf.ser.gz',
          'C:/wamp/www/GoogleResultsParserTopK/NER/StanfordNLP/stanford-ner-2013-11-12/stanford-ner.jar'
        );            
        $a="Answer not found";
        //$pos->setJavaPath('C:/Program Files/Java/jdk1.7.0_45/bin');
        $result = $pos->tag(explode(' ', " $text")); 

        var_dump($result);


        $previousValue="";
        $previousType="";
        $FullName="";
        $i=0;
        foreach ($result as $eType) {

            echo $i." ".$FullName."</br>";
            $i++;
            if(!(strcmp($eType[1], 'PERSON')))
            {
                if(!(strcmp($previousType, 'PERSON')) && !(strcmp($FullName, "")))
                {
                    $FullName=$previousValue." ".$eType[0];
                }
                else if(!(strcmp($previousType, 'PERSON')) && (strcmp($FullName, "")))
                {
                    $FullName=$FullName." ".$eType[0];
                }
                else if(!(strcmp($a, "Answer not found")) && !(strcmp($FullName, "")))
                    $FullName=$eType[0];
                else if((strcmp($FullName, "")))
                    $FullName=$FullName." or ".$eType[0];


            }

            $previousValue=$eType[0];
            $previousType=$eType[1];
        }           
        echo $FullName;

?>

关于php - 在斯坦福 NER 中标记全名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25842982/

相关文章:

javascript - 使用 append() 将页面滚动到底部时如何显示数据;

php - 如何使用 PDO ssl 连接到 azure mysql 数据库

php - 如何在 android 中将 json 从 php 解析为 listview?

python - NLTK 中的斯坦福 NER 未正确标记多个句子 - Python

java - 使用 Stanford 命名实体识别器时如何包含多个分类器?

python - 我们如何使用 Spacy minibatch 和 GoldParse 来训练使用 BILUO 标记方案的 NER 模型?

PHP - 在双引号字符串中插入变量

javascript - javascript 中的事件不起作用

pytorch - CUDA 运行时错误 : Which Cuda version is compatible to run NER task using BERT-NER

pandas - NLP:根据分隔符创建 spaCy Doc 对象或组合多个 Doc 对象以形成单个对象