什么定义了 MS-Word 中的句子? [英] What defines a sentence in MS-Word?

查看:30
本文介绍了什么定义了 MS-Word 中的句子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道句子集合只是一堆范围,但我无法确切确定使用什么标准来决定这些范围的开始和结束位置.我已经能够确定句号 (.)、问号 (?) 或感叹号 (!) 后跟一个或多个空格是句子的结尾,并且这些空格包含在句子范围内.我还确定,如果你我之间没有空格,我会认为是两个句子,MS-Word 会认为它只是一个句子.

I know that the sentences collection is just a just a bunch of ranges, but I have not been able to determine exactly what criteria are used to decide where those ranges begin and end. I have been able to determine that a period (.) a question mark (?) or an exclamation point (!) followed by one or more spaces is the end of a sentence and that the spaces are included in the sentence range. I have also determined that if there are no spaces between what you and I would consider two sentences MS-Word considers it as only one sentence.

问题在于,当您开始输入制表符、分页符、换行符等内容时,事情就变得不清楚了.谁能准确地解释一下或向我指出一些参考资料,MS-Word 使用什么标准来决定一个句子在哪里结束,另一个句子在哪里开始?

The problem is when you start putting in things like tabs, page breaks, new line characters etc. things become unclear. Can anyone explain precisely or point me to some reference material what criteria MS-Word uses to decide where one sentence ends and another begins?

推荐答案

似乎是基于句尾类型的定界符(例如."、!"、?").如果你解释你正在尝试做什么或发布一些代码,更多的人会愿意提供帮助.

Seems to be based on a delimiter of a sentence ending type (e.g. ".","!","?"). If you explain what you are trying to do or post some code more people will be willing to help.

如果您担心组合句子(例如,这是一个单独的句子.即使它被分隔),您可以扩展此基本方法.特殊字符似乎更难处理.因此,建议您尝试做的事情

If you are concerned about combined sentences (e.g. This is a single Sentence.Even though it is deliminated) you could expand upon this basic methodology. Special Characters seem to be much harder to handle. So positn what you are trying to do would be suggested

Sub sent_counter()
    Dim s As Integer

    For s = 1 To ActiveDocument.Sentences.Count
        ActiveDocument.Sentences(s) = splitSentences(ActiveDocument.Sentences(s))
    Next s
End Sub

Function splitSentences(s As String) As String
    Dim delims As New Collection
    Dim delim As Variant
    delims.Add "."
    delims.Add "!"
    delims.Add "?"

    Dim ender As String
    Dim sub_s As String

    s = Trim(s)
    ender = Right(s, 1)
    sub_s = Left(s, Len(s) - 1)

    For Each delim In delims
      If InStr(1, sub_s, delim) Then
        sub_s = Replace(sub_s, delim, delim & "  ")
      End If
    Next delim


    splitSentences = sub_s & ender
End Function

这篇关于什么定义了 MS-Word 中的句子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