Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $var = array();
- function printTag($tags) {
- foreach($tags as $t) {
- echo $t['token'] . "/" . $t['tag'] . " ";
- if($t['tag'] == 'NN' OR $t['tag']== 'JJ'){
- array_push($var, $t['token']) ;
- }
- }
- echo "n";
- }
- array_push() expects parameter 1 to be array, null given in /var/www/html/postag/poscall.php on line 9
- <?php
- // little helper function to print the results
- include ("postag.php");
- $var = array();
- function printTag($tags) {
- foreach($tags as $t) {
- echo $t['token'] . "/" . $t['tag'] . " ";
- if($t['tag'] == 'NN' OR $t['tag']== 'JJ'){
- array_push($var, $t['token']) ;
- }
- }
- echo "n";
- }
- $tagger = new PosTagger('lexicon.txt');
- $tags = $tagger->tag('The quick brown fox jumped over the lazy dog. this is really yummy and excellent pizza I have seen have really in love it it');
- printTag($tags);
- ?>
- function printTag($tags) {
- $var = array();
- foreach($tags as $t) {
- echo $t['token'] . "/" . $t['tag'] . " ";
- if($t['tag'] == 'NN' OR $t['tag']== 'JJ'){
- array_push($var, $t['token']) ;
- }
- }
- echo "n";
- }
- $var = array_reduce($tags, function(&$result, $t) {
- if (in_array($t['tag'], ['NN', 'JJ'])) {
- $result[] = $t['token'];
- }
- // you could do some output here as well
- return $result;
- }, []);
- function printTag(array $tags)
- {
- $var = [];
- foreach($tags as $t) {
- // ...
- }
- return $var;
- }
- // ...
- $var = printTag($tags);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement