WORD'2007: word repetitions
Thread poster: DZiW

DZiW
Ukraine
English to Russian
+ ...
Jul 1, 2017

Dear colleagues,

Now I'm struggling with a problem to mark all the repetitions within 50 words...
First I thought about CreateObject("Scripting.Dictionary"), but not sure how to handle it better.

The idea is simple: Prepare a 50-word FiFO (first-in, first-out) 'buffer' list as a string with space delimiters and check every next word, marking any repetitions and updating the list--deleting the first word and adding the new word--till the end.

I'm not a big coder, yet here is a quick'n'dirty draft
Code:
For i=1 to ThisDocument.Words.Count 'main loop
Set S=ThisDocument.Words(i) 'reference to the i-th word
W=Ucase(Trim(S)) 'no spaces and not case sensitive
'---------------------
If Left(W,1)=Letter Then 'IsAlpha only
If i>50 Then 'after the initial 50-word list is ready
q=InStr(1,W,T) 'is there a substring W in T?
if q>0 then S.Font.Color=some_color 'mark the repetition
q=InStr(1," ",T) 'find the first space delimiter
T=Mid(T,q+1) 'delete the first word plus space
End IF 'i>50
'---------------------
T=T+W+" " 'add new word to the list
End If 'Left(W,1)=Letter
Next

However, something went wrong, in the very concept, perhaps)
How would you solve such a task? Also I'm not sure about CleanString, AscW and such for ANSI/Unicode, any ideas?

TY


Direct link Reply with quote
 

DZiW
Ukraine
English to Russian
+ ...
TOPIC STARTER
Slowpoking, but works Jul 2, 2017

Knowing several languages does interfere, even when it's just programming, especially when tired)
Code:
Sub Repetitions()
Const SPAN = 49 'range
N = ThisDocument.Words.Count: If N < 50 Then Exit Sub 'exit if nothing to do
Application.ScreenUpdating = 0 'to speed a little up
repetition = 0
Dim list As String
Dim word As String
list = ""
'-----------------------------------
For i% = 1 To N 'loop with each word
Set s = ThisDocument.Words(i%) 'a reference to word
word = UCase(Trim(s)) 'clean word up

If Left(word, 1) Like "[A-ZА-Я]" Then 'if begins with a letter (=ignore numbers and garbage)

If i > SPAN Then 'if the list is ready
q = InStr(1, list, word + " ", 1): If q > 0 Then s.Font.ColorIndex = wdRed: repetition = repetition + 1 'found and marked
q = InStr(1, list, " ", 1): list = Mid(list, q + 1) 'remove the first (obsolete) word from list
End If 'i>49

list = list + word + " " 'add the new word to list
End If 'like

Application.StatusBar = N - i 'countdown
If i Mod 200 = 0 Then DoEvents 'check events, including CTRL+SCRLOCK
Next
'-----------------------------------
Application.ScreenUpdating = 1 'restore screen
Application.StatusBar = False 'reset status
DoEvents
'If repetition > 0 Then
MsgBox repetition, , "Repetitions"
End Sub



[Edited at 2017-07-02 20:14 GMT]


Direct link Reply with quote
 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

WORD'2007: word repetitions

Advanced search






SDL Trados Studio 2017 Freelance
The leading translation software used by over 250,000 translators.

SDL Trados Studio 2017 helps translators increase translation productivity whilst ensuring quality. Combining translation memory, terminology management and machine translation in one simple and easy-to-use environment.

More info »
Déjà Vu X3
Try it, Love it

Find out why Déjà Vu is today the most flexible, customizable and user-friendly tool on the market. See the brand new features in action: *Completely redesigned user interface *Live Preview *Inline spell checking *Inline

More info »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search