@@ -658,8 +658,7 @@ def to_json(self) -> dict:
658658 -------
659659 out : dict
660660 """
661- return {
662- 'id' : self .id ,
661+ d = {
663662 'type' : self .__class__ .__name__ ,
664663 'propositions' : list (
665664 map (
@@ -669,6 +668,10 @@ def to_json(self) -> dict:
669668 ),
670669 'value' : self .value
671670 }
671+ if not self .generated_id :
672+ d ['id' ] = self .id
673+
674+ return d
672675
673676 def to_b64 (self , str_decoding : str = 'utf8' ) -> str :
674677
@@ -810,17 +813,9 @@ def to_json(self) -> dict:
810813 -------
811814 out : dict
812815 """
813- return {
814- 'id' : self .id ,
815- 'type' : self .__class__ .__name__ ,
816- 'propositions' : list (
817- map (
818- operator .methodcaller ("to_json" ),
819- self .propositions
820- )
821- ),
822- 'value' : - 1 * self .value
823- }
816+ d = super ().to_json ()
817+ d ['value' ] = - 1 * self .value
818+ return d
824819
825820class All (AtLeast ):
826821
@@ -871,16 +866,15 @@ def to_json(self) -> dict:
871866 -------
872867 out : dict
873868 """
874- return {
875- 'id' : self .id ,
876- 'type' : self .__class__ .__name__ ,
877- 'propositions' : list (
878- map (
879- operator .methodcaller ("to_json" ),
880- self .propositions
881- )
882- ),
883- }
869+ d = super ().to_json ()
870+ del d ['value' ]
871+ d ['propositions' ] = list (
872+ map (
873+ operator .methodcaller ("to_json" ),
874+ self .propositions
875+ )
876+ )
877+ return d
884878
885879class Any (AtLeast ):
886880
@@ -931,16 +925,15 @@ def to_json(self) -> dict:
931925 -------
932926 out : dict
933927 """
934- return {
935- 'id' : self .id ,
936- 'type' : self .__class__ .__name__ ,
937- 'propositions' : list (
938- map (
939- operator .methodcaller ("to_json" ),
940- self .propositions
941- )
942- ),
943- }
928+ d = super ().to_json ()
929+ del d ['value' ]
930+ d ['propositions' ] = list (
931+ map (
932+ operator .methodcaller ("to_json" ),
933+ self .propositions
934+ )
935+ )
936+ return d
944937
945938class Imply (Any ):
946939
@@ -1002,12 +995,14 @@ def to_json(self) -> dict:
1002995 -------
1003996 out : dict
1004997 """
1005- return {
1006- 'id' : self .id ,
998+ d = {
1007999 'type' : self .__class__ .__name__ ,
10081000 'condition' : self .condition .negate ().to_json (),
10091001 'consequence' : self .consequence .to_json (),
10101002 }
1003+ if not self .generated_id :
1004+ d ['id' ] = self .id
1005+ return d
10111006
10121007 @staticmethod
10131008 def from_cicJE (data : dict , id_ident : str = "id" ) -> "Imply" :
@@ -1131,8 +1126,7 @@ def to_json(self) -> dict:
11311126 -------
11321127 out : dict
11331128 """
1134- return {
1135- 'id' : self .id ,
1129+ d = {
11361130 'type' : self .__class__ .__name__ ,
11371131 'propositions' : list (
11381132 map (
@@ -1141,6 +1135,9 @@ def to_json(self) -> dict:
11411135 )
11421136 ) if len (self .propositions ) > 0 else [],
11431137 }
1138+ if not self .generated_id :
1139+ d ['id' ] = self .id
1140+ return d
11441141
11451142class Not ():
11461143
@@ -1213,6 +1210,28 @@ def from_json(data: dict, class_map) -> "XNor":
12131210 def from_list (propositions : list , variable : typing .Union [str , puan .variable ] = None ):
12141211 return XNor (* propositions , variable = variable )
12151212
1213+ def to_json (self ) -> dict :
1214+
1215+ """
1216+ Returns proposition as a readable json.
1217+
1218+ Returns
1219+ -------
1220+ out : dict
1221+ """
1222+ d = {
1223+ 'type' : self .__class__ .__name__ ,
1224+ 'propositions' : list (
1225+ map (
1226+ operator .methodcaller ("to_json" ),
1227+ self .propositions [0 ].propositions
1228+ )
1229+ ) if len (self .propositions ) > 0 else [],
1230+ }
1231+ if not self .generated_id :
1232+ d ['id' ] = self .id
1233+ return d
1234+
12161235def from_json (data : dict , class_map : list = [puan .variable ,AtLeast ,AtMost ,All ,Any ,Xor ,Not ,XNor ,Imply ]) -> typing .Any :
12171236
12181237 """
0 commit comments