Permalink
Browse files

Allow model to be run without context.

  • Loading branch information...
1 parent 16be1da commit 1c84f5368ff5d18bbb0b3917a86df5fb1bd9615b @jodaiber jodaiber committed Mar 22, 2013
@@ -120,7 +120,10 @@ class DBTwoStepDisambiguator(
// step2: query once for the paragraph context, get scores for each candidate resource
- val contextScores = getContextSimilarityScores(paragraph.text, allCandidateResources)
+ val contextScores = if (contextStore != null)
+ getContextSimilarityScores(paragraph.text, allCandidateResources)
+ else
+ mutable.Map[DBpediaResource, Double]()
// pick the best k for each surface form
occs.keys.foldLeft(Map[SurfaceFormOccurrence, List[DBpediaResourceOccurrence]]())( (acc, aSfOcc) => {
@@ -138,7 +141,11 @@ class DBTwoStepDisambiguator(
case _ =>
}
- val nilContextScore = contextSimilarity.nilScore(getQuery(aSfOcc.context))
+ val nilContextScore = if (contextStore != null)
+ contextSimilarity.nilScore(getQuery(aSfOcc.context))
+ else
+ 0.0
+
eNIL.setFeature(new Score("P(c|e)", nilContextScore))
eNIL.setFeature(new Score("P(e)", MathUtil.ln( 1 / surfaceFormStore.getTotalAnnotatedCount.toDouble ) )) //surfaceFormStore.getTotalAnnotatedCount = total number of entity mentions
val nilEntityScore = mixture.getScore(eNIL)
@@ -39,7 +39,10 @@ object SpotlightModel {
val sfStore = MemoryStore.loadSurfaceFormStore(new FileInputStream(new File(modelDataFolder, "sf.mem")))
val resStore = MemoryStore.loadResourceStore(new FileInputStream(new File(modelDataFolder, "res.mem")))
val candMapStore = MemoryStore.loadCandidateMapStore(new FileInputStream(new File(modelDataFolder, "candmap.mem")), resStore)
- val contextStore = MemoryStore.loadContextStore(new FileInputStream(new File(modelDataFolder, "context.mem")), tokenTypeStore)
+ val contextStore = if (new File(modelDataFolder, "context.mem").exists())
+ MemoryStore.loadContextStore(new FileInputStream(new File(modelDataFolder, "context.mem")), tokenTypeStore)
+ else
+ null
val stopwords = loadStopwords(modelFolder)

0 comments on commit 1c84f53

Please sign in to comment.