在word中使用zotero添加参考文献并附带超链接

news2025/3/31 6:32:24

一、引言

在写大论文时,为了避免文中引用与文末参考文献频繁对照、修改文中引用顺序/引用文献时手动维护参考文献耗易出错,拟在 word 中使用 zotero 插入参考文献,并为每个参考文献附加超链接,实现交互式阅读。

版本:word2016 + zotero7.0.15

二、配置zotero

这里我首先对 zotero 进行了一下更新,原本我是 6.0 版本,更新为 7.0 版本后发现好多东西 zotero 都已经自带了,不需要再自行下载配置。

1. 添加引用文献样式

下载链接
里面有非常多学校的模板,感谢各位大佬的分享。

下载好后,选择自己学校的模板,然后双击 cls 文件,即可添加至 zotero 参考文献样式库。

在这里插入图片描述
安装。

在这里插入图片描述
OK。

调用这个模板后没有出现中英文混杂等任何问题。

2. 配置宏实现超链接

参考链接1
参考链接2

  1. word 选项卡——>视图——>宏——>查看宏
    在这里插入图片描述
  2. 创建一个名为 ZoteroLinkCitation 的宏
    在这里插入图片描述
  3. 在编辑器中填入以下代码并保存
Public Sub ZoteroLinkCitation()
    
' get selected area (if applicable)
    Dim nStart&, nEnd&
    nStart = Selection.Start
    nEnd = Selection.End
    
' toggle screen updating
    Application.ScreenUpdating = False
    
' define variables
    Dim title As String
    Dim titleAnchor As String
    Dim style As String
    Dim fieldCode As String
    Dim numOrYear As String
    Dim pos&, n1&, n2&, n3&

    ActiveWindow.View.ShowFieldCodes = True
    Selection.Find.ClearFormatting
 
' find the Zotero bibliography
    With Selection.Find
        .Text = "^d ADDIN ZOTERO_BIBL"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    
    ' add bookmark for the Zotero bibliography
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="Zotero_Bibliography"
        .DefaultSorting = wdSortByName
        .ShowHidden = True
    End With
    
    ' loop through each field in the document
    For Each aField In ActiveDocument.Fields
        ' check if the field is a Zotero in-text reference
        '##################################################
        If InStr(aField.Code, "ADDIN ZOTERO_ITEM") > 0 Then
            fieldCode = aField.Code
            '#############
            ' Prepare
            ' Plain citation== Format of Textfield shown
            ' must be in Brackets
            Dim plain_Cit As String
            plCitStrBeg = """plainCitation"":""["
            plCitStrEnd = "]"""
            n1 = InStr(fieldCode, plCitStrBeg)
            n1 = n1 + Len(plCitStrBeg)
            n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), plCitStrEnd) - 1 + n1
            plain_Cit = Mid$(fieldCode, n1 - 1, n2 - n1 + 2)
            'Reference 'as shown' in word as a string
            
            'Title array in fieldCode (all referenced Titles within this field)
            Dim array_RefTitle(32) As String
            i = 0
            Do While InStr(fieldCode, """title"":""") > 0
                n1 = InStr(fieldCode, """title"":""") + Len("""title"":""")
                n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), """,""") - 1 + n1
                If n2 < n1 Then 'Exception the type 'Article'
                    n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), "}") - 1 + n1 - 1
                End If
                array_RefTitle(i) = Mid(fieldCode, n1, n2 - n1)
                fieldCode = Mid(fieldCode, n2 + 1, Len(fieldCode) - n2 - 1)
                i = i + 1
            Loop
            Titles_in_Cit = i
            
            'Number array with References shown in PlainCit
            'Numer is equal or less than Titels, depending on the type
            '[3], [8]-[10]; [2]-[4]; [2], [4], [5]
            ' All citations have to be in Brackets each! [3], [8] not [3, 8]
            ' This doesnt work otherwise!
            ' --> treatment of other delimiters could be implemented here
            Dim RefNumber(32) As String
            i = 0
            Do While (InStr(plain_Cit, "]") Or InStr(plain_Cit, "[")) > 0
                n1 = InStr(plain_Cit, "[")
                n2 = InStr(plain_Cit, "]")
                RefNumber(i) = Mid(plain_Cit, n1 + 1, n2 - (n1 + 1))
                plain_Cit = Mid(plain_Cit, n2 + 1, Len(plain_Cit) - (n2 + 1) + 1)
            i = i + 1
            Loop
            Refs_in_Cit = i
              'treat only the shown references (skip the rest)
            '[3], [8]-[10] --> skip [9]
            'Order of titles given from fieldcode, not checked!
            If Titles_in_Cit > Refs_in_Cit Then
                array_RefTitle(Refs_in_Cit - 1) = array_RefTitle(Titles_in_Cit - 1)
                i = 1
                Do While Refs_in_Cit + i <= Titles_in_Cit
                    array_RefTitle(Refs_in_Cit + i - 1) = ""
                    i = i + 1
                Loop
            End If
            
            '#############
            'Make the links
            For Refs = 0 To Refs_in_Cit - 1 Step 1
                title = array_RefTitle(Refs)
                array_RefTitle(Refs) = ""
                ' make title a valid bookmark name
                titleAnchor = title
                titleAnchor = MakeValidBMName(titleAnchor)
                
                ActiveWindow.View.ShowFieldCodes = False
                Selection.GoTo What:=wdGoToBookmark, Name:="Zotero_Bibliography"
                
                '' locate the corresponding reference in the bibliography
                '' by searching for its title
                Selection.Find.ClearFormatting
                With Selection.Find
                    .Text = Left(title, 255)
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
                Selection.Find.Execute
                               
                ' select the whole caption (for mouseover tooltip)
                Selection.MoveStartUntil ("["), Count:=wdBackward
                Selection.MoveEndUntil (vbBack)
                lnkcap = "[" & Selection.Text
                lnkcap = Left(lnkcap, 70)
                
                ' add bookmark for the reference within the bibliography
                Selection.Shrink
                With ActiveDocument.Bookmarks
                    .Add Range:=Selection.Range, Name:=titleAnchor
                    .DefaultSorting = wdSortByName
                    .ShowHidden = True
                End With
                
                ' jump back to the field
                aField.Select
                ' find and select the numeric part of the field which will become the hyperlink
                Selection.Find.ClearFormatting
                With Selection.Find
                    .Text = RefNumber(Refs)
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
                Selection.Find.Execute
                        
                numOrYear = Selection.Range.Text & ""
                                    
                ' store current style
                style = Selection.style
                ' Generate the Hyperlink -->Forward!
                ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", SubAddress:=titleAnchor, ScreenTip:=lnkcap, TextToDisplay:="" & numOrYear
                ' reset the style

                ' comment if you want standard link style
                aField.Select
                With Selection.Font
                     .Underline = wdUnderlineNone
                     .ColorIndex = wdBlack
                End With
                    
            Next Refs 'References in Cit

        End If  'If Zotero-Field
        '#########################

        Next aField ' next field

        ' go back to original range selected
        ActiveWindow.View.ShowFieldCodes = False
        ActiveDocument.Range(nStart, nEnd).Select
        
    End Sub
    Function MakeValidBMName(strIn As String)
        Dim pFirstChr As String
        Dim i As Long
        Dim tempStr As String
        strIn = Trim(strIn)
        pFirstChr = Left(strIn, 1)
        If Not pFirstChr Like "[A-Za-z]" Then
            strIn = "A_" & strIn
        End If
        For i = 1 To Len(strIn)
            Select Case Asc(Mid$(strIn, i, 1))
            Case 49 To 57, 65 To 90, 97 To 122
                tempStr = tempStr & Mid$(strIn, i, 1)
            Case Else
                tempStr = tempStr & "_"
            End Select
            Next i
            tempStr = Replace(tempStr, "  ", " ")
            MakeValidBMName = Left(tempStr, 40)
        End Function


  1. 添加超链接
    回到Word,切换到视图栏,然后打开宏窗口,找到刚刚创建好的宏,然后点击运行:
    在这里插入图片描述
    即可为每篇文献添加超链接。

三、问题

1. 新建宏

这里我首先用了 zotero 自带的 ZoteroLinkCitation 宏,运行后出现了如下问题:
在这里插入图片描述
然后我又新建了一个 ZoteroLinkCitation 宏,复制了 CSDN 上另外一个大佬分享的代码,但是运行时出现了如下错误:
在这里插入图片描述
搜索了一下好像是因为选中的文本中包含了换行符?我改了一下没有改好,然后又换成了上面那位大佬分享的代码,没有选择任何文本,直接运行之后没有错误,成功添加了超链接。

2. 在同一个位置引用多篇文献的方法

经典视图中点击“多重来源”,并且可以调整多个文献的相对顺序:

在这里插入图片描述

在这里插入图片描述

3.无法在同一个位置添加多个超链接

1. 问题描述

这里我使用新建宏添加了超链接后,出现了一个问题,即 1 个方括号只能为 1 篇参考文献添加超链接。具体来讲,就是当 1 个位置同时引用了多篇参考文献时,只能添加最后 1 篇参考文献的链接:
在这里插入图片描述
由于 zoero 实际上是通过书签的方式添加超链接的,因此我们先查看一下参考文献中是不是每篇都添加了书签。

word 选项卡——>文件——>选项——>高级——>显示书签
在这里插入图片描述

然后看到参考文献中的确有些文献没有附上书签,例如文献 2、4:

在这里插入图片描述
或者查看所有书签的名称:
在这里插入图片描述
宏代码中是使用文献名称作为书签名的,可以发现书签数量与文献数量并不相符。因此确实有些文献没有成功创建超链接。

2. 解决方案

来看一下这段 VBA 代码写了什么(不得不说有大模型太方便了,分分钟解释清楚代码在干嘛):

' 声明一个公共子程序(宏)ZoteroLinkCitation
Public Sub ZoteroLinkCitation()
    
' 获取当前选中的文本区域(如果存在选择)
' 定义长整型变量存储选区起始和结束位置
    Dim nStart&, nEnd&
    nStart = Selection.Start  ' 记录选区开始位置
    nEnd = Selection.End      ' 记录选区结束位置
    
' 关闭屏幕刷新(提升执行速度)
    Application.ScreenUpdating = False
    
' 定义变量
    Dim title As String           ' 存储文献标题
    Dim titleAnchor As String     ' 存储有效书签名
    Dim style As String           ' 存储文本样式
    Dim fieldCode As String       ' 存储字段代码
    Dim numOrYear As String       ' 存储引用编号或年份
    Dim pos&, n1&, n2&, n3&       ' 存储位置索引

    ActiveWindow.View.ShowFieldCodes = True  ' 显示字段代码
    Selection.Find.ClearFormatting          ' 清除查找格式,确保查找操作不会受到之前格式设置的影响。
 
' 查找Zotero参考文献目录字段
    With Selection.Find
        .Text = "^d ADDIN ZOTERO_BIBL"  ' 查找特殊字段标识
        .Replacement.Text = ""
        .Forward = True                 ' 向前查找
        .Wrap = wdFindContinue          ' 查找范围为整个文档
        .Format = False                 ' 不匹配格式
        .MatchCase = False              ' 不区分大小写
        .MatchWholeWord = False         ' 不匹配整个单词
        .MatchWildcards = False         ' 不使用通配符
        .MatchSoundsLike = False        ' 不匹配发音相似的单词
        .MatchAllWordForms = False      ' 不匹配所有词形
    End With
    Selection.Find.Execute              ' 执行查找
    
    ' 为找到的参考文献目录添加书签
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="Zotero_Bibliography"  ' 创建书签
        .DefaultSorting = wdSortByName                            ' 默认按名称排序
        .ShowHidden = True                                        ' 显示隐藏书签
    End With
    
    ' 遍历文档中的所有字段
    For Each aField In ActiveDocument.Fields
        ' 检查是否是Zotero的引用字段
        If InStr(aField.Code, "ADDIN ZOTERO_ITEM") > 0 Then
            fieldCode = aField.Code  ' 获取字段代码
            
            '############# 准备阶段 #############
            ' 提取纯文本引用(例如[3])
            Dim plain_Cit As String
            plCitStrBeg = """plainCitation"":""["  ' 定义引用开始标记
            plCitStrEnd = """]"""                   ' 定义引用结束标记
            n1 = InStr(fieldCode, plCitStrBeg)       ' 查找开始位置
            n1 = n1 + Len(plCitStrBeg)
            n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), plCitStrEnd) - 1 + n1
            plain_Cit = Mid$(fieldCode, n1 - 1, n2 - n1 + 2)  ' 提取引用内容
            
            ' 提取所有文献标题到数组
            Dim array_RefTitle(32) As String  ' 最多存储32个标题
            i = 0
            Do While InStr(fieldCode, """title"":""") > 0  ' 循环查找所有标题
                n1 = InStr(fieldCode, """title"":""") + Len("""title"":""")
                n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), """,""") - 1 + n1
                If n2 < n1 Then  ' 处理特殊类型(如文章)
                    n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), "}") - 1 + n1 - 1
                End If
                array_RefTitle(i) = Mid(fieldCode, n1, n2 - n1)  ' 存储标题
                fieldCode = Mid(fieldCode, n2 + 1, Len(fieldCode) - n2 - 1)
                i = i + 1
            Loop
            Titles_in_Cit = i  ' 记录找到的标题数量
            
            ' 提取引用编号(例如[3]中的3)
            Dim RefNumber(32) As String
            i = 0
            Do While (InStr(plain_Cit, "]") Or InStr(plain_Cit, "[")) > 0
                n1 = InStr(plain_Cit, "[")
                n2 = InStr(plain_Cit, "]")
                RefNumber(i) = Mid(plain_Cit, n1 + 1, n2 - (n1 + 1))  ' 提取编号
                plain_Cit = Mid(plain_Cit, n2 + 1, Len(plain_Cit) - (n2 + 1) + 1)
            i = i + 1
            Loop
            Refs_in_Cit = i  ' 记录引用编号数量
            
            ' 处理标题与引用编号数量不一致的情况
            If Titles_in_Cit > Refs_in_Cit Then
                array_RefTitle(Refs_in_Cit - 1) = array_RefTitle(Titles_in_Cit - 1)
                i = 1
                Do While Refs_in_Cit + i <= Titles_in_Cit
                    array_RefTitle(Refs_in_Cit + i - 1) = ""
                    i = i + 1
                Loop
            End If
            
            '############# 创建链接 #############
            For Refs = 0 To Refs_in_Cit - 1 Step 1
                title = array_RefTitle(Refs)
                array_RefTitle(Refs) = ""
                
                ' 生成有效书签名(调用函数处理非法字符)
                titleAnchor = MakeValidBMName(title)
                
                ' 跳转到参考文献书签位置
                ActiveWindow.View.ShowFieldCodes = False
                Selection.GoTo What:=wdGoToBookmark, Name:="Zotero_Bibliography"
                
                ' 在参考文献中查找对应标题
                Selection.Find.ClearFormatting
                With Selection.Find
                    .Text = Left(title, 255)  ' 限制搜索长度
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
                Selection.Find.Execute
                               
                ' 选择完整的引用条目
                Selection.MoveStartUntil ("["), Count:=wdBackward
                Selection.MoveEndUntil (vbBack)
                lnkcap = "[" & Selection.Text  ' 创建悬浮提示文本
                lnkcap = Left(lnkcap, 70)      ' 截断前70个字符
                
                ' 为文献条目添加书签
                Selection.Shrink
                With ActiveDocument.Bookmarks
                    .Add Range:=Selection.Range, Name:=titleAnchor
                    .DefaultSorting = wdSortByName
                    .ShowHidden = True
                End With
                
                ' 返回原引用位置
                aField.Select
                ' 查找引用编号所在位置
                Selection.Find.ClearFormatting
                With Selection.Find
                    .Text = RefNumber(Refs)
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
                Selection.Find.Execute
                        
                numOrYear = Selection.Range.Text & ""  ' 获取显示的编号
                                    
                ' 创建超链接
                ActiveDocument.Hyperlinks.Add _
                    Anchor:=Selection.Range, _
                    Address:="", _
                    SubAddress:=titleAnchor, _
                    ScreenTip:=lnkcap, _
                    TextToDisplay:="" & numOrYear
                    
                ' 重置字体样式(取消下划线)
                aField.Select
                With Selection.Font
                     .Underline = wdUnderlineNone
                     .ColorIndex = wdBlack
                End With
                    
            Next Refs  ' 处理下一个引用

        End If  ' 结束Zotero字段判断
        Next aField  ' 处理下一个字段

        ' 恢复原始视图和选区
        ActiveWindow.View.ShowFieldCodes = False
        ActiveDocument.Range(nStart, nEnd).Select
        
    End Sub

' 辅助函数:生成有效书签名(移除非法字符)
Function MakeValidBMName(strIn As String)
    Dim pFirstChr As String
    Dim i As Long
    Dim tempStr As String
    strIn = Trim(strIn)
    pFirstChr = Left(strIn, 1)
    If Not pFirstChr Like "[A-Za-z]" Then  ' 首字符非字母时加前缀
        strIn = "A_" & strIn
    End If
    For i = 1 To Len(strIn)
        Select Case Asc(Mid$(strIn, i, 1))  ' 只保留字母数字
        Case 49 To 57, 65 To 90, 97 To 122  ' 允许1-9, A-Z, a-z
            tempStr = tempStr & Mid$(strIn, i, 1)
        Case Else
            tempStr = tempStr & "_"        ' 替换其他字符为下划线
        End Select
        Next i
        tempStr = Replace(tempStr, "  ", " ")  ' 替换双空格
        MakeValidBMName = Left(tempStr, 40)    ' 截断为前40字符
    End Function
1)参考文献以逗号形式隔开

参考链接

当遇到引用形式类似 [2, 3] 这种情况时,在执行完下面这段代码后:

 'Title array in fieldCode (all referenced Titles within this field) fieldCode中的标题数组(此字段中引用的所有标题)
            Dim array_RefTitle(32) As String
            i = 0
            Do While InStr(fieldCode, """title"":""") > 0
                n1 = InStr(fieldCode, """title"":""") + Len("""title"":""")
                n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), """,""") - 1 + n1
                If n2 < n1 Then 'Exception the type 'Article'
                    n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), "}") - 1 + n1 - 1
                End If
                array_RefTitle(i) = Mid(fieldCode, n1, n2 - n1)
                fieldCode = Mid(fieldCode, n2 + 1, Len(fieldCode) - n2 - 1)
                i = i + 1
            Loop

可以看到 array_RefTitle 确实存入了文献 2 和文献 3 的标题:
在这里插入图片描述
在执行完下面这段代码后,RefNumber 变为了 ‘2, 3’, Refs_in_Cit 变为了 1:

'Number array with References shown in PlainCit 'PlainCit中显示了引用的数字数组
            'Numer is equal or less than Titels, depending on the type 'Numer等于或小于Titels,具体取决于类型
            '[3], [8]-[10]; [2]-[4]; [2], [4], [5] '[3], [8]-[10]; [2]-[4]; [2], [4], [5]
            ' All citations have to be in Brackets each! [3], [8] not [3, 8] 所有引文都必须用括号括起来![3] [8]不是[3,8]
            ' This doesnt work otherwise! 否则,这行不通!
            ' --> treatment of other delimiters could be implemented here
            Dim RefNumber(32) As String
            i = 0
            Do While (InStr(plain_Cit, "]") Or InStr(plain_Cit, "[")) > 0
                n1 = InStr(plain_Cit, "[")
                n2 = InStr(plain_Cit, "]")
                RefNumber(i) = Mid(plain_Cit, n1 + 1, n2 - (n1 + 1))
                plain_Cit = Mid(plain_Cit, n2 + 1, Len(plain_Cit) - (n2 + 1) + 1)
            i = i + 1
            Loop
            Refs_in_Cit = i

在这里插入图片描述

在这里插入图片描述
在执行完下面这段代码后,array_RefTitle 就只剩下了文献 3 的标题:

              'treat only the shown references (skip the rest) 仅处理显示的引用(跳过其余部分)
            '[3], [8]-[10] --> skip [9] [3] ,[8]-[10]-->跳过[9]
            'Order of titles given from fieldcode, not checked! 从字段代码给出的标题顺序,未选中!
            If Titles_in_Cit > Refs_in_Cit Then
                array_RefTitle(Refs_in_Cit - 1) = array_RefTitle(Titles_in_Cit - 1)
                i = 1
                Do While Refs_in_Cit + i <= Titles_in_Cit
                    array_RefTitle(Refs_in_Cit + i - 1) = ""
                    i = i + 1
                Loop

在这里插入图片描述
在执行到下面这段代码时:

 ' find and select the numeric part of the field which will become the hyperlink 查找并选择将成为超链接的字段的数字部分
                Selection.Find.ClearFormatting
                With Selection.Find
                    .Text = RefNumber(Refs)
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
                Selection.Find.Execute
                        
                numOrYear = Selection.Range.Text & ""
                                    
                ' store current style
                style = Selection.style
                ' Generate the Hyperlink -->Forward!
                ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", SubAddress:=titleAnchor, ScreenTip:=lnkcap, TextToDisplay:="" & numOrYear

可以看到,插入超链接的文本就是 RefNumber,这里即为 ‘2, 3’。

看到这里问题已经很明白了。现在的代码是为每个方括号添加了超链接,且只能添加最后 1 篇文献的超链接。而我们需要的实际上是为每个引文编号添加超链接。
因此,我们只需要将插入超链接的文本由每个方括号的内容改为每个引用编号即可。将 RefNumber 部分的代码改为如下形式:

'Number array with References shown in PlainCit 'PlainCit中显示了引用的数字数组
            'Numer is equal or less than Titels, depending on the type 'Numer等于或小于Titels,具体取决于类型
            '[3], [8]-[10]; [2]-[4]; [2], [4], [5] '[3], [8]-[10]; [2]-[4]; [2], [4], [5]
            ' All citations have to be in Brackets each! [3], [8] not [3, 8] 所有引文都必须用括号括起来![3] [8]不是[3,8]
            ' This doesnt work otherwise! 否则,这行不通!
            ' --> treatment of other delimiters could be implemented here
            Dim RefNumber(32) As String
            i = 0
            ' 初始化起始位置和数组
            startPosition = InStr(plain_Cit, "[")
            commaPosition = 0
            ReDim commaPositions(0 To 0)
            Do While (InStr(plain_Cit, "]") Or InStr(plain_Cit, "[")) > 0
                
                ' 查找逗号的位置
                commaPosition = InStr(plain_Cit, ",")  ' 这里查找的是第一个逗号的位置
                
                If commaPosition = 0 Then    ' 引文数量 = 1
                    commaPosition = InStr(plain_Cit, "]")
                    RefNumber(i) = Mid(plain_Cit, startPosition + 1, commaPosition - (startPosition + 1))
                    plain_Cit = Mid(plain_Cit, commaPosition + 1, Len(plain_Cit) - (commaPosition + 1) + 1)
                Else    ' 引文数量 > 1
                    RefNumber(i) = Mid(plain_Cit, startPosition + 1, commaPosition - (startPosition + 1))
                    plain_Cit = Mid(plain_Cit, commaPosition + 2, Len(plain_Cit) - (commaPosition + 2))
                    ' 检查是否为空字符串
                    If Len(Trim(plain_Cit)) = 0 Then
                        plain_Cit = plain_Cit
                    Else
                        plain_Cit = "[" & plain_Cit & "]"
                    End If
                End If
                
            i = i + 1
            Loop
            Refs_in_Cit = i

以逗号为分隔,为每个引用编号添加超链接。这里由于我使用的引用文献样式中每个逗号后面都会有一个空格,所以提取字符串部分使用的是 commaPosition + 2,若没有空格则应该改为 commaPosition + 1。

运行后发现 4、5 分别引用成功了:
在这里插入图片描述
可以看到参考文献部分添加的书签也明显多了,例如2、4,都成功添加了书签:
在这里插入图片描述

2)参考文献以短横线连接

除了形如 [2, 3] 类的引用形式外,还存在 [6-8] 这类的形式。显然,这种形式的引用也只能添加最后 1 篇参考文献的链接:
在这里插入图片描述
以上如为例,我们需要的是为文献 2、6、8 分别添加超链接,这里 2 添加成功了,但是 6-8 只添加了文献 8 的链接。因此我们只需要再查找一下 “-” 的位置即可。

将 RefNumber 部分的代码改为如下形式:

'Number array with References shown in PlainCit 'PlainCit中显示了引用的数字数组
            'Numer is equal or less than Titels, depending on the type 'Numer等于或小于Titels,具体取决于类型
            '[3], [8]-[10]; [2]-[4]; [2], [4], [5] '[3], [8]-[10]; [2]-[4]; [2], [4], [5]
            ' All citations have to be in Brackets each! [3], [8] not [3, 8] 所有引文都必须用括号括起来![3] [8]不是[3,8]
            ' This doesnt work otherwise! 否则,这行不通!
            ' --> treatment of other delimiters could be implemented here
            Dim RefNumber(32) As String
            i = 0
            ' 初始化起始位置和数组
            startPosition = InStr(plain_Cit, "[")
            commaPosition = 0   ' 初始化逗号位置
            dashPosition = 0    ' 初始化短横线位置
            ReDim commaPositions(0 To 0)
            Do While (InStr(plain_Cit, "]") Or InStr(plain_Cit, "[")) > 0
                
                ' 查找逗号的位置
                commaPosition = InStr(plain_Cit, ",")  ' 这里查找的是第一个逗号的位置
                ' 查找短横线的位置
                dashPosition = InStr(plain_Cit, "-")  ' 这里查找的是第一个短横线的位置
                
                
                If commaPosition = 0 And dashPosition = 0 Then   ' 情况0:都不存在
                    commaPosition = InStr(plain_Cit, "]")
                    RefNumber(i) = Mid(plain_Cit, startPosition + 1, commaPosition - (startPosition + 1))
                    plain_Cit = Mid(plain_Cit, commaPosition + 1, Len(plain_Cit) - (commaPosition + 1) + 1)
                ElseIf commaPosition > 0 And dashPosition > 0 Then   ' 情况1/2:两者都存在
                    If commaPosition < dashPosition Then   ' 逗号在前
                        RefNumber(i) = Mid(plain_Cit, startPosition + 1, commaPosition - (startPosition + 1))
                        plain_Cit = Mid(plain_Cit, commaPosition + 2, Len(plain_Cit) - (commaPosition + 2))
                        ' 检查是否为空字符串
                        If Len(Trim(plain_Cit)) = 0 Then
                            plain_Cit = plain_Cit
                        Else
                            plain_Cit = "[" & plain_Cit & "]"
                        End If
                    Else   ' 短横线在前
                        RefNumber(i) = Mid(plain_Cit, startPosition + 1, dashPosition - (startPosition + 1))
                        plain_Cit = Mid(plain_Cit, dashPosition + 1, Len(plain_Cit) - (dashPosition + 1))
                        ' 检查是否为空字符串
                        If Len(Trim(plain_Cit)) = 0 Then
                            plain_Cit = plain_Cit
                        Else
                            plain_Cit = "[" & plain_Cit & "]"
                        End If
                    End If
                ElseIf commaPosition > 0 Then   ' 情况3:只有逗号
                    RefNumber(i) = Mid(plain_Cit, startPosition + 1, commaPosition - (startPosition + 1))
                    plain_Cit = Mid(plain_Cit, commaPosition + 2, Len(plain_Cit) - (commaPosition + 2))
                    ' 检查是否为空字符串
                    If Len(Trim(plain_Cit)) = 0 Then
                        plain_Cit = plain_Cit
                    Else
                        plain_Cit = "[" & plain_Cit & "]"
                    End If
                Else   ' 情况4:只有短横线
                    RefNumber(i) = Mid(plain_Cit, startPosition + 1, dashPosition - (startPosition + 1))
                    plain_Cit = Mid(plain_Cit, dashPosition + 1, Len(plain_Cit) - (dashPosition + 1))
                    ' 检查是否为空字符串
                    If Len(Trim(plain_Cit)) = 0 Then
                        plain_Cit = plain_Cit
                    Else
                        plain_Cit = "[" & plain_Cit & "]"
                    End If
                End If
                
            i = i + 1
            Loop
            Refs_in_Cit = i

运行结束后可以分别为每个引用编号添加超链接:
在这里插入图片描述
再次查看参考文献部分,每篇论文都成功添加了书签,所有论文都被成功引用了。
修改后完整的代码如下:

Public Sub ZoteroLinkCitation()
    
' get selected area (if applicable)获取选定区域(如果适用)
    Dim nStart&, nEnd&
    nStart = Selection.Start
    nEnd = Selection.End
    
' toggle screen updating 切换屏幕更新
    Application.ScreenUpdating = False
    
' define variables 定义变量
    Dim title As String
    Dim titleAnchor As String
    Dim style As String
    Dim fieldCode As String
    Dim numOrYear As String
    Dim pos&, n1&, n2&, n3&

    ActiveWindow.View.ShowFieldCodes = True
    Selection.Find.ClearFormatting
 
' find the Zotero bibliography 查找Zotero参考目录
    With Selection.Find
        .Text = "^d ADDIN ZOTERO_BIBL"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    
    ' add bookmark for the Zotero bibliography 为Zotero参考目录添加书签
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="Zotero_Bibliography"
        .DefaultSorting = wdSortByName
        .ShowHidden = True
    End With
    
    ' loop through each field in the document 遍历文档中的每个字段
    For Each aField In ActiveDocument.Fields
        ' check if the field is a Zotero in-text reference 检查文本引用中的字段是否为Zotero
        '##################################################
        If InStr(aField.Code, "ADDIN ZOTERO_ITEM") > 0 Then
            fieldCode = aField.Code
            '#############
            ' Prepare
            ' Plain citation== Format of Textfield shown  纯文本引用
            ' must be in Brackets      必须放在方括号中
            Dim plain_Cit As String
            plCitStrBeg = """plainCitation"":""["
            plCitStrEnd = "]"""
            n1 = InStr(fieldCode, plCitStrBeg)
            n1 = n1 + Len(plCitStrBeg)
            n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), plCitStrEnd) - 1 + n1
            plain_Cit = Mid$(fieldCode, n1 - 1, n2 - n1 + 2)
            'Reference 'as shown' in word as a string
            
            'Title array in fieldCode (all referenced Titles within this field) fieldCode中的标题数组(此字段中引用的所有标题)
            Dim array_RefTitle(32) As String
            i = 0
            Do While InStr(fieldCode, """title"":""") > 0
                n1 = InStr(fieldCode, """title"":""") + Len("""title"":""")
                n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), """,""") - 1 + n1
                If n2 < n1 Then 'Exception the type 'Article'
                    n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), "}") - 1 + n1 - 1
                End If
                array_RefTitle(i) = Mid(fieldCode, n1, n2 - n1)
                fieldCode = Mid(fieldCode, n2 + 1, Len(fieldCode) - n2 - 1)
                i = i + 1
            Loop
            Titles_in_Cit = i
            
            'Number array with References shown in PlainCit 'PlainCit中显示了引用的数字数组
            'Numer is equal or less than Titels, depending on the type 'Numer等于或小于Titels,具体取决于类型
            '[3], [8]-[10]; [2]-[4]; [2], [4], [5] '[3], [8]-[10]; [2]-[4]; [2], [4], [5]
            ' All citations have to be in Brackets each! [3], [8] not [3, 8] 所有引文都必须用括号括起来![3] [8]不是[3,8]
            ' This doesnt work otherwise! 否则,这行不通!
            ' --> treatment of other delimiters could be implemented here
            Dim RefNumber(32) As String
            i = 0
            ' 初始化起始位置和数组
            startPosition = InStr(plain_Cit, "[")
            commaPosition = 0   ' 初始化逗号位置
            dashPosition = 0    ' 初始化短横线位置
            ReDim commaPositions(0 To 0)
            Do While (InStr(plain_Cit, "]") Or InStr(plain_Cit, "[")) > 0
                
                ' 查找逗号的位置
                commaPosition = InStr(plain_Cit, ",")  ' 这里查找的是第一个逗号的位置
                ' 查找短横线的位置
                dashPosition = InStr(plain_Cit, "-")  ' 这里查找的是第一个短横线的位置
                
                
                If commaPosition = 0 And dashPosition = 0 Then   ' 情况0:都不存在
                    commaPosition = InStr(plain_Cit, "]")
                    RefNumber(i) = Mid(plain_Cit, startPosition + 1, commaPosition - (startPosition + 1))
                    plain_Cit = Mid(plain_Cit, commaPosition + 1, Len(plain_Cit) - (commaPosition + 1) + 1)
                ElseIf commaPosition > 0 And dashPosition > 0 Then   ' 情况1/2:两者都存在
                    If commaPosition < dashPosition Then   ' 逗号在前
                        RefNumber(i) = Mid(plain_Cit, startPosition + 1, commaPosition - (startPosition + 1))
                        plain_Cit = Mid(plain_Cit, commaPosition + 2, Len(plain_Cit) - (commaPosition + 2))
                        ' 检查是否为空字符串
                        If Len(Trim(plain_Cit)) = 0 Then
                            plain_Cit = plain_Cit
                        Else
                            plain_Cit = "[" & plain_Cit & "]"
                        End If
                    Else   ' 短横线在前
                        RefNumber(i) = Mid(plain_Cit, startPosition + 1, dashPosition - (startPosition + 1))
                        plain_Cit = Mid(plain_Cit, dashPosition + 1, Len(plain_Cit) - (dashPosition + 1))
                        ' 检查是否为空字符串
                        If Len(Trim(plain_Cit)) = 0 Then
                            plain_Cit = plain_Cit
                        Else
                            plain_Cit = "[" & plain_Cit & "]"
                        End If
                    End If
                ElseIf commaPosition > 0 Then   ' 情况3:只有逗号
                    RefNumber(i) = Mid(plain_Cit, startPosition + 1, commaPosition - (startPosition + 1))
                    plain_Cit = Mid(plain_Cit, commaPosition + 2, Len(plain_Cit) - (commaPosition + 2))
                    ' 检查是否为空字符串
                    If Len(Trim(plain_Cit)) = 0 Then
                        plain_Cit = plain_Cit
                    Else
                        plain_Cit = "[" & plain_Cit & "]"
                    End If
                Else   ' 情况4:只有短横线
                    RefNumber(i) = Mid(plain_Cit, startPosition + 1, dashPosition - (startPosition + 1))
                    plain_Cit = Mid(plain_Cit, dashPosition + 1, Len(plain_Cit) - (dashPosition + 1))
                    ' 检查是否为空字符串
                    If Len(Trim(plain_Cit)) = 0 Then
                        plain_Cit = plain_Cit
                    Else
                        plain_Cit = "[" & plain_Cit & "]"
                    End If
                End If
                
            i = i + 1
            Loop
            Refs_in_Cit = i
              'treat only the shown references (skip the rest) 仅处理显示的引用(跳过其余部分)
            '[3], [8]-[10] --> skip [9] [3] ,[8]-[10]-->跳过[9]
            'Order of titles given from fieldcode, not checked! 从字段代码给出的标题顺序,未选中!
            If Titles_in_Cit > Refs_in_Cit Then
                array_RefTitle(Refs_in_Cit - 1) = array_RefTitle(Titles_in_Cit - 1)
                i = 1
                Do While Refs_in_Cit + i <= Titles_in_Cit
                    array_RefTitle(Refs_in_Cit + i - 1) = ""
                    i = i + 1
                Loop
            End If
            
            '#############
            'Make the links
            For Refs = 0 To Refs_in_Cit - 1 Step 1
                title = array_RefTitle(Refs)
                array_RefTitle(Refs) = ""
                ' make title a valid bookmark name
                titleAnchor = title
                titleAnchor = MakeValidBMName(titleAnchor)
                
                ActiveWindow.View.ShowFieldCodes = False
                Selection.GoTo What:=wdGoToBookmark, Name:="Zotero_Bibliography"
                
                '' locate the corresponding reference in the bibliography
                '' by searching for its title
                Selection.Find.ClearFormatting
                With Selection.Find
                    .Text = Left(title, 255)
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
                Selection.Find.Execute
                               
                ' select the whole caption (for mouseover tooltip) 选择整个标题(用于鼠标悬停工具提示)
                Selection.MoveStartUntil ("["), Count:=wdBackward
                Selection.MoveEndUntil (vbBack)
                lnkcap = "[" & Selection.Text
                lnkcap = Left(lnkcap, 70)
                
                ' add bookmark for the reference within the bibliography 为参考目录中的参考添加书签
                Selection.Shrink
                With ActiveDocument.Bookmarks
                    .Add Range:=Selection.Range, Name:=titleAnchor
                    .DefaultSorting = wdSortByName
                    .ShowHidden = True
                End With
                
                ' jump back to the field
                aField.Select
                ' find and select the numeric part of the field which will become the hyperlink 查找并选择将成为超链接的字段的数字部分
                Selection.Find.ClearFormatting
                With Selection.Find
                    .Text = RefNumber(Refs)
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
                Selection.Find.Execute
                        
                numOrYear = Selection.Range.Text & ""
                                    
                ' store current style
                style = Selection.style
                ' Generate the Hyperlink -->Forward!
                ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", SubAddress:=titleAnchor, ScreenTip:=lnkcap, TextToDisplay:="" & numOrYear
                ' reset the style

                ' comment if you want standard link style
                aField.Select
                With Selection.Font
                     .Underline = wdUnderlineNone
                     .ColorIndex = wdBlack
                End With
                    
            Next Refs 'References in Cit

        End If  'If Zotero-Field
        '#########################

        Next aField ' next field

        ' go back to original range selected
        ActiveWindow.View.ShowFieldCodes = False
        ActiveDocument.Range(nStart, nEnd).Select
        
    End Sub
    Function MakeValidBMName(strIn As String)
        Dim pFirstChr As String
        Dim i As Long
        Dim tempStr As String
        strIn = Trim(strIn)
        pFirstChr = Left(strIn, 1)
        If Not pFirstChr Like "[A-Za-z]" Then
            strIn = "A_" & strIn
        End If
        For i = 1 To Len(strIn)
            Select Case Asc(Mid$(strIn, i, 1))
            Case 49 To 57, 65 To 90, 97 To 122
                tempStr = tempStr & Mid$(strIn, i, 1)
            Case Else
                tempStr = tempStr & "_"
            End Select
            Next i
            tempStr = Replace(tempStr, "  ", " ")
            MakeValidBMName = Left(tempStr, 40)
        End Function

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2323102.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

性能测试、负载测试、压力测试的全面解析

在软件测试领域&#xff0c;性能测试、负载测试和压力测试是评估系统稳定性和可靠性的关键手段。​它们各自关注不同的测试目标和应用场景&#xff0c;理解这些差异对于制定有效的测试策略至关重要。 本文对性能测试、负载测试和压力测试进行深入分析&#xff0c;探讨其定义、…

Redis中的数据类型与适用场景

目录 前言1. 字符串 (String)1.1 特点1.2 适用场景 2. 哈希 (Hash)2.1 特点2.2 适用场景 3. 列表 (List)3.1 特点3.2 适用场景 4. 集合 (Set)4.1 特点4.2 适用场景 5. 有序集合 (Sorted Set)5.1 特点5.2 适用场景 6. Redis 数据类型的选型建议结语 前言 Redis 作为一款高性能的…

gz sim机器人SDF模型 [持续更新]

机器人SDF模型 linklink的一级pose材质 plugin话题信息通信键盘操作plugin Sensor传感器imu 不算教学&#xff0c;个人的记录 sdf的格式跟urdf有所不同&#xff0c;必须是完整的一个包括&#xff0c;比如< pose></ pose>这样前一个后一个&#xff0c;urdf中是有<…

【MySQL | 六、索引特性(进一步理解)】

目录 索引的理解索引的作用MySQL与磁盘的IOPage单个Page的分类多个Page的组织B树的特点 B树和B树的区别聚簇索引 VS 非聚簇索引聚簇索引的优缺点非聚簇索引的优缺点 创建索引常见索引分为&#xff1a;主键索引InnoDB主键索引的生成过程&#xff08;1&#xff09;初始化&#xf…

计算机网络高频(三)UDP基础

计算机网络高频(三)UDP基础 1.UDP的头部格式是什么样的?⭐ UDP 头部具有以下字段: 源端口(Source Port):16 位字段,表示发送方的端口号。目标端口(Destination Port):16 位字段,表示接收方的端口号。长度(Length):16 位字段,表示 UDP 数据报(包括头部和数据部…

【测试开发】OKR 小程序端黑盒测试报告

【测试报告】OKR 小程序端 项目名称版本号测试负责人测试完成日期联系方式OKR 小程序端4.0马铭胜2025-03-2515362558972 1、项目背景 1.1 OKR 用户端 在如今这个快节奏的时代中&#xff0c;个人和组织的成长往往依赖于清晰、明确且意义深远的目标。然而&#xff0c;如何设定…

部署高可用PostgreSQL14集群

目录 基础依赖包安装 consul配置 patroni配置 vip-manager配置 pgbouncer配置 haproxy配置 验证 本文将介绍如何使用Patroni、Consul、vip-manager、Pgbouncer、HaProxy组件来部署一个3节点的高可用、高吞吐、负载均衡的PostgresSQL集群&#xff08;14版本&#xff09;&…

Vue3中keep-alive缓存组件应用场景。

文章目录 一、KeepAlive是什么&#xff1f;二、基本使用1.例子2.keep-alive使用 三、其他属性3.1 包含/排除3.2 最大缓存实例数3.3 缓存实例的生命周期 总结 一、KeepAlive是什么&#xff1f; 是一个内置组件&#xff0c;它的功能是在多个组件间动态切换时缓存被移除的组件实例…

CosyVoice2在Windows系统上本地部署的详细步骤

CosyVoice2在Windows系统上本地部署的详细步骤&#xff1a; 下载源码并初始化&#xff1a; 确保你的设备上安装了Git。打开命令提示符&#xff08;cmd&#xff09;&#xff0c;执行以下命令来克隆仓库&#xff1a;git clone --recursive https://github.com/FunAudioLLM/CosyVo…

鸿蒙入门——ArkUI 跨页面数据同步和应用全局单例的UI状态存储AppStorage 小结(三)

文章大纲 引言一、AppStorage 应用全局的UI状态存储1、StorageProp和StorageLink装饰器建立联系2、StorageProp2.1、StorageProp使用规则2.2、StorageProp变量的传递/访问规则2.3、StorageProp支持的观察变化2.4、StorageProp 值初始化和更新 3、StorageLink3.1、StorageLink使…

海思烧录工具HITool电视盒子刷机详解

HiTool是华为开发的一款用于海思芯片设备的刷机和调试工具&#xff0c;可对搭载海思芯片的机顶盒、智能电视等设备进行固件烧录、参数配置等操作。以下为你详细介绍&#xff1a; 功能用途 固件烧录&#xff1a;这是HiTool最主要的功能之一。它能够将下载好的适配固件文件烧录到…

使用VS2022编译CEF

前提 选择编译的版本 CEF自动编译&#xff0c;在这里可以看到最新的稳定版和Beta版。 从这里得出&#xff0c;最新的稳定版是134.0.6998.118&#xff0c;对应的cef branch是6998。通过这个信息可以在Build requirements查到相关的软件配置信息。 这里主要看Windows下的编译要…

Pytorch学习笔记(八)Learn the Basics - Save and Load the Model

这篇博客瞄准的是 pytorch 官方教程中 Learn the Basics 章节的 Save and Load the Model 部分。 官网链接&#xff1a;https://pytorch.org/tutorials/beginner/basics/saveloadrun_tutorial.html 完整网盘链接: https://pan.baidu.com/s/1L9PVZ-KRDGVER-AJnXOvlQ?pwdaa2m …

MATLAB 绘制空间分布图 方法总结

方法一&#xff1a;用mapshow函数 figure(1); hold on %% 添加陆地 land shaperead(landareas); mapshow(landareas.shp, FaceColor, [1 1 1], EdgeColor, [0.3 0.3 0.3],FaceAlpha,0)%% 添加站点 for i 1:size(mycmap,1)mapshow(lon(label i),lat(label i),displaytype,po…

Docker+Ollama+Xinference+RAGFlow+Dify+Open webui部署及踩坑问题

目录 一、Xinference部署 &#xff08;一&#xff09;简介 &#xff08;二&#xff09;部署 &#xff08;三&#xff09;参数 &#xff08;四&#xff09;错误问题 &#xff08;五&#xff09;Xinference配置Text-embedding模型 &#xff08;六&#xff09;Xinference配…

Axure项目实战:智慧城市APP(四)医疗信息(动态面板、选中交互应用)

亲爱的小伙伴&#xff0c;在您浏览之前&#xff0c;烦请关注一下&#xff0c;在此深表感谢&#xff01; 课程主题&#xff1a;智慧城市APP医疗信息模块 主要内容&#xff1a;医疗信息模块原型设计与交互 应用场景&#xff1a;医疗信息行业 案例展示&#xff1a; 案例视频&…

【网络通信安全】基于华为 eNSP 的链路聚合、手工负载分担模式与 LACP 扩展配置 全解析

目录 一、引言 二、链路聚合技术基础 2.1 链路聚合的定义与作用 2.2 链路聚合的工作原理 2.3 链路聚合的模式分类 三、华为 eNSP 简介 3.1 eNSP 的概述 3.2 eNSP 的安装与配置 3.2.1 安装环境要求 3.2.2 安装步骤 3.2.3 配置虚拟网卡 四、手工负载分担模式配置 4.…

Transformer 通关秘籍2:利用 BERT 将文本 token 化

前面两节分别通过两个代码示例展示了模型将文本转换为 token 之后是什么样的&#xff0c;希望你可以对此有一个感性的认识。 本节来简要介绍一下将一个连续的文本转换为 token 序列的大致过程&#xff0c;这个过程被称为分词&#xff0c;也叫 tokenization。 在你没了解这方面…

网络运维学习笔记(DeepSeek优化版) 024 HCIP-Datacom OSPF域内路由计算

文章目录 OSPF域内路由计算&#xff1a;单区域的路由计算一、OSPF单区域路由计算原理二、1类LSA详解2.1 1类LSA的作用与结构2.2 1类LSA的四种链路类型 三、OSPF路由表生成验证3.1 查看LSDB3.2 查看OSPF路由表3.3 查看全局路由表 四、2类LSA详解4.1 2类LSA的作用与生成条件4.2 2…

【云馨AI-大模型】自动化部署Dify 1.1.2,无需科学上网,Linux环境轻松实现,附Docker离线安装等

Dify介绍 官网&#xff1a;https://dify.ai/zh生成式 AI 应用创新引擎开源的 LLM 应用开发平台。提供从 Agent 构建到 AI workflow 编排、RAG 检索、模型管理等能力&#xff0c;轻松构建和运营生成式 AI 原生应用。 Dify安装脚本 目录创建 mkdir -p /data/yunxinai &&a…