WORD'2007: word repetitions
Thread poster: DZiW (X)
DZiW (X)
DZiW (X)
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'
... See more
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
Collapse


 
DZiW (X)
DZiW (X)
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
... See more
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]
Collapse


 


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






Trados Business Manager Lite
Create customer quotes and invoices from within Trados Studio

Trados Business Manager Lite helps to simplify and speed up some of the daily tasks, such as invoicing and reporting, associated with running your freelance translation business.

More info »
Protemos translation business management system
Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!

The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.

More info »



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