Java Array Slice sliceFromFinalBoundary(Object[] sequence, Boolean[] boundaries)

Here you can find the source of sliceFromFinalBoundary(Object[] sequence, Boolean[] boundaries)

Description

Return the slice between the final boundary and the end of the sequence.

License

Open Source License

Parameter

Parameter Description
sequence sequence to slice
boundaries boundaries in the utterance

Return

the subsequence of the text corresponding to the newest word

Declaration

public static Object[] sliceFromFinalBoundary(Object[] sequence,
        Boolean[] boundaries) 

Method Source Code

//package com.java2s;
/*/*from w  w w . j a  v  a  2s.  c  om*/
 Copyright (C) 2010, 2011 Constantine Lignos

 This file is a part of CATS.

 CATS is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 CATS 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 General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with CATS.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Arrays;

public class Main {
    /**
     * Return the slice between the final boundary and the end of the sequence.
     * @param sequence sequence to slice
     * @param boundaries boundaries in the utterance
     * @return the subsequence of the text corresponding to the newest word
     */
    public static Object[] sliceFromFinalBoundary(Object[] sequence,
            Boolean[] boundaries) {
        // Find the last boundary. If no boundary is found, -1 is correct since
        // when it is incremented it will be zero, the first index in the text
        int last = -1;
        for (int i = 0; i < boundaries.length; i++) {
            if (boundaries[i])
                last = i;
        }

        // Now get the appropriate slice from last to the end. Increase last
        // by one since it is aligned one left of the text
        return Arrays.copyOfRange(sequence, last + 1, sequence.length,
                sequence.getClass());
    }
}

Related

  1. slice(T[] array, int start, int finish)
  2. slice(T[] items, int offset, int length)
  3. sliceArray(final String[] array, final int start)
  4. SliceByteArray(byte data[], int offset, int length)
  5. sliceBytes(byte[] bytes, int offset, int length)
  6. slicesFromAllBoundaries(Object[] sequence, Boolean[] boundaries)
  7. sliceStringArray(String[] a, Integer l)