Search in sources :

Example 86 with Activate

use of org.apache.felix.scr.annotations.Activate 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());
}
Also used : CoreferenceFinder(org.apache.stanbol.enhancer.engines.entitycoreference.impl.CoreferenceFinder) ConfigurationException(org.osgi.service.cm.ConfigurationException) NounPhraseFilterer(org.apache.stanbol.enhancer.engines.entitycoreference.impl.NounPhraseFilterer) Activate(org.apache.felix.scr.annotations.Activate)

Example 87 with Activate

use of org.apache.felix.scr.annotations.Activate in project stanbol by apache.

the class LuceneLabelTokenizer method activate.

@Activate
protected void activate(ComponentContext ctx) throws ConfigurationException {
    // init the Solr ResourceLoader used for initialising the components
    resourceLoader = new StanbolResourceLoader(parentResourceLoader);
    // init the Solr CharFilterFactory (optional)
    Object value = ctx.getProperties().get(PROPERTY_CHAR_FILTER_FACTORY);
    if (value != null && !value.toString().isEmpty() && !DEFAULT_CLASS_NAME_CONFIG.equals(value)) {
        Entry<String, Map<String, String>> charFilterConfig = parseConfigLine(PROPERTY_CHAR_FILTER_FACTORY, value.toString());
        charFilterFactory = initAnalyzer(PROPERTY_CHAR_FILTER_FACTORY, charFilterConfig.getKey(), CharFilterFactory.class, charFilterConfig.getValue());
    } else {
        charFilterFactory = null;
    }
    // now initialise the TokenizerFactory (required)
    value = ctx.getProperties().get(PROPERTY_TOKENIZER_FACTORY);
    if (value == null || value.toString().isEmpty() || DEFAULT_CLASS_NAME_CONFIG.equals(value)) {
        throw new ConfigurationException(PROPERTY_TOKENIZER_FACTORY, "The class name of the Lucene Tokemizer MUST BE configured");
    }
    Entry<String, Map<String, String>> tokenizerConfig = parseConfigLine(PROPERTY_CHAR_FILTER_FACTORY, value.toString());
    tokenizerFactory = initAnalyzer(PROPERTY_TOKENIZER_FACTORY, tokenizerConfig.getKey(), TokenizerFactory.class, tokenizerConfig.getValue());
    // initialise the list of Token Filters
    Collection<String> values;
    value = ctx.getProperties().get(PROPERTY_TOKEN_FILTER_FACTORY);
    if (value == null) {
        values = Collections.emptyList();
    } else if (value instanceof Collection<?>) {
        values = new ArrayList<String>(((Collection<?>) value).size());
        for (Object v : (Collection<Object>) value) {
            values.add(v.toString());
        }
    } else if (value instanceof String[]) {
        values = Arrays.asList((String[]) value);
    } else if (value instanceof String) {
        values = Collections.singleton((String) value);
    } else {
        throw new ConfigurationException(PROPERTY_TOKEN_FILTER_FACTORY, "The type '" + value.getClass() + "' of the parsed value is not supported (supported are " + "Collections, String[] and String values)!");
    }
    for (String filterConfigLine : values) {
        if (filterConfigLine == null || filterConfigLine.isEmpty() || DEFAULT_CLASS_NAME_CONFIG.equals(filterConfigLine)) {
            // ignore null, empty and the default value
            continue;
        }
        Entry<String, Map<String, String>> filterConfig = parseConfigLine(PROPERTY_CHAR_FILTER_FACTORY, filterConfigLine);
        TokenFilterFactory tff = initAnalyzer(PROPERTY_TOKEN_FILTER_FACTORY, filterConfig.getKey(), TokenFilterFactory.class, filterConfig.getValue());
        filterFactories.add(tff);
    }
    // init the language configuration
    value = ctx.getProperties().get(LabelTokenizer.SUPPORTED_LANUAGES);
    if (value == null) {
        throw new ConfigurationException(LabelTokenizer.SUPPORTED_LANUAGES, "The language " + "configuration MUST BE present!");
    }
    langConf.setConfiguration(ctx.getProperties());
}
Also used : StanbolResourceLoader(org.apache.stanbol.commons.solr.utils.StanbolResourceLoader) TokenizerFactory(org.apache.lucene.analysis.util.TokenizerFactory) ConfigurationException(org.osgi.service.cm.ConfigurationException) CharFilterFactory(org.apache.lucene.analysis.util.CharFilterFactory) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory) Activate(org.apache.felix.scr.annotations.Activate)

Example 88 with Activate

use of org.apache.felix.scr.annotations.Activate in project stanbol by apache.

the class MainLabelTokenizer method activate.

