Skip to content

Commit

Permalink
[Clean-Up] Code Clean-Up
Browse files Browse the repository at this point in the history
  • Loading branch information
Raspberry-Monster committed Jun 15, 2024
1 parent eee1a30 commit 36be94c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion LyricParser/Abstraction/KaraokeWordInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public KaraokeWordInfo(string currentWords, TimeSpan startTime, TimeSpan duratio
Duration = duration;
}


}
}
16 changes: 9 additions & 7 deletions LyricParser/Abstraction/LrcLyricsLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public sealed class LrcLyricsLine : ILyricLine
{
public string CurrentLyric { get; }
public TimeSpan StartTime { get; }
public string LyricWithoutPunc
{
get
public string LyricWithoutPunc
{
get
{
if (string.IsNullOrEmpty(_lyricWithoutPunc))
if (string.IsNullOrEmpty(_lyricWithoutPunc))
{
var builder = new StringBuilder();
foreach(var curChar in CurrentLyric)
foreach (var curChar in CurrentLyric)
{
if (!char.IsPunctuation(curChar) && !char.IsWhiteSpace(curChar))
{
Expand All @@ -24,9 +24,11 @@ public string LyricWithoutPunc
_lyricWithoutPunc = builder.ToString();
}
return _lyricWithoutPunc;
}
}
}
private string _lyricWithoutPunc;
#nullable enable
private string? _lyricWithoutPunc;
#nullable restore
public TimeSpan? PossibleStartTime { get; set; }
public LrcLyricsLine(string currentLyric, TimeSpan startTime)
{
Expand Down
4 changes: 2 additions & 2 deletions LyricParser/Implementation/KaraokeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static ILyricCollection ParseKaraoke(ReadOnlySpan<char> input)
{
if (input[i + 1] == '\n' || input[i + 1] == '\r') i++;
karaokeWordInfos.Add(new KaraokeWordInfo(lyricStringBuilder.ToString(), TimeSpan.FromMilliseconds(wordTimespan), TimeSpan.FromMilliseconds(wordDuration)));
lines.Add(new KaraokeLyricsLine(karaokeWordInfos, lyricWithoutPuncBuilder.ToString(),TimeSpan.FromMilliseconds(lyricTimespan), TimeSpan.FromMilliseconds(lyricDuration)));
lines.Add(new KaraokeLyricsLine(karaokeWordInfos, lyricWithoutPuncBuilder.ToString(), TimeSpan.FromMilliseconds(lyricTimespan), TimeSpan.FromMilliseconds(lyricDuration)));
karaokeWordInfos.Clear();
lyricWithoutPuncBuilder.Clear();
lyricStringBuilder.Clear();
Expand Down Expand Up @@ -159,7 +159,7 @@ public static ILyricCollection ParseKaraoke(ReadOnlySpan<char> input)
case CurrentState.Lyric:
if (reachesEnd && (input[i] == '\n' || input[i] == '\r')) break;
lyricStringBuilder.Append(curChar);
if(!char.IsPunctuation(curChar)&&!char.IsWhiteSpace(curChar)) lyricWithoutPuncBuilder.Append(curChar);
if (!char.IsPunctuation(curChar) && !char.IsWhiteSpace(curChar)) lyricWithoutPuncBuilder.Append(curChar);
break;
}
if (reachesEnd)
Expand Down
1 change: 0 additions & 1 deletion LyricParser/Implementation/LrcParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Text;

namespace LyricParser.Implementation
{
Expand Down
15 changes: 7 additions & 8 deletions LyricParser/Implementation/MigrationTool.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using LyricParser.Abstraction;
using F23.StringSimilarity;
using LyricParser.Abstraction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using F23.StringSimilarity;
using System.Diagnostics;

namespace LyricParser.Implementation
{
public static class MigrationTool
{
private static Cosine _cosine = new Cosine();
private static ILyricLine FindLyric(ILyricLine lyricLine, ILyricCollection collection, double similarity, int range)
#nullable enable
private static ILyricLine? FindLyric(ILyricLine lyricLine, ILyricCollection collection, double similarity, int range)
{
var sameTime = collection.Lines.Where(t => t.StartTime == lyricLine.StartTime);
if (sameTime.Any())
Expand All @@ -22,7 +20,7 @@ private static ILyricLine FindLyric(ILyricLine lyricLine, ILyricCollection colle
else
{
var lyrics = collection.Lines.Where(t => Math.Abs((t.StartTime - lyricLine.StartTime).TotalMilliseconds) <= range).ToList();
if(!lyrics.Any())
if (!lyrics.Any())
{
return default;
}
Expand All @@ -41,10 +39,11 @@ private static ILyricLine FindLyric(ILyricLine lyricLine, ILyricCollection colle
}
return default;
}
#nullable restore
public static MigrateCollection Migrate(ILyricCollection target, ILyricCollection source, double similarity = 0.80, int range = 750)
{
var newLines = new List<ILyricLine>();
foreach(var line in source.Lines)
foreach (var line in source.Lines)
{
if (string.IsNullOrWhiteSpace(line.CurrentLyric)) continue;
var lyric = FindLyric(line, target, similarity, range);
Expand Down

0 comments on commit 36be94c

Please sign in to comment.