@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(); }
/** * 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); }
/** * Transforms the given arrays to sequences. It is assumed that each * entry arrays[s] is a sequence. * Your sequences are allowed to have different lengths. * * @param arrays an array of double arrays that shall be converted to * sequences. * * @return an array of Sequences. */ public static Sequence[] toSequences(@NonNull double[][] arrays) { final KeywordSpecification[] keywordSpecs = {new VectorialKeywordSpecification(1, STDKEYWORD)}; final NodeSpecification nodeSpec = new NodeSpecification(keywordSpecs); final Sequence[] sequences = new Sequence[arrays.length]; for (int s = 0; s < arrays.length; s++) { sequences[s] = new Sequence(nodeSpec); for (int i = 0; i < arrays[s].length; i++) { final Node node = new Node(sequences[s]); node.setValue(0, new VectorialValue(new double[]{arrays[s][i]})); sequences[s].add(node); } } return sequences; }
public V extractValue(@NonNull Node node) { final Value val = node.getValue(keyword); if (val == null) { return null; } switch (type) { case STRING: return (V) ((StringValue) val).getString(); case SYMBOLIC: return (V) ((SymbolicValue) val).getSymbol(); case VECTOR: return (V) ((VectorialValue) val).getVector(); default: throw new IllegalArgumentException("Unsupported ValueType: " + type); } }
case REPLACEMENT: final VectorialValue leftVal = (VectorialValue) op.getLeft(). getValue(spec.getOriginalIndex(k)); local_d = leftVal.getVector().length; System.arraycopy(leftVal.getVector(), 0, case REPLACEMENT: final VectorialValue rightVal = (VectorialValue) op.getRight(). getValue(spec.getOriginalIndex(k)); local_d = rightVal.getVector().length; System.arraycopy(rightVal.getVector(), 0,
out[n] = new Sequence(nodeSpec); for (int l = 0; l < L; l++) { final Node node = new Node(out[n]); out[n].add(node); for (int k = 0; k < K; k++) { final SymbolicValue randomSymbol = new SymbolicValue( alpha, alpha.getSymbol(r)); node.setValue(k, randomSymbol); content[d] = rand.nextGaussian(); node.setValue(k, new VectorialValue(content)); builder.append(c); node.setValue(k, new StringValue(builder.toString()));