stanford-nlp-tagger

PHP wrapper for the Stanford Natural Language Processing library. Supports POSTagger and CRFClassifier.

Github星跟踪图

stanford-nlp-tagger

Version
Total Downloads
Minimum PHP Version
License

A PHP wrapper for the Stanford Natural Language Processing library. Supports POSTagger and CRFClassifier.
Loads automatically the right packages and detects the language of the given text.

Requirements

  • You have to install Java in version 1.8+ or higher.
  • Download the right packages and extract them into the directory.
    (The script loads automatically the right packages, no matter where they are.)

Installation with Composer

$ composer require patrickschur/stanford-nlp-tagger

Example

  • Download the required packages for the POSTagger here for English only
    or here for Arabic, Chinese, French, Spanish, and German.
  • Extract the (.zip) package into your directory. (Please do not rename the packages, only if you want to add this packages manually.)
$pos = new \StanfordTagger\POSTagger();
 
$pos->tag('My dog also likes eating sausage.');

Results in

My_PRP$ dog_NN also_RB likes_VBZ eating_JJ sausage_NN ._.

setOutputFormat()

There are three ways of output formats (xml, slashTags and tsv)

$pos = new \StanfordTagger\POSTagger();
 
$pos->setOutputFormat(StanfordTagger::OUTPUT_FORMAT_XML);
 
$pos->tag('My dog also likes eating sausage.');

Result as XML:

<?xml version="1.0" encoding="UTF-8"?>
<pos>
<sentence id="0">
  <word wid="0" pos="PRP$">My</word>
  <word wid="1" pos="NN">dog</word>
  <word wid="2" pos="RB">also</word>
  <word wid="3" pos="VBZ">likes</word>
  <word wid="4" pos="JJ">eating</word>
  <word wid="5" pos="NN">sausage</word>
  <word wid="6" pos=".">.</word>
</sentence>
</pos>

or use

$pos->setOutputFormat(StanfordTagger::OUTPUT_FORMAT_TSV);

for

My	PRP$
dog	NN
also	RB
likes	VBZ
eating	JJ
sausage	NN
.	.

setModel(), setJarArchive() and setClassfier()

All packages are loaded automatically but if you want to change that you can set them manually.

$pos = new \StanfordTagger\POSTagger();
 
$pos->setModel(__DIR__ . '/stanford-postagger-full-2018-10-16/models/english-bidirectional-distsim.tagger');
 
$pos->setJarArchive(__DIR__ . '/stanford-postagger-full-2018-10-16/stanford-postagger.jar');

CRFClassifier

  • For English only, download the required packages for the CRFClassifier here.
  • You have to download the language models separately:
  • Extract the (.jar) files if you downloaded a language model and add them into your directory.

Example

$ner = new \StanfordTagger\CRFClassifier();
 
$ner->tag('Albert Einstein was a theoretical physicist born in Germany.');
Albert/PERSON Einstein/PERSON was/O theoretical/O physicist/O born/O in/O Germany/LOCATION./O 

Contribute

Feel free to contribute to this repository. Any help is welcome.

主要指标

概览
名称与所有者patrickschur/stanford-nlp-tagger
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2017-02-06 20:46:00
推送于2020-08-02 09:06:54
最后一次提交2020-08-02 11:05:57
发布数5
最新版本名称v0.3.0 (发布于 )
第一版名称v0.1.0 (发布于 )
用户参与
星数75
关注者数7
派生数13
提交数15
已启用问题?
问题数5
打开的问题数1
拉请求数2
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?