PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Dennis de Swart   PHP Stanford Core NLP Adapter   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Stanford Core NLP Adapter
Natural language processing using Stanford server
Author: By
Last change: Increased execution time, improved error messages, updated README
Date: 7 years ago
Size: 1,675 bytes
 

Contents

Class file image Download
<?php

/**
 * Important notes:
 * - To use the online API : set ONLINE_API to TRUE
 * - To use Java CoreNLP : set ONLINE_API to FALSE
 *
 * - ONLINE_API is set to FALSE by default. You can change this setting in "bootstrap.php"
 * - OpenIE annotator is only available on the Java version
 */

   
require_once __DIR__.'/bootstrap.php'; // bootstrap also contains the config
   
/**
 * Demo usage
 */
   
    // instantiate the class
   
$coreNLP = new CorenlpAdapter();

   
$text1 = 'I will meet Mary in New York at 10pm';
   
$coreNLP->getOutput($text1);

   
// Second text
   
$text2 = 'The Golden Gate Bridge was designed by Joseph Strauss.';
   
$coreNLP->getOutput($text2);
   
/**
 * Display result
 */
   
    // this makes it easier to read
   
echo '<pre>';

   
// show complete output
   
headerText('The "Server Memory Object" (below) contains all the server output');
   
print_r($coreNLP->serverMemory);

   
// first text tree
   
headerText('FIRST TEXT: Part-Of-Speech tree');
   
print_r($coreNLP->trees[0]);

   
// second text tree
   
headerText('SECOND TEXT: Part-Of-Speech tree');
   
print_r($coreNLP->trees[1]);
   
   
// get IDs for a tree
   
headerText('EVERY TREE HAS UNIQUE IDs: this shows the Word-tree-IDs for the second tree');
   
print_r($coreNLP->getWordValues($coreNLP->trees[1]));

   
// this is just a helper function for a nice header
   
function headerText($header){
            echo
'<br />***'.str_repeat('*', strlen($header)).'***<br />';
            echo
'** '.$header.' **<br />';
            echo
'***'.str_repeat('*', strlen($header)).'***<br /><br />';
    }