Skip to content

Commit

Permalink
Separate translation and WA alignedwordpair; add score; fix usings
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Feb 25, 2025
1 parent a020acf commit ac0aae5
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ComponentModel;
using Polly.Extensions.Http;
using Serval.Translation.V1;
using Serval.WordAlignment.V1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.ComponentModel;

namespace Serval.Machine.Shared.Services;
namespace Serval.Machine.Shared.Services;

public class ClearMLMonitorService(
IServiceProvider services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ private static WordAlignment.V1.AlignedWordPair Map(SIL.Machine.Corpora.AlignedW
return new WordAlignment.V1.AlignedWordPair
{
SourceIndex = alignedWordPair.SourceIndex,
TargetIndex = alignedWordPair.TargetIndex
TargetIndex = alignedWordPair.TargetIndex,
Score = alignedWordPair.TranslationScore
};
}
}
1 change: 1 addition & 0 deletions src/Machine/src/Serval.Machine.Shared/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
global using System.Collections.Concurrent;
global using System.Collections.Immutable;
global using System.ComponentModel;
global using System.Data;
global using System.Diagnostics;
global using System.Formats.Tar;
Expand Down
18 changes: 16 additions & 2 deletions src/Serval/src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10547,7 +10547,21 @@ public partial class WordAlignmentResult

[Newtonsoft.Json.JsonProperty("alignment", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
public System.Collections.Generic.IList<AlignedWordPair> Alignment { get; set; } = new System.Collections.ObjectModel.Collection<AlignedWordPair>();
public System.Collections.Generic.IList<AlignedWordPair2> Alignment { get; set; } = new System.Collections.ObjectModel.Collection<AlignedWordPair2>();

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class AlignedWordPair2
{
[Newtonsoft.Json.JsonProperty("sourceIndex", Required = Newtonsoft.Json.Required.Always)]
public int SourceIndex { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("targetIndex", Required = Newtonsoft.Json.Required.Always)]
public int TargetIndex { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("score", Required = Newtonsoft.Json.Required.Always)]
public double Score { get; set; } = default!;

}

Expand Down Expand Up @@ -10640,7 +10654,7 @@ public partial class WordAlignment

[Newtonsoft.Json.JsonProperty("alignment", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
public System.Collections.Generic.IList<AlignedWordPair> Alignment { get; set; } = new System.Collections.ObjectModel.Collection<AlignedWordPair>();
public System.Collections.Generic.IList<AlignedWordPair2> Alignment { get; set; } = new System.Collections.ObjectModel.Collection<AlignedWordPair2>();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Serval.Shared.Contracts;
namespace Serval.Translation.Contracts;

public record AlignedWordPairDto
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace Serval.Shared.Models;
namespace Serval.Translation.Models;

public record AlignedWordPair
{
public required int SourceIndex { get; set; }
public required int TargetIndex { get; set; }
public double? Score { get; set; }
}
4 changes: 2 additions & 2 deletions src/Serval/src/Serval.Translation/Services/EngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,9 @@ private Models.TranslationResult Map(V1.TranslationResult source)
return source.Values.Cast<Contracts.TranslationSource>().ToHashSet();
}

private Shared.Models.AlignedWordPair Map(V1.AlignedWordPair source)
private Models.AlignedWordPair Map(V1.AlignedWordPair source)
{
return new Shared.Models.AlignedWordPair { SourceIndex = source.SourceIndex, TargetIndex = source.TargetIndex };
return new Models.AlignedWordPair { SourceIndex = source.SourceIndex, TargetIndex = source.TargetIndex };
}

private Models.Phrase Map(V1.Phrase source)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Serval.WordAlignment.Contracts;

public record AlignedWordPairDto
{
public required int SourceIndex { get; init; }
public required int TargetIndex { get; init; }
public required double Score { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,12 @@ private WordAlignmentResultDto Map(WordAlignmentResult source)

private AlignedWordPairDto Map(AlignedWordPair source)
{
return new AlignedWordPairDto() { SourceIndex = source.SourceIndex, TargetIndex = source.TargetIndex };
return new AlignedWordPairDto()
{
SourceIndex = source.SourceIndex,
TargetIndex = source.TargetIndex,
Score = source.Score
};
}

private static WordAlignmentDto Map(Models.WordAlignment source)
Expand All @@ -1004,7 +1009,8 @@ private static WordAlignmentDto Map(Models.WordAlignment source)
.Alignment.Select(c => new AlignedWordPairDto()
{
SourceIndex = c.SourceIndex,
TargetIndex = c.TargetIndex
TargetIndex = c.TargetIndex,
Score = c.Score
})
.ToList(),
};
Expand Down
8 changes: 8 additions & 0 deletions src/Serval/src/Serval.WordAlignment/Models/AlignedWordPair.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Serval.WordAlignment.Models;

public record AlignedWordPair
{
public required int SourceIndex { get; set; }
public required int TargetIndex { get; set; }
public double Score { get; set; }
}
4 changes: 2 additions & 2 deletions src/Serval/src/Serval.WordAlignment/Services/EngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ private Models.WordAlignmentResult Map(V1.WordAlignmentResult source)
};
}

private Shared.Models.AlignedWordPair Map(V1.AlignedWordPair source)
private Models.AlignedWordPair Map(V1.AlignedWordPair source)
{
return new Shared.Models.AlignedWordPair
return new Models.AlignedWordPair
{
SourceIndex = source.SourceIndex,
TargetIndex = source.TargetIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ ServerCallContext context
SourceTokens = request.SourceTokens.ToList(),
TargetTokens = request.TargetTokens.ToList(),
Alignment = request
.Alignment.Select(a => new Shared.Models.AlignedWordPair
.Alignment.Select(a => new Models.AlignedWordPair
{
SourceIndex = a.SourceIndex,
TargetIndex = a.TargetIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1480,12 +1480,12 @@ public void TearDown()
_env.Dispose();
}

private static IReadOnlyList<Shared.Models.AlignedWordPair> CreateNAlignedWordPair(int numberOfAlignedWords)
private static IReadOnlyList<WordAlignment.Models.AlignedWordPair> CreateNAlignedWordPair(int numberOfAlignedWords)
{
var alignedWordPairs = new List<Shared.Models.AlignedWordPair>();
var alignedWordPairs = new List<WordAlignment.Models.AlignedWordPair>();
for (int i = 0; i < numberOfAlignedWords; i++)
{
alignedWordPairs.Add(new Shared.Models.AlignedWordPair { SourceIndex = i, TargetIndex = i });
alignedWordPairs.Add(new WordAlignment.Models.AlignedWordPair { SourceIndex = i, TargetIndex = i });
}
return alignedWordPairs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1677,12 +1677,12 @@ private static AsyncUnaryCall<TResponse> CreateAsyncUnaryCall<TResponse>(TRespon
}
}

private static IReadOnlyList<Shared.Models.AlignedWordPair> CreateNAlignedWordPair(int numberOfAlignedWords)
private static IReadOnlyList<Models.AlignedWordPair> CreateNAlignedWordPair(int numberOfAlignedWords)
{
var alignedWordPairs = new List<Shared.Models.AlignedWordPair>();
var alignedWordPairs = new List<Models.AlignedWordPair>();
for (int i = 0; i < numberOfAlignedWords; i++)
{
alignedWordPairs.Add(new Shared.Models.AlignedWordPair { SourceIndex = i, TargetIndex = i });
alignedWordPairs.Add(new Models.AlignedWordPair { SourceIndex = i, TargetIndex = i });
}
return alignedWordPairs;
}
Expand Down

0 comments on commit ac0aae5

Please sign in to comment.