Sort by

recency

|

60 Discussions

|

  • + 0 comments

    AI Sigil: Elevating AI governance with automated tools for policy creation, audits, and legal documents. Ethics and compliance made simple. EU AI Act solutions

  • + 0 comments
    import re
    s = input()
    
    
    pattern = r'(?<!")([.?!])(?!")'
    split_text = re.split(pattern, s)
    #merge back the sentence + last character
    merged_list = [split_text[i] + split_text[i + 1] for i in range(0, len(split_text) - 1, 2)]
    
    #check for words <= 2 and anding on a fullstop. These are like Dr. Mr. Ms. etc and merge these back
    new_text = []
    do_continue = False
    for i in range(len(merged_list) - 1):
        #print(i, "new_text: " , merged_list[i])
        if do_continue:
            do_continue = False
            continue
            
        if len(merged_list[i].strip()) <= 3 and merged_list[i][-1] == ".":
            new_text[-1] = new_text[-1] + " " + merged_list[i].strip()
            new_text[-1] = new_text[-1] + " " + merged_list[i+1].strip()
    				#skip the next entry in the list
            do_continue = True
        else:
            new_text.append(merged_list[i])
            
    for i in new_text:   
         print(i)
    
  • + 0 comments

    light

  • + 0 comments

    Hiden test case 0 and 1 error. But I can run it on Collab and here. Why?

    My code: input_text = input("Enter your text: ")

    def split_into_sentences(text): pattern = r'(?

  • + 0 comments

    import re

    def split_sentences(text): # Define the regular expression pattern to match sentence boundaries pattern = r"""(?<=\w.)\s+"""

    # Split the text into sentences using the pattern
    sentences = re.split(pattern, text)
    
    # Clean up the sentences by removing leading and trailing whitespace and empty strings
    sentences = [sentence.strip() for sentence in sentences if sentence.strip()]
    
    # Handle sentences ending with common abbreviations (e.g., Dr., Mr., Mrs.)
    sentences = [sentence[:-1] if sentence.endswith(".") and sentence[-2:] in [".D", ".M", ".M"] else sentence for sentence in sentences]
    
    return sentences
    

    Get the input text from the user

    input_text = input("Enter your text: ")

    Split the text into sentences

    sentences = split_sentences(input_text)

    Print the sentences

    for sentence in sentences: print(sentence)