List of usage examples for java.util ArrayList set
public E set(int index, E element)
From source file:org.springframework.cloud.dataflow.rest.util.DeploymentPropertiesUtils.java
/** * Parses a String comprised of 0 or more delimited key=value pairs where each key * has the format: {@code app.[appname].[key]} or {@code deployer.[appname].[key]}. Values * may themselves contain commas, since the split points will be based upon the key * pattern./*from www . j av a2 s.co m*/ * <p> * Logic of parsing key/value pairs from a string is based on few rules and assumptions 1. * keys will not have commas or equals. 2. First raw split is done by commas which will * need to be fixed later if value is a comma-delimited list. * * @param s the string to parse * @param delimiter delimiter used to split the string into pairs * @return the List key=value pairs */ public static List<String> parseParamList(String s, String delimiter) { ArrayList<String> pairs = new ArrayList<>(); // get raw candidates as simple comma split String[] candidates = StringUtils.delimitedListToStringArray(s, delimiter); for (int i = 0; i < candidates.length; i++) { if (i > 0 && !candidates[i].contains("=")) { // we don't have '=' so this has to be latter parts of // a comma delimited value, append it to previously added // key/value pair. // we skip first as we would not have anything to append to. this // would happen if dep prop string is malformed and first given // key/value pair is not actually a key/value. pairs.set(pairs.size() - 1, pairs.get(pairs.size() - 1) + delimiter + candidates[i]); } else { // we have a key/value pair having '=', or malformed first pair pairs.add(candidates[i]); } } return pairs; }
From source file:Anaphora_Resolution.ParseAllXMLDocuments.java
public static Tree HobbsResolve(Tree pronoun, ArrayList<Tree> forest) { Tree wholetree = forest.get(forest.size() - 1); // The last one is the one I am going to start from ArrayList<Tree> candidates = new ArrayList<Tree>(); List<Tree> path = wholetree.pathNodeToNode(wholetree, pronoun); System.out.println(path);// w ww . j a v a2 s. c o m // Step 1 Tree ancestor = pronoun.parent(wholetree); // This one locates the NP the pronoun is in, therefore we need one more "parenting" ! // Step 2 ancestor = ancestor.parent(wholetree); //System.out.println("LABEL: "+pronoun.label().value() + "\n\tVALUE: "+pronoun.firstChild()); while (!ancestor.label().value().equals("NP") && !ancestor.label().value().equals("S")) ancestor = ancestor.parent(wholetree); Tree X = ancestor; path = X.pathNodeToNode(wholetree, pronoun); System.out.println(path); // Step 3 for (Tree relative : X.children()) { for (Tree candidate : relative) { if (candidate.contains(pronoun)) break; // I am looking to all the nodes to the LEFT (i.e. coming before) the path leading to X. contain <-> in the path //System.out.println("LABEL: "+relative.label().value() + "\n\tVALUE: "+relative.firstChild()); if ((candidate.parent(wholetree) != X) && (candidate.parent(wholetree).label().value().equals("NP") || candidate.parent(wholetree).label().value().equals("S"))) if (candidate.label().value().equals("NP")) // "Propose as the antecedent any NP node that is encountered which has an NP or S node between it and X" candidates.add(candidate); } } // Step 9 is a GOTO step 4, hence I will envelope steps 4 to 8 inside a while statement. while (true) { // It is NOT an infinite loop. // Step 4 if (X.parent(wholetree) == wholetree) { for (int q = 1; q < MAXPREVSENTENCES; ++q) {// I am looking for the prev sentence (hence we start with 1) if (forest.size() - 1 < q) break; // If I don't have it, break Tree prevTree = forest.get(forest.size() - 1 - q); // go to previous tree // Now we look for each S subtree, in order of recency (hence right-to-left, hence opposite order of that of .children() ). ArrayList<Tree> backlist = new ArrayList<Tree>(); for (Tree child : prevTree.children()) { for (Tree subtree : child) { if (subtree.label().value().equals("S")) { backlist.add(child); break; } } } for (int i = backlist.size() - 1; i >= 0; --i) { Tree Treetovisit = backlist.get(i); for (Tree relative : Treetovisit.children()) { for (Tree candidate : relative) { if (candidate.contains(pronoun)) continue; // I am looking to all the nodes to the LEFT (i.e. coming before) the path leading to X. contain <-> in the path //System.out.println("LABEL: "+relative.label().value() + "\n\tVALUE: "+relative.firstChild()); if (candidate.label().value().equals("NP")) { // "Propose as the antecedent any NP node that you find" if (!candidates.contains(candidate)) candidates.add(candidate); } } } } } break; // It will always come here eventually } // Step 5 ancestor = X.parent(wholetree); //System.out.println("LABEL: "+pronoun.label().value() + "\n\tVALUE: "+pronoun.firstChild()); while (!ancestor.label().value().equals("NP") && !ancestor.label().value().equals("S")) ancestor = ancestor.parent(wholetree); X = ancestor; // Step 6 if (X.label().value().equals("NP")) { // If X is an NP for (Tree child : X.children()) { // Find the nominal nodes that X directly dominates if (child.label().value().equals("NN") || child.label().value().equals("NNS") || child.label().value().equals("NNP") || child.label().value().equals("NNPS")) if (!child.contains(pronoun)) candidates.add(X); // If one of them is not in the path between X and the pronoun, add X to the antecedents } } // Step SETTE for (Tree relative : X.children()) { for (Tree candidate : relative) { if (candidate.contains(pronoun)) continue; // I am looking to all the nodes to the LEFT (i.e. coming before) the path leading to X. contain <-> in the path //System.out.println("LABEL: "+relative.label().value() + "\n\tVALUE: "+relative.firstChild()); if (candidate.label().value().equals("NP")) { // "Propose as the antecedent any NP node that you find" boolean contains = false; for (Tree oldercandidate : candidates) { if (oldercandidate.contains(candidate)) { contains = true; break; } } if (!contains) candidates.add(candidate); } } } // Step 8 if (X.label().value().equals("S")) { boolean right = false; // Now we want all branches to the RIGHT of the path pronoun -> X. for (Tree relative : X.children()) { if (relative.contains(pronoun)) { right = true; continue; } if (!right) continue; for (Tree child : relative) { // Go in but do not go below any NP or S node. Go below the rest if (child.label().value().equals("NP")) { candidates.add(child); break; // not sure if this means avoid going below NP but continuing with the rest of non-NP children. Should be since its DFS. } if (child.label().value().equals("S")) break; // Same } } } } // Step 9 is a GOTO, so we use a while. System.out.println(pronoun + ": CHAIN IS " + candidates.toString()); ArrayList<Integer> scores = new ArrayList<Integer>(); for (int j = 0; j < candidates.size(); ++j) { Tree candidate = candidates.get(j); Tree parent = null; int parent_index = 0; for (Tree tree : forest) { if (tree.contains(candidate)) { parent = tree; break; } ++parent_index; } scores.add(0); if (parent_index == 0) scores.set(j, scores.get(j) + 100); // If in the last sentence, +100 points scores.set(j, scores.get(j) + syntacticScore(candidate, parent)); if (existentialEmphasis(candidate)) // Example: "There was a dog standing outside" scores.set(j, scores.get(j) + 70); if (!adverbialEmphasis(candidate, parent)) scores.set(j, scores.get(j) + 50); if (headNounEmphasis(candidate, parent)) scores.set(j, scores.get(j) + 80); int sz = forest.size() - 1; // System.out.println("pronoun in sentence " + sz + "(sz). Candidate in sentence "+parent_index+" (parent_index)"); int dividend = 1; for (int u = 0; u < sz - parent_index; ++u) dividend *= 2; //System.out.println("\t"+dividend); scores.set(j, scores.get(j) / dividend); System.out.println(candidate + " -> " + scores.get(j)); } int max = -1; int max_index = -1; for (int i = 0; i < scores.size(); ++i) { if (scores.get(i) > max) { max_index = i; max = scores.get(i); } } Tree final_candidate = candidates.get(max_index); System.out.println("My decision for " + pronoun + " is: " + final_candidate); // Decide what candidate, with both gender resolution and Lappin and Leass ranking. Tree pronounparent = pronoun.parent(wholetree).parent(wholetree); // 1 parent gives me the NP of the pronoun int pos = 0; for (Tree sibling : pronounparent.children()) { System.out.println("Sibling " + pos + ": " + sibling); if (sibling.contains(pronoun)) break; ++pos; } System.out.println("Before setchild: " + pronounparent); @SuppressWarnings("unused") Tree returnval = pronounparent.setChild(pos, final_candidate); System.out.println("After setchild: " + pronounparent); return wholetree; // wholetree is already modified, since it contains pronounparent }
From source file:opennlp.tools.textsimilarity.TextProcessor.java
public static ArrayList<String> tokenizeAndStemWithPunctuation(String txt) { // tokenize// w ww. j a va 2 s . co m ArrayList<String> tokens = fastTokenize(txt, true); for (int i = 0; i < tokens.size(); i++) { if (!tokens.get(i).equals("<punc>")) { tokens.set(i, TextProcessor.stemTerm(tokens.get(i))); } } return tokens; }
From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.Test.java
private static ArrayList<String> rankedCategories(HashSet<String> chosenAttributes) { ArrayList<Pair> topKcategories = new ArrayList<>(); for (String category : categories) { Integer cc = categoryCount.get(category); //number of instances in this category if (cc == null) { continue; }//from w w w.j a v a 2 s. com double p = 1.0 * cc / n; double invcc = 1.0 / (cc + 0.5 * attributes.size()); for (String a : chosenAttributes) { Integer pac = categoryAttributeCount.get(category).get(a); if (pac != null) { p *= (pac + 0.5) * invcc; } else { p *= 0.5 * invcc; } } if (topKcategories.size() < topCategories) { topKcategories.add(new Pair(category, p)); Collections.sort(topKcategories); } else if (p > topKcategories.get(topCategories - 1).p) { topKcategories.set(topCategories - 1, new Pair(category, p)); Collections.sort(topKcategories); } } ArrayList<String> rankedCategories = new ArrayList<>(); for (Pair p : topKcategories) { rankedCategories.add(p.s); } return rankedCategories; }
From source file:com.uniteddev.Unity.Downloader.java
public static void removeOutdated() throws IOException, InterruptedException { Login.progressText.setText("Removing outdated files..."); System.out.println("Removing outdated files..."); class removefile implements Runnable { private int i; removefile(int i) { this.i = i; }//from w ww. j a v a 2s . c om public void run() { if (!((folders.get(this.i).contains("bin/")) || (folders.get(this.i).contains("resources/")))) { try { //System.out.println("Currently attempting Pool Index: "+this.i); ArrayList<String> online_list = getDirectoryListing(folders.get(this.i)); ArrayList<String> offline_list = new ArrayList<String>(); if (new File(Minecraft.getWorkingDirectory(), folders.get(this.i)).isDirectory()) { File[] offline_files = new File(Minecraft.getWorkingDirectory(), folders.get(this.i)) .listFiles(); for (int j = 0; j < offline_files.length; j++) { if (!offline_files[j].isDirectory()) { offline_list.add(offline_files[j].getName()); } } } for (int j = 0; j < online_list.size(); j++) { online_list.set(j, namefix(online_list.get(j))); } for (int j = 0; j < offline_list.size(); j++) { if (!online_list.contains(offline_list.get(j))) { clean(Minecraft.getWorkingDirectory() + File.separator + folders.get(this.i), offline_list.get(j)); } } } catch (IOException e) { e.printStackTrace(); } } } } ExecutorService pool = Executors.newFixedThreadPool(cores + 2); for (int i = 0; i < folders.size(); i++) { pool.submit(new removefile(i)); } pool.shutdown(); pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); }
From source file:ch.unil.genescore.pathway.GeneSetLibrary.java
License:asdf
public static List<Gene> getRandomSample(ArrayList<Gene> items, int m) { for (int i = 0; i < m; i++) { int pos = i + rand.nextInt(items.size() - i); Gene tmp = items.get(pos);//w ww .j a v a2 s . c o m items.set(pos, items.get(i)); items.set(i, tmp); } return items.subList(0, m); }
From source file:de.wikilab.android.friendica01.fragment.MainMenuFragment.java
private void appendNumber(ArrayList<String> listWithNotifications, int index, String number) { listWithNotifications.set(index, listWithNotifications.get(index) + " <b>[<font color=red>" + number + "</font>]</b>"); }
From source file:org.bigbluebutton.conference.service.poll.PollService.java
public void savePoll(ArrayList clientSidePoll) { String pollTime = DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"); clientSidePoll.set(6, pollTime); poll = new Poll(clientSidePoll); application.savePoll(poll);/*from w w w . j av a2 s. c om*/ }
From source file:configuration.Cluster.java
/** * Test if the output is here path is a Unix path * Added by JG 2017// w w w .ja v a 2 s .c om * @param * @return true or false */ public static boolean downloadResults(workflow_properties properties) { if (isP2RsaHere()) { Enumeration<Object> e = properties.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); if (key.contains("ClusterLocalOutput_")) { String fLoc = ""; if (isDocker(properties)) { fLoc = restoreLocalDocker(properties.get(key))[0]; } else { fLoc = properties.get(key); } String fDir = fLoc; if (Util.testIfFile(fLoc)) fDir = Util.getParentOfFile(fLoc); String clusterDir = properties.get("ClusterDirPath"); String fClus = clusterDir + "/outputs/"; ArrayList<String> tab = runSshCommand(properties, "ls " + fClus); if (tab.size() >= 2 && !tab.get(0).contains("ls")) { tab.remove(tab.size() - 1); for (int i = 0; i < tab.size(); i++) { tab.set(i, fClus + tab.get(i)); } String[] tabTmp = tab.toArray(new String[tab.size()]); boolean b2 = runDownloadDir(properties, fDir, tabTmp); if (!b2) { return false; } } else { return false; } } } return true; } return false; }
From source file:com.chinamobile.bcbsp.examples.kmeans.KCentersAggregator.java
@Override public KCentersAggregateValue aggregate(Iterable<KCentersAggregateValue> values) { KCentersAggregateValue kcenters = new KCentersAggregateValue(); Iterator<KCentersAggregateValue> it = values.iterator(); ArrayList<ArrayList<Float>> contents = null; // Init the contents with the first aggregate value. if (it.hasNext()) { contents = (ArrayList<ArrayList<Float>>) it.next().getValue().clone(); }/*from w w w . j a v a2s .co m*/ // Sum the same class's coordinate values and point's counts into the // content. while (it.hasNext()) { ArrayList<ArrayList<Float>> value = it.next().getValue(); // Sum the corresponding element of the array except the first k rows. for (int i = 0; i < value.size(); i++) { ArrayList<Float> center = contents.get(i); ArrayList<Float> valueCenter = value.get(i); for (int j = 0; j < valueCenter.size(); j++) { center.set(j, center.get(j) + valueCenter.get(j)); } contents.set(i, center); } } if (contents != null) { kcenters.setValue(contents); } return kcenters; }