Package org.apache.lucene.facet.index.attributes

Examples of org.apache.lucene.facet.index.attributes.CategoryAttributeImpl


   */
  private final CategoryAttribute mapCategoryAttribute(
      CategoryPath categoryPath) {
    CategoryAttribute ca = map.get(categoryPath);
    if (ca == null) {
      ca = new CategoryAttributeImpl(categoryPath);
      map.put(categoryPath, ca);
    }
    return ca;
  }
View Full Code Here


    LuceneTaxonomyWriter taxoW = new LuceneTaxonomyWriter(tDir);
   
    CategoryContainer cc = new CategoryContainer();
    EnhancementsDocumentBuilder builder = new EnhancementsDocumentBuilder(taxoW, iParams);
    for (int i = 1; i <= NUM_CATEGORIES; i++) {
      CategoryAttributeImpl ca = new CategoryAttributeImpl(new CategoryPath(Integer.toString(i)));
      ca.addProperty(new CustomProperty(i));
     
      cc.addCategory(ca);
    }
    builder.setCategories(cc);
    w.addDocument(builder.build(new Document()));
View Full Code Here

   * @throws FacetException
   */
  @Test
  public void testAddCategoryAttributeWithoutProperties()
      throws FacetException {
    CategoryAttribute newCA = new CategoryAttributeImpl(new CategoryPath(
        "seven", "eight"));
    categoryContainer.addCategory(newCA);
  }
View Full Code Here

   *
   * @throws FacetException
   */
  @Test
  public void testAddCategoryAttributeWithProperty() throws FacetException {
    CategoryAttribute newCA = new CategoryAttributeImpl(new CategoryPath(
        "seven", "eight"));
    newCA.addProperty(new DummyProperty());
    categoryContainer.addCategory(newCA);
    Iterator<CategoryAttribute> iterator = categoryContainer.iterator();

    // count the number of tokens, and check there is one DummyAttribute
    int nCategories;
View Full Code Here

public class CategoryAttributeImplTest extends LuceneTestCase {

  @Test
  public void testCategoryPath() {
    CategoryAttribute ca = new CategoryAttributeImpl();

    assertNull("Category Path should be null", ca.getCategoryPath());

    CategoryPath cp = new CategoryPath("a", "b");
    ca.setCategoryPath(cp);

    assertEquals("Wrong Category Path", cp, ca.getCategoryPath());

    ca.setCategoryPath(null);
    assertNull("Category Path should be null", ca.getCategoryPath());

    ca = new CategoryAttributeImpl(cp);
    assertEquals("Wrong Category Path", cp, ca.getCategoryPath());
  }
View Full Code Here

    assertEquals("Wrong Category Path", cp, ca.getCategoryPath());
  }

  @Test
  public void testProperties() throws FacetException {
    CategoryAttribute ca = new CategoryAttributeImpl();

    assertNull("Attribute should be null", ca
        .getProperty(DummyProperty.class));
    assertNull("Attribute classes should be null", ca.getPropertyClasses());

    ca.addProperty(new DummyProperty());
    assertEquals("DummyProperty should be in properties",
        new DummyProperty(), ca.getProperty(DummyProperty.class));
    assertEquals("Attribute classes should contain 1 element", 1, ca
        .getPropertyClasses().size());

    boolean failed = false;
    try {
      ca.addProperty(new DummyProperty());
    } catch (UnsupportedOperationException e) {
      failed = true;
    }

    if (!failed) {
      fail("Two DummyAttributes added to the same CategoryAttribute");
    }

    ca.clearProperties();
    assertNull("Attribute classes should be null", ca.getPropertyClasses());

    ca.addProperty(new DummyProperty());
    assertEquals("DummyProperty should be in properties",
        new DummyProperty(), ca.getProperty(DummyProperty.class));
    ca.remove(DummyProperty.class);
    assertEquals("DummyProperty should not be in properties", null, ca
        .getProperty(DummyProperty.class));
    assertNull("Attribute classes should be null", ca.getPropertyClasses());

    ca.addProperty(new DummyProperty());
    List<Class<? extends CategoryProperty>> propertyClasses = new ArrayList<Class<? extends CategoryProperty>>();
    assertEquals("No property expected when no classes given", null, ca
        .getProperty(propertyClasses));
    propertyClasses.add(DummyProperty.class);
    assertEquals("DummyProperty should be in properties",
        new DummyProperty(), ca.getProperty(propertyClasses));
    propertyClasses.add(OrdinalProperty.class);
    assertEquals("DummyProperty should be in properties",
        new DummyProperty(), ca.getProperty(propertyClasses));
    propertyClasses.clear();
    propertyClasses.add(OrdinalProperty.class);
    assertEquals("No ordinal property expected", null, ca
        .getProperty(propertyClasses));
  }
View Full Code Here

        .getProperty(propertyClasses));
  }

  @Test
  public void testCloneCopyToAndSet() throws FacetException {
    CategoryAttributeImpl ca1 = new CategoryAttributeImpl();

    CategoryPath cp = new CategoryPath("a", "b");
    ca1.setCategoryPath(cp);
    ca1.addProperty(new DummyProperty());

    CategoryAttribute ca2 = ca1.clone();
    assertEquals("Error in cloning", ca1, ca2);

    CategoryAttributeImpl ca3 = new CategoryAttributeImpl();
    assertNotSame("Should not be the same", ca1, ca3);
    ca1.copyTo(ca3);
    assertEquals("Error in cloning", ca1, ca3);

    ca2.setCategoryPath(null);
View Full Code Here

   */
  @Test
  public void testStream() throws IOException {
    ArrayList<CategoryAttribute> attributesList = new ArrayList<CategoryAttribute>();
    for (int i = 0; i < initialCatgeories.length; i++) {
      attributesList.add(new CategoryAttributeImpl(initialCatgeories[i]));
    }

    // test number of tokens
    CategoryAttributesStream stream = new CategoryAttributesStream(
        attributesList);
View Full Code Here

   */
  private final CategoryAttribute mapCategoryAttribute(
      CategoryPath categoryPath) {
    CategoryAttribute ca = map.get(categoryPath);
    if (ca == null) {
      ca = new CategoryAttributeImpl(categoryPath);
      map.put(categoryPath, ca);
    }
    return ca;
  }
View Full Code Here

    DirectoryTaxonomyWriter taxoW = new DirectoryTaxonomyWriter(tDir);
   
    CategoryContainer cc = new CategoryContainer();
    EnhancementsDocumentBuilder builder = new EnhancementsDocumentBuilder(taxoW, iParams);
    for (int i = 1; i <= NUM_CATEGORIES; i++) {
      CategoryAttributeImpl ca = new CategoryAttributeImpl(new CategoryPath(Integer.toString(i)));
      ca.addProperty(new CustomProperty(i));
     
      cc.addCategory(ca);
    }
    builder.setCategories(cc);
    w.addDocument(builder.build(new Document()));
View Full Code Here

TOP

Related Classes of org.apache.lucene.facet.index.attributes.CategoryAttributeImpl

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.