Spaces:
Running
Running
File size: 6,211 Bytes
b110593 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
// _ _
// __ _____ __ ___ ___ __ _| |_ ___
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
// \ V V / __/ (_| |\ V /| | (_| | || __/
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
//
// Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
//
// CONTACT: [email protected]
//
package additional
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/tailor-inc/graphql"
)
func TestNearestNeighborsField(t *testing.T) {
t.Run("should generate nearestNeighbors argument properly", func(t *testing.T) {
// given
classname := "Class"
// when
nearestNeighbors := additionalNearestNeighborsField(classname)
// then
// the built graphQL field needs to support this structure:
// Type: {
// neighbors: {
// concept: "c1",
// distance: 0.8
// }
// }
assert.NotNil(t, nearestNeighbors)
assert.Equal(t, "ClassAdditionalNearestNeighbors", nearestNeighbors.Type.Name())
assert.NotNil(t, nearestNeighbors.Type)
nearestNeighborsObject, nearestNeighborsObjectOK := nearestNeighbors.Type.(*graphql.Object)
assert.True(t, nearestNeighborsObjectOK)
assert.Equal(t, 1, len(nearestNeighborsObject.Fields()))
neighbors, neighborsOK := nearestNeighborsObject.Fields()["neighbors"]
assert.True(t, neighborsOK)
neighborsList, neighborsListOK := neighbors.Type.(*graphql.List)
assert.True(t, neighborsListOK)
neighborsListObjects, neighborsListObjectsOK := neighborsList.OfType.(*graphql.Object)
assert.True(t, neighborsListObjectsOK)
assert.Equal(t, 2, len(neighborsListObjects.Fields()))
assert.NotNil(t, neighborsListObjects.Fields()["concept"])
assert.NotNil(t, neighborsListObjects.Fields()["distance"])
})
}
func TestFeatureProjectionField(t *testing.T) {
t.Run("should generate featureProjection argument properly", func(t *testing.T) {
// given
classname := "Class"
// when
featureProjection := additionalFeatureProjectionField(classname)
// then
// the built graphQL field needs to support this structure:
// Args: {
// algorithm: "a",
// dimensions: 1,
// learningRate: 2,
// iterations: 3,
// perplexity: 4
// }
// Type: {
// vector: [0, 1]
// }
assert.NotNil(t, featureProjection)
assert.Equal(t, "ClassAdditionalFeatureProjection", featureProjection.Type.Name())
assert.NotNil(t, featureProjection.Args)
assert.Equal(t, 5, len(featureProjection.Args))
assert.NotNil(t, featureProjection.Args["algorithm"])
assert.NotNil(t, featureProjection.Args["dimensions"])
assert.NotNil(t, featureProjection.Args["learningRate"])
assert.NotNil(t, featureProjection.Args["iterations"])
assert.NotNil(t, featureProjection.Args["perplexity"])
featureProjectionObject, featureProjectionObjectOK := featureProjection.Type.(*graphql.Object)
assert.True(t, featureProjectionObjectOK)
assert.Equal(t, 1, len(featureProjectionObject.Fields()))
assert.NotNil(t, featureProjectionObject.Fields()["vector"])
})
}
func TestSemanticPathField(t *testing.T) {
t.Run("should generate semanticPath argument properly", func(t *testing.T) {
// given
classname := "Class"
// when
semanticPath := additionalSemanticPathField(classname)
// then
// the built graphQL field needs to support this structure:
// Type: {
// path: [
// {
// concept: "c1",
// distanceToQuery: 0.1,
// distanceToResult: 0.2,
// distanceToNext: 0.3,
// distanceToPrevious: 0.4,
// }
// }
assert.NotNil(t, semanticPath)
assert.Equal(t, "ClassAdditionalSemanticPath", semanticPath.Type.Name())
semanticPathObject, semanticPathObjectOK := semanticPath.Type.(*graphql.Object)
assert.True(t, semanticPathObjectOK)
assert.Equal(t, 1, len(semanticPathObject.Fields()))
assert.NotNil(t, semanticPathObject.Fields()["path"])
semanticPathObjectList, semanticPathObjectListOK := semanticPathObject.Fields()["path"].Type.(*graphql.List)
assert.True(t, semanticPathObjectListOK)
semanticPathObjectListObjects, semanticPathObjectListOK := semanticPathObjectList.OfType.(*graphql.Object)
assert.True(t, semanticPathObjectListOK)
assert.Equal(t, 5, len(semanticPathObjectListObjects.Fields()))
assert.NotNil(t, semanticPathObjectListObjects.Fields()["concept"])
assert.NotNil(t, semanticPathObjectListObjects.Fields()["distanceToQuery"])
assert.NotNil(t, semanticPathObjectListObjects.Fields()["distanceToResult"])
assert.NotNil(t, semanticPathObjectListObjects.Fields()["distanceToNext"])
assert.NotNil(t, semanticPathObjectListObjects.Fields()["distanceToPrevious"])
})
}
func TestNearestInterpretationField(t *testing.T) {
t.Run("should generate interpretation argument properly", func(t *testing.T) {
// given
classname := "Class"
// when
interpretation := additionalInterpretationField(classname)
// then
// the built graphQL field needs to support this structure:
// Type: {
// source: [
// {
// concept: "c1",
// weight: 0.1,
// occurrence: 0.2,
// }
// }
assert.NotNil(t, interpretation)
assert.Equal(t, "ClassAdditionalInterpretation", interpretation.Type.Name())
interpretationObject, interpretationObjectOK := interpretation.Type.(*graphql.Object)
assert.True(t, interpretationObjectOK)
assert.Equal(t, 1, len(interpretationObject.Fields()))
assert.NotNil(t, interpretationObject.Fields()["source"])
interpretationObjectList, interpretationObjectListOK := interpretationObject.Fields()["source"].Type.(*graphql.List)
assert.True(t, interpretationObjectListOK)
interpretationObjectListObjects, interpretationObjectListObjectsOK := interpretationObjectList.OfType.(*graphql.Object)
assert.True(t, interpretationObjectListObjectsOK)
assert.Equal(t, 3, len(interpretationObjectListObjects.Fields()))
assert.NotNil(t, interpretationObjectListObjects.Fields()["concept"])
assert.NotNil(t, interpretationObjectListObjects.Fields()["weight"])
assert.NotNil(t, interpretationObjectListObjects.Fields()["occurrence"])
})
}
|