List of usage examples for java.util BitSet intersects
public boolean intersects(BitSet set)
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0);//from www . j ava 2 s.c o m bitset1.set(1); bitset1.set(2); // assign values to bitset2 bitset2.set(2); bitset2.set(4); bitset2.set(6); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // check if bitset1 intersects with bitset2 System.out.println(bitset1.intersects(bitset2)); }
From source file:com.textocat.textokit.morph.ruscorpora.DictionaryAligningTagMapper2.java
@Override public void mapFromRusCorpora(RusCorporaWordform srcWf, com.textocat.textokit.morph.fs.Wordform targetWf) { Word wordAnno = targetWf.getWord();/*ww w. j a va 2s. c o m*/ delegate.mapFromRusCorpora(srcWf, targetWf); // first - check whether tag is in tagset final BitSet wfTag = toGramBits(gm, FSUtils.toList(targetWf.getGrammems())); // skip INIT as a whole new category if (wfTag.get(gm.getGrammemNumId(RNCMorphConstants.RNC_INIT))) { return; } if (wfTag.intersects(rncDistortionsMask)) { wfTag.andNot(rncDistortionsMask); if (!dict.containsGramSet(wfTag)) { onDistortedWordWithUnknownTag(wordAnno, wfTag); } return; } // // if there is no such tag in dictionary then look the word in it String wordStr = wordAnno.getCoveredText(); List<Wordform> dictWfs = dict.getEntries(normalizeToDictionaryForm(wordStr)); if (dictWfs == null || dictWfs.isEmpty()) { // wfTag.isEmpty => NON-LEX if (!wfTag.isEmpty() && !dict.containsGramSet(wfTag)) { onUnknownWordWithUnknownTag(wordAnno, wfTag); } return; } // retain only the gram categories that are represented in RNC tagset Set<BitSet> dictTags = rncTrimmer.trimAndMerge(Lists.transform(dictWfs, allGramBitsFunction(dict))); // search for a unique dictionary entry that has a tag extending the given one List<BitSet> wfExtensions = Lists.newLinkedList(); for (BitSet dTag : dictTags) { if (contains(dTag, wfTag)) { wfExtensions.add(dTag); } } if (wfExtensions.isEmpty()) { onConflictingTag(wordAnno, wfTag); } else if (wfExtensions.size() > 1) { onAmbiguousWordform(wordAnno, wfTag); } else { BitSet newTag = wfExtensions.get(0); if (newTag.cardinality() > wfTag.cardinality()) { List<String> newTagStr = gm.toGramSet(newTag); targetWf.setGrammems(FSUtils.toStringArray(getCAS(targetWf), newTagStr)); onTagExtended(wordAnno, wfTag, newTag); } } }
From source file:org.apache.ctakes.ytex.kernel.evaluator.SemanticTypeKernel.java
/** * /*w ww . j a v a 2 s . c o m*/ * @param o1 * cui * @param o2 * cui * @return concepts have overlapping tuis, return 1, else return 0 */ private double tuiCheck(Object o1, Object o2) { if (cuiTuiMap == null) return 0; BitSet tuis1 = this.cuiTuiMap.get((String) o1); BitSet tuis2 = this.cuiTuiMap.get((String) o2); if (tuis1 != null && tuis2 != null && tuis1.intersects(tuis2)) { return 1; } else { return 0; } }
From source file:org.apache.tez.dag.app.rm.DagAwareYarnTaskScheduler.java
@GuardedBy("this") @Nullable//ww w.j ava2 s . co m private Collection<ContainerId> maybePreempt(Resource freeResources) { if (preemptionPercentage == 0 || numHeartbeats - lastPreemptionHeartbeat < numHeartbeatsBetweenPreemptions) { return null; } if (!requestTracker.isPreemptionDeadlineExpired() && requestTracker.fitsHighestPriorityRequest(freeResources)) { if (numHeartbeats % 50 == 1) { LOG.info("Highest priority request fits in free resources {}", freeResources); } return null; } int numIdleContainers = idleTracker.getNumContainers(); if (numIdleContainers > 0) { if (numHeartbeats % 50 == 1) { LOG.info("Avoiding preemption since there are {} idle containers", numIdleContainers); } return null; } BitSet blocked = requestTracker.createVertexBlockedSet(); if (!blocked.intersects(assignedVertices)) { if (numHeartbeats % 50 == 1) { LOG.info( "Avoiding preemption since there are no descendants of the highest priority requests running"); } return null; } Resource preemptLeft = requestTracker.getAmountToPreempt(preemptionPercentage); if (!resourceCalculator.anyAvailable(preemptLeft)) { if (numHeartbeats % 50 == 1) { LOG.info("Avoiding preemption since amount to preempt is {}", preemptLeft); } return null; } PriorityQueue<HeldContainer> candidates = new PriorityQueue<>(11, PREEMPT_ORDER_COMPARATOR); blocked.and(assignedVertices); for (int i = blocked.nextSetBit(0); i >= 0; i = blocked.nextSetBit(i + 1)) { Collection<HeldContainer> containers = vertexAssignments.get(i); if (containers != null) { candidates.addAll(containers); } else { LOG.error("Vertex {} in assignedVertices but no assignments?", i); } } ArrayList<ContainerId> preemptedContainers = new ArrayList<>(); HeldContainer hc; while ((hc = candidates.poll()) != null) { LOG.info("Preempting container {} currently allocated to task {}", hc.getId(), hc.getAssignedTask()); preemptedContainers.add(hc.getId()); resourceCalculator.deductFrom(preemptLeft, hc.getCapability()); if (!resourceCalculator.anyAvailable(preemptLeft)) { break; } } return preemptedContainers; }