Forward and backward chaining using horn clauses as input in Java