@Override default <U> Tree<Tuple2<T, U>> zipAll(Iterable<U> that, T thisElem, U thatElem) { Objects.requireNonNull(that, "that is null"); if (isEmpty()) { return Iterator.ofAll(that).map(elem -> Tuple.of(thisElem, elem)).toTree(); } else { final java.util.Iterator<U> thatIter = that.iterator(); final Tree<Tuple2<T, U>> tree = ZipAll.apply((Node<T>) this, thatIter, thatElem); if (thatIter.hasNext()) { final Iterable<Node<Tuple2<T, U>>> remainder = Iterator.ofAll(thatIter).map(elem -> Tree.of(Tuple.of(thisElem, elem))); return new Node<>(tree.getValue(), tree.getChildren().appendAll(remainder)); } else { return tree; } } }
@Override public void reduce(Text key, Iterable<HMapStIW> values, Context context) throws IOException, InterruptedException { Iterator<HMapStIW> iter = values.iterator(); HMapStIW map = new HMapStIW(); while (iter.hasNext()) { map.plus(iter.next()); } HMapStFW writeMap = new HMapStFW(); double pmi = 0.0; for (MapKI.Entry<String> entry : map.entrySet()) { String k = entry.getKey(); if (map.get(k) >= 10) { if (wordCounts.containsKey(key.toString()) && wordCounts.containsKey(k)) { int px = wordCounts.get(key.toString()); int py = wordCounts.get(k); pmi = Math.log10(((double) (map.get(k)) / (px * py)) * wordCounts.get("numLines*")); writeMap.put(k, (float) pmi); } } } if (writeMap.size() > 0) { context.write(key, writeMap); } }
@Override public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { Hashtable<String, Integer> wordCounts = new Hashtable<String, Integer>(); ArrayList docName = new ArrayList<String>(); LinkedList wordName = new LinkedList<String>(); while (values.iterator().hasNext()) { String[] items = values.iterator().next().toString().split("@"); if (!wordName.contains(items[0])) { wordName.add(items[0]); } String[] keys = items[1].split(":|,"); for (int i = 0; i < keys.length; i += 2) { if (!docName.contains(keys[i])) { docName.add(keys[i]); wordCounts.put(keys[i], 0); } int tmp = wordCounts.get(keys[i]); tmp += Integer.parseInt(keys[i + 1]); wordCounts.put(keys[i], tmp); } } for (int i = 0; i < docName.size() - 1; ++i) { for (int j = i + 1; j < docName.size(); ++j) { if (wordCounts.get(docName.get(i)) < wordCounts.get(docName.get(j))) { String stmp = docName.get(i).toString(); docName.set(i, docName.get(j).toString()); docName.set(j, stmp); } } } String retKey = wordName.get(0).toString(); for (int i = 1; i < wordName.size(); ++i) { retKey += "," + wordName.get(i); } String retValue = ""; // ="\n" + docName.get(0).toString() + ":" + // wordCounts.get(docName.get(0).toString()); for (int i = 0; i < docName.size(); ++i) { retValue += "\n" + docName.get(i).toString() + ": " + wordCounts.get(docName.get(i).toString()); } context.write(new Text(retKey), new Text(retValue)); }
@Override default <U> Tree<Tuple2<T, U>> zip(Iterable<U> that) { Objects.requireNonNull(that, "that is null"); if (isEmpty()) { return Empty.instance(); } else { return Zip.apply((Node<T>) this, that.iterator()); } }
@Override public void reduce(Text key, Iterable<HMapStIW> values, Context context) throws IOException, InterruptedException { Iterator<HMapStIW> iter = values.iterator(); HMapStIW map = new HMapStIW(); while (iter.hasNext()) { map.plus(iter.next()); } context.write(key, map); }
private void convertFile( File par1File, Iterable par2Iterable, WorldChunkManager par3WorldChunkManager, int par4, int par5, IProgressUpdate par6IProgressUpdate) { int i; for (Iterator iterator = par2Iterable.iterator(); iterator.hasNext(); par6IProgressUpdate.setLoadingProgress(i)) { File file = (File) iterator.next(); convertChunks(par1File, file, par3WorldChunkManager, par4, par5, par6IProgressUpdate); par4++; i = (int) Math.round((100D * (double) par4) / (double) par5); } }
private static Iterator<Node> findPath(Node s, Node e) { Iterator<Node> it; try (Transaction tx = graphDb.beginTx()) { PathFinder<Path> finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypeAndDirection(RelTypes.STD, Direction.OUTGOING), 15); Iterable<Path> paths = finder.findAllPaths(s, e); Path path = paths.iterator().next(); it = path.nodes().iterator(); if (it.hasNext()) { System.out.println(it.next().getProperty("name")); } if (it.hasNext()) { System.out.println(it.next().getProperty("name")); } if (it.hasNext()) { System.out.println(it.next().getProperty("name")); } tx.success(); } return it; }
public static <T> T getFirst(Iterable<T> container) { return container.iterator().next(); }