Record(Mapping, Hashable):

Record.__init__(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

The Record class has the following methods:


Record.__eq__(other):

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

Parameters

other : Record

Another Record to be compared against

Returns

bool

If the records are the same then True is returned


Record.__str__():

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

Returns

str

The title of the Record


Record.__repr__():

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

Returns

str

The representation of the Record


Record.copy():

Correctly copies the Record

Returns

Record

A completely decoupled copy of the original


Record.__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.

Returns

int

A hopefully unique random number


Questions?

If you find bugs, or have questions, please write to:

Reid McIlroy-Young reid@reidmcy.com

John McLevey john.mclevey@uwaterloo.ca


License

metaknowledge is free and open source software, distributed under the GPL License.