Example #1
0
    def testResolutionRetrieval(self):
        """
        Test actual retrieval of literal occurances from the index.
        """
        index = ResolutionIndex()
        index.insertClause(self.c1)
        index.insertClause(self.c2)
        index.insertClause(self.c3)
        index.insertClause(self.c4)
        index.insertClause(self.c5)

        print("testResolutionRetrieval()")
        lit = self.c6.getLiteral(0)
        cands = index.getResolutionLiterals(lit)
        print(cands)
        self.assertEqual(len(cands), 8)
        for (c, i) in cands:
            l = c.getLiteral(i)
            self.assertEqual(l.isNegative(), not lit.isNegative())
            self.assertEqual(termFunc(l.atom), termFunc(lit.atom))

        lit = self.c7.getLiteral(0)
        cands = index.getResolutionLiterals(lit)
        print(cands)
        self.assertEqual(len(cands), 3)
        for (c, i) in cands:
            l = c.getLiteral(i)
            self.assertEqual(l.isNegative(), not lit.isNegative())
            self.assertEqual(termFunc(l.atom), termFunc(lit.atom))

        lit = self.c8.getLiteral(0)
        cands = index.getResolutionLiterals(lit)
        print(cands)
        self.assertEqual(cands, [])
Example #2
0
 def removeClause(self, clause):
     for i in range(len(clause)):
         lit = clause.getLiteral(i)
         if lit.isInferenceLit():
             if lit.isPositive():
                 self.removeData(self.pos_idx, termFunc(lit.atom),
                                 (clause, i))
             else:
                 self.removeData(self.neg_idx, termFunc(lit.atom),
                                 (clause, i))
Example #3
0
 def removeClause(self, clause):
     """
     Remove all inference literals of the clause from the index.
     """
     for i in range(len(clause)):
         lit = clause.getLiteral(i)
         if lit.isInferenceLit():
             if lit.isPositive():
                 self.removeData(self.pos_idx, termFunc(lit.atom),
                                 (clause, i))
             else:
                 self.removeData(self.neg_idx, termFunc(lit.atom),
                                 (clause, i))
Example #4
0
 def insertClause(self, clause):
     """
     Insert all inference literals of clause into the appropriate
     index (positive or negative, depending on the sign of the
     literal).
     """
     for i in range(len(clause)):
         lit = clause.getLiteral(i)
         if lit.isInferenceLit():
             if lit.isPositive():
                 self.insertData(self.pos_idx, termFunc(lit.atom),
                                 (clause, i))
             else:
                 self.insertData(self.neg_idx, termFunc(lit.atom),
                                 (clause, i))
Example #5
0
 def getResolutionLiterals(self, lit):
     if lit.isPositive():
         idx = self.neg_idx
     else:
         idx = self.pos_idx
     try:
         return list(idx[termFunc(lit.atom)])
     except KeyError:
         return list()
Example #6
0
 def getResolutionLiterals(self, lit):
     """
     Return a list of resolution candidates for lit. Every
     candidate is a pair (clause, pos), where pos is the position
     of the literal that potentially unifies with lit (and has the
     opposite sign).
     """
     if lit.isPositive():
         idx = self.neg_idx
     else:
         idx = self.pos_idx
     try:
         return list(idx[termFunc(lit.atom)])
     except KeyError:
         return list()