All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.amygdalum.util.text.QGramAlphabet Maven / Gradle / Ivy

Go to download

Searching and Matching Strings with efficient algorithms: - Knuth-Morris-Pratt - Shift-And/Or - Boyer-Moore-Horspool - Sunday (QuickSearch) - BNDM - BOM - Aho-Corasick - Set-Horspool - Wu-Manber - Set-BOM

There is a newer version: 0.4.4
Show newest version
package net.amygdalum.util.text;

import java.util.List;

public class QGramAlphabet {

	private QGramMapping mapping;
	private int minQGram;
	private int maxQGram;

	private QGramAlphabet(QGramMapping mapping) {
		this.mapping = mapping;
		this.minQGram = Integer.MAX_VALUE;
		this.maxQGram = 0;
	}

	public static QGramAlphabet of(List patterns, QGramMapping mapping) {
		QGramAlphabet qgramAlphabet = new QGramAlphabet(mapping);
		for (char[] pattern : patterns) {
			for (int qc : mapping.iterate(pattern)) {
				qgramAlphabet.add(qc);
			}
		}
		return qgramAlphabet;
	}
	
	public QGramMapping getMapping() {
		return mapping;
	}

	public void add(int qc) {
		if (qc < minQGram) {
			minQGram = qc;
		}
		if (qc > maxQGram) {
			maxQGram = qc;
		}
	}

	public int minQGram() {
		return minQGram;
	}

	public int maxQGram() {
		return maxQGram;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy