Consulting

Results 1 to 3 of 3

Thread: Sentence Type Detection

  1. #1

    Sentence Type Detection

    I try to detect simple, compound, complex and complex-compound using Word VBA and color the sentence using occurrence of punctuation pattern.
    Having challenge detecting the start of the sentence in .Text = ";*." and find complex-compound overrides complex function.

    Expected output

    Tom reads newspapers.
    Tom reads novels and newspapers.
    Tom reads and enjoys novels.
    Tom and Harry read novels.
    Tom and Harry read and enjoy novels and newspapers.

    Tom reads novels, but Jack reads comics.
    Tom reads novels; however, Jack reads comics.
    Tom reads novels; his friend reads comics.


    Although Tom reads novels, Jack reads comics.
    Jack reads comics although Tom reads novels.
    Jack Smith, who reads comics, rarely reads novels.
    People who read comics rarely read novels.


    While Tom reads novels, Jack reads comics, but Sam reads only magazines.
    Tom reads novels, but Jack reads comics because books are too difficult.
    Jack, who reads comics, rarely reads novels; however, Tom enjoys novels.
    People who read comics rarely read novels; they often find books difficult.


    Sub clause()
    StatusBar = "Phrase highlighting."
         'A basic Word macro coded by Greg Maxey
        Dim oPar As Paragraph
        Dim oRng, oRng1 As Range
        Set oPar = ActiveDocument.Paragraphs(1)
        Do
            If InStr(1, oPar.Range.Text, ",") > 0 Then
                Set oRng = oPar.Range
                With oRng
                    .Collapse 1
                    .MoveEndUntil "."
                    .Font.Color = wdColorRed
                End With
            End If
            Set oPar = oPar.Next
        Loop Until oPar Is Nothing
      Application.ScreenUpdating = False
        With ActiveDocument.Range
            With .Find
                .ClearFormatting
                .Replacement.ClearFormatting
                .Text = ";*."
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindStop
                .Format = False
                .MatchWildcards = True
                .Execute
            End With
            Do While .Find.Found
                 .Font.Color = wdColorBlue
    
    
                .Find.Execute
            Loop
        End With
        Application.ScreenUpdating = True
    StatusBar = ""
    End Sub
    Current output
    Untitled.jpg



    How to go about with this? Is my approach correct?

    Future scope - Planning to put conjunction and conjugate adverb in an array and color sentences based on its occurrence. Is there a link or way where i can check how to color a sentence if a particular word occurs within the sentence.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    IMO, you are too dependent on absolutely proper punctuation.

    Ex: Tom reads novels, his friend reads comics.

    What if you compared each part after Splitting on punctuations...
    Tom reads novels + his friend reads comics
    ? Simple + Simple = Compound? Yes ?
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Yes you are right.

    It is very basic level check for sentences that adhere to correct punctuation.

    Sort of experimental tool in my tool box. I am okay even if it raises false positives or misses a few right ones.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •