forked from dbpedia-spotlight/dbpedia-spotlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Run from Java or Scala
sandroacoelho edited this page Jul 26, 2013
·
1 revision
This is how to use DBpedia Spotlight from your code.
You can use our factory that builds objects for you based on the configuration file.
import org.dbpedia.spotlight.annotate.DefaultParagraphAnnotator
import org.dbpedia.spotlight.disambiguate.{TwoStepDisambiguator, ParagraphDisambiguatorJ}
import org.dbpedia.spotlight.model.SpotlightConfiguration
import org.dbpedia.spotlight.model.SpotlightFactory
val text = new String("Brazilian oil giant Petrobras and U.S. oilfield service company Halliburton have signed a technological cooperation agreement, Petrobras announced Monday. The two companies agreed on three projects: studies on contamination of fluids in oil wells, laboratory simulation of well production, and research on solidification of salt and carbon dioxide formations, said Petrobras. Twelve other projects are still under negotiation.")
val configuration = new SpotlightConfiguration("conf/server.properties")
val factory = new SpotlightFactory(configuration)
val disambiguator = new ParagraphDisambiguatorJ(new TwoStepDisambiguator(factory.candidateSearcher, factory.contextSearcher))
val spotter = factory.spotter()
val annotator = new DefaultParagraphAnnotator(spotter, disambiguator);
println(annotator.annotate(text))
Note:If no word is spotted,it may throw an "empty list" exception.