Skip to content

Commit

Permalink
A little refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Oct 14, 2024
1 parent a574439 commit b547740
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 114 deletions.
32 changes: 2 additions & 30 deletions src/Serval/src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12821,7 +12821,7 @@ public partial class WordAlignmentBuild
public System.Collections.Generic.IList<TrainingCorpus2>? TrainOn { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("wordAlignOn", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IList<WordAlignOnCorpus>? WordAlignOn { get; set; } = default!;
public System.Collections.Generic.IList<TrainingCorpus2>? WordAlignOn { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("step", Required = Newtonsoft.Json.Required.Always)]
public int Step { get; set; } = default!;
Expand Down Expand Up @@ -12880,20 +12880,6 @@ public partial class ParallelCorpusFilter2

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class WordAlignOnCorpus
{
[Newtonsoft.Json.JsonProperty("parallelCorpus", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public ResourceLink? ParallelCorpus { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("sourceFilters", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IList<ParallelCorpusFilter2>? SourceFilters { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("targetFilters", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IList<ParallelCorpusFilter2>? TargetFilters { get; set; } = default!;

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class WordAlignmentBuildConfig
{
Expand All @@ -12904,7 +12890,7 @@ public partial class WordAlignmentBuildConfig
public System.Collections.Generic.IList<TrainingCorpusConfig2>? TrainOn { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("wordAlignOn", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IList<WordAlignOnCorpusConfig>? WordAlignOn { get; set; } = default!;
public System.Collections.Generic.IList<TrainingCorpusConfig2>? WordAlignOn { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public object? Options { get; set; } = default!;
Expand Down Expand Up @@ -12940,20 +12926,6 @@ public partial class ParallelCorpusFilterConfig2

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class WordAlignOnCorpusConfig
{
[Newtonsoft.Json.JsonProperty("parallelCorpusId", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? ParallelCorpusId { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("sourceFilters", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IList<ParallelCorpusFilterConfig2>? SourceFilters { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("targetFilters", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IList<ParallelCorpusFilterConfig2>? TargetFilters { get; set; } = default!;

}

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class FileParameter
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public record WordAlignmentBuildConfigDto
{
public string? Name { get; init; }
public IReadOnlyList<TrainingCorpusConfigDto>? TrainOn { get; init; }
public IReadOnlyList<WordAlignOnCorpusConfigDto>? WordAlignOn { get; init; }
public IReadOnlyList<TrainingCorpusConfigDto>? WordAlignOn { get; init; }

/// <example>
/// {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public record WordAlignmentBuildDto
public string? Name { get; init; }
public required ResourceLinkDto Engine { get; init; }
public IReadOnlyList<TrainingCorpusDto>? TrainOn { get; init; }
public IReadOnlyList<WordAlignOnCorpusDto>? WordAlignOn { get; init; }
public IReadOnlyList<TrainingCorpusDto>? WordAlignOn { get; init; }
public required int Step { get; init; }
public double? PercentCompleted { get; init; }
public string? Message { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,37 +768,6 @@ private static Build Map(Engine engine, WordAlignmentBuildConfigDto source)
};
}

private static List<WordAlignmentCorpus>? Map(Engine engine, IReadOnlyList<WordAlignOnCorpusConfigDto>? source)
{
if (source is null)
return null;

var corpusIds = new HashSet<string>(engine.ParallelCorpora.Select(c => c.Id));
var wordAlignmentCorpora = new List<WordAlignmentCorpus>();
foreach (WordAlignOnCorpusConfigDto cc in source)
{
if (cc.ParallelCorpusId == null)
{
throw new InvalidOperationException($"One of ParallelCorpusId and CorpusId must be set.");
}
if (!corpusIds.Contains(cc.ParallelCorpusId))
{
throw new InvalidOperationException(
$"The parallel corpus {cc.ParallelCorpusId} is not valid: This parallel corpus does not exist for engine {engine.Id}."
);
}
wordAlignmentCorpora.Add(
new WordAlignmentCorpus
{
ParallelCorpusRef = cc.ParallelCorpusId,
SourceFilters = cc.SourceFilters?.Select(Map).ToList(),
TargetFilters = cc.TargetFilters?.Select(Map).ToList()
}
);
}
return wordAlignmentCorpora;
}

private static List<TrainingCorpus>? Map(Engine engine, IReadOnlyList<TrainingCorpusConfigDto>? source)
{
if (source is null)
Expand Down Expand Up @@ -903,26 +872,6 @@ private WordAlignmentBuildDto Map(Build source)
};
}

private WordAlignOnCorpusDto Map(string engineId, WordAlignmentCorpus source)
{
return new WordAlignOnCorpusDto
{
ParallelCorpus =
source.ParallelCorpusRef != null
? new ResourceLinkDto
{
Id = source.ParallelCorpusRef,
Url = _urlService.GetUrl(
Endpoints.GetParallelTranslationCorpus,
new { id = engineId, parallelCorpusId = source.ParallelCorpusRef }
)
}
: null,
SourceFilters = source.SourceFilters?.Select(Map).ToList(),
TargetFilters = source.TargetFilters?.Select(Map).ToList()
};
}

private TrainingCorpusDto Map(string engineId, TrainingCorpus source)
{
return new TrainingCorpusDto
Expand Down
2 changes: 1 addition & 1 deletion src/Serval/src/Serval.WordAlignment/Models/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public record Build : IEntity
public string? Name { get; init; }
public required string EngineRef { get; init; }
public IReadOnlyList<TrainingCorpus>? TrainOn { get; init; }
public IReadOnlyList<WordAlignmentCorpus>? WordAlignOn { get; init; }
public IReadOnlyList<TrainingCorpus>? WordAlignOn { get; init; }
public int Step { get; init; }
public double? PercentCompleted { get; init; }
public string? Message { get; init; }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,7 @@ private Shared.Models.AlignedWordPair Map(V1.AlignedWordPair source)
return new Shared.Models.AlignedWordPair { SourceIndex = source.SourceIndex, TargetIndex = source.TargetIndex };
}

private V1.ParallelCorpus Map(
Models.ParallelCorpus source,
TrainingCorpus? trainOn,
WordAlignmentCorpus? wordAlignOn
)
private V1.ParallelCorpus Map(Models.ParallelCorpus source, TrainingCorpus? trainOn, TrainingCorpus? wordAlignOn)
{
string? referenceFileLocation =
source.TargetCorpora.Count > 0 && source.TargetCorpora[0].Files.Count > 0
Expand Down
1 change: 0 additions & 1 deletion src/Serval/test/Serval.Translation.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
global using NUnit.Framework;
global using Serval.Shared.Configuration;
global using Serval.Shared.Contracts;
global using Serval.Shared.Models;
global using Serval.Shared.Services;
global using Serval.Shared.Utils;
global using Serval.Translation.Contracts;
Expand Down

0 comments on commit b547740

Please sign in to comment.