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?

Dani AI

Generated

The exception you saw is almost always a classpath / compile-time mismatch rather than a runtime bug in your small tagging code. , NetBeans is compiling or loading Stanford NLP classes from the project sources and also seeing a prebuilt jar or a different copy of those classes. That creates generics/TaggedWord type conflicts and produces the “Uncompilable source code - type parameter … not within its bound” error. Fix it by using one consistent artifact only: either compile the Stanford sources in your project (and remove any stanford jar), or remove the Stanford sources from src and add the official stanford-postagger.jar to Project → Properties → Libraries (better option).

A simpler, correct usage pattern avoids hand-rolling a List implementation. After the jar is on the classpath you can tag a single sentence like this:

MaxentTagger tagger = new MaxentTagger("path/to/model.tagger");
String tagged = tagger.tagString("Large cats eat small rats.");
System.out.println(tagged);

For : the TaggedWord class is in the postagger jar; once that jar is added to your project libraries you import it with import edu.stanford.nlp.ling.TaggedWord;. If the import still fails, NetBeans does not see the jar on the project classpath — re-add it and then do Clean and Build.

Quick checklist

  • Remove any duplicate stanford-postagger classes (no source + jar at the same time).
  • Put the tagger jar in your project’s lib or add it via Project → Properties → Libraries (do not drop it in the JDK bin).
  • Keep the model file with the project (or give an absolute path); use tagger.tagString(...) for quick tests.
  • Clean & Build and restart NetBeans if errors persist.

These steps will resolve the generics/initializer error and let you import/use TaggedWord normally.

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()));

  }

}

how to import package import edu.stanford.nlp.ling.TaggedWord??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.