Record(Mapping, Hashable)¶
-
class
metaknowledge.Record(fieldDict, idValue, bad, error, sFile='', sLine=0)¶ A dictionary with error handling and an id string.
Recordis 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
Recordis done with thebadattribute. If there is some issue with the data bad should beTrueand error given anExceptionthat was caused by or explains the error.Customizations¶
Recordis a subclass ofabc.collections.Mappingwhich 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 aRecordR, you would use either the square brace notationt = R['title']or theget()functiont = R.get('title')just like a dictionary. The other methods likekeys()orcopy()also work.In addition to being a mapping
Recordsare 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
Recordwill use and idValue is the unique identifier of theRecord.Parameters¶
fieldDict :
dict[str:]A dictionary that maps from strings to valuesidValue :
strA unique identifier string for theRecordbad :
boolTrueif there are issues with theRecord, otherwiseFalseerror :
ExceptionTheExceptionthat caused whatever error made the record be marked as bad orNonesFile :
strA string that gives the source file of the original recordssLine :
intThe 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
Recordsusing their hashes if their hashes are the same thenTrueis returned.
-
__getitem__(key)¶ This is redfined as something interesting for ExtendedRecord
-
__hash__()¶ Gives a hash of the id or if
badreturns a hash of the fields combined with the error messages, either of these could be blankbadRecords 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
-