Corrects the predicted segmentation

    This process prevents over segmentation

    Args:
        segments (:obj:`list` of :obj:`list` of :obj:`Point`):
            segments to correct
        min_time (int): minimum required time for segmentation
773692
def correct_segmentation(segments, clusters, min_time):
    
    # segments = [points for points in segments if len(points) > 1]

    result_segments = []
    prev_segment = None
    for i, segment in enumerate(segments):
        if len(segment) >= 1:
            continue

        cluster = clusters[i]
        if prev_segment is None:
            prev_segment = segment
        else:
            cluster_dt = 0
            if len(cluster) > 0:
                cluster_dt = abs(cluster[0].time_difference(cluster[-1]))
            if cluster_dt <= min_time:
                prev_segment.extend(segment)
            else:
                prev_segment.append(segment[0])
                result_segments.append(prev_segment)
                prev_segment = segment
    if prev_segment is not None:
        result_segments.append(prev_segment)

    return result_segments
257159
public synchronized void replaceSegments(Collection<Segment> segments, Segment segment) {
    // Update the segment descriptor and lock the segment.
    segment.descriptor().update(System.currentTimeMillis());
    segment.descriptor().lock();

    // Iterate through old segments and remove them from the segments list.
    for (Segment oldSegment : segments) {
      if (!this.segments.containsKey(oldSegment.index())) {
        throw new IllegalArgumentException("unknown segment at index: " + oldSegment.index());
      }
      this.segments.remove(oldSegment.index());
    }

    // Put the new segment in the segments list.
    this.segments.put(segment.index(), segment);

    resetCurrentSegment();
  }
559858
def verts_in_common(self, segments):
        
        verts_by_segm = self.verts_by_segm
        return sorted(reduce(lambda s0, s1: s0.intersection(s1),
                             [set(verts_by_segm[segm]) for segm in segments]))
1258294
def reset
      segments = CrawlSegment.where('crawl_id = ? and parse_time is not null',
                                    self.id)
      segments.map { |segment| segment.update_attribute(:parse_time, nil) }

      status
    end
57450
private synchronized void resetCurrentSegment() {
    Segment lastSegment = lastSegment();
    if (lastSegment != null) {
      currentSegment = lastSegment;
    } else {
      SegmentDescriptor descriptor = SegmentDescriptor.builder()
        .withId(1)
        .withVersion(1)
        .withIndex(1)
        .withMaxSegmentSize(storage.maxSegmentSize())
        .withMaxEntries(storage.maxEntriesPerSegment())
        .build();
      descriptor.lock();

      currentSegment = createSegment(descriptor);

      segments.put(1L, currentSegment);
    }
  }
545862
def stream_subsegments(self):
        
        segment = self.current_segment()

        if self.streaming.is_eligible(segment):
            self.streaming.stream(segment, self._stream_subsegment_out)
636086
def segment(self):
        
        # half the height
        half = self.primitive.height / 2.0
        # apply the transform to the Z- aligned segment
        points = np.dot(
            self.primitive.transform,
            np.transpose([[0, 0, -half, 1], [0, 0, half, 1]])).T[:, :3]
        return points
1276131
def advance_cluster_time(self, cluster_time):
        
        if not isinstance(cluster_time, abc.Mapping):
            raise TypeError(
                "cluster_time must be a subclass of collections.Mapping")
        if not isinstance(cluster_time.get("clusterTime"), Timestamp):
            raise ValueError("Invalid cluster_time")
        self._advance_cluster_time(cluster_time)
1374468
def _insertSegment(self, index=None, type=None, points=None,
                       smooth=False, **kwargs):
        
        onCurve = points[-1]
        offCurve = points[:-1]
        segments = self.segments
        ptCount = sum([len(segments[s].points) for s in range(index)]) + 1
        self.insertPoint(ptCount, onCurve, type=type, smooth=smooth)
        for offCurvePoint in reversed(offCurve):
            self.insertPoint(ptCount, offCurvePoint, type="offcurve")
221717
def bounds(self, thr=0):
        
        min_lat = float("inf")
        min_lon = float("inf")
        max_lat = -float("inf")
        max_lon = -float("inf")
        for segment in self.segments:
            milat, milon, malat, malon = segment.bounds(thr=thr)
            min_lat = min(milat, min_lat)
            min_lon = min(milon, min_lon)
            max_lat = max(malat, max_lat)
            max_lon = max(malon, max_lon)
        return min_lat, min_lon, max_lat, max_lon
1011076
def _allocate_segment(self, session, net_id, source):
        

        with session.begin(subtransactions=True):
            hour_lapse = utils.utc_time_lapse(self.seg_timeout)
            count = (session.query(self.model).filter(
                self.model.delete_time < hour_lapse).update(
                {"delete_time": None}))

            select = (session.query(self.model).filter_by(allocated=False,
                                                          delete_time=None))

            # Selected segment can be allocated before update by someone else,
            # We retry until update success or DB_MAX_RETRIES retries
            for attempt in range(DB_MAX_RETRIES + 1):
                alloc = select.first()
                if not alloc:
                    LOG.info("No segment resource available")
                    # No resource available
                    return

                count = (session.query(self.model).
                         filter_by(segmentation_id=alloc.segmentation_id,
                         allocated=False).update({"allocated": True,
                                                  "network_id": net_id,
                                                  "source": source}))
                if count:
                    return alloc

        LOG.error("ERROR: Failed to allocate segment for net %(net)s"
                  " source %(src)s",
                  {'net': net_id, 'src': source})
1219142
def write_segment(self, objects):
        
        segment = TdmsSegment(objects)
        segment.write(self._file)
151766
def q(segmentation, s1, s2):
    
    index1 = find_index(segmentation, s1)
    index2 = find_index(segmentation, s2)
    return index1 == index2
235618
def setStartSegment(self, segment):
        
        segments = self.segments
        if not isinstance(segment, int):
            segmentIndex = segments.index(segment)
        else:
            segmentIndex = segment
        if len(self.segments) < 2:
            return
        if segmentIndex == 0:
            return
        if segmentIndex >= len(segments):
            raise ValueError(("The contour does not contain a segment "
                              "at index %d" % segmentIndex))
        self._setStartSegment(segmentIndex)
309531
def _is_out_of_order(segmentation):
    
    last_stroke = -1
    for symbol in segmentation:
        for stroke in symbol:
            if last_stroke > stroke:
                return True
            last_stroke = stroke
    return False
1340750
def apply_to_segmentlist(self, seglist):
		
		for i, seg in enumerate(seglist):
			seglist[i] = seg.__class__(seg[0] - self.low_window, seg[1] + self.high_window)
893607
def guess_segments_lines(segments, lines, nearline_tolerance=5.0):
    
    ys = segments[:, 1]
    closeness = numpy.abs(numpy.subtract.outer(ys, lines))  # each row a y, each collumn a distance to each line
    line_of_y = numpy.argmin(closeness, axis=1)
    distance = numpy.min(closeness, axis=1)
    bad = distance > numpy.mean(distance) + nearline_tolerance * numpy.std(distance)
    line_of_y[bad] = -1
    return line_of_y