定制 patrickschur/stanford-nlp-tagger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

patrickschur/stanford-nlp-tagger

最新稳定版本:v0.3.0

Composer 安装命令:

composer require patrickschur/stanford-nlp-tagger

包简介

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

README 文档

README

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.

统计信息

  • 总下载量: 24.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 74
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 74
  • Watchers: 7
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-06