Skip to content

ankane/mitie-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MITIE PHP

MITIE - named-entity recognition, binary relation detection, and text categorization - for PHP

  • Finds people, organizations, and locations in text
  • Detects relationships between entities, like PERSON was born in LOCATION

Build Status

Installation

Run:

composer require ankane/mitie

And download the pre-trained models for your language:

Getting Started

Named Entity Recognition

Load an NER model

$model = new Mitie\NER('ner_model.dat');

Create a document

$doc = $model->doc('Nat works at GitHub in San Francisco');

Get entities

$doc->entities();

This returns

[
    ['text' => 'Nat',           'tag' => 'PERSON',       'score' => 0.3112371212688382, 'offset' => 0],
    ['text' => 'GitHub',        'tag' => 'ORGANIZATION', 'score' => 0.5660115198329334, 'offset' => 13],
    ['text' => 'San Francisco', 'tag' => 'LOCATION',     'score' => 1.3890524313885309, 'offset' => 23]
]

Get tokens

$doc->tokens();

Get tokens and their offset

$doc->tokensWithOffset();

Get all tags for a model

$model->tags();

Binary Relation Detection

Detect relationships betweens two entities, like:

  • PERSON was born in LOCATION
  • ORGANIZATION was founded in LOCATION
  • FILM was directed by PERSON

There are 21 detectors for English. You can find them in the binary_relations directory in the model download.

Load a detector

$detector = new Mitie\BinaryRelationDetector('rel_classifier_organization.organization.place_founded.svm');

And create a document

$doc = $model->doc('Shopify was founded in Ottawa');

Get relations

$detector->relations($doc);

This returns

[['first' => 'Shopify', 'second' => 'Ottawa', 'score' => 0.17649169745814464]]

Text Categorization

Load a model into a trainer

$trainer = new Mitie\TextCategorizerTrainer('total_word_feature_extractor.dat');

Add labeled text to the trainer

$trainer->add('This is super cool', 'positive');

Train the model

$model = $trainer->train();

Save the model

$model->saveToDisk('text_categorization_model.dat');

Load a saved model

$model = new Mitie\TextCategorizer('text_categorization_model.dat');

Categorize text

$model->categorize('What a super nice day');

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/mitie-php.git
cd mitie-php
composer install
composer test

About

Named-entity recognition for PHP

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages