I'm working on a program that uses pyDatalog to query an sqlite database. The key table in the database is Event, which is defined as follows:
class Event(Base):
__tablename__ = 'Event'
id = Column('id', Integer, primary_key = True)
eventType = Column('eventType', Integer, ForeignKey('EventType.id'))
dateTime = Column('dateTime', DateTime)
def __init__(self, eventType, dateTime):
self.eventType = eventType
self.dateTime = dateTime
def __repr__(self):
return "<Event(%d, %d, %s)>" % (self.id, self.eventType, self.dateTime)
Each event then refers to a details table with more information.
What I want to be able to do is run a series of queries on each event in the sequence. The rulesets are loaded from an external file using pyDatalog.load()
The part I'm having trouble with is passing a reference to each event id into datalog from python. I keep getting the error "TypeError: Object is incompatible with the class that is queried."
I've reduced the rules down to these for debugging:
+ parent(bill, 'John Adams')
ancestor(X,Y) <= parent(X,Y)
ancestor(X,Y) <= parent(X,Z) & ancestor(Z,Y)
getEvent(EvtId, Evt) <= (Event.id[Evt] == EvtId)
The code that asks the query looks like this (part of a larger class):
def validateEvent(self, event):
# validate the event instance 'event'
print "validating event: %s" % (event)
#query = 'parent(bill, X)'
query = 'getEvent(' + str(event.id) + ', Evt)'
print query
print pyDatalog.ask(query)
If I uncomment the "query='parent(bill,X)'" line, it works OK (it prints the (bill, 'John Adams') tuple), but with the "query = 'getEvent(..." line, it keeps failing with the above error on the last line shown above.
Does anyone know what this error means, and how to pass the reference to the event id into pyDatalog correctly?
This error is generated when pyDatalog parses prefixed predicates, e.g. (Event.id[Evt] == EvtId) : it means that Evt is not an instance of Event, nor a pyDatalog variable.
Thus, I could imagine that you get the error on this in-line pyDatalog statement.
I cannot explain how you would get the error on this line (with pyDatalog 0.13):