@Activate
protected void activate(ComponentContext ctx) {
    final BundleContext bundleContext = ctx.getBundleContext();
    final String managerServicePid = (String) ctx.getProperties().get(Constants.SERVICE_PID);
    labelTokenizerTracker = new ServiceTracker(bundleContext, LabelTokenizer.class.getName(), new ServiceTrackerCustomizer() {

        @Override
        public Object addingService(ServiceReference reference) {
            if (managerServicePid.equals(reference.getProperty(Constants.SERVICE_PID))) {
                // do not track this manager!
                return null;
            }
            LanguageConfiguration langConf = new LanguageConfiguration(SUPPORTED_LANUAGES, DEFAULT_LANG_CONF);
            try {
                langConf.setConfiguration(reference);
            } catch (ConfigurationException e) {
                log.error("Unable to track ServiceReference {} becuase of invalid LanguageConfiguration(" + SUPPORTED_LANUAGES + "=" + reference.getProperty(SUPPORTED_LANUAGES) + ")!", e);
                return null;
            }
            Object service = bundleContext.getService(reference);
            if (service != null) {
                ref2LangConfig.put(reference, langConf);
                langTokenizers.clear();
            }
            return service;
        }

        @Override
        public void modifiedService(ServiceReference reference, Object service) {
            if (managerServicePid.equals(reference.getProperty(Constants.SERVICE_PID))) {
                // ignore this service!
                return;
            }
            LanguageConfiguration langConf = new LanguageConfiguration(SUPPORTED_LANUAGES, DEFAULT_LANG_CONF);
            try {
                langConf.setConfiguration(reference);
                ref2LangConfig.put(reference, langConf);
                langTokenizers.clear();
            } catch (ConfigurationException e) {
                log.error("Unable to track ServiceReference {} becuase of invalid LanguageConfiguration(" + SUPPORTED_LANUAGES + "=" + reference.getProperty(SUPPORTED_LANUAGES) + ")!", e);
                if (ref2LangConfig.remove(reference) != null) {
                    langTokenizers.clear();
                }
            }
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            if (managerServicePid.equals(reference.getProperty(Constants.SERVICE_PID))) {
                // ignore this service
                return;
            }
            bundleContext.ungetService(reference);
            if (ref2LangConfig.remove(reference) != null) {
                langTokenizers.clear();
            }
        }
    });
    labelTokenizerTracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) LanguageConfiguration(org.apache.stanbol.enhancer.nlp.utils.LanguageConfiguration) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Activate(org.apache.felix.scr.annotations.Activate)

Example 89 with Activate

use of org.apache.felix.scr.annotations.Activate in project jackrabbit-oak by apache.

the class MountInfoProviderService method activate.

@Activate
private void activate(BundleContext bundleContext, Map<String, ?> config) {
    String[] paths = PropertiesUtil.toStringArray(config.get(PROP_MOUNT_PATHS));
    String mountName = PropertiesUtil.toString(config.get(PROP_MOUNT_NAME), PROP_MOUNT_NAME_DEFAULT);
    boolean readOnly = PropertiesUtil.toBoolean(config.get(PROP_MOUNT_READONLY), PROP_MOUNT_READONLY_DEFAULT);
    String[] pathsSupportingFragments = PropertiesUtil.toStringArray(config.get(PROP_PATHS_SUPPORTING_FRAGMENTS), PROP_PATHS_SUPPORTING_FRAGMENTS_DEFAULT);
    MountInfoProvider mip = Mounts.defaultMountInfoProvider();
    if (paths != null) {
        mip = Mounts.newBuilder().mount(mountName.trim(), readOnly, trim(pathsSupportingFragments), trim(paths)).build();
        log.info("Enabling mount for {}", mip);
    } else {
        log.info("No mount config provided. Mounting would be disabled");
    }
    reg = bundleContext.registerService(MountInfoProvider.class.getName(), mip, null);
}
Also used : MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Activate(org.apache.felix.scr.annotations.Activate)

Example 90 with Activate

use of org.apache.felix.scr.annotations.Activate in project jackrabbit-oak by apache.

the class DocumentNodeStoreService method activate.

@Activate
protected void activate(ComponentContext context, Map<String, ?> config) throws Exception {
    closer = Closer.create();
    this.context = context;
    whiteboard = new OsgiWhiteboard(context.getBundleContext());
    executor = new WhiteboardExecutor();
    executor.start(whiteboard);
    maxReplicationLagInSecs = toLong(config.get(PROP_REPLICATION_LAG), DEFAULT_MAX_REPLICATION_LAG);
    customBlobStore = toBoolean(prop(CUSTOM_BLOB_STORE), false);
    documentStoreType = DocumentStoreType.fromString(PropertiesUtil.toString(config.get(PROP_DS_TYPE), "MONGO"));
    registerNodeStoreIfPossible();
}
Also used : OsgiWhiteboard(org.apache.jackrabbit.oak.osgi.OsgiWhiteboard) WhiteboardExecutor(org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardExecutor) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

Activate (org.apache.felix.scr.annotations.Activate)153 ConfigurationException (org.osgi.service.cm.ConfigurationException)31 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 BundleContext (org.osgi.framework.BundleContext)19 File (java.io.File)15 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)12 URL (java.net.URL)11 Hashtable (java.util.Hashtable)11 ServiceReference (org.osgi.framework.ServiceReference)11 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)9 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Session (javax.jcr.Session)5 StandardMBean (javax.management.StandardMBean)5 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)5 Filter (org.osgi.framework.Filter)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4