Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recognize names from a text using php

I want to extract name(firstnames and lastnames) from a text using php. Example: From text below I want to extract names(in this case Aline Wright and Jesse Wright)

Aline Wright is a cancer survivor, amputee and a newlywed. Wednesday night she began to show signs she was having a stroke.

"I started feeling some left arm numbness and a facial droop," said Aline.

"It appeared to me that I was probably having a stroke."

That's when her husband of four days, Jesse Wright, put her in the car and rushed her to the Erlanger Medical Center. Wright knows an emergency. He is a nurse technician at Erlanger.

like image 467
Iulian Boiculese Avatar asked Dec 07 '22 00:12

Iulian Boiculese


2 Answers

If you want to do named entity recognition (NER) using PHP, you'll need to either call out to an external NER package or make use of an online natural language processing API.

APIs

NLP API are listed below. Complexity Intelligence and Alchemy API will probably be moderately easier to use for beginners than OpenCalais.

  • Complexity Intelligence - see the PHP named entity tagging sample code here.
  • Alchemy API - download their PHP SDK here.
  • OpenCalais - see the PHP sample code here.
  • No Code API - by using their api-calls provide text which u need to process. 10K free requests is quite enough for checking any hypothesis.

NER Packages

A few software packages you can use for NER are:

  • Stanford CoreNLP (Java)
  • LingPipe (Java)
  • NLTK (Python)
  • OpenNLP (Java)
  • YamCha (C++)

Of these, Stanford CoreNLP is probably a good place to start. Similar to many NLP APIs, it provides a complete processing pipeline for common tasks such as NER.

like image 103
dmcer Avatar answered Dec 20 '22 11:12

dmcer


I'd use a named entity recognizer. There are many of these up on CPAN where there is an active linguistics community.

Then, in PHP, do something like:

$result = \`perl named_entity_recogniser.pl "myText"\`;
like image 34
Eamorr Avatar answered Dec 20 '22 09:12

Eamorr