Pete
Pete

Reputation: 514

The method is undefined for the type error

I just don't get why the following lines won't compile:

TreebankLanguagePack tlp = new PennTreebankLanguagePack();
tlp.setGenerateOriginalDependencies(true);

It was already working before, but now it throws me a

The method setGenerateOriginalDependencies(boolean) is undefined for the type TreebankLanguagePack

, although TreebankLanguagePack is marked as the correct interface. I removed everything and put this minimal class together, but it still doesn't work.

import java.util.Collection;

import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.trees.GrammaticalStructure;
import edu.stanford.nlp.trees.GrammaticalStructureFactory;
import edu.stanford.nlp.trees.PennTreebankLanguagePack;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreebankLanguagePack;
import edu.stanford.nlp.trees.TypedDependency;

public class TreebankTest {

    public void test() {
        LexicalizedParser lp = LexicalizedParser.loadModel(
                "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz",
                "-maxLength", "80", "-retainTmpSubcategories");
        TreebankLanguagePack tlp = new PennTreebankLanguagePack();
        tlp.setGenerateOriginalDependencies(true);
        GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();

        String[] sent = { "This", "is", "an", "easy", "sentence", "." };
        Tree parse = lp.apply(Sentence.toWordList(sent));
        GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
        Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed();
        System.out.println(tdl);
    }

}

Upvotes: 0

Views: 13122

Answers (2)

AlexWien
AlexWien

Reputation: 28727

This is a typical situation of "What you see is NOT what you get" in contrast to the well known WYSIWYG.

You see the method setGenerateOriginalDependencies(boolean) in your src, but the compiler or build system does not see it. Typical situations:
If the method is in an external library (jar) then either it is not yet built, or you have forgotten to Refresh (eclipse F5) the project. Or you are looking into the wrong project. Or have not saved the file, etc.

Or the method does not exist anymore, a working colleague might have removed it. In eclipse you can click on the jar file that contains the method and check what eclipse sees.

Upvotes: 4

Firzen
Firzen

Reputation: 2095

In eclipse check your Java buildpath (check your Java JDK/JRE too!), refresh the project (F5) and do Project>Clean of your project.

Upvotes: 0

Related Questions