Skip to content

Commit

Permalink
Enhance PEC (#1704)
Browse files Browse the repository at this point in the history
* Add HttpListener:enable control of project from report

* HttpListener: Respond better to difrerent scenarios

* HttpListener: Add ChangeStatus endpoint

* Two way interaction - first steps

* Add Post-Edit Report Viewer

* ReportExplorer: convert to MVVM

* Report-Studio Integration: Use webView2 messaging instead of HTTP

* Sync report and editor comments

* Refactoring

* Handle multiple target files

* Added updateSegmentStatus JS function
Added sync buttons in ribbon

* Comment update in Studio Editor reflects in report

* Move JS functions outside of the XSLT

* Add comment functionality (both ways) finished
ChangeStatus finished

* SyncOn -> No other report selectable

* Add actions: Save, Export, Open Report Folder to Ribbon
Move Refresh Report List action to ribbon

* Export action: delete interactivity elements before exporting

* Remove WinForms report
Stop autostarting HTML report in browser

* Remove WinForms report 2
Stop autostarting HTML report in browser 2

* Remove WinForms report 3
Stop autostarting HTML report in browser 3

* Extend Comparison Report Settings: Add FuzzyMatch bands

* Extend Comparison Report Settings: Take FuzzyMatch settings into account

* Add ReportViewFilter

* Add ReportViewFilter Functionality

* ReportFilter: Add fuzzy bands when fuzzy matches selected

* Refactoring

* Correct solution structure

* Fix issues discovered in testing
Add Scripts.js as resource

* Create Report Wizard: Add more details to error

* Enhance filter functionality

* ReportViewer: Export to Excel

* Excel export: add style for headers and percentages

* Add all tables as sheets to excel report

* Refactor
Try infer original project path when not set
Add ErrorHandler
Backup synchronized report
Change style of excel report

* Report Comparison Window: Close after a report has been created

* Navigate to report: ask user

* Enhance report

* Enhance Excel report

* Enhance Excel report

* Create excel report: Add error handling

* Excel report: statuses shown on separate lines
Sync ribbon: correct status of SyncOn button
  • Loading branch information
ealbu authored Feb 21, 2025
1 parent cbd446a commit 7f039f3
Show file tree
Hide file tree
Showing 175 changed files with 4,248 additions and 1,589 deletions.
2 changes: 1 addition & 1 deletion Post Edit Compare/Build/SolutionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("8.0.0.0")]
[assembly: AssemblyFileVersion("8.0.4.0")]
[assembly: AssemblyFileVersion("8.0.5.16")]

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Sdl.Community.PostEdit.Compare.Core.Comparison.Text;
using Sdl.Community.PostEdit.Compare.Core.Helper;
using Sdl.Community.PostEdit.Compare.Core.Reports;
using Sdl.Community.PostEdit.Compare.Core.SDLXLIFF;
using Convert = System.Convert;

namespace Sdl.Community.PostEdit.Compare.Core.Comparison
{
Expand Down Expand Up @@ -84,9 +84,9 @@ internal Dictionary<string, Dictionary<string, ComparisonParagraphUnit>> GetComp
}

var fileParagraphUnitUpdated = xFileParagraphUnitsUpdated[fileParagraphUnitOriginal.Key];
if ((from paragraphUnitOriginalPair in fileParagraphUnitOriginal.Value
select paragraphUnitOriginalPair.Value into paragraphUnitOriginal
let paragraphUnitUpdated = new ParagraphUnit(paragraphUnitOriginal.ParagraphUnitId, new List<SegmentPair>())
if ((from paragraphUnitOriginalPair in fileParagraphUnitOriginal.Value
select paragraphUnitOriginalPair.Value into paragraphUnitOriginal
let paragraphUnitUpdated = new ParagraphUnit(paragraphUnitOriginal.ParagraphUnitId, new List<SegmentPair>())
select paragraphUnitOriginal).Any(paragraphUnitOriginal => !fileParagraphUnitUpdated.ContainsKey(paragraphUnitOriginal.ParagraphUnitId)))
{
errorMatchingParagraphLevel = true;
Expand Down Expand Up @@ -115,8 +115,9 @@ select paragraphUnitOriginalPair.Value into paragraphUnitOriginal


var nameOriginal = Path.GetFileName(fileParagraphUnitOriginal.Key);
var fileParagraphUnitUpdated = (from kvp in xFileParagraphUnitsUpdated let fileNameUpdated = Path.GetFileName(kvp.Key)
where string.Compare(nameOriginal, fileNameUpdated, StringComparison.OrdinalIgnoreCase) == 0
var fileParagraphUnitUpdated = (from kvp in xFileParagraphUnitsUpdated
let fileNameUpdated = Path.GetFileName(kvp.Key)
where string.Compare(nameOriginal, fileNameUpdated, StringComparison.OrdinalIgnoreCase) == 0
select kvp.Value).FirstOrDefault();

if (fileParagraphUnitUpdated == null)
Expand Down Expand Up @@ -308,7 +309,7 @@ where string.Compare(nameOriginal, fileNameUpdated, StringComparison.OrdinalIgno

return comparisonFileParagraphUnits;
}

private void AddToComparision(ref ComparisonParagraphUnit comparisonParagraphUnit
, ComparisonSegmentUnit comparisonSegmentUnit
, SegmentPair segmentPairOriginal
Expand All @@ -317,6 +318,13 @@ private void AddToComparision(ref ComparisonParagraphUnit comparisonParagraphUni
comparisonSegmentUnit.SegmentStatusOriginal = segmentPairOriginal.SegmentStatus;
comparisonSegmentUnit.SegmentStatusUpdated = segmentPairUpdated.SegmentStatus;


if (Processor.Settings.ReportFilterTranslationMatchValuesOriginal == SharedStrings.FuzzyMatch)
if (!FuzzyRange.IsInFuzzyRange(segmentPairOriginal.TranslationOrigin.MatchPercentage, Processor.Settings.FuzzyMatchValuesOriginal)) return;

if (Processor.Settings.ReportFilterTranslationMatchValuesUpdated == SharedStrings.FuzzyMatch)
if (!FuzzyRange.IsInFuzzyRange(segmentPairUpdated.TranslationOrigin.MatchPercentage, Processor.Settings.FuzzyMatchValuesUpdated)) return;

comparisonSegmentUnit.TranslationStatusOriginal = GetTranslationStatus(segmentPairOriginal);
comparisonSegmentUnit.TranslationStatusUpdated = GetTranslationStatus(segmentPairUpdated);

Expand All @@ -334,7 +342,7 @@ private void AddToComparision(ref ComparisonParagraphUnit comparisonParagraphUni
comparisonSegmentUnit.ComparisonTextUnits = GetComparisonTextUnits(segmentPairOriginal.TargetSections, segmentPairUpdated.TargetSections);

comparisonSegmentUnit.SegmentTextUpdated = true;
comparisonParagraphUnit.ParagraphIsUpdated = true;
comparisonParagraphUnit.ParagraphIsUpdated = true;
}

comparisonSegmentUnit.SourceWordsOriginal = segmentPairOriginal.SourceWords;
Expand Down Expand Up @@ -379,7 +387,7 @@ private void AddToComparision(ref ComparisonParagraphUnit comparisonParagraphUni
comparisonParagraphUnit.ComparisonSegmentUnits.Add(comparisonSegmentUnit);
}


private static string GetTranslationStatus(SegmentPair segmentPair)
{
var match = string.Empty;
Expand All @@ -395,24 +403,24 @@ private static string GetTranslationStatus(SegmentPair segmentPair)
match = "CM";
}
else if (string.Compare(segmentPair.TranslationOrigin.OriginType, "mt", StringComparison.OrdinalIgnoreCase) == 0
|| string.Compare(segmentPair.TranslationOrigin.OriginType, "nmt", StringComparison.OrdinalIgnoreCase) == 0
|| string.Compare(segmentPair.TranslationOrigin.OriginType, "amt", StringComparison.OrdinalIgnoreCase) == 0)
|| string.Compare(segmentPair.TranslationOrigin.OriginType, "nmt", StringComparison.OrdinalIgnoreCase) == 0
|| string.Compare(segmentPair.TranslationOrigin.OriginType, "amt", StringComparison.OrdinalIgnoreCase) == 0)
{
match = "AT";
}
else

else
{
match = segmentPair.TranslationOrigin.MatchPercentage + "%";
}
}
else if (string.Compare(segmentPair.TranslationOrigin.OriginType, "mt", StringComparison.OrdinalIgnoreCase) == 0
|| string.Compare(segmentPair.TranslationOrigin.OriginType, "nmt", StringComparison.OrdinalIgnoreCase) == 0
|| string.Compare(segmentPair.TranslationOrigin.OriginType, "amt", StringComparison.OrdinalIgnoreCase) == 0)
|| string.Compare(segmentPair.TranslationOrigin.OriginType, "nmt", StringComparison.OrdinalIgnoreCase) == 0
|| string.Compare(segmentPair.TranslationOrigin.OriginType, "amt", StringComparison.OrdinalIgnoreCase) == 0)
{
match = "AT";
}
else if (segmentPair.TranslationOrigin.MatchPercentage > 0)
}
else if (segmentPair.TranslationOrigin.MatchPercentage > 0)
{
match = segmentPair.TranslationOrigin.MatchPercentage + "%";
}
Expand Down Expand Up @@ -509,24 +517,24 @@ private static List<string> GetSectionsList(IReadOnlyList<SegmentSection> segmen
}
}
return items;

}
internal static int DamerauLevenshteinDistanceFromObject(List<SegmentSection> source, List<SegmentSection> target)
{

var sourceLen = 0;
var sourceItems = GetSectionsList(source, ref sourceLen);

var targetLen = 0;
var targetItems = GetSectionsList(target, ref targetLen);


if (sourceLen == 0)

if (sourceLen == 0)
return targetLen == 0 ? 0 : targetLen;
if (targetLen == 0)

if (targetLen == 0)
return sourceLen;


var score = new int[sourceLen + 2, targetLen + 2];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public class FileUnitProperties
public decimal TotalSourceFuzzy74Tags { get; set; }
public decimal TotalSourceNewTags { get; set; }

private Dictionary<string, Dictionary<string, ComparisonParagraphUnit>> ComparisonFileParagraphUnits { get; set; }
public Dictionary<string, Dictionary<string, ComparisonParagraphUnit>> ComparisonFileParagraphUnits { get; set; }
public FileUnitProperties(FileUnitProperties fileUnitProperties, Dictionary<string, Dictionary<string, ComparisonParagraphUnit>> comparisonFileParagraphUnits)
{
SourceLanguageIdOriginal = fileUnitProperties.SourceLanguageIdOriginal;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Sdl.Community.PostEdit.Compare.Core;
using Sdl.Desktop.IntegrationApi.Interfaces;
using Sdl.TranslationStudioAutomation.IntegrationApi;
using System;

namespace Sdl.Community.PostEdit.Compare.Core.Helper;

public static class EventAggregator
{
private static IStudioEventAggregator StudioEventAggregator => SdlTradosStudio.Application.GetService<IStudioEventAggregator>();

public static void PublishEvent<T>(T message)
{
StudioEventAggregator.Publish(message);
}

public static void Subscribe<T>(Action<T> action)
{
StudioEventAggregator.GetEvent<T>().Subscribe(action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,27 @@ public static void CreateReportHeader(ExcelPackage xlPackage, ExcelWorksheet wor

public static void CreateExcelReport(string filePath,string sheetName)
{
var newFile = new FileInfo(filePath);
if (newFile.Exists)
{
newFile.Delete(); // ensures we create a new workbook
newFile = new FileInfo(filePath);
}
using (var package = new ExcelPackage(newFile))
{
// Add a new worksheet to the empty workbook
var worksheet = package.Workbook.Worksheets.Add(NormalizeWorksheetName(sheetName));
package.Save();
}

}
try
{
var newFile = new FileInfo(filePath);
if (newFile.Exists)
{
newFile.Delete(); // ensures we create a new workbook
newFile = new FileInfo(filePath);
}

using (var package = new ExcelPackage(newFile))
{
// Add a new worksheet to the empty workbook
var worksheet = package.Workbook.Worksheets.Add(NormalizeWorksheetName(sheetName));
package.Save();
}
}
catch (Exception ex)
{
throw new Exception($"{nameof(CreateExcelReport)}: An error occurred while creating the Excel report", ex);
}
}

public static string NormalizeWorksheetName(string sheetName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.IO;
using System.Windows;
using System.Xml;

namespace Sdl.Community.PostEdit.Compare.Core.Helper
{
public static class FileIdentifier
{
public static string GetFileInfo(string filepath)
{
if (string.IsNullOrEmpty(filepath) || !File.Exists(filepath))
{
MessageBox.Show($"{nameof(GetFileInfo)}: Original project filepath missing. ");
return null;
}
var filename = Path.GetFileName(filepath);
var currentFileParentDirName = Directory.GetParent(filepath)?.Name;
var fileInfo = $"{currentFileParentDirName}//{filename}";
return fileInfo;
}

public static string GetProjectId(string projectFilePath)
{
var filepath = GetSdlProjFilePathFromProjectFile(projectFilePath);
return ReadProjectId(filepath);
}

public static string GetSdlProjFilePathFromProjectFile(string projectFilePath)
{
if (string.IsNullOrEmpty(projectFilePath) || !File.Exists(projectFilePath))
{
MessageBox.Show($"{nameof(ReadProjectId)}: Original project filepath missing. ");
return null;
}

var projectFolderPath = Directory.GetParent(Path.GetDirectoryName(projectFilePath));
while (projectFolderPath is not null)
{
var sdlProjFiles = Directory.GetFiles(projectFolderPath.FullName, "*.sdlproj",
SearchOption.TopDirectoryOnly);

if (sdlProjFiles.Length == 1) return sdlProjFiles[0];

projectFolderPath = projectFolderPath.Parent;
}

return null;
}

private static string ReadProjectId(string projectFilePath)
{
if (string.IsNullOrWhiteSpace(projectFilePath)) return null;

var doc = new XmlDocument();
doc.Load(projectFilePath);

var root = doc.DocumentElement;

return root.Attributes["Guid"].Value;
}
}
}
Loading

0 comments on commit 7f039f3

Please sign in to comment.