/** * Sets up an AlignmentSpecification for an array of vectorial sequences. * This uses the given comparators. * * @param dataSpace an array of sequences. * @param comparators a comparator for each dimension that works on * VectorialValues. * * @return an AlignmentSpecification. */ public static AlignmentSpecification setUpSpecification(Sequence[] dataSpace, @NonNull ValueComparator[] comparators) { if (dataSpace == null || dataSpace.length == 0) { throw new IllegalArgumentException("The given data space is empty!"); } //check for NodeSpecification consistency. final NodeSpecification nodeSpec = dataSpace[0].getNodeSpecification(); for (int s = 1; s < dataSpace.length; s++) { if (!nodeSpec.equals(dataSpace[s].getNodeSpecification())) { throw new IllegalArgumentException("The NodeSpecifications in the given data space are not consistent!"); } } final String[] keywords = nodeSpec.getKeywords(); return new AlignmentSpecification(nodeSpec, keywords, comparators); }
this.originalIndices = new int[K]; for (int k = 0; k < K; k++) { if (!nodeSpecification.hasKeyword(keywords[k])) { throw new RuntimeException("The keyword " + keywords[k] + " is not contained in the given NodeSpecification!"); final KeywordSpecification keywordSpec = nodeSpecification.getKeywordSpecification( keywords[k]); if (keywordSpec.getType() != comparators[k].getType()) { + " has the wrong type!"); this.originalIndices[k] = nodeSpecification.getKeywordIndex(keywords[k]);
@Override public int hashCode() { int hash = 7; hash = 79 * hash + (this.nodeSpecification != null ? this.nodeSpecification.hashCode() : 0); hash = 79 * hash + super.hashCode(); return hash; }
/** * 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 value stored in this Node for the given keyword or null of no * value is stored for the given keyword in this node. * * @param keyword a keyword * * @return the value stored in this Node for the given keyword or null of no * value is stored for the given keyword in this node. * * @throws UnsupportedOperationException is thrown if the given keyword is * not supported by the NodeSpecification. */ public Value getValue(@NonNull final String keyword) throws UnsupportedOperationException { if (!sequence.getNodeSpecification().hasKeyword(keyword)) { throw new UnsupportedOperationException("The given keyword is not defined in the sequence!"); } return valueMap[sequence.getNodeSpecification().getKeywordIndex(keyword)]; }
@Override public String toString() { final StringBuilder builder = new StringBuilder(); final boolean labeling = nodeSpecification.size() > 1; for (final Node node : this) { //append all values for each node and label them if necessary for (int k = 0; k < nodeSpecification.size(); k++) { if (labeling) { builder.append(nodeSpecification.getKeyword(k)); builder.append("#"); } final Value value = node.getValue(k); if (value != null) { builder.append(value.toString()); } if (labeling) { builder.append(";"); } } if (labeling) { builder.delete(builder.length() - 1, builder.length()); } builder.append("|"); } if (builder.length() > 0) { builder.delete(builder.length() - 1, builder.length()); } return builder.toString(); }
if (!nodeSpec.equals(dataSpace[s].getNodeSpecification())) { throw new IllegalArgumentException("The NodeSpecifications in the given data space are not consistent!"); final ValueComparator[] comparators = new ValueComparator[nodeSpec.size()]; for (int k = 0; k < comparators.length; k++) { final VectorialKeywordSpecification keySpec = (VectorialKeywordSpecification) nodeSpec.getKeywordSpecification(k); comparators[k] = new DerivableVectorialComparatorWrapper(keySpec.getKeyword(), new L1NormComparator(keySpec.getLength()));
if (!nodeSpec.equals(dataSpace[s].getNodeSpecification())) { throw new IllegalArgumentException("The NodeSpecifications in the given data space are not consistent!"); getKeywordSpecification(0)).getAlphabet(); final DerivableSymbolicComparatorWrapper comp = new DerivableSymbolicComparatorWrapper( Sequence.DEFAULTKEYWORD,
this.nodeSpecification = new NodeSpecification(new KeywordSpecification[]{spec}); this.nodeSpecification = new NodeSpecification(new KeywordSpecification[]{spec});
final int K = nodeSpec.size(); final Sequence[] out = new Sequence[N]; final Random rand = new Random(); for (int k = 0; k < K; k++) { final KeywordSpecification keywordSpec = nodeSpec.getKeywordSpecification(k); switch (keywordSpec.getType()) { case SYMBOLIC: {
/** * Sets the comparator for a given keyword. * * @param index a keyword index that is used in this Alignment. * @param comparator a fitting Comparator that defines a local normalized * distance on the values for the given keyword. */ public void setComparator(final int index, @NonNull final ValueComparator comparator) { if (nodeSpecification.getKeywordSpecification(getOriginalIndex(index)).getType() != comparator.getType()) { throw new RuntimeException("The given comparator has not the correct type!"); } comparators[index] = comparator; }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Sequence other = (Sequence) obj; if (this.nodeSpecification != other.nodeSpecification && (this.nodeSpecification == null || !this.nodeSpecification.equals(other.nodeSpecification))) { return false; } if (!super.equals(other)) { return false; } return true; } }
@Override public String toString() { if (size() == 0) { return "<empty NodeSpecification>"; } 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(); }
/** * * @param nodeSpecification The node specification that is the basis of all * sequences for this alignment. * @param comparators the comparators that shall be used for the keywords. * Please note that these have to match the types of the keywords. */ public AlignmentSpecification(@NonNull NodeSpecification nodeSpecification, @NonNull ValueComparator[] comparators) { this(nodeSpecification, nodeSpecification.getKeywords(), comparators); }
public NodeSpecification(@NonNull final KeywordSpecification[] keywordSpecs) { super(extractKeywords(keywordSpecs)); this.keywordSpecs = keywordSpecs; }
/** * Sets up an AlignmentSpecification for an array of vectorial sequences. * This uses a default comparator (L1 norm and hyperbolic normalization). * * @param dataSpace an array of sequences. * * @return an AlignmentSpecification. */ public static AlignmentSpecification setUpSpecification(Sequence[] dataSpace) { if (dataSpace == null || dataSpace.length == 0) { throw new IllegalArgumentException("The given data space is empty!"); } //construct an array of L1NormComparators. //check for NodeSpecification consistency. final NodeSpecification nodeSpec = dataSpace[0].getNodeSpecification(); for (int s = 1; s < dataSpace.length; s++) { if (!nodeSpec.equals(dataSpace[s].getNodeSpecification())) { throw new IllegalArgumentException("The NodeSpecifications in the given data space are not consistent!"); } } final ValueComparator[] comparators = new ValueComparator[nodeSpec.size()]; for (int k = 0; k < comparators.length; k++) { final VectorialKeywordSpecification keySpec = (VectorialKeywordSpecification) nodeSpec.getKeywordSpecification(k); comparators[k] = new DerivableVectorialComparatorWrapper(keySpec.getKeyword(), new L1NormComparator(keySpec.getLength())); } return setUpSpecification(dataSpace, comparators); }
if (!nodeSpec.equals(dataSpace[s].getNodeSpecification())) { throw new IllegalArgumentException("The NodeSpecifications in the given data space are not consistent!"); getKeywordSpecification(Sequence.DEFAULTKEYWORD)).getAlphabet(); final DerivableSymbolicComparatorWrapper comp = new DerivableSymbolicComparatorWrapper( Sequence.DEFAULTKEYWORD,
/** * Sets the value for the given keyword. * * @param keyword a keyword. * @param value a value with the correct type. * * @throws UnsupportedOperationException is thrown if the given keyword is * not supported by the NodeSpecification or if the given value has the * wrong type. */ public void setValue(@NonNull final String keyword, final Value value) throws UnsupportedOperationException { if (!sequence.getNodeSpecification().hasKeyword(keyword)) { throw new UnsupportedOperationException("The given keyword is not defined in the sequence!"); } setValue(sequence.getNodeSpecification().getKeywordIndex(keyword), value); }
this.nodeSpecification = new NodeSpecification(new KeywordSpecification[]{spec}); this.nodeSpecification = new NodeSpecification(new KeywordSpecification[]{spec});
/** * Sets the value for the given keyword. * * @param index a keyword index. * @param value a value with the correct type. * * @throws UnsupportedOperationException is thrown if the given value has * the wrong type. * @throws ArrayIndexOutOfBoundsException is thrown if the given index is * too large or too small. */ public void setValue(final int index, final Value value) throws UnsupportedOperationException, ArrayIndexOutOfBoundsException { if (!sequence.getNodeSpecification().getKeywordSpecification(index).validate(value)) { throw new UnsupportedOperationException("The given value " + value + " does not meet the given specification for the keyword!"); } valueMap[index] = value; }