org.carrot2.text.suffixtree.SuffixTreeBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of carrot2-mini Show documentation
Show all versions of carrot2-mini Show documentation
Carrot2 search results clustering framework. Minimal functional subset
(core algorithms and infrastructure, no document sources).
/*
* Carrot2 project.
*
* Copyright (C) 2002-2013, Dawid Weiss, Stanisław Osiński.
* All rights reserved.
*
* Refer to the full license file "carrot2.LICENSE"
* in the root folder of the repository checkout or at:
* http://www.carrot2.org/carrot2.LICENSE
*/
package org.carrot2.text.suffixtree;
/**
* Builds a suffix tree using method chains, thus avoiding direct dependency on
* specialized constructors of {@link SuffixTree}.
*
* @see #from(ISequence)
* @see #build()
*/
public final class SuffixTreeBuilder
{
/**
* The input sequence for the tree.
*/
private final ISequence sequence;
/* */
private SuffixTree.IStateCallback newStateCallback;
/* */
private SuffixTree.IProgressCallback progressCallback;
/**
* @see #from(ISequence)
*/
private SuffixTreeBuilder(ISequence sequence)
{
this.sequence = sequence;
}
/**
* Returns the builder for a suffix tree made from sequence
.
*/
public static SuffixTreeBuilder from(ISequence sequence)
{
return new SuffixTreeBuilder(sequence);
}
/**
* @return Return a new suffix tree according to current parameters. This method call
* may take a long time, depending on the length of the input sequence.
*/
public SuffixTree build()
{
return new SuffixTree(sequence, newStateCallback, progressCallback);
}
public SuffixTreeBuilder withProgressCallback(SuffixTree.IProgressCallback callback)
{
this.progressCallback = callback;
return this;
}
public SuffixTreeBuilder withStateCallback(SuffixTree.IStateCallback callback)
{
this.newStateCallback = callback;
return this;
}
}