PDA

View Full Version : [SOLVED:] Check if the first word of previous paragraph is the same as the next paragraph.



ossosso
12-26-2017, 03:41 AM
Hi,
I'm Daniele from Italy.

I thank you for the possibility you give to me to ask in this forum. I try to be as clear and short as possible. Forgive me for my simple English.

I'm a transcriber. I listen audio and I transcribe. The kind of transcription is a dialogue, like an interview. This is the output:

SPEAKER ONE - Bla bla bla.
SPEAKER TWO - Bla bla bla.
SPEAKER ONE - Bla bla bla.
SPEAKER TWO - Bla bla bla.

...and so on...

During the job I have to type really fast, almost in realtime, and could happen I confuse the speaker, and I press the wrong shortcut to insert the speaker name, like this:

SPEAKER ONE - Bla bla bla.
SPEAKER ONE - Bla bla bla.
SPEAKER ONE - Bla bla bla.
SPEAKER TWO - Bla bla bla.

This is a mistake I cannot check using Spellchecker. Basically if the first 9 characters of a paragraph are the same of the first 9 characters of the next paragraph, for sure I made a mistake.

Once I finished to type, is it possible to check the whole document with a macro? To check if the the first 9 characters of a new paragraph are the same of the first 9 characters of the next paragraph. This for all the paragraph, and inform me when it matches, so I can fix.
Let me also say that until the speaker doesn't change, I don't press ENTER, so the paragraph is always the same. Only when the new speaker speaks, I change paragraph pressing ENTER, so each new paragraph correspond to a new speaker.

I thank yoy very very much foro any suggestion.

Good holidays!

Daniele.

gmaxey
12-26-2017, 07:52 AM
Could probably be more efficient, but seems to work for your example:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 12/26/2017
Dim strPattern1 As String, strPattern2 As String
Dim oRngCompare As Range, oRng As Range
strPattern1 = "SPEAKER ONE"
strPattern2 = "SPEAKER TWO"
Set oRngCompare = ActiveDocument.Paragraphs(2).Range
oRngCompare.Start = ActiveDocument.Range.Start
On Error GoTo lbl_Exit
Do
If InStr(oRngCompare, strPattern1) <> 1 Then
Set oRng = oRngCompare.Paragraphs(1).Range
oRng.Collapse wdCollapseStart
oRng.MoveEnd wdCharacter, Len(strPattern1)
oRng.HighlightColorIndex = wdRed
End If
If InStr(oRngCompare.Paragraphs(2), strPattern2) <> 1 Then
Set oRng = oRngCompare.Paragraphs(2).Range
oRng.Collapse wdCollapseStart
oRng.MoveEnd wdCharacter, Len(strPattern2)
oRng.HighlightColorIndex = wdRed
End If
oRngCompare.MoveStart wdParagraph, 2
oRngCompare.MoveEnd wdParagraph, 2
If oRngCompare.Paragraphs.Count < 2 Then Exit Sub
Loop
lbl_Exit:
Exit Sub
End Sub

ossosso
12-26-2017, 03:09 PM
I thank you very much Greg for your fast and useful reply.

I forget to tell one thing. In my example I've used "SPEAKER ONE" and "SPEAKER TWO". But this is just an example, because these words in each document are replaced with the name of the speakers. And in one document there are a lot of different speakers. So a real example could be:

TESTIMONE ROSSI M. - Bla bla bla
DOTT. BIANCHI S. - Bla bla bla
GIUDICE - Bla Bla bla
AVV. VERDI - Bla bla bla

and so on. I cannot insert into the macro a specific name of a paerson, because for each document it changes. But for sure if the following paragraph has the first 9 letters like the previous one, it is an error. Like this

TESTIMONE ROSSI M. - Bla bla bla
DOTT. BIANCHI S. - Bla bla bla
DOTT. BIANCHI S. - Bla Bla bla
AVV. VERDI - Bla bla bla

Paragraph 3 is for sure a mistake, because it is the same as paragraph 2. The spaker changes, because I pressed ENTER for a new paragraph. But I've inserted the same name as the previous paragraph, so I made a mistake. During fast typing can happens that I don't recognize, above all after hours of job. If I could check with a macro once finished the document, would be really useful.

Thanks again.

Daniele.

gmaxey
12-26-2017, 03:59 PM
Daniele,

Try this. I think I will flag a repeated speaker but in some case it might flag the first instance rather than second.


Sub ScratchMacro()
Dim oRngPar As Range
Dim oRngCompare As Range
Dim bRngPar As Boolean
Set oRngPar = ActiveDocument.Paragraphs(2).Range
Set oRngCompare = ActiveDocument.Paragraphs(1).Range
On Error GoTo lbl_Exit
bRngPar = True
oRngPar.Collapse wdCollapseStart
oRngPar.MoveEnd wdCharacter, 9
oRngCompare.Collapse wdCollapseStart
oRngCompare.MoveEnd wdCharacter, 9
Do
If oRngPar.Text = oRngCompare.Text And Not bRngPar Then
oRngPar.HighlightColorIndex = wdRed
ElseIf oRngPar.Text = oRngCompare.Text And bRngPar Then
oRngCompare.HighlightColorIndex = wdRed
End If
If oRngPar.InRange(ActiveDocument.Paragraphs.Last.Range) Then Exit Do
bRngPar = Not bRngPar
oRngPar.Move wdParagraph, 1
oRngPar.MoveEnd wdCharacter, 9
oRngCompare.Move wdParagraph, 1
oRngCompare.MoveEnd wdCharacter, 9
Loop
lbl_Exit:
Exit Sub
End Sub

macropod
12-26-2017, 05:22 PM
You could just use a wildcard Find, where:
Find = ^13([A-z]@>)[!^13]@^13\1
The last-highlighted word will the be same as the first-highlighted word. No macros required.

gmaxey
12-26-2017, 05:36 PM
Paul,

Yes, I suppose for the example she gives that should work. If the names changes as she indicates, then with this case not so well:

Tom Smith blah, blah
Tom Taylor blah, blah
Tom Taylor blah, blah
Tom Taylor blah, blah
Tom Smith blah, blah
Tom Taylor blah, blah
Tom Smith blah, blah

I'm not completely clear on what your expression is actually doing so can't suggest how or even guess if it could be adapted to for cases when the first word is identical but not problematic as in this case.

macropod
12-26-2017, 10:39 PM
I suppose for the example she gives that should work. If the names changes as she indicates, then with this case not so well

That could easily-enough accommodated by changing the expression to look for a match of the first two words, for example:
Find = ^13([A-z.]@ [A-z]@>)[!^13]@^13\1


I'm not completely clear on what your expression is actually doing
The updated example looks for a paragraph break ^13 followed by two words ([A-z.]@ [A-z]@>), spans anything else in the paragraph
[!^13]@^13, followed by the same first two words in the following paragraph \1.

gmaxey
12-27-2017, 05:52 AM
Paul,

Yes that makes sense. Thanks. I have a feeling that blah, blah may actually be lengthy text in some cases so I've plugged your expression into a macro for her:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 12/27/2017
Dim oRng As Word.Range
Dim oRngDup As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "^13([A-z.]@ [A-z]@>)[!^13]@^13\1"
.MatchWildcards = True
While .Execute
Set oRngDup = oRng.Duplicate
oRng.Select
With oRngDup
.Start = oRngDup.Paragraphs(3).Range.Start
.Collapse wdCollapseStart
.MoveEnd wdWord, 2
.HighlightColorIndex = wdRed
End With
oRng.Collapse wdCollapseEnd
Wend
End With
lbl_Exit:
Exit Sub
End Sub