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

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

Description

Return slices from all boundaries.

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[][] slicesFromAllBoundaries(Object[] sequence,
        Boolean[] boundaries) 

Method Source Code

//package com.java2s;
/*/*from  w  ww.j  av  a  2  s.  c  o  m*/
 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;
import java.util.LinkedList;
import java.util.List;

public class Main {
    private static final Object[][] DUMMY_OBJECT_NESTED_ARRAY = new Object[0][0];

    /**
     * Return slices from all boundaries.
     * @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[][] slicesFromAllBoundaries(Object[] sequence,
            Boolean[] boundaries) {
        List<Object[]> slices = new LinkedList<Object[]>();

        int start = -1;
        int end = -1;
        // Go through all boundaries, slicing out each spot
        for (int i = 0; i < boundaries.length; i++) {
            if (boundaries[i]) {
                start = end;
                end = i;

                // Now get the appropriate slice. Increase start and
                // end by one since they are aligned one left of the text
                slices.add(Arrays.copyOfRange(sequence, start + 1, end + 1,
                        sequence.getClass()));
            }
        }
        // Now get the final slice, similarly offset end by 1
        slices.add(Arrays.copyOfRange(sequence, end + 1, sequence.length,
                sequence.getClass()));

        // Do a crazy conversion to Object[][], thanks toArray!
        return slices.toArray(DUMMY_OBJECT_NESTED_ARRAY);
    }
}

Related

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