Java Code Examples for it.unimi.dsi.fastutil.objects.ObjectArrayList#addAll()
The following examples show how to use
it.unimi.dsi.fastutil.objects.ObjectArrayList#addAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastUtil.java From minie with GNU General Public License v3.0 | 6 votes |
/** * Given a list of lists, return all the combinations between the lists (i.e. their indices). For example, suppose we * have the list of lists: [[1, 2, 3], [4, 5], [6, 7, 8]]. Then, this function will return: * [[0, 1], [1, 0], [0, 2], [2, 0], [1, 2], [2, 1], * [0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1]] * @param lists: list of lists * @return */ public static <T> ObjectArrayList<IntArrayList> getListsCombinationIndices(ObjectArrayList<ObjectArrayList<T>> lists){ ObjectArrayList<IntArrayList> combinationsInd = new ObjectArrayList<>(); ObjectArrayList<IntArrayList> result = new ObjectArrayList<>(); int[][] combinations; for (int k = 2; k <= lists.size(); k++){ result.clear(); combinations = null; combinations = getCombinations(k, lists.size()); for (int i = 0; i < combinations.length; i++) { IntArrayList indices = new IntArrayList(); for (int j = 0; j < combinations[i].length; j++) { indices.add(combinations[i][j]); } permute(indices, 0, result); } combinationsInd.addAll(result); } return combinationsInd; }
Example 2
Source File: MathInputScreen.java From WarpPI with Apache License 2.0 | 6 votes |
private ObjectArrayList<Function> getKnownVariables(final Function[] fncs) { final ObjectArrayList<Function> res = new ObjectArrayList<>(); for (final Function f : fncs) { if (f instanceof FunctionOperator) { res.addAll(getKnownVariables(new Function[] { ((FunctionOperator) f).getParameter1(), ((FunctionOperator) f).getParameter2() })); } else if (f instanceof FunctionDynamic) { res.addAll(getKnownVariables(((FunctionDynamic) f).getParameters())); } else if (f instanceof FunctionSingle) { res.addAll(getKnownVariables(new Function[] { ((FunctionSingle) f).getParameter() })); } else if (f instanceof Variable) { if (((Variable) f).getType() == Variable.V_TYPE.CONSTANT) { if (!res.contains(f)) { res.add(f); } } } } return res; }
Example 3
Source File: Power.java From WarpPI with Apache License 2.0 | 6 votes |
@Override public ObjectArrayList<Block> toBlock(final MathContext context) throws Error { final ObjectArrayList<Block> result = new ObjectArrayList<>(); final ObjectArrayList<Block> sub1 = getParameter1().toBlock(context); final ObjectArrayList<Block> sub2 = getParameter2().toBlock(context); final BlockPower bp = new BlockPower(); final BlockContainer ec = bp.getExponentContainer(); result.addAll(sub1); for (final Block b : sub2) { ec.appendBlockUnsafe(b); } ec.recomputeDimensions(); bp.recomputeDimensions(); result.add(bp); return result; }
Example 4
Source File: Negative.java From WarpPI with Apache License 2.0 | 6 votes |
@Override public ObjectArrayList<Block> toBlock(final MathContext context) throws Error { final ObjectArrayList<Block> blocks = new ObjectArrayList<>(); blocks.add(new BlockChar(MathematicalSymbols.MINUS)); if (new Expression(context, getParameter()).parenthesisNeeded()) { final BlockParenthesis par = new BlockParenthesis(); final ObjectArrayList<Block> parBlocks = getParameter().toBlock(context); for (final Block b : parBlocks) { par.getNumberContainer().appendBlockUnsafe(b); // Skips recomputeDimension } par.recomputeDimensions(); // Recompute dimensions after appendBlockUnsafe blocks.add(par); } else { blocks.addAll(getParameter().toBlock(context)); } return blocks; // throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + getClass().getSimpleName()); }
Example 5
Source File: Equation.java From WarpPI with Apache License 2.0 | 6 votes |
public ObjectArrayList<Equation> solveStep(final char charIncognita) { ObjectArrayList<Equation> result = new ObjectArrayList<>(); result.add(clone()); for (final SolveMethod t : SolveMethod.techniques) { final ObjectArrayList<Equation> newResults = new ObjectArrayList<>(); final int sz = result.size(); for (int n = 0; n < sz; n++) { newResults.addAll(t.solve(result.get(n))); } final Set<Equation> hs = new HashSet<>(); hs.addAll(newResults); newResults.clear(); newResults.addAll(hs); result = newResults; } // TODO: controllare se รจ a posto return result; }
Example 6
Source File: FastUtil.java From minie with GNU General Public License v3.0 | 5 votes |
/** * Given a list of lists, get the combinations of the elements between the lists. * For example, if we have lists = [[1, 2, 3], [4, 5]], then * getElementsCombinations(lists) = [1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5] * @param lists: list of lists * @return combination of elements between the lists */ public static <T> Set<ObjectArrayList<T>> getElementsCombinations(ObjectArrayList<ObjectArrayList<T>> lists) { Set<ObjectArrayList<T>> combinations = new HashSet<ObjectArrayList<T>>(); Set<ObjectArrayList<T>> newCombinations = new HashSet<ObjectArrayList<T>>(); ObjectArrayList<T> newList = new ObjectArrayList<T>(); int index = 0; // Extract each of the integers in the first list and add each to ints as a new list for(T i: lists.get(0)) { newList.clear(); newList.add(i); combinations.add(newList.clone()); } index++; List<T> nextList; while(index < lists.size()) { nextList = lists.get(index).clone(); newCombinations.clear(); for(List<T> first: combinations) { for(T second: nextList) { newList.clear(); newList.addAll(first); newList.add(second); newCombinations.add(newList.clone()); } } combinations = newCombinations; index++; nextList.clear(); } return combinations; }
Example 7
Source File: AnnotatedProposition.java From minie with GNU General Public License v3.0 | 5 votes |
/** * Get all the quantities in the annotated proposition * @return */ public ObjectArrayList<Quantity> getAllQuantities() { ObjectArrayList<Quantity> quantities = new ObjectArrayList<>(); for (int i = 0; i < this.getTriple().size(); i++) { quantities.addAll(this.getTriple().get(i).getQuantities()); } return quantities; }
Example 8
Source File: ClausIE.java From minie with GNU General Public License v3.0 | 5 votes |
/** Get the list of propositions, without the information about the clauses they are derived from **/ public ObjectArrayList<Proposition> getPropositions() { ObjectArrayList<Proposition> props = new ObjectArrayList<>(); for (Clause cl: this.clauses) { props.addAll(cl.getPropositions()); } return props; }
Example 9
Source File: FunctionDynamic.java From WarpPI with Apache License 2.0 | 5 votes |
@Override public final ObjectArrayList<Function> simplify(final Rule rule) throws Error, InterruptedException { final Function[] fncs = getParameters(); if (Thread.interrupted()) { throw new InterruptedException(); } final ObjectArrayList<Function> result = new ObjectArrayList<>(); final ObjectArrayList<ObjectArrayList<Function>> ln = new ObjectArrayList<>(); boolean alreadySolved = true; for (final Function fnc : fncs) { final ObjectArrayList<Function> l = new ObjectArrayList<>(); if (Thread.interrupted()) { throw new InterruptedException(); } final ObjectArrayList<Function> simplifiedFnc = fnc.simplify(rule); if (simplifiedFnc == null) { l.add(fnc); } else { l.addAll(simplifiedFnc); alreadySolved = false; } ln.add(l); } if (alreadySolved) { return rule.execute(this); } final Function[][] results = Utils.joinFunctionsResults(ln); for (final Function[] f : results) { result.add(this.setParameters(f)); } return result; }
Example 10
Source File: IndexerTest.java From fasten with Apache License 2.0 | 5 votes |
@Test public void testLargeIndex() throws JSONException, IOException, RocksDBException, URISyntaxException, ClassNotFoundException { final ObjectArrayList<String> jsonSpecs = new ObjectArrayList<>(); jsonSpecs.addAll(Arrays.asList(JSON_SPECS)); for(int i = 2; i < 10; i++) for(final String s : JSON_SPECS) jsonSpecs.add(s.replaceAll("1\\.0", i + ".0")); testKnowledgeBase(jsonSpecs.toArray(new String[0])); }
Example 11
Source File: Sum.java From WarpPI with Apache License 2.0 | 5 votes |
@Override public ObjectArrayList<Block> toBlock(final MathContext context) throws Error { final ObjectArrayList<Block> result = new ObjectArrayList<>(); result.addAll(getParameter1().toBlock(context)); result.add(new BlockChar(MathematicalSymbols.SUM)); result.addAll(getParameter2().toBlock(context)); return result; }
Example 12
Source File: Subtraction.java From WarpPI with Apache License 2.0 | 5 votes |
@Override public ObjectArrayList<Block> toBlock(final MathContext context) throws Error { final ObjectArrayList<Block> result = new ObjectArrayList<>(); result.addAll(getParameter1().toBlock(context)); result.add(new BlockChar(MathematicalSymbols.SUBTRACTION)); result.addAll(getParameter2().toBlock(context)); return result; }
Example 13
Source File: SumSubtraction.java From WarpPI with Apache License 2.0 | 5 votes |
@Override public ObjectArrayList<Block> toBlock(final MathContext context) throws Error { final ObjectArrayList<Block> result = new ObjectArrayList<>(); result.addAll(getParameter1().toBlock(context)); result.add(new BlockChar(MathematicalSymbols.SUM_SUBTRACTION)); result.addAll(getParameter2().toBlock(context)); return result; }
Example 14
Source File: MathSolver.java From WarpPI with Apache License 2.0 | 4 votes |
private ObjectArrayList<Function> applyRules(final ObjectArrayList<Function> fncs, final RuleType currentAcceptedRules) throws InterruptedException, Error { final ObjectArrayList<Rule> rules = initialFunction.getMathContext().getAcceptableRules(currentAcceptedRules); ObjectArrayList<Function> results = null; final ObjectArrayList<Rule> appliedRules = new ObjectArrayList<>(); for (final Function fnc : fncs) { boolean didSomething = false; for (final Rule rule : rules) { if (isSimplified(fnc, rule) == false) { final List<Function> ruleResults = fnc.simplify(rule); if (ruleResults != null && !ruleResults.isEmpty()) { if (results == null) { results = new ObjectArrayList<>(); } results.addAll(ruleResults); appliedRules.add(rule); setSimplified(fnc, rule); didSomething = true; break; } } } if (!didSomething && fncs.size() > 1) { if (results == null) { results = new ObjectArrayList<>(); } results.add(fnc); } } if (appliedRules.isEmpty()) { results = null; } if (WarpPI.getPlatform().getConsoleUtils().getOutputLevel() >= ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN & results != null && !appliedRules.isEmpty()) { final StringBuilder rulesStr = new StringBuilder(); for (final Rule r : appliedRules) { rulesStr.append(r.getRuleName()); rulesStr.append(','); } if (rulesStr.length() > 0) { rulesStr.setLength(rulesStr.length() - 1); } WarpPI.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", currentAcceptedRules.toString(), "Applied rules: " + rulesStr); } return results; }
Example 15
Source File: BlockDivision.java From WarpPI with Apache License 2.0 | 4 votes |
@Override public ObjectArrayList<Block> getInnerBlocks() { ObjectArrayList<Block> output = containerUp.getContent(); output.addAll(containerDown.getContent()); return output; }
Example 16
Source File: BlockLogarithm.java From WarpPI with Apache License 2.0 | 4 votes |
@Override public ObjectArrayList<Block> getInnerBlocks() { ObjectArrayList<Block> output = containerBase.getContent(); output.addAll(containerNumber.getContent()); return output; }
Example 17
Source File: FunctionOperator.java From WarpPI with Apache License 2.0 | 4 votes |
@Override public final ObjectArrayList<Function> simplify(final Rule rule) throws Error, InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } final ObjectArrayList<Function> simplifiedParam1 = parameter1.simplify(rule); final ObjectArrayList<Function> simplifiedParam2 = parameter2.simplify(rule); try { if (simplifiedParam1 == null & simplifiedParam2 == null) { return rule.execute(this); } } catch (final Exception e) { final Error err = new Error(Errors.ERROR, "Error while executing rule '" + rule.getRuleName() + "'!\n" + e.getMessage()); err.initCause(e); throw err; } if (Thread.interrupted()) { throw new InterruptedException(); } final ObjectArrayList<Function> result = new ObjectArrayList<>(); final ObjectArrayList<Function> l1 = new ObjectArrayList<>(); final ObjectArrayList<Function> l2 = new ObjectArrayList<>(); if (Thread.interrupted()) { throw new InterruptedException(); } if (simplifiedParam1 == null) { l1.add(parameter1); } else { if (Thread.interrupted()) { throw new InterruptedException(); } l1.addAll(simplifiedParam1); } if (Thread.interrupted()) { throw new InterruptedException(); } if (simplifiedParam2 == null) { l2.add(parameter2); } else { if (Thread.interrupted()) { throw new InterruptedException(); } l2.addAll(simplifiedParam2); } final Function[][] results = Utils.joinFunctionsResults(l1, l2); for (final Function[] f : results) { result.add(setParameter1(f[0]).setParameter2(f[1])); } return result; }
Example 18
Source File: AnnotatedPhrase.java From minie with GNU General Public License v3.0 | 4 votes |
/** * When there are already annotated quantities, merge the ones which are right next to each other in a sequence. */ public void mergeAdjacentQuantities(){ // Reusable variables ObjectArrayList<IndexedWord> mergedQuantityWords = new ObjectArrayList<>(); ObjectArrayList<SemanticGraphEdge> mergedEdges = new ObjectArrayList<>(); ObjectArrayList<String> qIds = new ObjectArrayList<>(); ObjectOpenHashSet<IndexedWord> remWords = new ObjectOpenHashSet<>(); ObjectArrayList<IndexedWord> matches; // Token regex pattern and matcher TokenSequencePattern tPattern = TokenSequencePattern.compile(REGEX.ADJACENT_QUANTITIES); TokenSequenceMatcher tMatcher = tPattern.getMatcher(this.getWordCoreLabelList()); // Merge the quantities when matched while (tMatcher.find()){ // Get the merged words and edges from the quantities that should be merged. matches = CoreNLPUtils.getWordListFromCoreMapList(tMatcher.groupNodes()); for (int i = 0; i < matches.size(); i++){ // If it has preposition bridging two quantities, add it to the mergedQuantityWords list if (matches.get(i).tag().equals(POS_TAG.IN)) { mergedQuantityWords.add(matches.get(1)); remWords.add(matches.get(1)); } // Merge the adjacent quantities for (Quantity q: this.getQuantities()){ if ((Quantity.ST_QUANT + CHARACTER.UNDERSCORE + q.getId()).equals(matches.get(i).word())){ qIds.add(q.getId()); mergedQuantityWords.addAll(q.getQuantityWords()); mergedEdges.addAll(q.getQuantityEdges()); } } } // Add all the words and edges from the merged quantities to the first one and remove the rest for (int i = 0; i < this.getWordList().size(); i++){ if (this.getWordList().get(i).word().equals(Quantity.ST_QUANT + CHARACTER.UNDERSCORE + qIds.get(0))){ if (this.getQuantityByID(qIds.get(0)) != null){ this.getQuantityByID(qIds.get(0)).setWords(mergedQuantityWords); this.getQuantityByID(qIds.get(0)).setEdges(mergedEdges); for (int j = 1; j < qIds.size(); j++){ this.removeQuantityByID(qIds.get(j)); for (int k = i; k < this.getWordList().size(); k++){ if (this.getWordList().get(k).word().equals(Quantity.ST_QUANT + CHARACTER.UNDERSCORE + qIds.get(j))){ remWords.add(this.getWordList().get(k)); continue; } } } break; } } } // Remove and clear this.removeWordsFromList(remWords); remWords.clear(); qIds.clear(); } }
Example 19
Source File: Utils.java From minie with GNU General Public License v3.0 | 4 votes |
/** * formats an annotated proposition in Ollie style * @param proposition: annotated proposition to format * @return formatted proposition */ public static String formatProposition(AnnotatedProposition proposition) { // First the triple StringJoiner tripleJoiner = new StringJoiner(";", "(", ")"); String subject = proposition.getSubject().toString(); if (!subject.isEmpty()) tripleJoiner.add(subject); String relation = proposition.getRelation().toString(); if (!relation.isEmpty()) tripleJoiner.add(relation); String object = proposition.getObject().toString(); if (!object.isEmpty()) tripleJoiner.add(object); // Factuality String factualityString = ""; String factuality = formatFactuality(proposition.getPolarity().getType().toString(), proposition.getModality().getModalityType().toString()); if (!factuality.isEmpty()) factualityString = String.format("[factuality=%s]", factuality); /*String clausalModifier = proposition.getClauseModifier().toString(); if (!clausalModifier.isEmpty()) annotations.add("clausalModifier=" + clausalModifier);*/ // Attribution Attribution attribution = proposition.getAttribution(); String attributionString = ""; // Only process the attribution if there is a attribution phrase TODO is this suitable? if (attribution != null && attribution.getAttributionPhrase() != null) { StringJoiner attributionAttributesJoiner = new StringJoiner(";"); String attributionPhrase = attribution.getAttributionPhrase().toString(); if (!attributionPhrase.isEmpty()) attributionAttributesJoiner.add("phrase:" + attributionPhrase); String attributionPredicate = attribution.getPredicateVerb().toString(); if (!attributionPredicate.isEmpty()) attributionAttributesJoiner.add("predicate:" + attributionPredicate); String attributionFactuality = formatFactuality(attribution.getPolarityType().toString(), attribution.getModalityType().toString()); if (!attributionFactuality.isEmpty()) attributionAttributesJoiner.add("factuality:" + attributionFactuality); attributionString = String.format("[attribution=%s]", attributionAttributesJoiner.toString()); } // Quantities StringJoiner quantityJoiner = new StringJoiner(";"); String quantitiesString = ""; ObjectArrayList<Quantity> quantities = new ObjectArrayList<Quantity>(); // Add all quantities quantities.addAll(proposition.getSubject().getQuantities()); quantities.addAll(proposition.getRelation().getQuantities()); quantities.addAll(proposition.getObject().getQuantities()); if (quantities.size() > 0) { for (Quantity q : quantities) { StringJoiner quantityPhrase = new StringJoiner(" "); for (IndexedWord w : q.getQuantityWords()) { quantityPhrase.add(w.originalText()); } quantityJoiner.add(String.format("QUANT_%s:%s", q.getId(),quantityPhrase.toString())); } quantitiesString = String.format("[quantities=%s]", quantityJoiner.toString()); } String output = tripleJoiner.toString() + factualityString + attributionString + quantitiesString; return output; }