Package com.grt192.core

Examples of com.grt192.core.Controller


        final String resourceLookupKey = AttributeUtils.getKey(DefaultLexicalDataFactory.class, "resourceLookup");
        final String resourceReloadKey = AttributeUtils.getKey(DefaultLexicalDataFactory.class, "reloadResources");

        // Create pooling controller, use tempDir1
        final Controller ctrl1 = ControllerFactory.createPooling();
        {
            ctrl1.init(ImmutableMap.<String, Object> of(
                resourceLookupKey,
                new ResourceLookup(new DirLocator(tempDir1.getPath()), classpathLocator),
                resourceReloadKey,
                true));
   
            final ProcessingResult result = ctrl1.process(
                Collections.<String, Object> emptyMap(), TestComponent.class);
            final ILexicalData data = result.getAttribute("english");

            assertTrue(data.isCommonWord(new MutableCharArray("uniquea")));
            assertFalse(data.isCommonWord(new MutableCharArray("uniqueb")));
        }

        // Create pooling controller, use tempDir2
        final Controller ctrl2 = ControllerFactory.createPooling();
        {
            ctrl2.init(ImmutableMap.<String, Object> of(resourceLookupKey,
                new ResourceLookup(new DirLocator(tempDir2.getPath()), classpathLocator)));
   
            final ProcessingResult result = ctrl2.process(
                Collections.<String, Object> emptyMap(), TestComponent.class);
            final ILexicalData data = result.getAttribute("english");

            assertFalse(data.isCommonWord(new MutableCharArray("uniquea")));
            assertTrue(data.isCommonWord(new MutableCharArray("uniqueb")));
View Full Code Here


    {
        IResource initXslt = resourceLocator.getFirst("/xsl/carrot2-identity.xsl");
        initAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xslt"),
            initXslt);
       
        @SuppressWarnings("unchecked")
        Controller controller = getCachingController(initAttributes);

        // Run with identity XSLT
        {
            IResource xml = resourceLocator.getFirst("/xml/carrot2-test.xml");
View Full Code Here

        IResource initXslt = resourceLocator.getFirst(
            "/xsl/carrot2-title-snippet-switch.xsl");
        initAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xslt"),
            initXslt);

        @SuppressWarnings("unchecked")
        Controller controller = getCachingController(initAttributes);
       
        // Run with swapping XSLT
        {
            IResource xml = resourceLocator.getFirst("/xml/carrot2-test.xml");
View Full Code Here

    /**
     * Processes all input.
     */
    private int process() throws Exception
    {
        final Controller controller = ControllerFactory.createPooling();
        final Map<String, Object> initAttributes = ImmutableMap.<String, Object> of(
            AttributeUtils.getKey(DefaultLexicalDataFactory.class, "resourceLookup"),
            new ResourceLookup(new DirLocator("resources")));

        controller.init(
            initAttributes,
            componentSuite.getComponentConfigurations());       

        // Prepare the algorithm
        if (StringUtils.isBlank(algorithm))
View Full Code Here

    public void testRepeatedClusteringWithCache()
    {
        // Caching controller is not available for .NET at the moment.
        assumeTrue("Java test only.", Platform.getPlatform() == Platform.JAVA);

        final Controller controller = getCachingController(initAttributes, IClusteringAlgorithm.class);

        final Map<String, Object> processingAttributes = ImmutableMap.of(
            AttributeNames.DOCUMENTS, (Object) DOCUMENTS_DATA_MINING);

        controller.process(processingAttributes, getComponentClass());
        controller.process(processingAttributes, getComponentClass());

        controller.dispose();
    }
View Full Code Here

        final int queriesPerThread = scaledRandomIntBetween(5, 25);

        /*
         * This yields a pooling controller effectively, because no cache interfaces are passed.
         */
        @SuppressWarnings("unchecked")
        final Controller controller = getCachingController(initAttributes);

        ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads);
        List<Callable<ProcessingResult>> callables = Lists.newArrayList();
        for (int i = 0; i < numberOfThreads * queriesPerThread; i++)
        {
            final int dataSetIndex = i;
            callables.add(new Callable<ProcessingResult>()
            {
                public ProcessingResult call() throws Exception
                {
                    Map<String, Object> localAttributes = Maps.newHashMap();
                    localAttributes.put(AttributeNames.DOCUMENTS, SampleDocumentData.ALL
                        .get(dataSetIndex % SampleDocumentData.ALL.size()));
                    localAttributes.put("dataSetIndex", dataSetIndex);
                    return controller.process(localAttributes, getComponentClass());
                }
            });
        }

        try
View Full Code Here

     * @return {@link ProcessingResult} returned from the controller.
     */
    public ProcessingResult cluster(Collection<Document> documents)
    {
        processingAttributes.put(AttributeNames.DOCUMENTS, documents);
        Controller controller = getSimpleController(initAttributes);
        try {
            ProcessingResult process = controller.process(processingAttributes, getComponentClass());
            return process;
        } finally {
            controller.dispose();
            super.simpleController = null;
        }
    }
View Full Code Here

        final Map<String, Object> attributes = Maps.newHashMap();
        attributes.put(AttributeNames.QUERY, getSmallQueryText());
        attributes.put(AttributeNames.RESULTS, getSmallQuerySize());

        // Cache results from all DataSources
        final Controller controller =
            getCachingController(initAttributes, IDocumentSource.class);
        int count = 3;
        final ExecutorService executorService = Executors.newFixedThreadPool(count);

        try {
            List<Callable<ProcessingResult>> callables = Lists.newArrayList();
            for (int i = 0; i < count; i++)
            {
                callables.add(new Callable<ProcessingResult>()
                {
                    public ProcessingResult call() throws Exception
                    {
                        Map<String, Object> localAttributes = Maps.newHashMap(attributes);
                        return controller.process(localAttributes, getComponentClass());
                    }
                });
            }
   
            final List<Future<ProcessingResult>> results = executorService.invokeAll(callables);
   
            List<Document> documents = null;
            int index = 0;
            for (Future<ProcessingResult> future : results)
            {
                ProcessingResult processingResult = future.get();
                final List<Document> documentsLocal = (List<Document>) processingResult
                    .getAttributes().get(AttributeNames.DOCUMENTS);
                assertThat(documentsLocal).as("documents at " + index).isNotNull();
                if (!canReturnMoreResultsThanRequested())
                {
                    assertThat(documentsLocal.size()).as("documents.size() at " + index)
                        .isLessThanOrEqualTo(getSmallQuerySize());
                }
                assertThat(documentsLocal.size()).as("documents.size() at " + index)
                    .isGreaterThanOrEqualTo(getSmallQuerySize() / 2);
   
                // Should have same documents (from the cache)
                if (documents != null)
                {
                    for (int i = 0; i < documents.size(); i++)
                    {
                        assertSame(documents.get(i), documentsLocal.get(i));
                    }
                }
                documents = documentsLocal;
                index++;
            }
        } finally {
            controller.dispose();
            executorService.shutdown();
        }
    }
View Full Code Here

                    /*
                     * We're not a threaded listener so we're running on the search thread. This
                     * is good -- we don't want to serve more clustering requests than we can handle
                     * anyway.
                     */
                    Controller controller = controllerSingleton.getController();
   
                    Map<String, Object> processingAttrs = Maps.newHashMap();
                    Map<String, Object> requestAttrs = clusteringRequest.getAttributes();
                    if (requestAttrs != null) {
                        processingAttrs.putAll(requestAttrs);
                    }

                    try {
                        CommonAttributesDescriptor.attributeBuilder(processingAttrs)
                            .documents(prepareDocumentsForClustering(clusteringRequest, response))
                            .query(clusteringRequest.getQueryHint());
       
                        final long tsClusteringStart = System.nanoTime();
                        final ProcessingResult result = controller.process(processingAttrs, algorithmId);
                        final DocumentGroup[] groups = adapt(result.getClusters());
                        final long tsClusteringEnd = System.nanoTime();

                        final Map<String,String> info = ImmutableMap.<String,String> builder()
                                .put(ClusteringActionResponse.Fields.Info.ALGORITHM, algorithmId)
View Full Code Here

        return algorithms;
    }

    @Override
    protected void doStop() throws ElasticsearchException {
        Controller c = controller;
        controller = null;

        if (c != null) {
            c.close();
        }
    }
View Full Code Here

TOP

Related Classes of com.grt192.core.Controller

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.