gpt4 book ai didi

excel - 解析列中的行以列出 excel 中的每个 unigram、bigram 和 trigram

转载 作者:行者123 更新时间:2023-12-04 22:03:57 26 4
gpt4 key购买 nike

如标题所述,我想使用空格作为分隔符来解析表中的每一行(1 列,~1k 行)。每行包含一个短语。我想列出每个短语的所有 unigrams、bigrams 和 trigrams。下面的示例数据和所需的输出格式。
the quick brown fox the the quick the quick brown
jumps over the lazy dog quick quick brown quick brown fox
brown brown fox jumps over the
fox jumps over over the lazy
jumps over the the lazy dog
over the lazy
the lazy dog
lazy
dog

最佳答案

假设你的不同句子在第一列

Sub splitIt()

Dim vArray As Variant

Dim x As Long
Dim y As Long

Dim SentenceRange As Range

Dim startRowB, startRowC, startRowD As Long

Dim LastRow As Long
Dim sht As Worksheet

Set sht = ThisWorkbook.Worksheets(1)

LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

Set SentenceRange = Range(Cells(1, 1), Cells(LastRow, 1))

startRowB = 1
startRowC = 1
startRowD = 1

For Each Cell In SentenceRange

vArray = Split(Cell.Value, " ")

For y = 0 To 2
For x = 0 To (UBound(vArray) - y)

If y = 0 Then
Cells(startRowB + x, 2).Value = vArray(x)

ElseIf y = 1 Then
Cells(startRowC + x, 3).Value = vArray(x) & " " & vArray(x + 1)

ElseIf y = 2 Then
Cells(startRowD + x, 4).Value = vArray(x) & " " & vArray(x + 1) & " " & vArray(x + 2)

Else

End If
Next x
Next y

startRowB = sht.Cells(sht.Rows.Count, 2).End(xlUp).Row + 1
startRowC = sht.Cells(sht.Rows.Count, 3).End(xlUp).Row + 1
startRowD = sht.Cells(sht.Rows.Count, 4).End(xlUp).Row + 1

Next Cell


End Sub

enter image description here

关于excel - 解析列中的行以列出 excel 中的每个 unigram、bigram 和 trigram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28610797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com