Skip to content

Experimental Feature #37

Description

@github-actions

https://api.github.com/psykei/psyki-python/blob/dbc3332eb579f2daee44e013f120710669f8ae38/psyki/logic/lyrics/predicate.py#L20

from .world import World
from .compiler import AtomTensor


class Predicate(object):
    def __init__(self, label, domains, function):
        if label in World.predicates:
            raise Exception("Predicate %s already exists" % label)
        self.label = label
        self.domains = [World.domains[d] if isinstance(d, str) else d for d in domains]
        World.predicates[label] = self
        self.arity = len(self.domains)
        if function is None:
            raise NotImplementedError(
                "Default function implementation in Relation not yet implemented"
            )
        else:
            self.function = function

    # TODO Experimental Feature
    def __call__(self, *variables):
        domains = tuple([v.domain for v in variables])
        key = (self, domains)
        if key not in World._predicates_cache:
            World._predicates_cache[key] = AtomTensor(self, variables)
            return World._predicates_cache[key]
        else:
            cached = World._predicates_cache[key]
            return AtomTensor(cached.predicate, variables, tensor=cached._tensor)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions