Page MenuHomeDevCentral

extract-proper-nouns-from-text

Authored By
dereckson
Nov 29 2014, 11:10
Size
1 KB
Referenced Files
None
Subscribers
None

extract-proper-nouns-from-text

#!/usr/bin/env php
<?php
require 'proper_nouns.php';
class ExtractorCommand {
/**
* An instance of the proper_nouns class
*
* @var proper_nouns
*/
private $extractor;
public static function getCommandName() {
global $argv;
return basename($argv[0]);
}
public static function usage () {
global $argv;
echo "Usage: " . self::getCommandName() . " <text file>\n";
}
public static function run () {
global $argc, $argv;
if ($argc < 2) {
self::usage();
exit;
}
$file = $argv[1];
if (!file_exists($file)) {
echo self::getCommandName() . ": $file: No such file\n";
exit;
}
self::printNounsFromFile($file);
}
public static function printNounsFromFile ($file) {
$text = file_get_contents($file);
$nouns = self::getNouns($text);
foreach ($nouns as $noun) {
echo "$noun\n";
}
}
public static function getNouns ($text) {
return (new proper_nouns())->get($text);
}
}
ExtractorCommand::run();

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
352
Default Alt Text
extract-proper-nouns-from-text (1 KB)

Event Timeline