Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
text2video-frontend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周成波
text2video-frontend
Commits
cd50ee18
Commit
cd50ee18
authored
Apr 14, 2024
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
一句话超过15个字则再拆分
parent
7f9e79ce
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
1 deletion
+29
-1
utils.ts
src/utils/utils.ts
+29
-1
No files found.
src/utils/utils.ts
View file @
cd50ee18
...
...
@@ -34,6 +34,32 @@ export default class utils {
return
formattedDateTime
}
// 对一句话再次拆分文本
static
splitDetailText
(
sentences
:
string
[])
{
// console.log(sentences)
let
result_sentences
:
string
[]
=
[];
sentences
.
forEach
(
s
=>
{
if
(
s
.
length
<=
15
){
result_sentences
.
push
(
s
);
}
else
{
let
detail_array
=
s
.
split
(
/
[
,|,
]
/
);
let
currentSentence
=
''
;
for
(
let
i
=
0
;
i
<
detail_array
.
length
;
i
++
)
{
const
str
=
detail_array
[
i
];
currentSentence
+=
str
+
','
;
if
(
i
<
detail_array
.
length
-
1
&&
(
currentSentence
+
detail_array
[
i
+
1
]).
length
<=
15
)
{
continue
;
}
result_sentences
.
push
(
currentSentence
.
endsWith
(
","
)
?
currentSentence
.
slice
(
0
,
-
1
)
:
currentSentence
);
currentSentence
=
''
;
}
// console.log('result_sentences=', result_sentences);
}
});
return
result_sentences
;
}
// 拆分文本
static
splitText
(
str
:
string
)
{
str
=
str
.
replaceAll
(
'“'
,
''
).
replaceAll
(
'”'
,
''
)
...
...
@@ -44,7 +70,9 @@ export default class utils {
// 过滤掉只包含标点符号的句子
sentences
=
sentences
.
filter
(
s
=>
!
utils
.
containsOnlyPunctuation
(
s
));
// console.log(sentences)
return
sentences
// return sentences
let
detailSplit
=
utils
.
splitDetailText
(
sentences
);
return
detailSplit
;
}
// 拆分英文文本
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment