Python API Reference¶
This page documents the Python API for the apyds package.
1 2 3 4 5 6 7 8 9 10 11 | |
buffer_size¶
Gets the current buffer size, or sets a new buffer size and returns the previous value.
1 | |
Parameters:
size(optional): The new buffer size to set. If 0 (default), returns current size without modification.
Returns: The previous buffer size value.
Example:
1 2 | |
scoped_buffer_size¶
Context manager for temporarily changing the buffer size.
1 2 | |
Parameters:
size: The temporary buffer size to set.
Example:
1 2 3 4 | |
String¶
Wrapper class for deductive system strings.
Constructor¶
1 | |
Parameters:
value: Initial value (string, bytes, or another String)size(optional): Buffer capacity for internal storage
Methods¶
__str__()¶
Convert the value to a string representation.
1 | |
data()¶
Get the binary representation of the value.
1 | |
size()¶
Get the size of the data in bytes.
1 | |
Example:
1 2 3 | |
Variable¶
Wrapper class for logical variables in the deductive system.
Constructor¶
1 | |
Parameters:
value: Initial value (string starting with backtick, bytes, or another Variable)size(optional): Buffer capacity for internal storage
Properties¶
name¶
Get the name of this variable (without the backtick prefix).
1 2 | |
Example:
1 2 3 | |
Item¶
Wrapper class for items (constants/functors) in the deductive system.
Constructor¶
1 | |
Properties¶
name¶
Get the name of this item.
1 2 | |
Example:
1 2 | |
List¶
Wrapper class for lists in the deductive system.
Constructor¶
1 | |
Methods¶
__len__()¶
Get the number of elements in the list.
1 | |
__getitem__()¶
Get an element from the list by index.
1 | |
Example:
1 2 3 | |
Term¶
Wrapper class for logical terms in the deductive system. A term can be a variable, item, or list.
Constructor¶
1 | |
Properties¶
term¶
Extracts the underlying term and returns it as its concrete type.
1 2 | |
Methods¶
ground()¶
Ground this term using a dictionary to substitute variables with values.
1 | |
Parameters:
other: A term representing a dictionary (list of pairs)scope(optional): Scope string for variable scoping
Returns: The grounded term, or None if grounding fails.
Example:
1 2 3 4 5 | |
__matmul__() / match¶
Match two terms and return the unification result as a dictionary.
1 | |
Parameters:
other: The term to match with this term
Returns: A term representing the unification dictionary (list of tuples), or None if matching fails.
Example:
1 2 3 4 5 | |
rename()¶
Rename all variables in this term by adding prefix and suffix.
1 | |
Parameters:
prefix_and_suffix: A term with format((prefix) (suffix))
Returns: The renamed term, or None if renaming fails.
Example:
1 2 3 4 5 | |
Rule¶
Wrapper class for logical rules in the deductive system.
Constructor¶
1 | |
Properties¶
conclusion¶
Get the conclusion of the rule.
1 2 | |
Methods¶
__len__()¶
Get the number of premises in the rule.
1 | |
__getitem__()¶
Get a premise term by index.
1 | |
ground()¶
Ground this rule using a dictionary.
1 | |
__matmul__() / match¶
Match this rule with another rule using unification.
1 | |
Parameters:
other: The rule to match against (must be a fact without premises)
Returns: The matched rule, or None if matching fails.
Example:
1 2 3 4 5 6 | |
rename()¶
Rename all variables in this rule.
1 | |
Search¶
Search engine for the deductive system.
Constructor¶
1 | |
Parameters:
limit_size(optional): Size of the buffer for storing rules/facts (default: 1000)buffer_size(optional): Size of the buffer for internal operations (default: 10000)
Methods¶
set_limit_size()¶
Set the size of the buffer for storing final objects.
1 | |
set_buffer_size()¶
Set the buffer size for internal operations.
1 | |
reset()¶
Reset the search engine, clearing all rules and facts.
1 | |
add()¶
Add a rule or fact to the knowledge base.
1 | |
Returns: True if successfully added, False otherwise.
execute()¶
Execute the search engine with a callback for each inferred rule.
1 | |
Parameters:
callback: Function called for each candidate rule. Return False to continue, True to stop.
Returns: The number of rules processed.
Example:
1 2 3 4 5 6 7 8 9 | |
Complete Example¶
Here's a complete example demonstrating most of the API:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |