-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CRDT sync handles parts of speech (#1203)
Parts of speech now sync both ways in FW and CRDT sync. Someday we may want to generalize this to include more types of CmPossibilityLists but for now parts of speech are working.
- Loading branch information
Showing
11 changed files
with
254 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
backend/FwLite/FwDataMiniLcmBridge/Api/UpdateProxy/UpdatePartOfSpeechProxy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using MiniLcm.Models; | ||
using SIL.LCModel; | ||
|
||
namespace FwDataMiniLcmBridge.Api.UpdateProxy; | ||
|
||
public class UpdatePartOfSpeechProxy : PartOfSpeech | ||
{ | ||
private readonly IPartOfSpeech _lcmPartOfSpeech; | ||
private readonly FwDataMiniLcmApi _lexboxLcmApi; | ||
|
||
public UpdatePartOfSpeechProxy(IPartOfSpeech lcmPartOfSpeech, FwDataMiniLcmApi lexboxLcmApi) | ||
{ | ||
_lcmPartOfSpeech = lcmPartOfSpeech; | ||
Id = lcmPartOfSpeech.Guid; | ||
_lexboxLcmApi = lexboxLcmApi; | ||
} | ||
|
||
public override MultiString Name | ||
{ | ||
get => new UpdateMultiStringProxy(_lcmPartOfSpeech.Name, _lexboxLcmApi); | ||
set => throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using MiniLcm; | ||
using MiniLcm.Models; | ||
using MiniLcm.SyncHelpers; | ||
using SystemTextJsonPatch; | ||
|
||
public static class PartOfSpeechSync | ||
{ | ||
public static async Task<int> Sync(PartOfSpeech[] currentPartsOfSpeech, | ||
PartOfSpeech[] previousPartsOfSpeech, | ||
IMiniLcmApi api) | ||
{ | ||
return await DiffCollection.Diff(api, | ||
previousPartsOfSpeech, | ||
currentPartsOfSpeech, | ||
pos => pos.Id, | ||
async (api, currentPos) => | ||
{ | ||
await api.CreatePartOfSpeech(currentPos); | ||
return 1; | ||
}, | ||
async (api, previousPos) => | ||
{ | ||
await api.DeletePartOfSpeech(previousPos.Id); | ||
return 1; | ||
}, | ||
async (api, previousPos, currentPos) => | ||
{ | ||
var updateObjectInput = PartOfSpeechDiffToUpdate(previousPos, currentPos); | ||
if (updateObjectInput is not null) await api.UpdatePartOfSpeech(currentPos.Id, updateObjectInput); | ||
return updateObjectInput is null ? 0 : 1; | ||
}); | ||
} | ||
|
||
public static UpdateObjectInput<PartOfSpeech>? PartOfSpeechDiffToUpdate(PartOfSpeech previousPartOfSpeech, PartOfSpeech currentPartOfSpeech) | ||
{ | ||
JsonPatchDocument<PartOfSpeech> patchDocument = new(); | ||
patchDocument.Operations.AddRange(MultiStringDiff.GetMultiStringDiff<PartOfSpeech>(nameof(PartOfSpeech.Name), | ||
previousPartOfSpeech.Name, | ||
currentPartOfSpeech.Name)); | ||
// TODO: Once we add abbreviations to MiniLcm's PartOfSpeech objects, then: | ||
// patchDocument.Operations.AddRange(GetMultiStringDiff<PartOfSpeech>(nameof(PartOfSpeech.Abbreviation), | ||
// previousPartOfSpeech.Abbreviation, | ||
// currentPartOfSpeech.Abbreviation)); | ||
if (patchDocument.Operations.Count == 0) return null; | ||
return new UpdateObjectInput<PartOfSpeech>(patchDocument); | ||
} | ||
} |