Eclipse Maven: “Cannot be resolved to a type” error

I am trying to build a simple sentence detector using OpenNLP 1.5.0. I am using Maven Eclipse for that. I downloaded "en-sent.bin" model file from http://opennlp.sourceforge.net/models-1.5/ and placed it inside src/main/resources folder. My pom.xml file is as follows.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>dakshila.research</groupId>
    <artifactId>new1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>new1</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project> 

Inside 'src/main/java' folder I have created "dk.research.new1" package and its App.java file contains the following code.

package dk.research.new1;

public class App{
    public void SentenceSplitter() {
        SentenceDetector sentenceDetector = null;
        InputStream modelIn = null;

        try {
           modelIn = getClass().getResourceAsStream("en-sent.bin");
           final SentenceModel sentenceModel = new SentenceModel(modelIn);
           modelIn.close();
           sentenceDetector = new SentenceDetectorME(sentenceModel);
        } catch (final IOException ioe) {
               ioe.printStackTrace();
        } finally {
            if (modelIn != null) {
                try {
                    modelIn.close();
                } catch (final IOException e) {}
            }
        }
        String sentences[]=(sentenceDetector.sentDetect("I am a student. I am learning programming. I like java language."));
        for(int i=0; i<sentences.length;i++) {
            System.out.println(sentences[i]);
        }
    }
}

I get the following error messages in App.java file.

  • SentenceDetector cannot be resolved to a type
  • InputStream cannot be resolved to a type
  • SentenceModel cannot be resolved to a type
  • SentenceDetectorME cannot be resolved to a type
  • IOException cannot be resolved to a type

Why am I getting these errors? I tried Project->Clean but I can't get rid of these errors. What do I have to do to get this solved?

Answers


In your POM in <dependencies> section add:

<dependency>
  <groupId>org.apache.opennlp</groupId>
  <artifactId>opennlp-tools</artifactId>
  <version>1.6.0</version>
</dependency>

And then, you have to import classes in Java file before line public class App add:

import java.io.IOException;
import java.io.InputStream;

import opennlp.tools.sentdetect.SentenceDetector;
import opennlp.tools.sentdetect.SentenceDetectorME;
import opennlp.tools.sentdetect.SentenceModel;

Need Your Help

UIImagePickerController: Check if returned image is in landscape or portrait?

ios objective-c cocoa-touch uiimagepickercontroller landscape

So, the UIImagePickerController does not support landscape orientation. However, there is a portion of application where it is essential that the image that comes from the controller is recognized ...

Access singleton class methods in blackberry 10

c++ singleton blackberry-10 blackberry-cascades

I have implemented Singleton class method hpp and cpp like the following