Query for intersections of terms in two lists

        Return a list of intersection result objects with keys:
         - x : term from x
         - y : term from y
         - c : count of intersection
         - j : jaccard score
109
def query_intersections(self, x_terms=None, y_terms=None, symmetric=False):
        
        if x_terms is None:
            x_terms = []
        if y_terms is None:
            y_terms = []
        xset = set(x_terms)
        yset = set(y_terms)
        zset = xset.union(yset)

        # first built map of gene->termClosure.
        # this could be calculated ahead of time for all g,
        # but this may be space-expensive. TODO: benchmark
        gmap={}
        for z in zset:
            gmap[z] = []
        for subj in self.subjects:
            ancs = self.inferred_types(subj)
            for a in ancs.intersection(zset):
                gmap[a].append(subj)
        for z in zset:
            gmap[z] = set(gmap[z])
        ilist = []
        for x in x_terms:
            for y in y_terms:
                if not symmetric or x<y:
                    shared = gmap[x].intersection(gmap[y])
                    union = gmap[x].union(gmap[y])
                    j = 0
                    if len(union)>0:
                        j = len(shared) / len(union)
                    ilist.append({'x':x,'y':y,'shared':shared, 'c':len(shared), 'j':j})
        return ilist
1119698
def dims_intersect(self):
        
        return set.intersection(*map(
            set, (getattr(arr, 'dims_intersect', arr.dims) for arr in self)))
348010
function intersects (data, p1, q1, p2, q2) {
  return orient(data, p1, q1, p2) !== orient(data, p1, q1, q2) &&
    orient(data, p2, q2, p1) !== orient(data, p2, q2, q1)
}
359717
def search_overlap(self, point_list):
        
        result = set()
        for j in point_list:
            self.search_point(j, result)
        return result
1345230
public void intersection(Formats other, Formats intersection) {
        intersection.list.clear();
        for (Format f1 : list) {
            for (Format f2 : other.list) {
                if (f1.matches(f2)) intersection.list.add(f2);
            }
        }
    }
48652
def intersection(self, other):
        
        startopen = other.startopen if self.start is None \
            else self.startopen if other.start is None \
            else other.startopen if self.start < other.start \
            else self.startopen if self.start > other.start \
            else (self.startopen or other.startopen)
        endopen = other.endopen if self.end is None \
            else self.endopen if other.end is None \
            else other.endopen if self.end > other.end \
            else self.endopen if self.end < other.end \
            else (self.endopen or other.endopen)

        new_start = self.start if other.start is None \
            else other.start if self.start is None \
            else max(self.start, other.start)
        new_end = self.end if other.end is None \
            else other.end if self.end is None \
            else min(self.end, other.end)

        interval = INTERVAL_LOOKUP[(startopen, endopen)]

        return DateRange(new_start, new_end, interval)
566796
def intersect_4(self, second, third, fourth):
    
    self.intersection(second)
    self.intersection(third)
    self.intersection(fourth)
    self.coalesce()
    return len(self)
1334674
private List<Period> _Intersect( List<Period> periods1, List<Period> periods2 )
	{
		List<Period> result = new ArrayList<Period>();

		int count1 = periods1.size();
		int count2 = periods2.size();

		int i = 0;
		int j = 0;

		while( i < count1 && j < count2 )
		{
			// one of the periods begins after the end of the other
			if( periods1.get( i ).getFrom().compareTo( periods2.get( j ).getTo() ) > 0 )
			{ // period 1 begins after period 2 finishes => period2 is
				// eliminated !
				j++;
			}
			else if( periods2.get( j ).getFrom().compareTo( periods1.get( i ).getTo() ) > 0 )
			{ // period 2 begins after end of period 1 => period 1 is eliminated
				// !
				i++;
			}

			// after that test, we can assume there is a non-void intersection
			else
			{
				// result[] = array( max($periods1[$i][0],$periods2[$j][0]),
				// min($periods1[$i][1],$periods2[$j][1]) );
				result.add( new Period( CalendarFunctions.max_date( periods1.get( i ).getFrom(), periods2.get( j ).getFrom() ), CalendarFunctions.min_date( periods1.get( i ).getTo(), periods2.get( j ).getTo() ) ) );

				if( periods1.get( i ).getTo().compareTo( periods2.get( j ).getTo() ) > 0 )
					j++;
				else
					i++;
			}
		}

		return result;
	}
