Package org.carrot2.core

Examples of org.carrot2.core.ProcessingResult


        final Map<String, Object> attributes = Maps.newHashMap();
        CommonAttributesDescriptor.attributeBuilder(attributes)
            .documents(new ArrayList<Document>(SampleDocumentData.DOCUMENTS_DATA_MINING))
            .query("data mining");

        final ProcessingResult result = controller.process(attributes,
            LingoClusteringAlgorithm.class);

        // Now, we can serialize the entire result to XML like this
        result.serializeJson(new PrintWriter(System.out));
        System.out.println();

        // Optionally, we can provide a callback for JSON-P-style calls
        result.serializeJson(
            new PrintWriter(System.out), "loadResults",
            true /* indent */,
            false /* save documents */,
            true /* save clusters */);

 
View Full Code Here


            // Perform clustering using the attribute set provided at initialization time
            Map<String, Object> requestAttributes = Maps.newHashMap();
            CommonAttributesDescriptor.attributeBuilder(requestAttributes)
                .documents(Lists.newArrayList(SampleDocumentData.DOCUMENTS_DATA_MINING))
                .query("data mining");
            ProcessingResult results = controller.process(requestAttributes, LingoClusteringAlgorithm.class);
            ConsoleFormatter.displayClusters(results.getClusters());

            // Perform clustering using some other attribute set, in this case the
            // one that is the default in the XML file.
            requestAttributes =
                CommonAttributesDescriptor.attributeBuilder(Maps.newHashMap(defaultAttributes))
                    .documents(Lists.newArrayList(SampleDocumentData.DOCUMENTS_DATA_MINING))
                    .query("data mining").map;

            results = controller.process(requestAttributes, LingoClusteringAlgorithm.class);
            ConsoleFormatter.displayClusters(results.getClusters());
        }
        finally
        {
            CloseableUtils.close(xmlStream);
        }
View Full Code Here

    @UsesExternalServices   
    @Test
    public void testGetWithExternalSource() throws Exception
    {
        final ProcessingResult result = getOrPost(RequestType.GET, ImmutableMap.<String, Object> of(
            "query", "kaczyński",
            "dcs.source", "bing-web",
            "results", "50",
            "dcs.algorithm", "url"
        ));
        assertThatClusters(result.getClusters()).isNotEmpty();
        assertThat(result.getAttribute(AttributeNames.QUERY)).isEqualTo("kaczyński");
    }
View Full Code Here

    @UsesExternalServices
    @Test
    public void testPostUrlEncodedWithExternalSource() throws Exception
    {
        final ProcessingResult result = getOrPost(RequestType.POST_WWW_URL_ENCODING, ImmutableMap.<String, Object> of(
            "query", "kaczyński",
            "dcs.source", "bing-web",
            "results", "50",
            "dcs.algorithm", "url"
        ));
        assertThatClusters(result.getClusters()).isNotEmpty();
        assertThat(result.getAttribute(AttributeNames.QUERY)).isEqualTo("kaczyński");
    }
View Full Code Here

    }

    @Test
    public void testPostUrlEncodedWithC2Stream() throws Exception
    {
        final ProcessingResult result = getOrPost(RequestType.POST_WWW_URL_ENCODING, ImmutableMap.<String, Object> of(
            "query", "kaczyński",
            "results", "50",
            "dcs.algorithm", "url",
            "dcs.c2stream", new String(Files.toByteArray(testFiles.get(KEY_KACZYNSKI)), "UTF-8")
        ));
        assertThatClusters(result.getClusters()).isNotEmpty();
        assertThat(result.getAttribute(AttributeNames.QUERY)).isEqualTo("kaczyński");
    }
View Full Code Here

        final Map<String, Object> attributes = Maps.newHashMap();
        CommonAttributesDescriptor.attributeBuilder(attributes)
            .documents(new ArrayList<Document>(SampleDocumentData.DOCUMENTS_DATA_MINING))
            .query("data mining");

        final ProcessingResult result = controller.process(attributes,
            LingoClusteringAlgorithm.class);

        // Now, we can serialize the entire result to XML like this
        result.serialize(System.out);
        System.out.println();

        // Optionally, we can choose whether we want to serialize documents and clusters
        result.serialize(System.out,
            false /* don't save documents */,
            true /* save clusters */);
    }
