Here you can find the source of count(T x0, T x1, T x2, Collection
private static <T> Double count(T x0, T x1, T x2, Collection<T[]> sentences)
//package com.java2s; /*/*from w ww. ja va 2 s . c o m*/ * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Collection; public class Main { private static <T> Double count(T x0, T x1, T x2, Collection<T[]> sentences) { Double count = 0d; for (T[] sentence : sentences) { int idx0 = contains(sentence, x0); if (idx0 >= 0) { if (idx0 + 2 < sentence.length && x1.equals(sentence[idx0 + 1]) && x2.equals(sentence[idx0 + 2])) { count++; } } } return count; } private static <T> Double count(T sequentWord, T precedingWord, Collection<T[]> set) { Double result = 0d; boolean foundPreceding = false; for (T[] sentence : set) { for (T w : sentence) { if (precedingWord.equals(w)) { foundPreceding = true; continue; } if (foundPreceding && sequentWord.equals(w)) { foundPreceding = false; result++; } else foundPreceding = false; } } return result; } private static <T> Double count(T word, Collection<T[]> set) { Double result = 0d; for (T[] sentence : set) { for (T w : sentence) { if (word.equals(w)) result++; } } return result; } private static <T> int contains(T[] sentence, T word) { for (int i = 0; i < sentence.length; i++) { if (word.equals(sentence[i])) { return i; } } return -1; } }