Attribute
Attribute identifies the subsections in a document.
Assume that a block of data in a document that is identified to be a particular object type. This block can have subsections. The concept of Attribute is introduced to identify these subsections. For example, if you have a document with the following block identified -
Here the lines "Maria .. => .. -084" form the "Address". Inside this block, assume that each of the line represents - name, location, city, zip code respectively. Now, if you think of "Address" as the complex object type, the "name", "location", "city", "zipcode" forms the attributes of Address.
Here are some basic characteristics while defining an Attribute:
- An Attribute identifies a particular section inside the object type and described by key semantics.
- It forms a HAS-A relationship with the object type that is Object type HAS attributes.
- From Object Oriented Programming perspective, if a "class" is an ObjectType; then the "fields of the class" represent the "Attributes".
- An Attribute has a type that represents how the value of the attribute would be.
- An Attribute has no sub-attributes. However, an Attribute of an Object type that has attributes, indirectly, nesting of attributes inside another attribute gets supported to a single level.
- The scope of the attribute is the same as that of the enclosing object type. However, the type of attribute can belong to a different scope. For example, there is a complex object "Address" under scope "US"; and it has an attribute named City of type CA.city where CA.city represents an object type called city under the (different) scope CA".
- An Attribute has a flag for Mandatory or Optional that determines the presence of attribute in the object type. If mandatory, then the attribute can be present inside the block that is identified by Object type.
- An Attribute has a flag for Cardinality - that specifies if the values of this
attribute exist as a list (more than one) or if a single value is present. And if the cardinality is
a list, there can be an optional delimiter to identify the separation of the values
in the list.
- If the cardinality is a list, then it means that the object type block might have more than one value that belongs to the same attribute.
- For example, an Address object type which identifies a block in the document. This block can have multiple lines. And one such line has a list of phone number separated by a "|". So, to represent this in object type, you have a complex object type "Address" which has an attribute "PhoneNo", whose "cardinality" is list and "delimiter" is "|"
- Note that the attribute is completely dependent on the enclosed object type. And it cannot exist on its own => the attribute can exist only after the object type block enclosing the attributes is identified.
- An Attribute JSON representation inside object type has the following fields:
- name - defines the display name of the attribute
- symbolicName - defines the unique name for the attribute; It is settable only during creation time, and once set, cannot be changed. It has to be unique in the "scope" of the object type in which it is present. Follows the same rules as that of the symbolicName of an object type.
- description - (optional) specifies some description for the attribute
- type - specifies what object type the attribute belongs to. Typically will be of the form "<scope>.<objectType>". The type can be another complex object type.
- scope - (optional and intuitive) will be the at the same scope of the enclosing object type
- mandatory - (Optional) integer - 0/1
- If 1, then it means that the attribute should be present in the block (to determine if the block represents the complex object type).
- If 0, then the presence of this attribute inside the block is optional.
- If the field is omitted, the default behavior is optional that is zero
- cardinality - (Optional) Specifies if there can be more than one attribute
identified in the block. Can have one of the two values - { single, list }
- if "single", it means that there is only one attribute in the block
- if "list", it means that there can be more than one attribute in the block
- If the field is omitted, the default behavior is "single"
- delimiter - (Optional) specifies how the multiple attributes in the block are
separated.
- Applies only if "cardinality" is "list"
- If not specified, comma is assumed to separate words is used.
- Inside an object type, the attributeList field contains an array of
attributes:
- attributeList (optional)
- Array consisting of attributes that reference other types in the ObjectTypeLibrary
- Each element (attribute) in the array is a JSON object representing the attribute (as above)
- attributeList (optional)
- On a KeyClass
- The attributes are referenced from the object type using <scope>.<symbolicNameOfObjectType>.<symbolicNameOfAttribute>.
- An Attribute is additionally define an optional context that specifies additional information how to identify the attribute inside the complex object block. This should be envisioned similar to a KeyContext of a key Class. There is a "attrContext" node which has an "AttrAliasList" that is an array of aliases; as well as a "PatternList" that is an array of extractors for attributes (same as keyExtractors).
- Just like a key class, an attribute defines custom extractors or validator.
- The JSON representation has the following fields:
- attrRef - (String) - References the attribute from the object type in the form <scope>.<symbolicNameOfObjectType>.<symbolicNameOfAttribute>
- mandatory- (Integer) - 0/1
- It overwrites the value that is specified on the object type level.
- If 1, then it means that the attribute should be present in the block (to determine if the block represents the complex object type).
- If 0, then the presence of this attribute inside the block is optional.
- cardinality - (String) - { single | list }
- It overwrites the value specified on the object type level.
- if single, it means that there is only one attribute in the block.
- if list, it means that there can be more than one attribute in the block.
- delimiter-
- It overwrites the value specified on the object type level.
- Applies only if cardinality is list.
- attrContext - (Optional and is only present inside KeyClass JSON) if
the attribute is present as KVP, that means it has key; then the context specifies how to identify
that "key" in the KVP. JSON object that contains two more JSON objects:
- A ttrAliasList - list of Aliases (just like keyAliases) that specifies the key for an attribute that is present inside the block.
- P atternList - list of patterns (keyExtractor patterns) that specifies the pattern to use to find the key of the attribute. The list contains the implementations similar to keyPatterns. The format for the implementation can be referred at https://ibm.ent.box.com/notes/538948480349 under "GOAL 1: DEFINE A LIBRARY OF TYPES (PAYLOAD MODEL)" > "(i) Implementation (JSON object)".
- extractor - (Optional) list of valueExtractor implementations similar to a KeyClass
- validator - (Optional) list of validator implementations similar to a KeyClass
- Refer section Working with Attributes in a KeyClass for more on usage in a KeyClass.