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 thebad
attribute. If there is some issue with the data bad should beTrue
and error given anException
that was caused by or explains the error.Customizations¶
Record
is a subclass ofabc.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 aRecord
R
, 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
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 theRecord
.Parameters¶
fieldDict :
dict[str:]
A dictionary that maps from strings to valuesidValue :
str
A unique identifier string for theRecord
bad :
bool
True
if there are issues with theRecord
, otherwiseFalse
error :
Exception
TheException
that caused whatever error made the record be marked as bad orNone
sFile :
str
A string that gives the source file of the original recordssLine :
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 thenTrue
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 blankbad
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
-