de.citec.tcs.alignment.sequence.Alphabet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sequences Show documentation
Show all versions of sequences Show documentation
This module contains the sequence datastructure of the
TCS Alignment Toolbox. It defines the possible value sets in the
ValueType enum as well as the different KeywordSpecification classes, namely:
1.) StringKeywordSpecification for string type values.
2.) SymbolicKeywordSpecification for values from a discrete alphabet (also refer to the Alphabet class)
3.) VectorialKeywordSpecification for vectors of some length (or for scalars)
A NodeSpecification is a vector of such KeywordSpecifications and defines
the order of value sets. A node, then, is defined as a vector of values
from these value sets (also refer to the Value interface as well as the
StringValue, SymbolicValue and VectorialValue classes). Finally a
sequence is defined as a list of such nodes.
/*
* TCS Alignment Toolbox Version 3
*
* Copyright (C) 2016
* Benjamin Paaßen
* AG Theoretical Computer Science
* Centre of Excellence Cognitive Interaction Technology (CITEC)
* University of Bielefeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package de.citec.tcs.alignment.sequence;
import java.util.HashMap;
import lombok.NonNull;
/**
* An alphabet is an ordered set of arbitrary symbols. It is somewhat related to
* an enum in that way. Internally we model an Alphabet as a HashMap from
* objects to integer-indices.
*
* Please note that the index position does not have to imply any similarity.
* The symbols are just supposed to be arbitrary objects that are stored in the
* alphabet in some order. The order might as well be arbitrary. The alphabet
* just garantuees consistency in the mapping from symbols to indices and vice
* versa.
*
* @author Benjamin Paassen - [email protected]
*/
public class Alphabet extends IndexingScheme {
public Alphabet(@NonNull HashMap indexMapping) {
super(indexMapping);
}
/**
* Constructor for symbols either encoded as single characters without
* delimiter or as strings with | as delimiter. If some symbols occur more
* often than once they are ignored in the mapping.
*
* @param symbols a string specifying the symbols this IndexingScheme should
* be initialized with.
*/
public Alphabet(@NonNull String symbols) {
super(symbols);
}
/**
* Constructs an IndexingScheme from a mapping of indices to strings.
*
* @param symbols a mapping of indices to strings
*/
public Alphabet(@NonNull String[] symbols) {
super(symbols);
}
/**
* This is equivalent to "hasKeyword".
*
* @param symbol the actual symbol.
* @return true if this symbol is contained in the Alphabet and false
* otherwise.
*/
public boolean hasSymbol(@NonNull String symbol) {
return hasKeyword(symbol);
}
/**
* This is equivalent to "getKeyword"
*
* @param index an index.
* @return the symbol for this index.
*/
public String getSymbol(int index) {
return getKeyword(index);
}
/**
* This is equivalent to "getKeywordIndex"
*
* @param symbol a symbol in this Alphabet.
* @return the index for that symbol.
*/
public int getSymbolIndex(@NonNull String symbol) {
return getKeywordIndex(symbol);
}
/**
* This is equivalent to "getKeywords"
*
* @return the symbols that are contained in this Alphabet.
*/
public String[] getSymbols() {
return getKeywords();
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < size() - 1; i++) {
builder.append(getKeyword(i).toString());
builder.append("|");
}
builder.append(getKeyword(size() - 1).toString());
return builder.toString();
}
}