493534
def intersection(self,other):
        
        if self.bounds[0] < other.bounds[0]:
            i1,i2 = self,other
        else:
            i2,i1 = self,other

        if self.is_disjoint(other):
            return Interval((1,0),(True,True))

        bounds = [None,None]
        included = [None,None]
        #sets are not disjoint, so i2.bounds[0] in i1:
        bounds[0] = i2.bounds[0]
        included[0] = i2.included[0]

        if i2.bounds[1] in i1:
            bounds[1] = i2.bounds[1]
            included[1] = i2.included[1]
        else:
            bounds[1] = i1.bounds[1]
            included[1] = i1.included[1]

        return Interval(bounds,included)
1146942
private static List<Term> intersectIgnorePosition(
            List<List<Term>> termsToIntersect) {
        if (termsToIntersect.isEmpty()) {
            return Collections.emptyList();
        }
        List<Term> termsUnderConsideration = new ArrayList<Term>(termsToIntersect.get(0));
        for (int i = 1; i < termsToIntersect.size(); i++) {
            List<Term> currentRoundTerms = termsToIntersect.get(i);
            List<Term> termsStillJustified = new ArrayList<Term>();
            for (Term term : termsUnderConsideration) {
                if (containsIgnorePosition(currentRoundTerms, term)) {
                    termsStillJustified.add(term);
                }
            }
            termsUnderConsideration = termsStillJustified;
        }
        return termsUnderConsideration;
    }
1119220
public static <E> Counter<E> intersection(Counter<E> c1, Counter<E> c2) {
    Counter<E> result = c1.getFactory().create();
    for (E key : Sets.union(c1.keySet(), c2.keySet())) {
      double count1 = c1.getCount(key);
      double count2 = c2.getCount(key);
      double minCount = (count1 < count2 ? count1 : count2);
      if (minCount > 0) {
        result.setCount(key, minCount);
      }
    }
    return result;
  }
711441
def intersection(self, other):
        
        if isinstance(other, self.__class__):
            return self.client.sinter([self.name, other.name])
        else:
            return self._as_set().intersection(other)
115543
public static <T> List<T> intersection(List<T> arr1, List<T> arr2) {
        return intersection(arr1, 0, arr1.size(), arr2, 0, arr2.size());
    }
824022
function intersection(arr) {
        var arrs = slice(arguments, 1),
            result = filter(unique(arr), function(needle){
                return every(arrs, function(haystack){
                    return contains(haystack, needle);
                });
            });
        return result;
    }
1072695
def compute_jaccard_index(x_set, y_set):
    
    if not x_set or not y_set:
        return 0.0

    intersection_cardinal = len(x_set & y_set)
    union_cardinal = len(x_set | y_set)

    return intersection_cardinal / float(union_cardinal)
838541
def intersect(self, range_):
        self.solver.intersection_broad_tests_count += 1

        """"""
        if range_.is_any():
            return self

        if self.solver.optimised:
            if range_ in self.been_intersected_with:
                return self

        if self.pr:
            self.pr.passive("intersecting %s wrt range '%s'...", self, range_)

        self.solver.intersection_tests_count += 1

        with self.solver.timed(self.solver.intersection_time):
            # this is faster than iter_intersecting :(
            entries = [x for x in self.entries if x.version in range_]

        if not entries:
            return None
        elif len(entries) < len(self.entries):
            copy_ = self._copy(entries)
            copy_.been_intersected_with.add(range_)
            return copy_
        else:
            self.been_intersected_with.add(range_)
            return self
552823
@SafeVarargs
	public static <T> Collection<T> intersection(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls) {
		Collection<T> intersection = intersection(coll1, coll2);
		if (isEmpty(intersection)) {
			return intersection;
		}
		for (Collection<T> coll : otherColls) {
			intersection = intersection(intersection, coll);
			if (isEmpty(intersection)) {
				return intersection;
			}
		}
		return intersection;
	}