读取Word中使用的回车数量

时间:2017-02-28 09:44:07

标签: vbscript ms-word

我通过计算跟踪审核开始后所做的更改总数来计算word文档的准确性。标点符号的错误使用计算为1/4标记,而对于上下文或语法错误,则扣除完整的1标记。

现在所有回车都计算为1满分。我想要将其完全删除,或者可以将其作为1/4标记扣除。我正在使用以下内容进行计数。 ;并且,作为1/4标记扣除。

For Each myRevision In ActiveDocument.Revisions
myRevision.Range.Select
    If myRevision.Type = wdRevisionInsert Then
        lngRevisions = Len(Selection.Text)
        For i = 1 To lngRevisions
            If Mid(Selection.Text, i, 1) = "," Then
                punct = punct + 1
            Else
            End If

            If Mid(Selection.Text, i, 1) = "." Then
                punct = punct + 1
            Else
            End If

            If Mid(Selection.Text, i, 1) = ";" Then
                punct = punct + 1
            Else
            End If
            If Mid(Selection.Text, i, 1) = "" Then
                punct = punct + 1
            Else
            End If
       Next i
       Count = Count + 1
    Else
    End If
Next

tCorrections = Count + punct * 0.25 - punct


Accuracy = ((tWords - tCorrections) / tWords) * 100
Accuracy = Round(Accuracy, 1)

1 个答案:

答案 0 :(得分:0)

使用类型名称数组(aLabels)和数据中出现的类型字符串(sC),通过类型映射(aMap)计算插槽,以便灵活地对字符串进行分类。如本演示所示:

Option Explicit

Dim aLabels : aLabels = Split("Vowels Consants Digits Punctuations EOLs Unclassified")
ReDim aCounts(UBound(aLabels))
Dim sC : sC = "abce1,2." & vbCr
Dim aMap : aMap = Array(0, 1, 1, 0, 2, 3, 2, 3, 4)
Dim sD : sD = sC & "d" & sC & "bb111."
Dim p, i
For p = 1 To Len(sD)
    i = Instr(sC, Mid(sD, p, 1))
    If 0 = i Then
       i = UBound(aLabels)
    Else
       i = aMap(i - 1)
    End If
    aCounts(i) = aCounts(i) + 1
Next
For i = 0 To UBound(aLabels)
    WScript.Echo Right("   " & aCounts(i), 3), aLabels(i)
Next

输出:

cscript 42505210.vbs
  4 Vowels
  6 Consants
  7 Digits
  5 Punctuations
  2 EOLs
  1 Unclassified

根据这些原始数据(类型的频率),您可以添加特殊权重。

更新评论:

正如我所说:在计算原始频率后添加权重:

... as above ...
Dim nSum
' Std - all weights = 1
nSum = 0 : For Each i In aCounts : nSum = nSum + i : Next
WScript.Echo "all pigs are equal:", nSum
' No EOLs
nSum = 0 : For Each i In aCounts : nSum = nSum + i : Next : nSum = nSum - aCounts(4)
WScript.Echo "EOLs don't count:", nSum
nSum = 0 : aCounts(0) = aCounts(0) * 4 : For Each i In aCounts : nSum = nSum + i : Next
WScript.Echo "vowels count * 4:", nSum

额外输出:

all pigs are equal: 25
EOLs don't count: 23
vowels count * 4: 37