This is the program in java which is an interface to stanford postagger. I have attached a copy of it. I am using netbeans 6.7.1 . I have placed the model file which is "left3words-wsj-0-18.tagger" in the bin folder of jdk and also placed the stanford-postagger.jar in that folder.
I have included the the stanford project in the src folder of netbeans projects so I could import files easily.But when I run this program, it gives following errors or exceptions:
run:
Enter sentence(s) to be tagged:
large cats eat small rats.

Exception in thread "main" java.lang.ExceptionInInitializerError
at testing.PosTagger.tag(PosTagger.java:18)
at testing.PosTagger.main(PosTagger.java:125)
Caused by: java.lang.RuntimeException: Uncompilable source code - type parameter edu.stanford.nlp.ling.TaggedWord is not within its bound
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<clini t>(MaxentTagger.java:189)
... 2 more
Java Result: 1
BUILD SUCCESSFUL (total time: 24 seconds)

How do I remove these errors to run it successfully?

Edited 5 Years Ago by peter_budo: Changed old code snipped to discussion thread

package testing;
//import edu.stanford.nlp.ling.Sentence;
import java.util.*;
import java.io.*;

//import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.ling.TaggedWord;
import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;

public class PosTagger {
   

 
    @SuppressWarnings("static-access")
  public String tag(String str) throws Exception {
	  String result = "";
          MaxentTagger tagger=new MaxentTagger("models/left3words-wsj-0-18.tagger");
          tagger.tokenizeText(new StringReader(str));
	  List<ArrayList<? extends HasWord>> sentences=new List() {

            public int size() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public boolean isEmpty() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public boolean contains(Object o) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public Iterator iterator() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public Object[] toArray() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public Object[] toArray(Object[] a) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public boolean add(Object e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public boolean remove(Object o) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public boolean containsAll(Collection c) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public boolean addAll(Collection c) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public boolean addAll(int index, Collection c) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public boolean removeAll(Collection c) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public boolean retainAll(Collection c) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void clear() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public Object get(int index) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public Object set(int index, Object element) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void add(int index, Object element) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public Object remove(int index) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public int indexOf(Object o) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public int lastIndexOf(Object o) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public ListIterator listIterator() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public ListIterator listIterator(int index) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public List subList(int fromIndex, int toIndex) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        };
	  for (ArrayList<? extends HasWord> sentence : sentences) {
	    ArrayList<TaggedWord> tSentence = tagger.tagSentence(sentence);
	    result += tSentence.toString();
	  }
	  return result;
  }

   public static void main(String[] args) throws Exception {
	  PosTagger pos = new PosTagger();
	  System.out.println("Enter sentence(s) to be tagged:");
	  BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
	  System.out.println("Result = " + pos.tag(buf.readLine()));

  }

}

Edited 5 Years Ago by peter_budo: Adding code tags to old post

This article has been dead for over six months. Start a new discussion instead.