import re
merge_list = []
all_sentences = []
with open("TrainNLI.txt", 'r') as input_file:
        for line in input_file:
            try: # This is added
                  
              # print("\n\n"+ line)
              words = line.split()
              if len(words)>0:
                  if len(words) == 1:
                      if len(merge_list)>0:
                              sentence = ' '.join(merge_list)
                              merge_list = []
                              all_sentences.append(sentence)
                      
                      merge_list.append(words[0])
                      
                  elif line.startswith('('):
                      merge_list.append(line)
                      #   print("\n\n"+ line)
                  else:
                      if len(merge_list)>0:
                              sentence = ' '.join(merge_list)
                              merge_list = []
                              all_sentences.append(sentence)
                              # print("\n\n"+ sentence)
                      else:
                              sentence = line
                              # print("\n\n"+ line)
                              all_sentences.append(line)
            except Exception as e:
                  print("Skip")


def process_sentence(line):
      
      try:

            
        label_match = re.search(r'^\s*(.*?)\s*\(', line)
        label = label_match.group(1) if label_match else ""

      # Removing brackets or replacing with spaces
        cleaned_sentence = re.sub(r'[\(\)]', '', line)

      # Extracting the premise and hypothesis sentences
        sentences = re.findall(r'\s+([^\(\)]+)\s+', cleaned_sentence)
        

        all_sent = sentences[0]
        twosentences = all_sent.split(".")
        # print(twosentences)

        premise = twosentences[0]
        hypothesis = twosentences[1]
        cleaned_premise = ' '.join(premise.split())
        cleaned_hypothesis = ' '.join(hypothesis.split())
      # Printing the extracted sentences
        print("Label:", label)
        print("Premise:", cleaned_premise.strip())
        print("Hypothesis:", cleaned_hypothesis.strip())
      except Exception as e:
           print(label)


      
                  
               
for sent in all_sentences:
      #print(sent)
      process_sentence(sent)

                  
                  

            
