github.com/weaviate/weaviate@v1.24.6/modules/ner-transformers/additional/tokens/tokens_graphql_field_test.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 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/tailor-inc/graphql" 19 ) 20 21 func Test_additionalTokensField(t *testing.T) { 22 // given 23 tokenProvider := &TokenProvider{} 24 classname := "Class" 25 26 // when 27 tokens := tokenProvider.additionalTokensField(classname) 28 29 // then 30 // the built graphQL field needs to support this structure: 31 // Args: { 32 // "properties": ["summary"], 33 // "limit": 1, 34 // "distance": 0.7 35 // } 36 // Type: { 37 // tokens: { 38 // "property": "summary", 39 // "entity": "I-PER", 40 // "distance": 0.8, 41 // "word": "original word", 42 // "startPosition": 1, 43 // "endPosition": 2, 44 // } 45 // } 46 47 assert.NotNil(t, tokens) 48 assert.Equal(t, "ClassAdditionalTokens", tokens.Type.Name()) 49 assert.NotNil(t, tokens.Type) 50 tokensObjectList, tokensObjectListOK := tokens.Type.(*graphql.List) 51 assert.True(t, tokensObjectListOK) 52 tokensObject, tokensObjectOK := tokensObjectList.OfType.(*graphql.Object) 53 assert.True(t, tokensObjectOK) 54 assert.Equal(t, 7, len(tokensObject.Fields())) 55 assert.NotNil(t, tokensObject.Fields()["property"]) 56 assert.NotNil(t, tokensObject.Fields()["entity"]) 57 assert.NotNil(t, tokensObject.Fields()["certainty"]) 58 assert.NotNil(t, tokensObject.Fields()["distance"]) 59 assert.NotNil(t, tokensObject.Fields()["word"]) 60 assert.NotNil(t, tokensObject.Fields()["startPosition"]) 61 assert.NotNil(t, tokensObject.Fields()["endPosition"]) 62 63 assert.NotNil(t, tokens.Args) 64 assert.Equal(t, 4, len(tokens.Args)) 65 assert.NotNil(t, tokens.Args["certainty"]) 66 assert.NotNil(t, tokens.Args["distance"]) 67 assert.NotNil(t, tokens.Args["limit"]) 68 assert.NotNil(t, tokens.Args["properties"]) 69 }