Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No such element exception #24

Open
Nujjy opened this issue Jan 16, 2018 · 0 comments
Open

No such element exception #24

Nujjy opened this issue Jan 16, 2018 · 0 comments

Comments

@Nujjy
Copy link

Nujjy commented Jan 16, 2018

I'm attempting to use the dbpedia spotlight annotators without the REST API client as per: https://github.com/dbpedia-spotlight/dbpedia-spotlight/wiki/Run-from-Java-or-Scala.

The only difference is that I am loading the model.

Here is my simple test program.

import java.io.File;
import java.util.List;

import org.dbpedia.spotlight.annotate.DefaultParagraphAnnotator;
import org.dbpedia.spotlight.db.SpotlightModel;
import org.dbpedia.spotlight.disambiguate.ParagraphDisambiguatorJ;
import org.dbpedia.spotlight.exceptions.ConfigurationException;
import org.dbpedia.spotlight.exceptions.InputException;
import org.dbpedia.spotlight.exceptions.SpottingException;
import org.dbpedia.spotlight.model.DBpediaResourceOccurrence;
import org.dbpedia.spotlight.model.SpotlightConfiguration.DisambiguationPolicy;
import org.dbpedia.spotlight.model.SpotterConfiguration.SpotterPolicy;
import org.dbpedia.spotlight.model.Text;
import org.dbpedia.spotlight.spot.Spotter;

class Test {

	public static void main(String[] args) throws ConfigurationException, InputException, SpottingException {

		String text = new String("President Obama gave a speech.");

		File modelFolder = null;

		try {
			modelFolder = new File("en_2+2");
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("\n Error");
			System.exit(1);
		}
		
		SpotlightModel db = SpotlightModel.fromFolder(modelFolder);
		ParagraphDisambiguatorJ disambiguator = db.disambiguators().get(DisambiguationPolicy.Default);
		Spotter spotter = db.spotters().get(SpotterPolicy.Default);
		DefaultParagraphAnnotator annotator = new DefaultParagraphAnnotator(spotter, disambiguator);
		List<DBpediaResourceOccurrence> occurences = annotator.annotate(text);

	}
}

For some reason, this gives me the following stacktrace when calling the annotate method.

106013 [main] INFO org.dbpedia.spotlight.db.memory.MemoryStore$ - Loading FSADictionary...
106349 [main] INFO org.dbpedia.spotlight.db.memory.MemoryStore$ - Done (335 ms)
106546 [main] INFO org.dbpedia.spotlight.annotate.DefaultParagraphAnnotator - Spotting... (FSA dictionary spotter)
Exception in thread "main" java.util.NoSuchElementException: None.get
	at scala.None$.get(Option.scala:313)
	at scala.None$.get(Option.scala:311)
	at org.dbpedia.spotlight.db.DBSpotter.extract(DBSpotter.scala:48)
	at org.dbpedia.spotlight.annotate.DefaultParagraphAnnotator.annotate(DefaultAnnotator.scala:63)
	at Test.main(Test.java:35)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants