Package org.carrot2.util.resource

Examples of org.carrot2.util.resource.ResourceLookup


    initAttributes.put("solrIndexSchema", core.getSchema());

    // Customize Carrot2's resource lookup to first look for resources
    // using Solr's resource loader. If that fails, try loading from the classpath.
    DefaultLexicalDataFactoryDescriptor.attributeBuilder(initAttributes)
        .resourceLookup(new ResourceLookup(new IResourceLocator() {
          public IResource[] getAll(final String resource) {
            final SolrResourceLoader resourceLoader = core.getResourceLoader();
            final String carrot2ResourcesDir = resourceLoader.getConfigDir()
                + initParams.get(CarrotParams.LEXICAL_RESOURCES_DIR, CARROT_RESOURCES_PREFIX);
            try {
View Full Code Here


                    .defaultLanguage(LanguageCode.ENGLISH);


                    File resourcesDir = new File(environment.configFile(), "carrot2/resources");

                    ResourceLookup resourceLookup = new ResourceLookup(new DirLocator(resourcesDir));

                    DefaultLexicalDataFactoryDescriptor.attributeBuilder(attributes)
                    .mergeResources(true);
                    LexicalDataLoaderDescriptor.attributeBuilder(attributes)
                    .resourceLookup(resourceLookup);
View Full Code Here

    @Override
    @SuppressWarnings("unchecked")
    public void init() throws ServletException
    {
        // Run in servlet container, load config from config.xml.
        ResourceLookup webInfLookup = new ResourceLookup(new PrefixDecoratorLocator(
            new ServletContextLocator(getServletContext()), "/WEB-INF/"));

        try
        {
            config = DcsConfig.deserialize(webInfLookup.getFirst("dcs-config.xml"));
        }
        catch (Exception e)
        {
            throw new ServletException("Could not read 'config.xml' resource.", e);
        }

        // Initialize XSLT
        initXslt(config, webInfLookup);

        // Load component suite. Use classpath too (for JUnit tests).
        try
        {
            List<IResourceLocator> resourceLocators = Lists.newArrayList();
            resourceLocators.add(new PrefixDecoratorLocator(new ServletContextLocator(
                getServletContext()), "/WEB-INF/suites/"));

            if (Boolean.getBoolean(ENABLE_CLASSPATH_LOCATOR)) resourceLocators
                .add(Location.CONTEXT_CLASS_LOADER.locator);

            ResourceLookup suitesLookup = new ResourceLookup(resourceLocators);

            IResource suiteResource = suitesLookup
                .getFirst(config.componentSuiteResource);
            if (suiteResource == null)
            {
                throw new Exception(
                    "Suite file not found in servlet context's /WEB-INF/suites: "
                        + config.componentSuiteResource);
            }
            componentSuite = ProcessingComponentSuite.deserialize(suiteResource,
                suitesLookup);
        }
        catch (Exception e)
        {
            throw new ServletException("Could initialize component suite.", e);
        }

        // Initialize defaults.
        if (componentSuite.getAlgorithms().size() == 0)
        {
            throw new ServletException("Component suite has no algorithms.");
        }
        defaultAlgorithmId = componentSuite.getAlgorithms().get(0).getId();

        // Initialize controller
        final List<Class<? extends IProcessingComponent>> cachedComponentClasses = Lists
            .newArrayListWithExpectedSize(2);
        if (config.cacheDocuments)
        {
            cachedComponentClasses.add(IDocumentSource.class);
        }
        if (config.cacheClusters)
        {
            cachedComponentClasses.add(IClusteringAlgorithm.class);
        }

        controller = ControllerFactory.createCachingPooling(cachedComponentClasses
            .toArray(new Class [cachedComponentClasses.size()]));

        List<IResourceLocator> locators = Lists.newArrayList();
        locators.add(new PrefixDecoratorLocator(new ServletContextLocator(
            getServletContext()), "/WEB-INF/resources/"));

        if (Boolean.getBoolean(ENABLE_CLASSPATH_LOCATOR)) locators
            .add(Location.CONTEXT_CLASS_LOADER.locator);

        // Allow multiple resource lookup paths for different component configurations.
        String resourceLookupAttrKey = AttributeUtils.getKey(DefaultLexicalDataFactory.class, "resourceLookup");
        String altResourceLookupAttrKey = "dcs.resource-lookup";
        ProcessingComponentConfiguration [] configurations = componentSuite.getComponentConfigurations();
        for (int i = 0; i < configurations.length; i++) {
            ProcessingComponentConfiguration config = configurations[i];
            Object location = config.attributes.get(altResourceLookupAttrKey);
            if (location != null && location instanceof String) {
                File resourceDir = new File((String) location);
                if (!resourceDir.isDirectory()) {
                    Logger.getRootLogger().warn("Not a resource folder, ignored: " + resourceDir);
                } else {
                    HashMap<String,Object> mutableMap = new HashMap<String,Object>(config.attributes);
                    mutableMap.put(resourceLookupAttrKey,
                        new ResourceLookup(new DirLocator(resourceDir)));
                    config = configurations[i] = new ProcessingComponentConfiguration(
                        config.componentClass,
                        config.componentId,
                        mutableMap);
                }
            }
        }

        controller.init(
            ImmutableMap.<String, Object> of(resourceLookupAttrKey, new ResourceLookup(locators)),
            configurations);
    }
View Full Code Here

        // Initialization-time attributes that will apply to all components.
        final Map<String, Object> initAttributes = Maps.newHashMap();

        // Prepare resource lookup facade. We will use the suites directory
        // and class path resources.
        final ResourceLookup resourceLookup = new ResourceLookup(
            new DirLocator(new File("suites")),
            new ContextClassLoaderLocator());

        // We know we'll be using Bing so set up its access key.
        // use your own ID here!
        Bing3WebDocumentSourceDescriptor
            .attributeBuilder(initAttributes)
                .appid(BingKeyAccess.getKey());
       
        // We'll read the component suite definition from an XML stream.
        // IResource is an abstraction layer over resources in Carrot2.
        IResource suiteXml = resourceLookup.getFirst("suite-examples.xml");

        // Deserialize the component suite definition.
        final ProcessingComponentSuite suite =
            ProcessingComponentSuite.deserialize(suiteXml, resourceLookup);
View Full Code Here

        // We will pass our custom resource locator at initialization time. There is a
        // variety of implementations of IResourceLocator interface, we will use
        // an explicit filesystem folder in the current working directory.
        File resourcesDir = new File("resources");
        ResourceLookup resourceLookup = new ResourceLookup(new DirLocator(resourcesDir));

        Map<String, Object> attrs = Maps.newHashMap();

        // Note that we tell the linguistic component to merge all lexical resources,
        // this is the default setting and it usually helps with multi-lingual content.
View Full Code Here

        locators.add(Location.CONTEXT_CLASS_LOADER.locator);

        Map<String, Object> initAttributes = Maps.newHashMap();
        initAttributes.put(
            DefaultLexicalDataFactoryDescriptor.Keys.RESOURCE_LOOKUP,
            new ResourceLookup(locators));

        controller = ControllerFactory.createCachingPooling(IDocumentSource.class);
        controller.init(initAttributes, componentSuite.getComponentConfigurations());       
    }
View Full Code Here

                        Utils.logError("Bundle inactive: " + bundleId, false);                       
                        continue;
                    }
                }

                final ResourceLookup resourceLookup = new ResourceLookup(
                    workspaceLocator,
                    new PrefixDecoratorLocator(new BundleResourceLocator(b), suiteRoot));

                IResource suiteResource = resourceLookup.getFirst(suiteResourceName);
                if (suiteResource == null)
                {
                    String message = "Suite extension resource not found in "
                        + b.getSymbolicName() + ": " + bundleId;
                    Utils.logError(message, false);
View Full Code Here

        ProcessingComponentDocs(String suitePath) throws Exception
        {
            // I assume only classpath is scanned for the suite. We could add another
            // argument to specify the lookup path explicitly.
            final ResourceLookup resourceLookup = new ResourceLookup(
                new ContextClassLoaderLocator());

            final ProcessingComponentSuite suite =
                ProcessingComponentSuite.deserialize(
                    resourceLookup.getFirst(suitePath), resourceLookup);

            final List<DocumentSourceDescriptor> sourceDescriptors = suite.getSources();
            this.sources = Lists.newArrayList();
            for (ProcessingComponentDescriptor descriptor : sourceDescriptors)
            {
View Full Code Here

        controller = ControllerFactory.createCachingPooling(
            ResultsCacheModel.toClassArray(webappConfig.caches));
        controller.init(
            ImmutableMap.<String, Object> of(
                AttributeUtils.getKey(DefaultLexicalDataFactory.class, "resourceLookup"),
                new ResourceLookup(locators)),
            webappConfig.components.getComponentConfigurations());

        jawrUrlGenerator = new JawrUrlGenerator(servletContext);
    }
View Full Code Here

    /**
     * Acquire {@link ResourceLookup} from a serialization/ deserialization session.
     */
    public static ResourceLookup getResourceLookup(Map<Object, Object> session)
    {
        ResourceLookup resourceLookup = (ResourceLookup) session.get(RESOURCE_LOOKUP_KEY);
        if (resourceLookup == null)
        {
            throw new RuntimeException("Session does not carry resource lookup context.");
        }
        return resourceLookup;
View Full Code Here

TOP

Related Classes of org.carrot2.util.resource.ResourceLookup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.