Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. $var = array();
  2. function printTag($tags) {
  3. foreach($tags as $t) {
  4. echo $t['token'] . "/" . $t['tag'] . " ";
  5. if($t['tag'] == 'NN' OR $t['tag']== 'JJ'){
  6. array_push($var, $t['token']) ;
  7. }
  8. }
  9. echo "n";
  10. }
  11.  
  12. array_push() expects parameter 1 to be array, null given in /var/www/html/postag/poscall.php on line 9
  13.  
  14. <?php
  15. // little helper function to print the results
  16. include ("postag.php");
  17. $var = array();
  18. function printTag($tags) {
  19. foreach($tags as $t) {
  20. echo $t['token'] . "/" . $t['tag'] . " ";
  21. if($t['tag'] == 'NN' OR $t['tag']== 'JJ'){
  22. array_push($var, $t['token']) ;
  23. }
  24. }
  25. echo "n";
  26. }
  27.  
  28. $tagger = new PosTagger('lexicon.txt');
  29. $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');
  30. printTag($tags);
  31. ?>
  32.  
  33. function printTag($tags) {
  34. $var = array();
  35. foreach($tags as $t) {
  36. echo $t['token'] . "/" . $t['tag'] . " ";
  37. if($t['tag'] == 'NN' OR $t['tag']== 'JJ'){
  38. array_push($var, $t['token']) ;
  39. }
  40. }
  41. echo "n";
  42. }
  43.  
  44. $var = array_reduce($tags, function(&$result, $t) {
  45. if (in_array($t['tag'], ['NN', 'JJ'])) {
  46. $result[] = $t['token'];
  47. }
  48. // you could do some output here as well
  49. return $result;
  50. }, []);
  51.  
  52. function printTag(array $tags)
  53. {
  54. $var = [];
  55.  
  56. foreach($tags as $t) {
  57. // ...
  58. }
  59.  
  60. return $var;
  61. }
  62.  
  63. // ...
  64. $var = printTag($tags);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement