use of org.apache.stanbol.enhancer.engines.entitycoreference.impl.NounPhraseFilterer in project stanbol by apache.
the class EntityCoReferenceEngine method activate.
@SuppressWarnings("unchecked")
@Activate
protected void activate(ComponentContext ctx) throws ConfigurationException {
super.activate(ctx);
Dictionary<String, Object> config = ctx.getProperties();
/* Step 1 - initialize the {@link NounPhraseFilterer} with the language config */
String languages = (String) config.get(CONFIG_LANGUAGES);
if (languages == null || languages.isEmpty()) {
throw new ConfigurationException(CONFIG_LANGUAGES, "The Languages Config is a required Parameter and MUST NOT be NULL or an empty String!");
}
nounPhraseFilterer = new NounPhraseFilterer(languages.split(","));
/* Step 2 - initialize the {@link CoreferenceFinder} */
String referencedSiteID = null;
Object referencedSiteIDfromConfig = config.get(REFERENCED_SITE_ID);
if (referencedSiteIDfromConfig == null) {
throw new ConfigurationException(REFERENCED_SITE_ID, "The ID of the Referenced Site is a required Parameter and MUST NOT be NULL!");
}
referencedSiteID = referencedSiteIDfromConfig.toString();
if (referencedSiteID.isEmpty()) {
throw new ConfigurationException(REFERENCED_SITE_ID, "The ID of the Referenced Site is a required Parameter and MUST NOT be an empty String!");
}
if (Entityhub.ENTITYHUB_IDS.contains(referencedSiteID.toLowerCase())) {
log.debug("Init NamedEntityTaggingEngine instance for the Entityhub");
referencedSiteID = null;
}
int maxDistance;
Object maxDistanceFromConfig = config.get(MAX_DISTANCE);
if (maxDistanceFromConfig == null) {
maxDistance = Constants.MAX_DISTANCE_DEFAULT_VALUE;
} else if (maxDistanceFromConfig instanceof Number) {
maxDistance = ((Number) maxDistanceFromConfig).intValue();
} else {
try {
maxDistance = Integer.parseInt(maxDistanceFromConfig.toString());
} catch (NumberFormatException nfe) {
throw new ConfigurationException(MAX_DISTANCE, "The Max Distance parameter must be a number");
}
}
if (maxDistance < -1) {
throw new ConfigurationException(MAX_DISTANCE, "The Max Distance parameter must not be smaller than -1");
}
String entityUriBase = (String) config.get(ENTITY_URI_BASE);
if (entityUriBase == null || entityUriBase.isEmpty()) {
throw new ConfigurationException(ENTITY_URI_BASE, "The Entity Uri Base parameter cannot be empty");
}
String spatialAttrForPerson = (String) config.get(SPATIAL_ATTR_FOR_PERSON);
String spatialAttrForOrg = (String) config.get(SPATIAL_ATTR_FOR_ORGANIZATION);
String spatialAttrForPlace = (String) config.get(SPATIAL_ATTR_FOR_PLACE);
String orgAttrForPerson = (String) config.get(ORG_ATTR_FOR_PERSON);
String entityClassesToExclude = (String) config.get(ENTITY_CLASSES_TO_EXCLUDE);
corefFinder = new CoreferenceFinder(languages.split(","), siteManager, entityhub, referencedSiteID, maxDistance, entityUriBase, spatialAttrForPerson, spatialAttrForOrg, spatialAttrForPlace, orgAttrForPerson, entityClassesToExclude);
log.info("activate {}[name:{}]", getClass().getSimpleName(), getName());
}
Aggregations