Package org.carrot2.core

Examples of org.carrot2.core.Document


        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);
            assertThat(d1.getTitle()).isEqualTo(d2.getTitle());
            assertThat(d1.getSummary()).isEqualTo(d2.getSummary());
        }
    }
View Full Code Here


    private static final String FIELD = "field";

    @Test
    public void testScalarField()
    {
        final Document d11 = documentWithField("1");
        final Document d12 = documentWithField("1");
        final Document d21 = documentWithField("2");
        final Document d22 = documentWithField("2");
        final Document dn = documentWithField(null);
        final List<Document> documents = Lists.newArrayList(d11, d12, d21, d22, dn);

        check(documents, Lists.<Cluster> newArrayList(new Cluster("1", d11, d12),
            new Cluster("2", d21, d22)), dn);
    }
View Full Code Here

    }

    @Test
    public void testCollectionField()
    {
        final Document d11 = documentWithField(Lists.newArrayList("11", "12"));
        final Document d12 = documentWithField(Lists.newArrayList("11"));
        final Document d21 = documentWithField(Lists.newArrayList("21", "22"));
        final Document d22 = documentWithField(Lists.newArrayList("23"));
        final Document dn = documentWithField(null);
        final List<Document> documents = Lists.newArrayList(d11, d12, d21, d22, dn);

        check(documents, Lists.<Cluster> newArrayList(new Cluster("11", d11, d12),
            new Cluster("12", d11), new Cluster("21", d21), new Cluster("22", d21),
            new Cluster("23", d22)), dn);
View Full Code Here

        assertThatClusters(clusters).isEquivalentTo(expectedClusters);
    }

    private Document documentWithField(Object fieldValue)
    {
        final Document document = new Document();
        document.setField(FIELD, fieldValue);
        return document;
    }
View Full Code Here

    protected void createDocumentsWithFields(String [] fields, String... fieldValues)
    {
        int fieldValuesIndex = 0;
        while (fieldValuesIndex < fieldValues.length)
        {
            Document document = new Document();
            for (String fieldName : fields)
            {
                document.setField(fieldName, fieldValues[fieldValuesIndex++]);

                if (fieldValuesIndex >= fieldValues.length)
                {
                    break;
                }
View Full Code Here

                final int topicId = Integer.parseInt(topicSplit[0]);
                final int resultIndex = Integer.parseInt(topicSplit[1]);

                // Build document
                final Document document = new Document();
                document.setField(Document.CONTENT_URL, split[1]);
                document.setField(Document.TITLE, split[2]);
                if (split.length > 3)
                {
                    document.setField(Document.SUMMARY, split[3]);
                }
                document
                    .setField(
                        Document.PARTITIONS,
                        ImmutableList
                            .of(buildTopicId(
                                topicId,
View Full Code Here

        attrs = Maps.newHashMap();
    }
   
    private void check(String query, String snippetToHighlight, String expectedSnippet)
    {
        final Document document = new Document();
        document.setField(Document.SUMMARY, snippetToHighlight);

        final Controller controller = ControllerFactory.createSimple();
        try
        {
            controller.init(attrs);
            ProcessingResult result = controller.process(
                Lists.newArrayList(document),
                query,
                QueryWordHighlighter.class);
           
            final Document highlightedDocument = result.getDocuments().get(0);
            assertThat(highlightedDocument.getField(Document.SUMMARY + QueryWordHighlighter.HIGHLIGHTED_FIELD_NAME_SUFFIX))
                .isEqualTo(expectedSnippet);
        }
        finally
        {
            controller.dispose();
View Full Code Here

        return newDoc(title, summary, null);
    }

    public PreprocessingContextBuilder newDoc(String title, String summary, String contentUrl)
    {
        documents.add(new Document(title, summary, contentUrl));
        return this;
    }
View Full Code Here

        return this;
    }

    public PreprocessingContextBuilder newDoc(FieldValue... fields)
    {
        Document doc = new Document();
        for (FieldValue fv : fields)
            doc.setField(fv.field, fv.value);
        documents.add(doc);
        return this;
    }
View Full Code Here

    {
        final List<Document> documents = Lists.newArrayList();
        final int documentCount = randomIntBetween(1, 100);
        for (int i = 0; i < documentCount; i++)
        {
            documents.add(new Document());
        }

        final List<Cluster> clusters = cluster(documents).getClusters();

        assertNotNull(clusters);
View Full Code Here

TOP

Related Classes of org.carrot2.core.Document

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.