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

de.citec.tcs.alignment.sequence.NodeSpecification Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 3.1.1
Show newest version
/* 
 * 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.Arrays;
import lombok.NonNull;

/**
 * This specifies the contents of the nodes in a given sequence. In essence this
 * is just a collection of keyword specifications, defining all possible
 * keywords that may be used in nodes as well as the corresponding types.
 *
 * More formally speaking a NodeSpecification defines a set of keywords K as
 * well as the value spaces V_k for each keyword k in K.
 *
 * @author Benjamin Paassen - [email protected]
 */
public class NodeSpecification extends IndexingScheme {

	private final KeywordSpecification[] keywordSpecs;

	public NodeSpecification(@NonNull final KeywordSpecification[] keywordSpecs) {
		super(extractKeywords(keywordSpecs));
		this.keywordSpecs = keywordSpecs;
	}

	private static String[] extractKeywords(@NonNull KeywordSpecification[] keywordSpecs) {
		final String[] out = new String[keywordSpecs.length];
		for (int i = 0; i < out.length; i++) {
			out[i] = keywordSpecs[i].getKeyword();
		}
		return out;
	}

	/**
	 * Returns the specification for the given keyword.
	 *
	 * @param keyword a keyword.
	 *
	 * @return the specification for the given keyword.
	 */
	public KeywordSpecification getKeywordSpecification(@NonNull final String keyword) {
		return getKeywordSpecification(getKeywordIndex(keyword));
	}

	/**
	 * Returns the specification for the given keyword.
	 *
	 * @param index a keyword index.
	 *
	 * @return the specification for the given keyword.
	 */
	public KeywordSpecification getKeywordSpecification(final int index) {
		return keywordSpecs[index];
	}

	public KeywordSpecification[] getKeywordSpecifications() {
		return keywordSpecs;
	}

	@Override
	public int hashCode() {
		int hash = 5;
		hash = 71 * hash + super.hashCode();
		hash = 71 * hash + Arrays.deepHashCode(this.keywordSpecs);
		return hash;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final NodeSpecification other = (NodeSpecification) obj;
		if (!super.equals(obj)) {
			return false;
		}
		if (!Arrays.deepEquals(this.keywordSpecs, other.keywordSpecs)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		if (size() == 0) {
			return "";
		}
		final StringBuilder builder = new StringBuilder();
		for (int k = 0; k < size(); k++) {
			builder.append(keywordSpecs[k].toString());
			builder.append("\n");
		}
		builder.delete(builder.length() - 1, builder.length());
		return builder.toString();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy