
com.intuit.fuzzymatcher.domain.Token Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fuzzy-matcher Show documentation
Show all versions of fuzzy-matcher Show documentation
A java library to determine probability of objects being similar
package com.intuit.fuzzymatcher.domain;
import com.intuit.fuzzymatcher.function.ScoringFunction;
import com.intuit.fuzzymatcher.util.Utils;
import java.util.Objects;
import java.util.stream.Stream;
/**
*
* Elements are broken down into Token class using the TokenizerFunction
*/
public class Token implements Matchable{
public Token(String value, Element element) {
this(value, element, false);
}
public Token(String value, Element element, boolean nGramTokenized) {
this.value = value;
this.element = element;
this.nGramTokenized = nGramTokenized;
}
private String value;
private Element element;
private boolean nGramTokenized;
private Stream searchGroups;
public String getValue() {
return value;
}
public Element getElement() {
return element;
}
public void setElement(Element element) {
this.element = element;
}
public boolean isnGramTokenized() {
return nGramTokenized;
}
public Stream getNGrams() {
if(isnGramTokenized()){
return Stream.of(new NGram(getValue(), this));
} else {
return Utils.getNGrams(getValue(), 3).map(str -> new NGram(str, this)).distinct();
}
}
public Stream getSearchGroups() {
return searchGroups == null ? Stream.empty() : searchGroups.filter(t -> t != this).distinct();
}
public void setSearchGroups(Stream searchGroups) {
this.searchGroups = searchGroups;
}
@Override
public long getChildCount() {
return 0;
}
@Override
public long getEmptyChildCount() {
return 0;
}
@Override
public ScoringFunction getScoringFunction() {
return null;
}
@Override
public double getWeight() {
return 1.0;
}
@Override
public String toString() {
return "{" +
value + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Token token = (Token) o;
return Objects.equals(value, token.value) &&
Objects.equals(element, token.element);
}
@Override
public int hashCode() {
return Objects.hash(value, element);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy