// TermVectors returns information and statistics on terms in the fields
// of a particular document.
3083
func (c *Client) TermVectors(index, typ string) *TermvectorsService {
	builder := NewTermvectorsService(c)
	builder = builder.Index(index).Type(typ)
	return builder
}
773934
func ArrayComprehensionTerm(term *Term, body Body) *Term {
	return &Term{
		Value: &ArrayComprehension{
			Term: term,
			Body: body,
		},
	}
}
708779
func unitVectorAt(vec1 []float64, vec2 []float64) ([]float64, float64) {
	ret := diff(vec1, vec2)

	// If the coordinates aren't on top of each other we can normalize.
	if mag := magnitude(ret); mag > zeroThreshold {
		return mul(ret, 1.0/mag), mag
	}

	// Otherwise, just return a random unit vector.
	for i := range ret {
		ret[i] = rand.Float64() - 0.5
	}
	if mag := magnitude(ret); mag > zeroThreshold {
		return mul(ret, 1.0/mag), 0.0
	}

	// And finally just give up and make a unit vector along the first
	// dimension. This should be exceedingly rare.
	ret = make([]float64, len(ret))
	ret[0] = 1.0
	return ret, 0.0
}
694368
func (v PreciseVector) Vector() Vector {
	// The accuracy flag is ignored on these conversions back to float64.
	x, _ := v.X.Float64()
	y, _ := v.Y.Float64()
	z, _ := v.Z.Float64()
	return Vector{x, y, z}.Normalize()
}
596888
func (mc MongoClient) ValueDescriptors() ([]contract.ValueDescriptor, error) {
	return mapValueDescriptors(mc.getValueDescriptors(nil))
}
1322918
func newSeriesFileMetrics(labels prometheus.Labels) *seriesFileMetrics {
	names := []string{"series_file_partition"} // All metrics have this label.
	for k := range labels {
		names = append(names, k)
	}
	sort.Strings(names)

	totalCompactions := append(append([]string(nil), names...), "status")
	sort.Strings(totalCompactions)

	durationCompaction := append(append([]string(nil), names...), "component")
	sort.Strings(durationCompaction)

	return &seriesFileMetrics{
		SeriesCreated: prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: seriesFileSubsystem,
			Name:      "series_created",
			Help:      "Number of series created in Series File.",
		}, names),
		Series: prometheus.NewGaugeVec(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: seriesFileSubsystem,
			Name:      "series_total",
			Help:      "Number of series in Series File.",
		}, names),
		DiskSize: prometheus.NewGaugeVec(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: seriesFileSubsystem,
			Name:      "disk_bytes",
			Help:      "Number of bytes Series File is using on disk.",
		}, names),
		Segments: prometheus.NewGaugeVec(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: seriesFileSubsystem,
			Name:      "segments_total",
			Help:      "Number of segment files in Series File.",
		}, names),
		CompactionsActive: prometheus.NewGaugeVec(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: seriesFileSubsystem,
			Name:      "index_compactions_active",
			Help:      "Number of active index compactions.",
		}, durationCompaction),
		CompactionDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
			Namespace: namespace,
			Subsystem: seriesFileSubsystem,
			Name:      "index_compactions_duration_seconds",
			Help:      "Time taken for a successful compaction of index.",
			// 30 buckets spaced exponentially between 5s and ~53 minutes.
			Buckets: prometheus.ExponentialBuckets(5.0, 1.25, 30),
		}, durationCompaction),
		Compactions: prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: seriesFileSubsystem,
			Name:      "compactions_total",
			Help:      "Number of compactions.",
		}, totalCompactions),
	}
}
1127805
func (t *Term) DTR() (bool, error) {
	var status int
	err := termios.Tiocmget(uintptr(t.fd), &status)
	return status&syscall.TIOCM_DTR == syscall.TIOCM_DTR, err
}
937128
func (_class VMGuestMetricsClass) GetAllRecords(sessionID SessionRef) (_retval map[VMGuestMetricsRef]VMGuestMetricsRecord, _err error) {
	_method := "VM_guest_metrics.get_all_records"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg)
	if _err != nil {
		return
	}
	_retval, _err = convertVMGuestMetricsRefToVMGuestMetricsRecordMapToGo(_method + " -> ", _result.Value)
	return
}
205234
func convertTermList(l []interface{}) termsList {
	if len(l) == 0 {
		return nil
	}

	terms := make(termsList, len(l))
	for i, v := range l {
		terms[i] = Expr(v)
	}

	return terms
}
635863
func (a Aggregations) Terms(name string) (*AggregationBucketKeyItems, bool) {
	if raw, found := a[name]; found {
		agg := new(AggregationBucketKeyItems)
		if raw == nil {
			return agg, true
		}
		if err := json.Unmarshal(raw, agg); err == nil {
			return agg, true
		}
	}
	return nil, false
}
676888
func (fs *TermvectorsFilterSettings) MaxTermFreq(value int64) *TermvectorsFilterSettings {
	fs.maxTermFreq = &value
	return fs
}
666962
func NewRawFeatureVector(bits ...FeatureBit) *RawFeatureVector {
	fv := &RawFeatureVector{features: make(map[FeatureBit]bool)}
	for _, bit := range bits {
		fv.Set(bit)
	}
	return fv
}
383905
func (t *TFIDF) TFIDF(word string, sentence string) float64 {
	sentence, _, _ = transform.String(t.sanitize, sentence)
	document := t.Tokenizer.Tokenize(sentence)

	return t.TermFrequency(word, document) * t.InverseDocumentFrequency(word)
}
1107387
func splitTerms(fieldSelector string) []string {
	if len(fieldSelector) == 0 {
		return nil
	}

	terms := make([]string, 0, 1)
	startIndex := 0
	inSlash := false
	for i, c := range fieldSelector {
		switch {
		case inSlash:
			inSlash = false
		case c == '\\':
			inSlash = true
		case c == ',':
			terms = append(terms, fieldSelector[startIndex:i])
			startIndex = i + 1
		}
	}

	terms = append(terms, fieldSelector[startIndex:])

	return terms
}
83479
func matrixSubVector(mat, vec *mat.Dense) *mat.Dense {
	rowsm, colsm := mat.Dims()
	_, colsv := vec.Dims()
	if colsv != colsm {
		panic("Error in dimension")
	}
	for i := 0; i < rowsm; i++ {
		for j := 0; j < colsm; j++ {
			mat.Set(i, j, (mat.At(i, j) - vec.At(0, j)))
		}
	}
	return mat
}
902185
func (s *SearchSource) DocvalueFields(docvalueFields ...string) *SearchSource {
	for _, f := range docvalueFields {
		s.docvalueFields = append(s.docvalueFields, DocvalueField{Field: f})
	}
	return s
}
398742
func (p *Parser) parseDimensions() (Dimensions, error) {
	// If the next token is not GROUP then exit.
	if tok, _, _ := p.ScanIgnoreWhitespace(); tok != GROUP {
		p.Unscan()
		return nil, nil
	}

	// Now the next token should be "BY".
	if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != BY {
		return nil, newParseError(tokstr(tok, lit), []string{"BY"}, pos)
	}

	var dimensions Dimensions
	for {
		// Parse the dimension.
		d, err := p.parseDimension()
		if err != nil {
			return nil, err
		}

		// Add new dimension.
		dimensions = append(dimensions, d)

		// If there's not a comma next then stop parsing dimensions.
		if tok, _, _ := p.Scan(); tok != COMMA {
			p.Unscan()
			break
		}
	}
	return dimensions, nil
}