Exemplo n.º 1
0
function process_the_content($the_text)
{
    // split text into an array of sentences
    $sentenceArray = preg_split('/(?<=[.?!])\\s+(?=[a-z])/i', $the_text);
    //echo json_encode($sentenceArray);
    foreach ($sentenceArray as $sentence) {
        // for each sentence,
        $this_result = tag_the_content($sentence);
    }
    // run the tagger
    echo json_encode($this_result);
    echo "\n";
    set_time_limit(40);
    $taggedSpans = "";
    // create spans with tag as class
    foreach ($this_result as $element) {
        set_time_limit(40);
        $text = $element[0];
        $tag = $element[1];
        $span = "<span class=" + $tag + ">" + $text + "</span>";
        $taggedSpans . append($span);
    }
    echo $taggedSpans;
}
Exemplo n.º 2
0
<?php

if (isset($_GET['done'])) {
    echo "calling the tagger";
    $the_text = $_GET['text'];
    tag_the_content($the_text);
}
function tag_the_content($the_text)
{
    echo "starting Tagger";
    $time_start = microtime(true);
    // sets DIR path variable
    $dir = dirname(__FILE__);
    // loads tagger
    include $dir . '/PHP-Stanford-NLP/autoload.php';
    // creates tagger
    $pos = new \StanfordNLP\POSTagger($dir . '/PHP-Stanford-NLP/stanford-postagger-2015-04-20/models/english-left3words-distsim.tagger', $dir . '/PHP-Stanford-NLP/stanford-postagger-2015-04-20/stanford-postagger.jar');
    // calls tagger to tag the_content
    // $result = $pos->tag(explode(' ', get_the_content() )); //  *** change back to this in production ***
    $result = $pos->tag(explode(' ', $the_text));
    // print_r($result); // prints readable array data
    echo "Tagger done";
    print_r($result);
    return $result;
}
function build_pos_arrays($result)
{
    $noun_tags = array("NN", "NNS", "NNP", "NNPS");
    $verb_tags = array("VB", "VBD", "VBG", "VBN", "VBP", "VBZ");
    $adjective_tags = array("JJ", "JJR", "JJS");
    $adverb_tags = array("RB", "RBR", "RBS");
Exemplo n.º 3
0
$sentenceArray = preg_split('/(?<=[.?!])\\s+(?=[a-z])/i', $the_text);
/*
foreach ($sentenceArray as $sentence){
	$result = explode(' ', $sentence );
	print_r($result);
	echo "\n";
}
*/
// for each sentence,
foreach ($sentenceArray as $sentence) {
    //print_r($sentence);
    //echo "  exploded ===>  ";
    $exploded = explode(' ', $sentence);
    //print_r( $exploded);
    //echo "            next.................. ";
    $this_result = tag_the_content($sentence);
    // run the tagger
    //print_r( $this_result);
    //echo ".              JSON                 . ";
    //echo json_encode( $this_result);
    set_time_limit(40);
    $taggedSpans = "";
    // create spans with tag as class
    foreach ($this_result as $element) {
        set_time_limit(40);
        $text = $element[0];
        $tag = $element[1];
        // if text is punctuation, do not add space
        $punct = array(".", ",", ";", ":", "!", "?", "(", ")", "[", "]", "{", "}", "'", "`", "\"");
        if (in_array($text, $punct)) {
            $span = "<span class=" . $tag . ">" . $text . "</span>";