-
-
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.
allow creating semantic domains and referencing them in senses, rewri…
…te json patch to change semantic domains of senses. Add tests for creating senses with and without semantic domains, and with and without part of speeches.
- Loading branch information
Showing
12 changed files
with
363 additions
and
25 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
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,24 @@ | ||
using Crdt.Changes; | ||
using Crdt.Entities; | ||
using MiniLcm; | ||
|
||
namespace LcmCrdt.Changes; | ||
|
||
public class AddSemanticDomainChange(SemanticDomain semanticDomain, Guid senseId) | ||
: EditChange<Sense>(senseId), ISelfNamedType<AddSemanticDomainChange> | ||
{ | ||
public SemanticDomain SemanticDomain { get; } = semanticDomain; | ||
|
||
public override async ValueTask ApplyChange(Sense entity, ChangeContext context) | ||
{ | ||
if (await context.IsObjectDeleted(SemanticDomain.Id)) | ||
{ | ||
//do nothing, don't add the domain if it's already deleted | ||
} | ||
else if (entity.SemanticDomains.All(s => s.Id != SemanticDomain.Id)) | ||
{ | ||
//only add the domain if it's not already in the list | ||
entity.SemanticDomains = [..entity.SemanticDomains, SemanticDomain]; | ||
} | ||
} | ||
} |
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,20 @@ | ||
using Crdt; | ||
using Crdt.Changes; | ||
using Crdt.Entities; | ||
using MiniLcm; | ||
using SemanticDomain = LcmCrdt.Objects.SemanticDomain; | ||
|
||
namespace LcmCrdt.Changes; | ||
|
||
public class CreateSemanticDomainChange(Guid semanticDomainId, MultiString name, string code, bool predefined = false) | ||
: CreateChange<SemanticDomain>(semanticDomainId), ISelfNamedType<CreateSemanticDomainChange> | ||
{ | ||
public MultiString Name { get; } = name; | ||
public bool Predefined { get; } = predefined; | ||
public string Code { get; } = code; | ||
|
||
public override async ValueTask<IObjectBase> NewEntity(Commit commit, ChangeContext context) | ||
{ | ||
return new SemanticDomain { Id = EntityId, Code = Code, Name = Name, Predefined = Predefined }; | ||
} | ||
} |
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,15 @@ | ||
using Crdt.Changes; | ||
using Crdt.Entities; | ||
|
||
namespace LcmCrdt.Changes; | ||
|
||
public class RemoveSemanticDomainChange(Guid semanticDomainId, Guid senseId) | ||
: EditChange<Sense>(senseId), ISelfNamedType<RemoveSemanticDomainChange> | ||
{ | ||
public Guid SemanticDomainId { get; } = semanticDomainId; | ||
|
||
public override async ValueTask ApplyChange(Sense entity, ChangeContext context) | ||
{ | ||
entity.SemanticDomains = [..entity.SemanticDomains.Where(s => s.Id != SemanticDomainId)]; | ||
} | ||
} |
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,27 @@ | ||
using Crdt.Changes; | ||
using Crdt.Entities; | ||
using MiniLcm; | ||
|
||
namespace LcmCrdt.Changes; | ||
|
||
public class ReplaceSemanticDomainChange(Guid oldSemanticDomainId, SemanticDomain semanticDomain, Guid senseId) | ||
: EditChange<Sense>(senseId), ISelfNamedType<ReplaceSemanticDomainChange> | ||
{ | ||
public Guid OldSemanticDomainId { get; } = oldSemanticDomainId; | ||
public SemanticDomain SemanticDomain { get; } = semanticDomain; | ||
|
||
public override async ValueTask ApplyChange(Sense entity, ChangeContext context) | ||
{ | ||
//remove the old domain | ||
entity.SemanticDomains = [..entity.SemanticDomains.Where(s => s.Id != OldSemanticDomainId)]; | ||
if (await context.IsObjectDeleted(SemanticDomain.Id)) | ||
{ | ||
//do nothing, don't add the domain if it's already deleted | ||
} | ||
else if (entity.SemanticDomains.All(s => s.Id != SemanticDomain.Id)) | ||
{ | ||
//only add if it's not already in the list | ||
entity.SemanticDomains = [..entity.SemanticDomains, SemanticDomain]; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.