View Full Code Here

    }

    @Test
    public void testPostWithVariousC2StreamXmlEncoding() throws Exception
    {
        final ProcessingResult result16 = post(KEY_KACZYNSKI_UTF16,
            ImmutableMap.<String, Object> of());
        final ProcessingResult result8 = post(KEY_KACZYNSKI,
            ImmutableMap.<String, Object> of());
       
        List<Document> doc16 = result16.getDocuments();
        List<Document> doc8 = result8.getDocuments();
        assertThat(doc16.size()).isEqualTo(doc8.size());
        for (int i = 0; i < Math.min(doc16.size(), doc8.size()); i++)
        {
            Document d1 = doc16.get(i);
            Document d2 = doc8.get(i);
View Full Code Here

    @Test
    public void directFeedAttributeOverriding() throws Exception
    {
        // Check the original query and attribute values contained in the XML
        final ProcessingResult result = post(KEY_KACZYNSKI,
            ImmutableMap.<String, Object> of());
        assertThatClusters(result.getClusters()).isNotEmpty();
        assertThat(result.getAttribute(AttributeNames.QUERY)).isEqualTo("kaczyński");
        assertThat(result.getAttribute("DocumentAssigner.exactPhraseAssignment"))
            .isEqualTo(true);
        final int initialClusterCount = result.getClusters().size();

        // Override query
        final String otherQuery = "other query";
        final ProcessingResult overriddenQueryResult = post(KEY_KACZYNSKI,
            ImmutableMap.<String, Object> of(AttributeNames.QUERY, otherQuery));
        assertThat(overriddenQueryResult.getAttribute(AttributeNames.QUERY)).isEqualTo(
            otherQuery);

        // Override some attributes
        final ProcessingResult overriddenAttributesResult = post(KEY_KACZYNSKI,
            ImmutableMap.<String, Object> of("LingoClusteringAlgorithm.desiredClusterCountBase", "5"));
        assertThat(overriddenAttributesResult.getClusters().size()).isNotEqualTo(
            initialClusterCount);

        // Note the string instead of an integer here. The reason for this is that the
        // attributes get passed as a string POST parameters and the controller echoes
        // input attributes to output exactly in the form they were provided, from string
        // type conversion is performed only for the purposes of binding to the
        // component's fields.
        assertThat(
            overriddenAttributesResult
                .getAttribute("LingoClusteringAlgorithm.desiredClusterCountBase")).isEqualTo("5");

    }
View Full Code Here

        boolean onlyClusters) throws IOException, Exception
    {
        final XmlPage dcsResponse = (XmlPage) clickSubmit(form);
        final String responseXml = dcsResponse.asXml();

        final ProcessingResult dcsResult = ProcessingResult
            .deserialize(new ByteArrayInputStream(responseXml.getBytes(UTF_8)));
        assertThat(dcsResult.getAttributes().get(AttributeNames.QUERY)).isEqualTo(query);
        if (onlyClusters)
        {
            assertThat(dcsResult.getDocuments()).isNull();
        }
        else
        {
            assertThat(dcsResult.getDocuments().size()).isGreaterThan(0);
        }
        assertThat(dcsResult.getClusters().size()).isGreaterThan(0);
    }
View Full Code Here

        /*
         * We need to refer to the Lucene component by its identifier we set during
         * initialization. As we've not assigned any identifier to the
         * LingoClusteringAlgorithm we want to use, we can its fully qualified class name.
         */
        ProcessingResult process = controller.process(processingAttributes, "lucene",
            LingoClusteringAlgorithm.class.getName());
       
        ConsoleFormatter.displayResults(process);
    }
View Full Code Here

TOP

Related Classes of org.carrot2.core.ProcessingResult

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.