![JAR search and dependency download from the Maven repository](/logo.png)
de.citec.tcs.alignment.sequence.VectorialValue 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.Arrays;
import lombok.NonNull;
/**
* This value is reserved for numeric vectors, represented internally as
* doubles.
*
* @author Benjamin Paassen - [email protected]
*/
public class VectorialValue extends AbstractValue {
private double[] vector;
public VectorialValue() {
super(ValueType.VECTOR);
}
public VectorialValue(@NonNull double[] vector) {
super(ValueType.VECTOR);
this.vector = vector;
}
public VectorialValue(@NonNull Object convertibleObject) {
super(ValueType.VECTOR);
this.vector = mapToDoubleVector(convertibleObject);
}
/**
* Returns the actual vector.
*
* @return the actual vector.
*/
public double[] getVector() {
return vector;
}
/**
* Sets the actual vector.
*
* @param vector the actual vector.
*/
public void setVector(@NonNull double[] vector) {
this.vector = vector;
}
/**
* Sets the actual vector.
*
* @param convertibleObject an object that can be converted to a double
* array or a double scalar.
*/
public void setVector(@NonNull Object convertibleObject) {
this.vector = mapToDoubleVector(convertibleObject);
}
/**
* Tries to convert an object to a double vector.
*
* @param object an object.
* @return a double object.
*/
public static double[] mapToDoubleVector(@NonNull Object object) {
final double[] out;
if (object instanceof double[]) {
out = (double[]) object;
} else if (object instanceof int[]) {
final int[] in = (int[]) object;
out = new double[in.length];
for (int i = 0; i < in.length; i++) {
out[i] = in[i];
}
} else if (object instanceof float[]) {
final float[] in = (float[]) object;
out = new double[in.length];
for (int i = 0; i < in.length; i++) {
out[i] = in[i];
}
} else if (object instanceof short[]) {
final short[] in = (short[]) object;
out = new double[in.length];
for (int i = 0; i < in.length; i++) {
out[i] = in[i];
}
} else if (object instanceof long[]) {
final long[] in = (long[]) object;
out = new double[in.length];
for (int i = 0; i < in.length; i++) {
out[i] = in[i];
}
} else if (object instanceof Double) {
out = new double[]{(Double) object};
} else if (object instanceof Integer) {
out = new double[]{(Integer) object};
} else if (object instanceof Short) {
out = new double[]{(Short) object};
} else if (object instanceof Long) {
out = new double[]{(Long) object};
} else if (object instanceof Float) {
out = new double[]{(Float) object};
} else {
throw new ClassCastException("Class "
+ object.getClass().getCanonicalName()
+ " is not convertible to double[].");
}
return out;
}
@Override
public String toString() {
return Arrays.toString(vector);
}
@Override
public int hashCode() {
int hash = 7;
hash = 47 * hash + Arrays.hashCode(this.vector);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final VectorialValue other = (VectorialValue) obj;
if (!Arrays.equals(this.vector, other.vector)) {
return false;
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy