<commit_before>#

# This source file is part of the EdgeDB open source project.
#
# Copyright 2008-present MagicStack Inc. and the EdgeDB authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


from edb.lang.edgeql import ast as qlast

from . import delta as sd
from . import inheriting
from . import name as sn
from . import named
from . import objects as so
from . import referencing
from . import types as s_types
from . import utils


class Attribute(inheriting.InheritingObject):
    _type = 'attribute'

    type = so.SchemaField(s_types.Type, compcoef=0.909)


class AttributeValue(inheriting.InheritingObject):
    _type = 'attribute-value'

    subject = so.SchemaField(
        named.NamedObject, compcoef=1.0, default=None, inheritable=False)

    attribute = so.Field(
        Attribute, compcoef=0.429)

    value = so.Field(
        str, compcoef=0.909)

    def __str__(self):
        return '<{}: at 0x{:x}>'.format(self.__class__.__name__, id(self))

    __repr__ = __str__


class AttributeSubject(referencing.ReferencingObject):
    attributes_refs = referencing.RefDict(
        attr='attributes',
        local_attr='own_attributes',
        ref_cls=AttributeValue)

    attributes = so.SchemaField(
        so.ObjectMapping,
        inheritable=False, ephemeral=True, coerce=True,
        default=so.ObjectMapping, hashable=False)

    own_attributes = so.SchemaField(
        so.ObjectMapping, compcoef=0.909,
        inheritable=False, ephemeral=True, coerce=True,
        default=so.ObjectMapping)

    def add_attribute(self, schema, attribute, replace=False):
        schema = self.add_classref(
            schema, 'attributes', attribute, replace=replace)<commit_msg>Migrate schema.AttributeValue to use SchemaFields<commit_after>#

# This source file is part of the EdgeDB open source project.
#
# Copyright 2008-present MagicStack Inc. and the EdgeDB authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


from edb.lang.edgeql import ast as qlast

from . import delta as sd
from . import inheriting
from . import name as sn
from . import named
from . import objects as so
from . import referencing
from . import types as s_types
from . import utils


class Attribute(inheriting.InheritingObject):
    _type = 'attribute'

    type = so.SchemaField(s_types.Type, compcoef=0.909)


class AttributeValue(inheriting.InheritingObject):
    _type = 'attribute-value'

    subject = so.SchemaField(
        named.NamedObject, compcoef=1.0, default=None, inheritable=False)

    attribute = so.SchemaField(
        Attribute, compcoef=0.429)

    value = so.SchemaField(
        str, compcoef=0.909)

    def __str__(self):
        return '<{}: at 0x{:x}>'.format(self.__class__.__name__, id(self))

    __repr__ = __str__


class AttributeSubject(referencing.ReferencingObject):
    attributes_refs = referencing.RefDict(
        attr='attributes',
        local_attr='own_attributes',
        ref_cls=AttributeValue)

    attributes = so.SchemaField(
        so.ObjectMapping,
        inheritable=False, ephemeral=True, coerce=True,
        default=so.ObjectMapping, hashable=False)

    own_attributes = so.SchemaField(
        so.ObjectMapping, compcoef=0.909,
        inheritable=False, ephemeral=True, coerce=True,
        default=so.ObjectMapping)

    def add_attribute(self, schema, attribute, replace=False):
        schema = self.add_classref(
            schema, 'attributes', attribute, replace=replace)
{'fraction_non_alphanumeric': 0.0883940620782726, 'fraction_numerical': 0.012145748987854251, 'mean_word_length': 3.5563524590163933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3076275', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1255, 'n_words': 409}