github.com/weaviate/weaviate@v1.24.6/modules/ner-transformers/additional/tokens/tokens.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package tokens
    13  
    14  import (
    15  	"context"
    16  	"errors"
    17  
    18  	"github.com/weaviate/weaviate/entities/moduletools"
    19  
    20  	"github.com/tailor-inc/graphql"
    21  	"github.com/tailor-inc/graphql/language/ast"
    22  	"github.com/weaviate/weaviate/entities/search"
    23  	"github.com/weaviate/weaviate/modules/ner-transformers/ent"
    24  )
    25  
    26  type nerClient interface {
    27  	GetTokens(ctx context.Context, property, text string) ([]ent.TokenResult, error)
    28  }
    29  
    30  type TokenProvider struct {
    31  	ner nerClient
    32  }
    33  
    34  func New(ner nerClient) *TokenProvider {
    35  	return &TokenProvider{ner}
    36  }
    37  
    38  func (p *TokenProvider) AdditionalPropertyDefaultValue() interface{} {
    39  	return &Params{}
    40  }
    41  
    42  func (p *TokenProvider) ExtractAdditionalFn(param []*ast.Argument) interface{} {
    43  	return p.parseTokenArguments(param)
    44  }
    45  
    46  func (p *TokenProvider) AdditionalFieldFn(classname string) *graphql.Field {
    47  	return p.additionalTokensField(classname)
    48  }
    49  
    50  func (p *TokenProvider) AdditionalPropertyFn(ctx context.Context,
    51  	in []search.Result, params interface{}, limit *int,
    52  	argumentModuleParams map[string]interface{}, cfg moduletools.ClassConfig,
    53  ) ([]search.Result, error) {
    54  	if parameters, ok := params.(*Params); ok {
    55  		return p.findTokens(ctx, in, parameters)
    56  	}
    57  	return nil, errors.New("wrong parameters")
    58  }