glossary.py 8.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/env/python

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you 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.

20
import apache_atlas.model.instance
21

22 23
from apache_atlas.model.misc import *
from apache_atlas.utils      import *
24 25 26


class AtlasGlossaryBaseObject(AtlasBaseModelObject):
27 28
    def __init__(self, attrs={}):
        AtlasBaseModelObject.__init__(self, attrs)
29

30 31 32 33 34 35
        self.qualifiedName        = attrs.get('qualifiedName')
        self.name                 = attrs.get('name')
        self.shortDescription     = attrs.get('shortDescription')
        self.longDescription      = attrs.get('longDescription')
        self.additionalAttributes = attrs.get('additionalAttributes')
        self.classifications      = attrs.get('classifications')
36

37 38
    def type_coerce_attrs(self):
        super(AtlasGlossaryBaseObject, self).type_coerce_attrs()
39

40
        self.classifications = type_coerce_list(self.classifications, apache_atlas.model.instance.AtlasClassification)
41 42 43


class AtlasGlossary(AtlasGlossaryBaseObject):
44 45
    def __init__(self, attrs={}):
        AtlasGlossaryBaseObject.__init__(self, attrs)
46

47 48 49 50
        self.language   = attrs.get('language')
        self.usage      = attrs.get('usage')
        self.terms      = attrs.get('terms')
        self.categories = attrs.get('categories')
51

52 53
    def type_coerce_attrs(self):
        super(AtlasGlossary, self).type_coerce_attrs()
54

55 56
        self.terms      = type_coerce_list(self.classifications, AtlasRelatedTermHeader)
        self.categories = type_coerce_list(self.categories, AtlasRelatedCategoryHeader)
57 58


59 60 61
class AtlasGlossaryExtInfo(AtlasGlossary):
    def __init__(self, attrs={}):
        AtlasGlossary.__init__(self, attrs)
62

63 64
        self.termInfo     = attrs.get('termInfo')
        self.categoryInfo = attrs.get('categoryInfo')
65

66 67
    def type_coerce_attrs(self):
        super(AtlasGlossaryExtInfo, self).type_coerce_attrs()
68

69 70
        self.termInfo     = type_coerce_dict(self.termInfo, AtlasGlossaryTerm)
        self.categoryInfo = type_coerce_dict(self.categoryInfo, AtlasGlossaryCategory)
71 72


73 74 75
class AtlasGlossaryCategory(AtlasGlossaryBaseObject):
    def __init__(self, attrs):
        AtlasGlossaryBaseObject.__init__(self, attrs)
76

77 78
        # Inherited attributes from relations
        self.anchor = attrs.get('anchor')
79

80 81 82
        # Category hierarchy links
        self.parentCategory     = attrs.get('parentCategory')
        self.childrenCategories = attrs.get('childrenCategories')
83

84 85
        # Terms associated with this category
        self.terms = attrs.get('terms')
86

87 88
    def type_coerce_attrs(self):
        super(AtlasGlossaryCategory, self).type_coerce_attrs()
89

90 91 92 93
        self.anchor             = type_coerce(self.anchor, AtlasGlossaryHeader)
        self.parentCategory     = type_coerce(self.parentCategory, AtlasRelatedCategoryHeader)
        self.childrenCategories = type_coerce_list(self.childrenCategories, AtlasRelatedCategoryHeader)
        self.terms              = type_coerce_list(self.terms, AtlasRelatedTermHeader)
94 95 96


class AtlasGlossaryTerm(AtlasGlossaryBaseObject):
97 98
    def __init__(self, attrs={}):
        AtlasGlossaryBaseObject.__init__(self, attrs)
99 100

        # Core attributes
101 102 103
        self.examples     = attrs.get('examples')
        self.abbreviation = attrs.get('abbreviation')
        self.usage        = attrs.get('usage')
104 105

        # Attributes derived from relationships
106 107 108
        self.anchor           = attrs.get('anchor')
        self.assignedEntities = attrs.get('assignedEntities')
        self.categories       = attrs.get('categories')
109 110

        # Related Terms
111
        self.seeAlso = attrs.get('seeAlso')
112 113

        # Term Synonyms
114
        self.synonyms = attrs.get('synonyms')
115 116

        # Term antonyms
117
        self.antonyms = attrs.get('antonyms')
118 119

        # Term preference
120 121
        self.preferredTerms   = attrs.get('preferredTerms')
        self.preferredToTerms = attrs.get('preferredToTerms')
