@@ -62,6 +62,7 @@ class Meta:
6262 "entailmentLabel" ,
6363 "extraData" ,
6464 "kbItems" ,
65+ "base" ,
6566 ]
6667
6768 def get_premises (self , problem ):
@@ -104,6 +105,7 @@ def create(self, validated_data: dict) -> Problem:
104105 )[0 ]
105106
106107 problem = Problem .objects .create (
108+ base_id = validated_data .get ("base" , None ),
107109 hypothesis = hypothesis_sentence ,
108110 dataset = Problem .Dataset .USER ,
109111 # TODO: Determine entailment label based on LangPro parser output.
@@ -132,6 +134,19 @@ def update(self, instance: Problem, validated_data: dict) -> Problem:
132134 instance .hypothesis = Sentence .objects .get_or_create (
133135 text = validated_data ["hypothesis" ],
134136 )[0 ]
137+
138+ validated_base_id = validated_data .get ("base" , None )
139+ if validated_base_id is None :
140+ instance .base = None
141+ else :
142+ try :
143+ base_problem = Problem .objects .get (id = validated_base_id )
144+ except Problem .DoesNotExist :
145+ raise serializers .ValidationError (
146+ f"Base problem with ID { validated_base_id } does not exist."
147+ )
148+ instance .base = base_problem # type: ignore
149+
135150 instance .save ()
136151
137152 premise_sentences = [
@@ -188,6 +203,8 @@ class ProblemInputSerializer(serializers.Serializer):
188203 many = True , allow_empty = True , help_text = "List of knowledge base items"
189204 )
190205
206+ base = serializers .IntegerField (required = False , allow_null = True )
207+
191208 def validate_id (self , value ):
192209 """Validate that the Problem ID, if provided, exists and belongs to a user-created problem."""
193210 if value is not None :
@@ -198,3 +215,12 @@ def validate_id(self, value):
198215 f"Problem with ID { value } does not exist."
199216 )
200217 return value
218+
219+ def validate_base (self , value ):
220+ """Validate that the base problem ID exists if provided."""
221+ if value is not None :
222+ if not Problem .objects .filter (id = value ).exists ():
223+ raise serializers .ValidationError (
224+ f"Base problem with ID { value } does not exist."
225+ )
226+ return value
0 commit comments