srlearn.Database¶
-
class
srlearn.Database[source]¶ Database of examples and facts.
-
__init__()[source]¶ Initialize a Database object
A database (in this respect) contains positive examples, negative examples, facts, and is augmented with background knowledge.
The implementation is done with four attributes:
pos,neg,facts, andmodes. Each attribute is a list that may be set by mutating, or loaded from files withDatabase.from_files().Examples
This initializes a Database object, then sets the
posattribute.>>> from srlearn import Database >>> db = Database() >>> db.pos = ["student(alexander)."]
-
static
from_files(pos='pos.pl', neg='neg.pl', facts='facts.pl', lazy_load=True)[source]¶ Load files into a Database
Return an instance of a Database with pos, neg, and facts set to the contents of files. By default this performs a “lazy load,” where the files are not loaded into Python lists, but copied at learning time.
Parameters: - pos : str or pathlib.Path
Location of positive examples
- neg : str or pathlib.Path
Location of negative examples
- facts : str or pathlib.Path
Location of facts
- lazy_load : bool (default: True)
Skip loading the files into a list
Returns: - db : srlearn.Database
Instance of a Database object
-
write(filename='train', location=PosixPath('train')) → None[source]¶ Write the database to disk
Parameters: - filename : str
Name of the file to write to: ‘train’ or ‘test’
- location :
pathlib.Path Path where data should be written to.
Notes
This function has polymorphic behavior. When attributes (
self.pos,self.neg,self.facts) are lists of strings, the lists are written to files. When the attributes are (path-like) strings or pathlib Paths (pathlib.Path), the files are copied.
-