122 123

        # Term replacements
124 125
        self.replacementTerms = attrs.get('replacementTerms')
        self.replacedBy       = attrs.get('replacedBy')
126 127

        # Term translations
128 129
        self.translationTerms = attrs.get('translationTerms')
        self.translatedTerms  = attrs.get('translatedTerms')
130 131

        # Term classification
132 133
        self.isA        = attrs.get('isA')
        self.classifies = attrs.get('classifies')
134 135

        # Values for terms
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
        self.validValues    = attrs.get('validValues')
        self.validValuesFor = attrs.get('validValuesFor')

    def type_coerce_attrs(self):
        super(AtlasGlossaryTerm, self).type_coerce_attrs()

        self.anchor           = type_coerce(self.anchor, AtlasGlossaryHeader)
        self.assignedEntities = type_coerce_list(self.assignedEntities, apache_atlas.model.instance.AtlasRelatedObjectId)
        self.categories       = type_coerce_list(self.categories, AtlasTermCategorizationHeader)
        self.seeAlso          = type_coerce_list(self.seeAlso, AtlasRelatedTermHeader)
        self.synonyms         = type_coerce_list(self.synonyms, AtlasRelatedTermHeader)
        self.antonyms         = type_coerce_list(self.antonyms, AtlasRelatedTermHeader)
        self.preferredTerms   = type_coerce_list(self.preferredTerms, AtlasRelatedTermHeader)
        self.preferredToTerms = type_coerce_list(self.preferredToTerms, AtlasRelatedTermHeader)
        self.replacementTerms = type_coerce_list(self.replacementTerms, AtlasRelatedTermHeader)
        self.replacedBy       = type_coerce_list(self.replacedBy, AtlasRelatedTermHeader)
        self.translationTerms = type_coerce_list(self.translationTerms, AtlasRelatedTermHeader)
        self.isA              = type_coerce_list(self.isA, AtlasRelatedTermHeader)
        self.classifies       = type_coerce_list(self.classifies, AtlasRelatedTermHeader)
        self.validValues      = type_coerce_list(self.validValues, AtlasRelatedTermHeader)
        self.validValuesFor   = type_coerce_list(self.validValuesFor, AtlasRelatedTermHeader)


class AtlasGlossaryHeader(AtlasBase):
    def __init__(self, attrs):
        AtlasBase.__init__(self, attrs)

        self.glossaryGuid = attrs.get('glossaryGuid')
        self.relationGuid = attrs.get('relationGuid')
        self.displayText  = attrs.get('displayText')


class AtlasRelatedCategoryHeader(AtlasBase):
    def __init__(self, attrs={}):
        AtlasBase.__init__(self, attrs)

        self.categoryGuid       = attrs.get('categoryGuid')
        self.parentCategoryGuid = attrs.get('parentCategoryGuid')
        self.relationGuid       = attrs.get('relationGuid')
        self.displayText        = attrs.get('displayText')
        self.description        = attrs.get('description')


class AtlasRelatedTermHeader(AtlasBase):
    def __init__(self, attrs={}):
        AtlasBase.__init__(self, attrs)

        self.termGuid     = attrs.get('termGuid')
        self.relationGuid = attrs.get('relationGuid')
        self.displayText  = attrs.get('displayText')
        self.description  = attrs.get('description')
        self.expression   = attrs.get('expression')
        self.steward      = attrs.get('steward')
        self.source       = attrs.get('source')
        self.status       = attrs.get('status')

class AtlasTermAssignmentHeader(AtlasBase):
    def __init__(self, attrs={}):
        AtlasBase.__init__(self, attrs)

        self.termGuid     = attrs.get('termGuid')
        self.relationGuid = attrs.get('relationGuid')
        self.description  = attrs.get('description')
        self.displayText  = attrs.get('displayText')
        self.expression   = attrs.get('expression')
        self.createdBy    = attrs.get('createdBy')
        self.steward      = attrs.get('steward')
        self.source       = attrs.get('source')
        self.confidence   = attrs.get('confidence')


class AtlasTermCategorizationHeader(AtlasBase):
    def __init__(self, attrs):
        AtlasBase.__init__(self, attrs)

        self.categoryGuid = attrs.get('categoryGuid')
        self.relationGuid = attrs.get('relationGuid')
        self.description  = attrs.get('description')
        self.displayText  = attrs.get('displayText')
        self.status       = attrs.get('status')
216 217