// ToPredicate converts the node found by the lexer and converts it into a
// BadWolf predicate.
193460
func ToPredicate(ce ConsumedElement) (*predicate.Predicate, error) {
	if ce.IsSymbol() {
		return nil, fmt.Errorf("semantic.ToPredicate cannot convert symbol %v to a predicate", ce)
	}
	tkn := ce.Token()
	if tkn.Type != lexer.ItemPredicate {
		return nil, fmt.Errorf("semantic.ToPredicate cannot convert token type %s to a predicate", tkn.Type)
	}
	return predicate.Parse(tkn.Text)
}
689040
func (d *Decoder) RootElement() error {
	for {
		err := d.next()
		if err != nil {
			return err
		}

		if d.TokenType == StartElement {
			break
		}

		if d.TokenType == EndXML {
			return fmt.Errorf("xmlp.StartRoot: failed finding root element before reaching XML last element")
		}
	}
	return nil
}
422094
func (iamRes *IAMResourceBuilder) ToPrivilege() sparta.IAMRolePrivilege {
	return sparta.IAMRolePrivilege{
		Actions:  iamRes.builder.apiCalls,
		Resource: gocf.Join("", iamRes.resourceParts...),
	}
}
872246
func (t *Triple) Reify() ([]*Triple, *node.Node, error) {
	// Function that creates the proper reification predicates.
	rp := func(id string, p *predicate.Predicate) (*predicate.Predicate, error) {
		if p.Type() == predicate.Temporal {
			ta, _ := p.TimeAnchor()
			return predicate.NewTemporal(id, *ta)
		}
		return predicate.NewImmutable(id)
	}
	b := node.NewBlankNode()
	s, err := rp("_subject", t.p)
	if err != nil {
		return nil, nil, err
	}
	ts, _ := New(b, s, NewNodeObject(t.s))
	p, err := rp("_predicate", t.p)
	if err != nil {
		return nil, nil, err
	}
	tp, _ := New(b, p, NewPredicateObject(t.p))
	var to *Triple
	if t.o.l != nil {
		o, err := rp("_object", t.p)
		if err != nil {
			return nil, nil, err
		}
		to, _ = New(b, o, NewLiteralObject(t.o.l))
	}
	if t.o.n != nil {
		o, err := rp("_object", t.p)
		if err != nil {
			return nil, nil, err
		}
		to, _ = New(b, o, NewNodeObject(t.o.n))
	}
	if t.o.p != nil {
		o, err := rp("_object", t.p)
		if err != nil {
			return nil, nil, err
		}
		to, _ = New(b, o, NewPredicateObject(t.o.p))
	}

	return []*Triple{t, ts, tp, to}, b, nil
}
704032
func (d *Dataset) Top(name string, k int, sortOption *SortOption) *Dataset {
	ret := d.LocalTop(name, k, sortOption)
	if len(d.Shards) > 1 {
		ret = ret.MergeSortedTo(name, 1).LocalLimit(name, k, 0)
	}
	return ret
}
147578
func NewStopwords() StopWords {
	cachedStopWords := make(map[string]*set.Set)
	for lang, stopwords := range sw {
		lines := strings.Split(stopwords, "\n")
		cachedStopWords[lang] = set.New(set.ThreadSafe).(*set.Set)
		for _, line := range lines {
			if strings.HasPrefix(line, "#") {
				continue
			}
			line = strings.TrimSpace(line)
			cachedStopWords[lang].Add(line)
		}
	}
	return StopWords{
		cachedStopWords: cachedStopWords,
	}
}
1100007
func Find(top *Node, expr string) []*Node {
	exp, err := xpath.Compile(expr)
	if err != nil {
		panic(err)
	}
	t := exp.Select(CreateXPathNavigator(top))
	var elems []*Node
	for t.MoveNext() {
		elems = append(elems, getCurrentNode(t))
	}
	return elems
}
263598
func (f *HumanPrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error) {
	if len(outputFormat) > 0 && outputFormat != "wide" {
		return nil, genericclioptions.NoCompatiblePrinterError{Options: f, AllowedFormats: f.AllowedFormats()}
	}

	showKind := false
	if f.ShowKind != nil {
		showKind = *f.ShowKind
	}

	showLabels := false
	if f.ShowLabels != nil {
		showLabels = *f.ShowLabels
	}

	columnLabels := []string{}
	if f.ColumnLabels != nil {
		columnLabels = *f.ColumnLabels
	}

	p := printers.NewTablePrinter(printers.PrintOptions{
		Kind:          f.Kind,
		WithKind:      showKind,
		NoHeaders:     f.NoHeaders,
		Wide:          outputFormat == "wide",
		WithNamespace: f.WithNamespace,
		ColumnLabels:  columnLabels,
		ShowLabels:    showLabels,
	})
	printersinternal.AddHandlers(p)

	// TODO(juanvallejo): handle sorting here

	return p, nil
}
1107949
func (s *Server) ListDir(ctx context.Context, dirPath string, full bool) ([]topo.DirEntry, error) {
	nodePath := path.Join(s.root, dirPath) + "/"
	if nodePath == "//" {
		// Special case where s.root is "/", dirPath is empty,
		// we would end up with "//". in that case, we want "/".
		nodePath = "/"
	}
	resp, err := s.cli.Get(ctx, nodePath,
		clientv3.WithPrefix(),
		clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend),
		clientv3.WithKeysOnly())
	if err != nil {
		return nil, convertError(err, dirPath)
	}
	if len(resp.Kvs) == 0 {
		// No key starts with this prefix, means the directory
		// doesn't exist.
		return nil, topo.NewError(topo.NoNode, nodePath)
	}

	prefixLen := len(nodePath)
	var result []topo.DirEntry
	for _, ev := range resp.Kvs {
		p := string(ev.Key)

		// Remove the prefix, base path.
		if !strings.HasPrefix(p, nodePath) {
			return nil, ErrBadResponse
		}
		p = p[prefixLen:]

		// Keep only the part until the first '/'.
		t := topo.TypeFile
		if i := strings.Index(p, "/"); i >= 0 {
			p = p[:i]
			t = topo.TypeDirectory
		}

		// Remove duplicates, add to list.
		if len(result) == 0 || result[len(result)-1].Name != p {
			e := topo.DirEntry{
				Name: p,
			}
			if full {
				e.Type = t
				if ev.Lease != 0 {
					// Only locks have a lease associated with them.
					e.Ephemeral = true
				}
			}
			result = append(result, e)
		}
	}

	return result, nil
}
703955
func (l *lexer) tokenize() {
	for l.state = lexData; l.state != nil; {
		l.state = l.state(l)
	}
}
541284
func getFirstCharsPrefix(tree *RegexTree) *Prefix {
	s := regexFcd{
		fcStack:  make([]regexFc, 32),
		intStack: make([]int, 32),
	}
	fc := s.regexFCFromRegexTree(tree)

	if fc == nil || fc.nullable || fc.cc.IsEmpty() {
		return nil
	}
	fcSet := fc.getFirstChars()
	return &Prefix{PrefixSet: fcSet, CaseInsensitive: fc.caseInsensitive}
}
1035482
func RegisterFitPredicate(name string, predicate predicates.FitPredicate) string {
	return RegisterFitPredicateFactory(name, func(PluginFactoryArgs) predicates.FitPredicate { return predicate })
}
897375
func (rs *Ruleset) Asciify(word string) string {
	for repl, regex := range lookalikes {
		word = regex.ReplaceAllString(word, repl)
	}
	return word
}
124699
func topsort(g Iterator, output bool) (order []int, acyclic bool) {
	indegree := make([]int, g.Order())
	for v := range indegree {
		g.Visit(v, func(w int, _ int64) (skip bool) {
			indegree[w]++
			return
		})
	}

	// Invariant: this queue holds all vertices with indegree 0.
	var queue []int
	for v, degree := range indegree {
		if degree == 0 {
			queue = append(queue, v)
		}
	}

	order = []int{}
	vertexCount := 0
	for len(queue) > 0 {
		v := queue[0]
		queue = queue[1:]
		if output {
			order = append(order, v)
		}
		vertexCount++
		g.Visit(v, func(w int, _ int64) (skip bool) {
			indegree[w]--
			if indegree[w] == 0 {
				queue = append(queue, w)
			}
			return
		})
	}
	if vertexCount != g.Order() {
		return
	}
	acyclic = true
	return
}
812133
func ByBuildConfigPredicate(labelValue string) PredicateFunc {
	return func(arg interface{}) bool {
		return hasBuildConfigAnnotation(arg.(buildv1.Build), buildapi.BuildConfigAnnotation, labelValue) ||
			hasBuildConfigLabel(arg.(buildv1.Build), buildapi.BuildConfigLabel, labelValue)
	}
}
569447
func (t *SimpleTokenizer) Tokenize(sentence string) []string {
	// is the tokenizer really the best place to be making
	// everything lowercase? is this really a sanitizaion func?
	return strings.Split(strings.ToLower(sentence), t.SplitOn)
}
276419
func (n *node) hasDuplicateSibling(key interface{}) bool {
	if n.parent == nil {
		return false
	}
	for _, sibling := range n.parent.children {
		if sibling == n {
			continue
		}
		if sibling.content.key() == key {
			return true
		}
	}
	return false
}