def test_get_complementary_formulas(self): self.assertEqual(self.sf1.get_complementary_formulas(), [SimpleFormula(self.im1, self.traits[1], self.s1), SimpleFormula(self.im1, self.traits[1], self.s2)]) self.assertEqual(self.sf3.get_complementary_formulas(), [SimpleFormula(self.im2, self.traits2[2], self.s1), SimpleFormula(self.im2, self.traits2[2], self.s2)])
def setUp(self): self.ident1 = QRCode("1") self.ident2 = QRCode("2") self.ident3 = QRCode("-231") self.traits = [Trait("Obly"), Trait("Krasny"), Trait("Sowiecki")] self.traits2 = [ Trait("Barowalny"), Trait("Konieczny"), Trait("Bolszoj") ] self.s1 = State.IS self.s2 = State.IS_NOT self.s3 = State.MAYHAPS self.object_type = ObjectType(1, self.traits) self.object_type2 = ObjectType(2, self.traits2) self.im1 = IndividualModel(self.ident1, self.object_type) self.im2 = IndividualModel(self.ident2, self.object_type2) self.o1 = Observation(self.ident1, [(self.traits[0], self.s1), (self.traits2[2], self.s1), (self.traits[1], self.s2)]) self.o2 = Observation(self.ident2, [(self.traits[1], self.s3), (self.traits2[1], self.s2), (self.traits[1], self.s2)], 1) self.o3 = Observation(self.ident3, [(self.traits[2], self.s1), (self.traits2[0], self.s3), (self.traits[2], self.s1)]) self.o4 = Observation(self.ident1, [(self.traits[2], self.s3), (self.traits2[0], self.s3), (self.traits[2], self.s2)]) self.o5 = Observation(self.ident2, [(self.traits[1], self.s1), (self.traits2[1], self.s2), (self.traits[1], self.s3)], 1) self.bp1 = BaseProfile(1, [self.o1, self.o2, self.o3]) self.bp2 = BaseProfile(2, [self.o1, self.o5, self.o4]) self.bp3 = BaseProfile(3, [self.o5, self.o1, self.o3]) self.bp4 = BaseProfile(3, [self.o5]) self.cf1 = ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s3], LogicalOperator.AND) self.cf2 = ComplexFormula(self.im2, [self.traits2[0], self.traits2[1]], [self.s1, self.s1], LogicalOperator.AND) self.sf1 = SimpleFormula(self.im1, self.traits[1], self.s1) self.sf3 = SimpleFormula(self.im2, self.traits2[2], self.s2) self.dk1 = DistributedKnowledge(self.cf1, [self.bp1, self.bp4], 1) self.dk2 = DistributedKnowledge(self.cf2, [self.bp2, self.bp3], 2) self.dk3 = DistributedKnowledge(self.sf1, [self.bp1, self.bp2]) self.dk4 = DistributedKnowledge(self.sf3, [self.bp3], 12)
def setUp(self): self.ident1 = QRCode("1") self.ident2 = QRCode("2") self.ident3 = QRCode("-231") self.traits = [Trait("Obly"),Trait("Krasny"), Trait("Sowiecki")] self.object_type = ObjectType(1, self.traits) self.traits2 = [Trait("Barowalny"), Trait("Konieczny"), Trait("Bolszoj")] self.object_type2 = ObjectType(2, self.traits2) self.im1 = IndividualModel(self.ident1, self.object_type) self.im2 = IndividualModel(self.ident2, self.object_type2) self.s1 = State.IS self.s2 = State.IS_NOT self.s3 = State.MAYHAPS self.sf1 = SimpleFormula(self.im1, self.traits[1], self.s1) self.sf3 = SimpleFormula(self.im2, self.traits2[2], self.s2)
def test_get_complementary_formulas(self): self.assertEqual(self.dk1.get_complementary_formulas(), [ ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s1, self.s1], LogicalOperator.AND), ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s1, self.s2], LogicalOperator.AND), ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s1], LogicalOperator.AND), ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s2], LogicalOperator.AND) ]) self.assertEqual( self.dk3.get_complementary_formulas(), [self.sf1, SimpleFormula(self.im1, self.traits[1], self.s2)])
def __init__(self, subject=None, traits=None, states=None, logicaloperator=None, modal_operator=None, tense=None): """ I really don't have any desire in explaining basic english :param subject (IndividualModel): subject :param traits (Trait or list(Traits)) : traits :param states (State or list(State)) : states :param logicaloperator (LogicalOperator): Logical operator :param modal_operator (ModalOperator): Modal Operator """ self.subject = subject self.gentleman_dict = { ModalOperator.NOIDEA: 'I cannot tell if ', ModalOperator.POS: 'I think its absolutely possible that ', ModalOperator.BEL: 'I deeply and truthfully believe that ', ModalOperator.KNOW: 'I definitely know that' } self.traits = traits self.states = states if traits is not None: if isinstance(traits, Trait): self.formula = SimpleFormula(subject, traits, states) elif len(traits) > 1: self.logicaloperator = logicaloperator self.formula = ComplexFormula(subject, traits, states, logicaloperator) elif tense is not None: self.formula = ComplexFormulaOT(subject, states, logicaloperator, tense) self.tense = tense self.logicaloperator = logicaloperator if modal_operator is not None: self.modaloperator = modal_operator
def setUp(self): self.ident1 = QRCode("1") self.ident2 = QRCode("2") self.ident3 = QRCode("-231") self.traits = [Trait("Obly"), Trait("Krasny"), Trait("Sowiecki")] self.traits2 = [ Trait("Barowalny"), Trait("Konieczny"), Trait("Bolszoj") ] self.s1 = State.IS self.s2 = State.IS_NOT self.s3 = State.MAYHAPS self.object_type = ObjectType(1, self.traits) self.object_type2 = ObjectType(2, self.traits2) self.im1 = IndividualModel(self.ident1, self.object_type) self.im2 = IndividualModel(self.ident2, self.object_type2) self.o1 = Observation(self.ident1, [(self.traits[0], self.s1), (self.traits2[2], self.s1), (self.traits[1], self.s2)]) self.o2 = Observation(self.ident2, [(self.traits[1], self.s1), (self.traits2[1], self.s2), (self.traits[1], self.s2)], 1) self.o3 = Observation(self.ident3, [(self.traits[2], self.s1), (self.traits2[0], self.s3), (self.traits[2], self.s1)]) self.o4 = Observation(self.ident1, [(self.traits[2], self.s3), (self.traits2[0], self.s3), (self.traits[2], self.s2)]) self.o5 = Observation(self.ident2, [(self.traits[1], self.s1), (self.traits2[1], self.s1), (self.traits[1], self.s3)], 1) self.o6 = Observation(self.ident2, [(self.traits2[1], self.s1), (self.traits[1], self.s1), (self.traits2[2], self.s1)], 1) self.o7 = Observation(self.ident1, [(self.traits[0], self.s2), (self.traits[1], self.s1), (self.traits[2], self.s1)], 1) self.o8 = Observation(self.ident2, [(self.traits2[0], self.s1), (self.traits2[1], self.s2), (self.traits2[2], self.s1)], 1) self.o9 = Observation(self.ident2, [(self.traits2[0], self.s1), (self.traits2[1], self.s2), (self.traits2[2], self.s1)], 1) self.bp1 = BaseProfile(1, [self.o1, self.o2, self.o3]) self.bp2 = BaseProfile(2, [self.o1, self.o5, self.o4]) self.bp3 = BaseProfile(3, [self.o5, self.o1, self.o3]) self.bp4 = BaseProfile(3, [self.o5]) self.bp5 = BaseProfile(14, [self.o7]) self.bp6 = BaseProfile(4, [self.o6]) self.bp7 = BaseProfile(324, [self.o8]) self.bp8 = BaseProfile(34, [self.o9]) self.cf1 = ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s1], LogicalOperator.AND) self.cf2 = ComplexFormula(self.im2, [self.traits2[0], self.traits2[1]], [self.s1, self.s1], LogicalOperator.AND) self.cf3 = ComplexFormula(self.im2, [self.traits2[0], self.traits2[1]], [self.s1, self.s1], LogicalOperator.OR) self.cf4 = ComplexFormula(self.im2, [self.traits2[0], self.traits2[1]], [self.s1, self.s1], LogicalOperator.XOR) self.sf1 = SimpleFormula(self.im1, self.traits[1], self.s1) self.sf3 = SimpleFormula(self.im2, self.traits2[2], self.s2) self.sf4 = SimpleFormula(self.im2, self.traits2[1], self.s1) self.dk1 = DistributedKnowledge(self.cf1, [self.bp1, self.bp4], 1) self.dk2 = DistributedKnowledge(self.cf2, [self.bp2, self.bp3], 2) self.dk3 = DistributedKnowledge(self.sf1, [self.bp4]) self.dk4 = DistributedKnowledge(self.sf3, [self.bp3], 12) self.dk5 = DistributedKnowledge(self.sf4, [self.bp6, self.bp4], 12) self.dk6 = DistributedKnowledge(self.cf1, [self.bp5], 12) self.dk7 = DistributedKnowledge(self.cf3, [self.bp7], 121) self.dk8 = DistributedKnowledge(self.cf4, [self.bp8], 11) self.cfot1 = ComplexFormulaOT([self.ident1, self.ident2], [self.s2, self.s1], LogicalOperator.AND) self.cfot2 = ComplexFormulaOT([self.ident1, self.ident3], [self.s1, self.s2], LogicalOperator.OR, Tense.FUTURE) self.dk9 = DistributedKnowledge(self.cfot1, [self.bp4], 11) self.dk10 = DistributedKnowledge(self.cfot2, [self.bp3, self.bp2], 1321)
def test_eq(self): self.assertEqual(self.sf1, SimpleFormula(self.im1, self.traits[1], self.s1)) self.assertEqual(self.sf3, SimpleFormula(self.im2, self.traits2[2], self.s2))
def test_error(self): self.assertRaises(TypeError, lambda: SimpleFormula(self.im1, [self.traits[1]], self.s1))
class SimpleFormulaTest(unittest.TestCase): def setUp(self): self.ident1 = QRCode("1") self.ident2 = QRCode("2") self.ident3 = QRCode("-231") self.traits = [Trait("Obly"),Trait("Krasny"), Trait("Sowiecki")] self.object_type = ObjectType(1, self.traits) self.traits2 = [Trait("Barowalny"), Trait("Konieczny"), Trait("Bolszoj")] self.object_type2 = ObjectType(2, self.traits2) self.im1 = IndividualModel(self.ident1, self.object_type) self.im2 = IndividualModel(self.ident2, self.object_type2) self.s1 = State.IS self.s2 = State.IS_NOT self.s3 = State.MAYHAPS self.sf1 = SimpleFormula(self.im1, self.traits[1], self.s1) self.sf3 = SimpleFormula(self.im2, self.traits2[2], self.s2) def test_get_states(self): self.assertEquals(self.sf1.get_states(), [self.s1]) self.assertEquals(self.sf3.get_states(), [self.s2]) def test_error(self): self.assertRaises(TypeError, lambda: SimpleFormula(self.im1, [self.traits[1]], self.s1)) def test_get_model(self): self.assertEqual(self.sf1.get_model(), self.im1) self.assertNotEqual(self.sf1.get_model(), self.im2) def test_test_get_type(self): self.assertEqual(self.sf1.get_type(), TypeOfFormula.SF) self.assertEqual(self.sf3.get_type(), TypeOfFormula.SF) def test_get_complementary_formulas(self): self.assertEqual(self.sf1.get_complementary_formulas(), [SimpleFormula(self.im1, self.traits[1], self.s1), SimpleFormula(self.im1, self.traits[1], self.s2)]) self.assertEqual(self.sf3.get_complementary_formulas(), [SimpleFormula(self.im2, self.traits2[2], self.s1), SimpleFormula(self.im2, self.traits2[2], self.s2)]) def test_eq(self): self.assertEqual(self.sf1, SimpleFormula(self.im1, self.traits[1], self.s1)) self.assertEqual(self.sf3, SimpleFormula(self.im2, self.traits2[2], self.s2)) def tearDown(self): self.traits2 = None self.traits = None self.object_type = None self.object_type2 = None self.ident1 = None self.ident2 = None self.ident3 = None self.im1 = None self.im2 = None self.sf1 = None self.sf2 = None self.s1 = None self.s2 = None self.s3 = None
def setUp(self): self.ident1 = QRCode("1") self.ident2 = QRCode("2") self.ident3 = QRCode("-231") self.traits = [Trait("Obly"),Trait("Krasny"), Trait("Sowiecki")] self.object_type = ObjectType(1, self.traits) self.traits2 = [Trait("Barowalny"), Trait("Konieczny"), Trait("Bolszoj")] self.s1 = State.IS self.s2 = State.IS_NOT self.s3 = State.MAYHAPS self.object_type = ObjectType(1, self.traits) self.object_type2 = ObjectType(2, self.traits2) self.im1 = IndividualModel(self.ident1, self.object_type) self.im2 = IndividualModel(self.ident2, self.object_type2) self.o1 = Observation(self.ident1, [(self.traits[0], self.s1), (self.traits2[2], self.s1), (self.traits[1], self.s2)]) self.o2 = Observation(self.ident2, [(self.traits[1], self.s1), (self.traits2[1], self.s2), (self.traits[1], self.s2)], 1) self.o3 = Observation(self.ident3, [(self.traits[2], self.s1), (self.traits2[0], self.s3), (self.traits[2], self.s1)]) self.o4 = Observation(self.ident1, [(self.traits[2], self.s3), (self.traits2[0], self.s3), (self.traits[2], self.s2)]) self.o5 = Observation(self.ident2, [(self.traits2[1], self.s2), (self.traits2[2], self.s2), (self.traits[1], self.s3)], 1) self.o6 = Observation(self.ident2, [(self.traits2[1], self.s1), (self.traits[1], self.s1), (self.traits2[2], self.s1)], 1) self.o7 = Observation(self.ident2, [(self.traits2[1], self.s1), (self.traits[1], self.s1), (self.traits2[2], self.s1)], 1) self.o8 = Observation(self.ident2, [(self.traits2[1], self.s2), (self.traits[1], self.s1), (self.traits2[2], self.s1)], 1) self.o9 = Observation(self.ident2, [(self.traits2[1], self.s1), (self.traits[1], self.s1), (self.traits2[2], self.s2)], 1) self.sf1 = SimpleFormula(self.im1, self.traits[1], self.s1) self.sf3 = SimpleFormula(self.im2, self.traits2[2], self.s2) self.cf1 = ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s3], LogicalOperator.AND) self.cf2 = ComplexFormula(self.im2, [self.traits2[0], self.traits2[1]], [self.s1, self.s1], LogicalOperator.AND) self.cf3 = ComplexFormula(self.im1, [self.traits[1], self.traits[2]], [self.s2, self.s1], LogicalOperator.AND) self.cf4 = ComplexFormula(self.im2, [self.traits2[1], self.traits2[2]], [self.s1, self.s1], LogicalOperator.AND) self.bp1 = BaseProfile(1, [self.o1, self.o2, self.o3]) self.bp2 = BaseProfile(2, [self.o1, self.o5, self.o4]) self.bp3 = BaseProfile(3, [self.o5, self.o1, self.o3]) self.bp4 = BaseProfile(3, [self.o5]) self.bp5 = BaseProfile(3, [self.o7]) self.bp6 = BaseProfile(3, [self.o8]) self.bp7 = BaseProfile(3, [self.o9]) self.dk1 = DistributedKnowledge(self.cf1, [self.bp1, self.bp4], 1) self.dk2 = DistributedKnowledge(self.cf2, [self.bp2, self.bp3], 2) self.dk3 = DistributedKnowledge(self.sf1, [self.bp4]) self.dk4 = DistributedKnowledge(self.sf3, [self.bp3], 12) self.dk5 = DistributedKnowledge(self.cf3, [self.bp1, self.bp4], 1) self.dk6 = DistributedKnowledge(self.cf4, [self.bp4, self.bp5, self.bp6, self.bp7], 2) self.nbholon1 = NonBinaryHolon(self.dk1) self.nbholon2 = NonBinaryHolon(self.dk2) self.ras = RiseAndShine() self.wM1 = WokeMemory([self.nbholon1, self.nbholon2], [self.bp4, self.bp5, self.bp6, self.bp7], [self.im1, self.im2]) self.testowyinterrcomplex = Interrogative(None, None, None, None, "is QRCode{id=2} Konieczny " "and is_not Bolszoj ?", self.wM1)
def setUp(self): self.ident1 = QRCode("1") self.ident2 = QRCode("2") self.ident3 = QRCode("-231") self.traits = [Trait("Obly"), Trait("Krasny"), Trait("Sowiecki")] self.traits2 = [Trait("Barowalny"), Trait("Konieczny"), Trait("Bolszoj")] self.s1 = State.IS self.s2 = State.IS_NOT self.s3 = State.MAYHAPS self.object_type = ObjectType(1, self.traits) self.object_type2 = ObjectType(2, self.traits2) self.im1 = IndividualModel(self.ident1, self.object_type) self.im2 = IndividualModel(self.ident2, self.object_type2) self.o1 = Observation(self.ident1, [(self.traits[0], self.s1), (self.traits2[2], self.s1), (self.traits[1], self.s2)]) self.o2 = Observation(self.ident2, [(self.traits[1], self.s1), (self.traits2[1], self.s2), (self.traits[1], self.s2)], 1) self.o3 = Observation(self.ident3, [(self.traits[2], self.s1), (self.traits2[0], self.s3), (self.traits[2], self.s1)]) self.o4 = Observation(self.ident1, [(self.traits[2], self.s3), (self.traits2[0], self.s3), (self.traits[2], self.s2)]) self.o5 = Observation(self.ident2, [(self.traits[1], self.s1), (self.traits2[1], self.s1), (self.traits[1], self.s3)], 1) self.o6 = Observation(self.ident2, [(self.traits2[1], self.s1), (self.traits[1], self.s1), (self.traits2[2], self.s1)], 1) self.o7 = Observation(self.ident2, [(self.traits2[1], self.s2), (self.traits[1], self.s1), (self.traits2[2], self.s1)], 1) self.bp1 = BaseProfile(1, [self.o1, self.o2, self.o3]) self.bp2 = BaseProfile(2, [self.o1, self.o5, self.o4]) self.bp3 = BaseProfile(3, [self.o5, self.o1, self.o3]) self.bp4 = BaseProfile(3, [self.o5]) self.bp6 = BaseProfile(4, [self.o6]) self.bp7 = BaseProfile(4, [self.o7]) self.cf1 = ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s3], LogicalOperator.AND) self.cf2 = ComplexFormula(self.im2, [self.traits2[0], self.traits2[1]], [self.s1, self.s1], LogicalOperator.AND) self.sf1 = SimpleFormula(self.im1, self.traits[1], self.s1) self.sf3 = SimpleFormula(self.im2, self.traits2[2], self.s2) self.sf4 = SimpleFormula(self.im2, self.traits2[1], self.s1) self.sf5 = SimpleFormula(self.im2, self.traits2[1], self.s2) self.dk1 = DistributedKnowledge(self.cf1, [self.bp1, self.bp4], 1) self.dk2 = DistributedKnowledge(self.cf2, [self.bp2, self.bp3], 2) self.dk3 = DistributedKnowledge(self.sf1, [self.bp4]) self.dk4 = DistributedKnowledge(self.sf3, [self.bp3], 12) self.dk5 = DistributedKnowledge(self.sf4, [self.bp6, self.bp4], 12) self.dk6 = DistributedKnowledge(self.sf5, [self.bp6, self.bp7], 12) self.DE = DistanceEstimator() self.CC = CompositeContext(self.DE, [self.bp6, self.bp7], 1, 1) self.CC2 = CompositeContext(self.DE, [self.bp6, self.bp7, self.bp4], 1, 1) self.CC3 = CompositeContext(self.DE, [self.bp6, self.bp6, self.bp2], 2, 1) self.bholon1 = BinaryHolon(self.dk3) self.bholon2 = BinaryHolon(self.dk4) self.bholon3 = BinaryHolon(self.dk5) self.bholon4 = BinaryHolon(self.dk6) self.bholon5 = BinaryHolon(self.dk6, self.CC.get_contextualized_bpset()) self.bholon6 = BinaryHolon(self.dk3, self.CC2.get_contextualized_bpset()) self.bholon7 = BinaryHolon(self.dk5, self.CC2.get_contextualized_bpset()) self.bholon8 = BinaryHolon(self.dk5, self.CC3.get_contextualized_bpset())
class BinaryHolonTest(unittest.TestCase): def setUp(self): self.ident1 = QRCode("1") self.ident2 = QRCode("2") self.ident3 = QRCode("-231") self.traits = [Trait("Obly"), Trait("Krasny"), Trait("Sowiecki")] self.traits2 = [Trait("Barowalny"), Trait("Konieczny"), Trait("Bolszoj")] self.s1 = State.IS self.s2 = State.IS_NOT self.s3 = State.MAYHAPS self.object_type = ObjectType(1, self.traits) self.object_type2 = ObjectType(2, self.traits2) self.im1 = IndividualModel(self.ident1, self.object_type) self.im2 = IndividualModel(self.ident2, self.object_type2) self.o1 = Observation(self.ident1, [(self.traits[0], self.s1), (self.traits2[2], self.s1), (self.traits[1], self.s2)]) self.o2 = Observation(self.ident2, [(self.traits[1], self.s1), (self.traits2[1], self.s2), (self.traits[1], self.s2)], 1) self.o3 = Observation(self.ident3, [(self.traits[2], self.s1), (self.traits2[0], self.s3), (self.traits[2], self.s1)]) self.o4 = Observation(self.ident1, [(self.traits[2], self.s3), (self.traits2[0], self.s3), (self.traits[2], self.s2)]) self.o5 = Observation(self.ident2, [(self.traits[1], self.s1), (self.traits2[1], self.s1), (self.traits[1], self.s3)], 1) self.o6 = Observation(self.ident2, [(self.traits2[1], self.s1), (self.traits[1], self.s1), (self.traits2[2], self.s1)], 1) self.o7 = Observation(self.ident2, [(self.traits2[1], self.s2), (self.traits[1], self.s1), (self.traits2[2], self.s1)], 1) self.bp1 = BaseProfile(1, [self.o1, self.o2, self.o3]) self.bp2 = BaseProfile(2, [self.o1, self.o5, self.o4]) self.bp3 = BaseProfile(3, [self.o5, self.o1, self.o3]) self.bp4 = BaseProfile(3, [self.o5]) self.bp6 = BaseProfile(4, [self.o6]) self.bp7 = BaseProfile(4, [self.o7]) self.cf1 = ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s3], LogicalOperator.AND) self.cf2 = ComplexFormula(self.im2, [self.traits2[0], self.traits2[1]], [self.s1, self.s1], LogicalOperator.AND) self.sf1 = SimpleFormula(self.im1, self.traits[1], self.s1) self.sf3 = SimpleFormula(self.im2, self.traits2[2], self.s2) self.sf4 = SimpleFormula(self.im2, self.traits2[1], self.s1) self.sf5 = SimpleFormula(self.im2, self.traits2[1], self.s2) self.dk1 = DistributedKnowledge(self.cf1, [self.bp1, self.bp4], 1) self.dk2 = DistributedKnowledge(self.cf2, [self.bp2, self.bp3], 2) self.dk3 = DistributedKnowledge(self.sf1, [self.bp4]) self.dk4 = DistributedKnowledge(self.sf3, [self.bp3], 12) self.dk5 = DistributedKnowledge(self.sf4, [self.bp6, self.bp4], 12) self.dk6 = DistributedKnowledge(self.sf5, [self.bp6, self.bp7], 12) self.DE = DistanceEstimator() self.CC = CompositeContext(self.DE, [self.bp6, self.bp7], 1, 1) self.CC2 = CompositeContext(self.DE, [self.bp6, self.bp7, self.bp4], 1, 1) self.CC3 = CompositeContext(self.DE, [self.bp6, self.bp6, self.bp2], 2, 1) self.bholon1 = BinaryHolon(self.dk3) self.bholon2 = BinaryHolon(self.dk4) self.bholon3 = BinaryHolon(self.dk5) self.bholon4 = BinaryHolon(self.dk6) self.bholon5 = BinaryHolon(self.dk6, self.CC.get_contextualized_bpset()) self.bholon6 = BinaryHolon(self.dk3, self.CC2.get_contextualized_bpset()) self.bholon7 = BinaryHolon(self.dk5, self.CC2.get_contextualized_bpset()) self.bholon8 = BinaryHolon(self.dk5, self.CC3.get_contextualized_bpset()) def test_get_tao(self): self.assertEqual(self.bholon1.get_tao(), [0, 0]) self.assertEqual(self.bholon2.get_tao(), [0, 0]) self.assertEqual(self.bholon3.get_tao(), [1.0, 0]) self.assertEqual(self.bholon4.get_tao(), [0.5, 0.5]) def test_get_kind(self): self.assertEqual(self.bholon1.get_kind(), HolonKind.BH) def test_get_formula(self): self.assertEqual(self.bholon1.get_formula(), self.sf1) def test_get_complementary_formulas(self): self.assertEqual(self.bholon1.get_complementary_formulas(), self.sf1.get_complementary_formulas()) def test_is_applicable(self): self.assertTrue(self.bholon1.is_applicable(self.sf1)) self.assertFalse(self.bholon1.is_applicable(self.sf5)) def test_get_tao_for_state(self): self.assertEqual(self.bholon1.get_tao_for_state(self.s1), 0.0) def test_context(self): self.assertEqual(self.bholon5.get_tao(), [0.5, 0.5]) self.assertEqual(self.bholon7.get_tao(), [0.6666666666666666, 0.3333333333333333]) self.assertEqual(self.bholon7.get_context(), [self.bp6, self.bp7, self.bp4]) self.assertEqual(self.bholon6.get_tao(), [0.0, 0.0]) self.assertEqual(self.bholon8.get_context(), [self.bp6, self.bp6, self.bp2]) def tearDown(self): self.traits2 = None self.traits = None self.ident1 = None self.ident2 = None self.ident3 = None self.o1 = None self.o2 = None self.o3 = None self.o4 = None self.o5 = None self.s1 = None self.s2 = None self.s3 = None self.bp1 = None self.bp2 = None self.bp3 = None
class TestDistributedKnowledge(unittest.TestCase): def setUp(self): self.ident1 = QRCode("1") self.ident2 = QRCode("2") self.ident3 = QRCode("-231") self.traits = [Trait("Obly"), Trait("Krasny"), Trait("Sowiecki")] self.traits2 = [ Trait("Barowalny"), Trait("Konieczny"), Trait("Bolszoj") ] self.s1 = State.IS self.s2 = State.IS_NOT self.s3 = State.MAYHAPS self.object_type = ObjectType(1, self.traits) self.object_type2 = ObjectType(2, self.traits2) self.im1 = IndividualModel(self.ident1, self.object_type) self.im2 = IndividualModel(self.ident2, self.object_type2) self.o1 = Observation(self.ident1, [(self.traits[0], self.s1), (self.traits2[2], self.s1), (self.traits[1], self.s2)]) self.o2 = Observation(self.ident2, [(self.traits[1], self.s3), (self.traits2[1], self.s2), (self.traits[1], self.s2)], 1) self.o3 = Observation(self.ident3, [(self.traits[2], self.s1), (self.traits2[0], self.s3), (self.traits[2], self.s1)]) self.o4 = Observation(self.ident1, [(self.traits[2], self.s3), (self.traits2[0], self.s3), (self.traits[2], self.s2)]) self.o5 = Observation(self.ident2, [(self.traits[1], self.s1), (self.traits2[1], self.s2), (self.traits[1], self.s3)], 1) self.bp1 = BaseProfile(1, [self.o1, self.o2, self.o3]) self.bp2 = BaseProfile(2, [self.o1, self.o5, self.o4]) self.bp3 = BaseProfile(3, [self.o5, self.o1, self.o3]) self.bp4 = BaseProfile(3, [self.o5]) self.cf1 = ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s3], LogicalOperator.AND) self.cf2 = ComplexFormula(self.im2, [self.traits2[0], self.traits2[1]], [self.s1, self.s1], LogicalOperator.AND) self.sf1 = SimpleFormula(self.im1, self.traits[1], self.s1) self.sf3 = SimpleFormula(self.im2, self.traits2[2], self.s2) self.dk1 = DistributedKnowledge(self.cf1, [self.bp1, self.bp4], 1) self.dk2 = DistributedKnowledge(self.cf2, [self.bp2, self.bp3], 2) self.dk3 = DistributedKnowledge(self.sf1, [self.bp1, self.bp2]) self.dk4 = DistributedKnowledge(self.sf3, [self.bp3], 12) def test_get_formula(self): self.assertEqual(self.dk1.get_formula(), self.cf1) self.assertEqual(self.dk2.get_formula(), self.cf2) self.assertEqual(self.dk3.get_formula(), self.sf1) def test_get_timestamp(self): self.assertEqual(self.dk1.get_episode(), 1) self.assertEqual(self.dk2.get_episode(), 2) self.assertEqual(self.dk4.get_episode(), 12) def test_get_bpset(self): self.assertEqual(self.dk1.get_bpset(), [self.bp1, self.bp4]) self.assertEqual(self.dk2.get_bpset(), [self.bp2, self.bp3]) self.assertEqual(self.dk4.get_bpset(), [self.bp3]) def test_get_complementary_formulas(self): self.assertEqual(self.dk1.get_complementary_formulas(), [ ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s1, self.s1], LogicalOperator.AND), ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s1, self.s2], LogicalOperator.AND), ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s1], LogicalOperator.AND), ComplexFormula(self.im1, [self.traits[0], self.traits[1]], [self.s2, self.s2], LogicalOperator.AND) ]) self.assertEqual( self.dk3.get_complementary_formulas(), [self.sf1, SimpleFormula(self.im1, self.traits[1], self.s2)]) def test_get_grounding_sets(self): self.assertEqual(len(self.dk4.get_grounding_sets()), 1) self.assertEqual( list(self.dk4.get_grounding_sets().keys())[0], self.sf3.get_traits()[0]) self.assertEqual(self.dk4.get_grounding_sets(), {self.traits2[2]: self.bp3}) def test_get_grounding_set(self): self.assertEqual(len(self.dk4.get_grounding_set(self.sf1)), 0) self.assertEqual(len(self.dk4.get_grounding_set(self.sf3)), 0) self.assertEqual(len(self.dk4.get_grounding_set(self.cf1)), 0) def tearDown(self): self.traits2 = None self.traits = None self.ident1 = None self.ident2 = None self.ident3 = None self.o1 = None self.o2 = None self.o3 = None self.o4 = None self.o5 = None self.s1 = None self.s2 = None self.s3 = None self.bp1 = None self.bp2 = None self.bp3 = None