Record(Mapping, Hashable)

class metaknowledge.Record(fieldDict, idValue, bad, error, sFile='', sLine=0)

A dictionary with error handling and an id string.

Record is the base class of the all objects in metaknowledge that contain information as key-value pairs, these are the grants and the records from different sources.

The error handling of the Record is done with the bad attribute. If there is some issue with the data bad should be True and error given an Exception that was caused by or explains the error.

Customizations

Record is a subclass of abc.collections.Mapping which means it has almost all the methods a dictionary does, the missing ones are those that modify entries. So to access the value of the key 'title' from a Record R, you would use either the square brace notation t = R['title'] or the get() function t = R.get('title') just like a dictionary. The other methods like keys() or copy() also work.

In addition to being a mapping Records are also hashable with their hashes being based on a unique id string they are given on creation, usually some kind of accession number the source gives them. The two optional arguments sFile and sLine, which should be given the name of the file the records came from and the line it started on respectively, are used to make the errors more useful.

__Init__

fieldDict is the dictionary the Record will use and idValue is the unique identifier of the Record.

Parameters

fieldDict : dict[str:]

A dictionary that maps from strings to values

idValue : str

A unique identifier string for the Record

bad : bool

True if there are issues with the Record, otherwise False

error : Exception

The Exception that caused whatever error made the record be marked as bad or None

sFile : str

A string that gives the source file of the original records

sLine : int

The first line the original record is found on in the source file
__bytes__()

Returns the binary form of the original

__contains__(item)

Checks if the tag item is in the Record

__eq__(other)

Compares Records using their hashes if their hashes are the same then True is returned.

__getitem__(key)

This is redfined as something interesting for ExtendedRecord

__hash__()

Gives a hash of the id or if bad returns a hash of the fields combined with the error messages, either of these could be blank

bad Records are more likely to cause hash collisions due to their lack of entropy when created.

__init__(fieldDict, idValue, bad, error, sFile='', sLine=0)

Initialize self. See help(type(self)) for accurate signature.

__iter__()

Iterates over the tags in the Record

__len__()

Returns the number of tags

__repr__()

Makes a string with the id of the file and its type

__str__()

Makes a string with the title of the file as given by self.title, if there is not one it returns “Untitled record”

__weakref__

list of weak references to the object (if defined)

copy()

Correctly copies the Record