github.com/weaviate/weaviate@v1.24.6/entities/schema/schema.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 schema
    13  
    14  import (
    15  	"strings"
    16  
    17  	"github.com/weaviate/weaviate/entities/models"
    18  )
    19  
    20  // Newtype to denote that this string is used as a Class name
    21  type ClassName string
    22  
    23  func (c ClassName) String() string {
    24  	return string(c)
    25  }
    26  
    27  // Newtype to denote that this string is used as a Property name
    28  type PropertyName string
    29  
    30  func (p PropertyName) String() string {
    31  	return string(p)
    32  }
    33  
    34  type ClassAndProperty struct {
    35  	ClassName    ClassName
    36  	PropertyName PropertyName
    37  }
    38  
    39  // Describes the schema that is used in Weaviate.
    40  type Schema struct {
    41  	Objects *models.Schema
    42  }
    43  
    44  func Empty() Schema {
    45  	return Schema{
    46  		Objects: &models.Schema{
    47  			Classes: []*models.Class{},
    48  		},
    49  	}
    50  }
    51  
    52  // Return one of the semantic schema's
    53  func (s *Schema) SemanticSchemaFor() *models.Schema {
    54  	return s.Objects
    55  }
    56  
    57  func UppercaseClassName(name string) string {
    58  	if len(name) < 1 {
    59  		return name
    60  	}
    61  
    62  	if len(name) == 1 {
    63  		return strings.ToUpper(name)
    64  	}
    65  
    66  	return strings.ToUpper(string(name[0])) + name[1:]
    67  }
    68  
    69  func LowercaseAllPropertyNames(props []*models.Property) []*models.Property {
    70  	for i, prop := range props {
    71  		props[i].Name = LowercaseFirstLetter(prop.Name)
    72  	}
    73  
    74  	return props
    75  }
    76  
    77  func LowercaseFirstLetter(name string) string {
    78  	if len(name) < 1 {
    79  		return name
    80  	}
    81  
    82  	if len(name) == 1 {
    83  		return strings.ToLower(name)
    84  	}
    85  
    86  	return strings.ToLower(string(name[0])) + name[1:]
    87  }
    88  
    89  func LowercaseFirstLetterOfStrings(in []string) []string {
    90  	if len(in) < 1 {
    91  		return in
    92  	}
    93  	out := make([]string, len(in))
    94  	for i, str := range in {
    95  		out[i] = LowercaseFirstLetter(str)
    96  	}
    97  
    98  	return out
    99  }