|
|
@@ -7,9 +7,13 @@ import (
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
|
|
|
+ "github.com/go-echarts/go-echarts/v2/charts"
|
|
|
+ "github.com/go-echarts/go-echarts/v2/opts"
|
|
|
"github.com/james-bowman/nlp"
|
|
|
"github.com/james-bowman/nlp/measures/pairwise"
|
|
|
"gonum.org/v1/gonum/mat"
|
|
|
+ "math/rand"
|
|
|
+ "os"
|
|
|
|
|
|
"strings"
|
|
|
"time"
|
|
|
@@ -79,14 +83,9 @@ func GetOffsetTime(baseEngSubFPath, srcSubFPath string) (time.Duration, error) {
|
|
|
return 0, nil
|
|
|
}
|
|
|
|
|
|
- print(infoSrc)
|
|
|
-
|
|
|
// 构建基准语料库,目前阶段只需要考虑是 En 的就行了
|
|
|
var baseCorpus = make([]string, 0)
|
|
|
for _, oneDialogueEx := range infoBase.DialoguesEx {
|
|
|
- if oneDialogueEx.EnLine == "" {
|
|
|
- continue
|
|
|
- }
|
|
|
baseCorpus = append(baseCorpus, oneDialogueEx.EnLine)
|
|
|
}
|
|
|
// 初始化
|
|
|
@@ -143,7 +142,7 @@ func GetOffsetTime(baseEngSubFPath, srcSubFPath string) (time.Duration, error) {
|
|
|
|
|
|
if sc.Add(baseIndex, srcIndex) == false {
|
|
|
sc.Clear()
|
|
|
- continue
|
|
|
+ sc.Add(baseIndex, srcIndex)
|
|
|
}
|
|
|
if sc.Check() == false {
|
|
|
continue
|
|
|
@@ -161,7 +160,6 @@ func GetOffsetTime(baseEngSubFPath, srcSubFPath string) (time.Duration, error) {
|
|
|
// baseIndex, infoBase.DialoguesEx[baseIndex].StartTime, infoBase.DialoguesEx[baseIndex].EndTime, baseCorpus[baseIndex],
|
|
|
// srcIndex, srcOneDialogueEx.StartTime, srcOneDialogueEx.EndTime, srcOneDialogueEx.EnLine))
|
|
|
}
|
|
|
- println("---------------------------------------------")
|
|
|
timeFormat := ""
|
|
|
if infoBase.Ext == common.SubExtASS || infoBase.Ext == common.SubExtSSA {
|
|
|
timeFormat = timeFormatAss
|
|
|
@@ -169,31 +167,32 @@ func GetOffsetTime(baseEngSubFPath, srcSubFPath string) (time.Duration, error) {
|
|
|
timeFormat = timeFormatSrt
|
|
|
}
|
|
|
// 上面找出了连续匹配 maxCompareDialogue:N 次的字幕语句块
|
|
|
+ // 求出平均时间偏移
|
|
|
for _, matchIndexItem := range matchIndexList {
|
|
|
|
|
|
for i := 0; i < maxCompareDialogue; i++ {
|
|
|
-
|
|
|
+ // 这里会统计连续的这 5 句话的时间差
|
|
|
tmpBaseIndex := matchIndexItem.BaseNowIndex + i
|
|
|
tmpSrcIndex := matchIndexItem.SrcNowIndex + i
|
|
|
|
|
|
- srtTimeStart, err := time.Parse(timeFormat, infoSrc.DialoguesEx[tmpSrcIndex].StartTime)
|
|
|
+ baseTimeStart, err := time.Parse(timeFormat, infoBase.DialoguesEx[tmpBaseIndex].StartTime)
|
|
|
if err != nil {
|
|
|
- println("srtTimeStart", err)
|
|
|
+ println("baseTimeStart", err)
|
|
|
continue
|
|
|
}
|
|
|
- srtTimeEnd, err := time.Parse(timeFormat, infoSrc.DialoguesEx[tmpSrcIndex].EndTime)
|
|
|
+ baseTimeEnd, err := time.Parse(timeFormat, infoBase.DialoguesEx[tmpBaseIndex].EndTime)
|
|
|
if err != nil {
|
|
|
- println("srtTimeEnd", err)
|
|
|
+ println("baseTimeEnd", err)
|
|
|
continue
|
|
|
}
|
|
|
- baseTimeStart, err := time.Parse(timeFormat, infoBase.DialoguesEx[tmpBaseIndex].StartTime)
|
|
|
+ srtTimeStart, err := time.Parse(timeFormat, infoSrc.DialoguesEx[tmpSrcIndex].StartTime)
|
|
|
if err != nil {
|
|
|
- println("baseTimeStart", err)
|
|
|
+ println("srtTimeStart", err)
|
|
|
continue
|
|
|
}
|
|
|
- baseTimeEnd, err := time.Parse(timeFormat, infoBase.DialoguesEx[tmpBaseIndex].EndTime)
|
|
|
+ srtTimeEnd, err := time.Parse(timeFormat, infoSrc.DialoguesEx[tmpSrcIndex].EndTime)
|
|
|
if err != nil {
|
|
|
- println("baseTimeEnd", err)
|
|
|
+ println("srtTimeEnd", err)
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
@@ -202,14 +201,39 @@ func GetOffsetTime(baseEngSubFPath, srcSubFPath string) (time.Duration, error) {
|
|
|
|
|
|
println(fmt.Sprintf("Diff Start-End: %s - %s Base[%d] %s-%s '%s' <--> Src[%d] %s-%s '%s'",
|
|
|
TimeDiffStart, TimeDiffEnd,
|
|
|
- tmpBaseIndex, infoBase.DialoguesEx[tmpBaseIndex].StartTime, infoBase.DialoguesEx[tmpBaseIndex].EndTime, baseCorpus[tmpBaseIndex],
|
|
|
+ tmpBaseIndex, infoBase.DialoguesEx[tmpBaseIndex].StartTime, infoBase.DialoguesEx[tmpBaseIndex].EndTime, infoBase.DialoguesEx[tmpBaseIndex].EnLine,
|
|
|
tmpSrcIndex, infoSrc.DialoguesEx[tmpSrcIndex].StartTime, infoSrc.DialoguesEx[tmpSrcIndex].EndTime, infoSrc.DialoguesEx[tmpSrcIndex].EnLine))
|
|
|
}
|
|
|
println("---------------------------------------------")
|
|
|
}
|
|
|
|
|
|
+ // 1.New 一个条形图对象
|
|
|
+ bar := charts.NewBar()
|
|
|
+ // 2.设置 标题 和 子标题
|
|
|
+ bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
|
|
|
+ Title: "My first bar chart generated by go-echarts",
|
|
|
+ Subtitle: "It's extremely easy to use, right?",
|
|
|
+ }))
|
|
|
+
|
|
|
+ // 3.设置 数据组
|
|
|
+ bar.SetXAxis([]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}).
|
|
|
+ AddSeries("Category A", generateBarItems()).
|
|
|
+ AddSeries("Category B", generateBarItems())
|
|
|
+ // 4.绘图 生成html
|
|
|
+ f, _ := os.Create("bar.html")
|
|
|
+ bar.Render(f)
|
|
|
+
|
|
|
return 0, nil
|
|
|
}
|
|
|
|
|
|
+// 数据生成数据
|
|
|
+func generateBarItems() []opts.BarData {
|
|
|
+ items := make([]opts.BarData, 0)
|
|
|
+ for i := 0; i < 7; i++ {
|
|
|
+ items = append(items, opts.BarData{Value: rand.Intn(300)})
|
|
|
+ }
|
|
|
+ return items
|
|
|
+}
|
|
|
+
|
|
|
const timeFormatAss = "15:04:05.00"
|
|
|
const timeFormatSrt = "15:04:05,000"
|