Page MenuHomeDevCentral

extract-proper-nouns-from-text
ActivePublic

Authored by dereckson on Nov 29 2014, 11:10.
Tags
None
Referenced Files
F361: extract-proper-nouns-from-text
Nov 29 2014, 12:17
F360: extract-proper-nouns-from-text
Nov 29 2014, 12:17
F359: extract-proper-nouns-from-text
Nov 29 2014, 11:10
Subscribers
None
#!/usr/bin/env php
<?php
require 'proper_nouns.php';
class ExtractorCommand {
public static function getCommandName() {
global $argv;
return basename($argv[0]);
}
public static function usage () {
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();

Event Timeline

dereckson changed the title of this paste from untitled to extract-proper-nouns-from-text.
dereckson updated the paste's language from autodetect to autodetect.
dereckson edited the content of this paste. (Show Details)
dereckson updated the paste's language from autodetect to php.Nov 29 2014, 15:50