Package org.carrot2.util.resource

Examples of org.carrot2.util.resource.IResource


                    .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


                  + carrot2ResourcesDir);
              final InputStream resourceStream = resourceLoader
                  .openResource(carrot2ResourcesDir + "/" + resource);
             
              log.info(resource + " loaded from " + carrot2ResourcesDir);
              final IResource foundResource = new IResource() {
                public InputStream open() throws IOException {
                  return resourceStream;
                }
              };
              return new IResource[] { foundResource };
View Full Code Here

            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: "
View Full Code Here

   
        InputStream xsltStream = null;
   
        if (StringUtils.isNotBlank(config.xslt))
        {
            IResource resource = resourceLookup.getFirst(config.xslt);
            if (resource == null)
            {
                config.logger.warn("XSLT stylesheet " + config.xslt
                    + " not found. No XSLT transformation will be applied.");
                return;
            }
   
            try
            {
                xsltStream = resource.open();
                xsltTemplates = tFactory.newTemplates(new StreamSource(xsltStream));
                config.logger.info("XSL stylesheet loaded successfully from: "
                    + config.xslt);
            }
            catch (IOException e)
View Full Code Here

            .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

    /**
     * Attempts to load <code>resourceName</code> from the provided {@link ResourceLookup}.
     */
    private static HashSet<String> load(ResourceLookup resourceLookup, String resourceName)
    {
        final IResource resource = resourceLookup.getFirst(resourceName);
        if (resource == null)
        {
            throw new RuntimeException(
                "No resource named " + resourceName +
                " in resource lookup locations: " +
                Arrays.toString(resourceLookup.getLocators()));
        }
        else
        {
            try
            {
                return load(resource);
            }
            catch (IOException e)
            {
                throw new RuntimeException(
                    "Resource named " + resourceName +
                    " failed to load from: " + resource.toString());
            }
        }
    }
View Full Code Here

                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

     */
    public static <T> T read(ResourceLookup resourceLookup,
        String resource, Class<T> clazz, boolean required)
        throws IOException
    {
        IResource res = resourceLookup.getFirst(resource);
        if (res == null)
        {
            if (required) throw new IOException("Required resource not found: " + resource);
            return null;
        }

        InputStream inputStream = null;
        try
        {
            inputStream = new BufferedInputStream(res.open());
            try
            {
                return PersisterHelpers.createPersister(resourceLookup,
                    new AnnotationStrategy()).read(clazz, inputStream);
            }
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testReadClusters()
    {
        IResource xml = resourceLocator.getFirst("/xml/carrot2-with-clusters.xml");

        processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xml"), xml);
        processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "readClusters"), true);
        runQuery();
View Full Code Here

    }

    @Test
    public void testLegacyXml()
    {
        IResource xml = resourceLocator.getFirst("/xml/carrot2-apple-computer.xml");

        processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xml"),
            xml);
        processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "results"),
            300);
View Full Code Here

TOP

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

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.