github.com/weaviate/weaviate@v1.24.6/usecases/classification/schema_for_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 classification 13 14 import ( 15 "fmt" 16 17 "github.com/go-openapi/strfmt" 18 "github.com/weaviate/weaviate/entities/models" 19 "github.com/weaviate/weaviate/entities/schema" 20 "github.com/weaviate/weaviate/entities/search" 21 ) 22 23 func testSchema() schema.Schema { 24 return schema.Schema{ 25 Objects: &models.Schema{ 26 Classes: []*models.Class{ 27 { 28 Class: "ExactCategory", 29 }, 30 { 31 Class: "MainCategory", 32 }, 33 { 34 Class: "Article", 35 Properties: []*models.Property{ 36 { 37 Name: "description", 38 DataType: []string{string(schema.DataTypeText)}, 39 }, 40 { 41 Name: "name", 42 DataType: schema.DataTypeText.PropString(), 43 Tokenization: models.PropertyTokenizationWhitespace, 44 }, 45 { 46 Name: "exactCategory", 47 DataType: []string{"ExactCategory"}, 48 }, 49 { 50 Name: "mainCategory", 51 DataType: []string{"MainCategory"}, 52 }, 53 { 54 Name: "categories", 55 DataType: []string{"ExactCategory"}, 56 }, 57 { 58 Name: "anyCategory", 59 DataType: []string{"MainCategory", "ExactCategory"}, 60 }, 61 { 62 Name: "words", 63 DataType: schema.DataTypeInt.PropString(), 64 }, 65 }, 66 }, 67 }, 68 }, 69 } 70 } 71 72 // vector position close to [1,0,0] means -> politics, [0,1,0] means -> society, [0, 0, 1] -> food&drink 73 func testDataToBeClassified() search.Results { 74 return search.Results{ 75 search.Result{ 76 ID: "75ba35af-6a08-40ae-b442-3bec69b355f9", 77 ClassName: "Article", 78 Vector: []float32{0.78, 0, 0}, 79 Schema: map[string]interface{}{ 80 "description": "Barack Obama is a former US president", 81 }, 82 }, 83 search.Result{ 84 ID: "f850439a-d3cd-4f17-8fbf-5a64405645cd", 85 ClassName: "Article", 86 Vector: []float32{0.90, 0, 0}, 87 Schema: map[string]interface{}{ 88 "description": "Michelle Obama is Barack Obamas wife", 89 }, 90 }, 91 search.Result{ 92 ID: "a2bbcbdc-76e1-477d-9e72-a6d2cfb50109", 93 ClassName: "Article", 94 Vector: []float32{0, 0.78, 0}, 95 Schema: map[string]interface{}{ 96 "description": "Johnny Depp is an actor", 97 }, 98 }, 99 search.Result{ 100 ID: "069410c3-4b9e-4f68-8034-32a066cb7997", 101 ClassName: "Article", 102 Vector: []float32{0, 0.90, 0}, 103 Schema: map[string]interface{}{ 104 "description": "Brad Pitt starred in a Quentin Tarantino movie", 105 }, 106 }, 107 search.Result{ 108 ID: "06a1e824-889c-4649-97f9-1ed3fa401d8e", 109 ClassName: "Article", 110 Vector: []float32{0, 0, 0.78}, 111 Schema: map[string]interface{}{ 112 "description": "Ice Cream often contains a lot of sugar", 113 }, 114 }, 115 search.Result{ 116 ID: "6402e649-b1e0-40ea-b192-a64eab0d5e56", 117 ClassName: "Article", 118 Vector: []float32{0, 0, 0.90}, 119 Schema: map[string]interface{}{ 120 "description": "French Fries are more common in Belgium and the US than in France", 121 }, 122 }, 123 } 124 } 125 126 const ( 127 idMainCategoryPoliticsAndSociety = "39c6abe3-4bbe-4c4e-9e60-ca5e99ec6b4e" 128 idMainCategoryFoodAndDrink = "5a3d909a-4f0d-4168-8f5c-cd3074d1e79a" 129 idCategoryPolitics = "1b204f16-7da6-44fd-bbd2-8cc4a7414bc3" 130 idCategorySociety = "ec500f39-1dc9-4580-9bd1-55a8ea8e37a2" 131 idCategoryFoodAndDrink = "027b708a-31ca-43ea-9001-88bec864c79c" 132 ) 133 134 // only used for contextual type classification 135 func testDataPossibleTargets() search.Results { 136 return search.Results{ 137 search.Result{ 138 ID: idMainCategoryPoliticsAndSociety, 139 ClassName: "MainCategory", 140 Vector: []float32{1.01, 1.01, 0}, 141 Schema: map[string]interface{}{ 142 "name": "Politics and Society", 143 }, 144 }, 145 search.Result{ 146 ID: idMainCategoryFoodAndDrink, 147 ClassName: "MainCategory", 148 Vector: []float32{0, 0, 0.99}, 149 Schema: map[string]interface{}{ 150 "name": "Food and Drinks", 151 }, 152 }, 153 search.Result{ 154 ID: idCategoryPolitics, 155 ClassName: "ExactCategory", 156 Vector: []float32{0.99, 0, 0}, 157 Schema: map[string]interface{}{ 158 "name": "Politics", 159 }, 160 }, 161 search.Result{ 162 ID: idCategorySociety, 163 ClassName: "ExactCategory", 164 Vector: []float32{0, 0.90, 0}, 165 Schema: map[string]interface{}{ 166 "name": "Society", 167 }, 168 }, 169 search.Result{ 170 ID: idCategoryFoodAndDrink, 171 ClassName: "ExactCategory", 172 Vector: []float32{0, 0, 0.99}, 173 Schema: map[string]interface{}{ 174 "name": "Food and Drink", 175 }, 176 }, 177 } 178 } 179 180 func beaconRef(target string) *models.SingleRef { 181 beacon := fmt.Sprintf("weaviate://localhost/%s", target) 182 return &models.SingleRef{Beacon: strfmt.URI(beacon)} 183 } 184 185 // only used for knn-type 186 func testDataAlreadyClassified() search.Results { 187 return search.Results{ 188 search.Result{ 189 ID: "8aeecd06-55a0-462c-9853-81b31a284d80", 190 ClassName: "Article", 191 Vector: []float32{1, 0, 0}, 192 Schema: map[string]interface{}{ 193 "description": "This article talks about politics", 194 "exactCategory": models.MultipleRef{beaconRef(idCategoryPolitics)}, 195 "mainCategory": models.MultipleRef{beaconRef(idMainCategoryPoliticsAndSociety)}, 196 }, 197 }, 198 search.Result{ 199 ID: "9f4c1847-2567-4de7-8861-34cf47a071ae", 200 ClassName: "Article", 201 Vector: []float32{0, 1, 0}, 202 Schema: map[string]interface{}{ 203 "description": "This articles talks about society", 204 "exactCategory": models.MultipleRef{beaconRef(idCategorySociety)}, 205 "mainCategory": models.MultipleRef{beaconRef(idMainCategoryPoliticsAndSociety)}, 206 }, 207 }, 208 search.Result{ 209 ID: "926416ec-8fb1-4e40-ab8c-37b226b3d68e", 210 ClassName: "Article", 211 Vector: []float32{0, 0, 1}, 212 Schema: map[string]interface{}{ 213 "description": "This article talks about food", 214 "exactCategory": models.MultipleRef{beaconRef(idCategoryFoodAndDrink)}, 215 "mainCategory": models.MultipleRef{beaconRef(idMainCategoryFoodAndDrink)}, 216 }, 217 }, 218 } 219 }