@@ -340,7 +340,7 @@ public async Task<string> LiftExport(
340
340
if ( src is null || ! File . Exists ( src ) )
341
341
{
342
342
continue ;
343
- } ;
343
+ }
344
344
345
345
var safeName = Sanitization . MakeFriendlyForPath ( speaker . Name ) ;
346
346
var fileName = safeName == "" ? Path . GetFileNameWithoutExtension ( src ) : safeName ;
@@ -549,7 +549,7 @@ private static async Task AddAudio(LexEntry entry, List<Pronunciation> pronuncia
549
549
if ( ! File . Exists ( src ) )
550
550
{
551
551
continue ;
552
- } ;
552
+ }
553
553
554
554
var dest = Path . Combine ( path , audio . FileName ) ;
555
555
if ( Path . GetExtension ( dest ) . Equals ( ".webm" , StringComparison . OrdinalIgnoreCase ) )
@@ -865,10 +865,16 @@ public void FinishEntry(LiftEntry entry)
865
865
// Only add audio if the files exist
866
866
if ( Directory . Exists ( extractedAudioDir ) )
867
867
{
868
- foreach ( var pro in entry . Pronunciations )
868
+ foreach ( var pronunciation in entry . Pronunciations )
869
869
{
870
- // Add audio with Protected = true to prevent modifying or deleting imported audio
871
- newWord . Audio . Add ( new Pronunciation ( pro . Media . First ( ) . Url ) { Protected = true } ) ;
870
+ foreach ( var media in pronunciation . Media )
871
+ {
872
+ if ( ! string . IsNullOrEmpty ( media . Url ) )
873
+ {
874
+ // Add audio with Protected = true to prevent modifying or deleting imported audio
875
+ newWord . Audio . Add ( new ( media . Url ) { Protected = true } ) ;
876
+ }
877
+ }
872
878
}
873
879
}
874
880
@@ -879,47 +885,44 @@ public void FinishEntry(LiftEntry entry)
879
885
/// <summary> Creates the object to transfer all the data from a word </summary>
880
886
public LiftEntry GetOrMakeEntry ( Extensible info , int order )
881
887
{
882
- return new LiftEntry ( info , info . Guid , order )
883
- {
884
- LexicalForm = new LiftMultiText ( ) ,
885
- CitationForm = new LiftMultiText ( )
886
- } ;
888
+ return new LiftEntry ( info , info . Guid , order ) { CitationForm = [ ] , LexicalForm = [ ] } ;
887
889
}
888
890
889
891
/// <summary> Creates an empty sense object and adds it to the entry </summary>
890
892
public LiftSense GetOrMakeSense ( LiftEntry entry , Extensible info , string rawXml )
891
893
{
892
- var sense = new LiftSense ( info , info . Guid , entry )
893
- {
894
- Definition = new LiftMultiText ( ) ,
895
- Gloss = new LiftMultiText ( )
896
- } ;
894
+ var sense = new LiftSense ( info , info . Guid , entry ) { Definition = [ ] , Gloss = [ ] } ;
897
895
entry . Senses . Add ( sense ) ;
898
896
return sense ;
899
897
}
900
898
901
899
/// <summary> Adds each citation form to the entry for the vernacular </summary>
902
900
public void MergeInCitationForm ( LiftEntry entry , LiftMultiText contents )
903
901
{
902
+ entry . CitationForm ??= [ ] ;
904
903
foreach ( var ( key , value ) in contents )
905
904
{
906
905
entry . CitationForm . Add ( key , value . Text ) ;
907
906
}
908
907
}
909
908
910
909
/// <summary> Adds field to the entry for plural forms </summary>
911
- public void MergeInField ( LiftObject extensible , string typeAttribute , DateTime dateCreated ,
910
+ public void MergeInField ( LiftObject extensible , string tagAttribute , DateTime dateCreated ,
912
911
DateTime dateModified , LiftMultiText contents , List < Trait > traits )
913
912
{
914
- var textEntry = new LiftMultiText ( contents . FirstValue . Key ,
915
- contents . FirstValue . Value . Text ) ;
916
- var fieldEntry = new LiftField ( typeAttribute , textEntry ) ;
917
- extensible . Fields . Add ( fieldEntry ) ;
913
+ var field = new LiftField ( tagAttribute , contents )
914
+ {
915
+ DateCreated = dateCreated ,
916
+ DateModified = dateModified ,
917
+ } ;
918
+ field . Traits . AddRange ( traits . Select ( t => new LiftTrait ( ) { Name = t . Name , Value = t . Value } ) ) ;
919
+ extensible . Fields . Add ( field ) ;
918
920
}
919
921
920
922
/// <summary> Adds sense's definitions to the entry. </summary>
921
923
public void MergeInDefinition ( LiftSense sense , LiftMultiText multiText )
922
924
{
925
+ sense . Definition ??= [ ] ;
923
926
foreach ( var ( key , value ) in multiText )
924
927
{
925
928
sense . Definition . Add ( key , value . Text ) ;
@@ -929,6 +932,7 @@ public void MergeInDefinition(LiftSense sense, LiftMultiText multiText)
929
932
/// <summary> Adds sense's glosses to the entry. </summary>
930
933
public void MergeInGloss ( LiftSense sense , LiftMultiText multiText )
931
934
{
935
+ sense . Gloss ??= [ ] ;
932
936
foreach ( var ( key , value ) in multiText )
933
937
{
934
938
sense . Gloss . Add ( key , value . Text ) ;
@@ -938,6 +942,7 @@ public void MergeInGloss(LiftSense sense, LiftMultiText multiText)
938
942
/// <summary> Adds each lexeme form to the entry for the vernacular </summary>
939
943
public void MergeInLexemeForm ( LiftEntry entry , LiftMultiText contents )
940
944
{
945
+ entry . LexicalForm ??= [ ] ;
941
946
foreach ( var ( key , value ) in contents )
942
947
{
943
948
entry . LexicalForm . Add ( key , value ) ;
@@ -947,50 +952,52 @@ public void MergeInLexemeForm(LiftEntry entry, LiftMultiText contents)
947
952
/// <summary> Adds field to the entry for semantic domains </summary>
948
953
public void MergeInTrait ( LiftObject extensible , Trait trait )
949
954
{
950
- extensible . Traits . Add ( new LiftTrait { Name = trait . Name , Value = trait . Value } ) ;
955
+ extensible . Traits . Add ( new ( ) { Name = trait . Name , Value = trait . Value } ) ;
951
956
}
952
957
953
958
/// <summary> Needs to be called before MergeInMedia </summary>
954
959
public LiftObject MergeInPronunciation ( LiftEntry entry , LiftMultiText contents , string rawXml )
955
960
{
956
- return entry ;
961
+ var pronunciation = new LiftPhonetic { Form = contents } ;
962
+ entry . Pronunciations . Add ( pronunciation ) ;
963
+ return pronunciation ;
957
964
}
958
965
959
966
/// <summary> Adds in media for audio pronunciation </summary>
960
967
public void MergeInMedia ( LiftObject pronunciation , string href , LiftMultiText caption )
961
968
{
962
- var entry = ( LiftEntry ) pronunciation ;
963
- var phonetic = new LiftPhonetic ( ) ;
964
- var url = new LiftUrlRef { Url = href , Label = caption } ;
965
- phonetic . Media . Add ( url ) ;
966
- entry . Pronunciations . Add ( phonetic ) ;
969
+ ( pronunciation as LiftPhonetic ) ? . Media . Add ( new ( ) { Label = caption , Url = href } ) ;
967
970
}
968
971
969
972
/// <summary> Adds in note, if there is one to add </summary>
970
973
public void MergeInNote ( LiftObject extensible , string type , LiftMultiText contents , string rawXml )
971
974
{
975
+ var note = new LiftNote ( type , contents ) ;
972
976
if ( extensible is LiftEntry entry )
973
977
{
974
- var note = new LiftNote (
975
- // This application only uses "basic" notes, which have no type
976
- null ,
977
- new LiftMultiText ( contents . FirstValue . Key , contents . FirstValue . Value . Text ) ) ;
978
978
entry . Notes . Add ( note ) ;
979
979
}
980
+ else if ( extensible is LiftSense sense )
981
+ {
982
+ sense . Notes . Add ( note ) ;
983
+ }
984
+ else if ( extensible is LiftExample example )
985
+ {
986
+ example . Notes . Add ( note ) ;
987
+ }
980
988
}
981
989
982
- public void MergeInGrammaticalInfo ( LiftObject senseOrReversal , string val , List < Trait > traits )
990
+ public void MergeInGrammaticalInfo ( LiftObject obj , string val , List < Trait > traits )
983
991
{
984
- if ( senseOrReversal is LiftSense sense )
992
+ var gramInfo = new LiftGrammaticalInfo { Value = val } ;
993
+ gramInfo . Traits . AddRange ( traits . Select ( t => new LiftTrait { Name = t . Name , Value = t . Value } ) ) ;
994
+ if ( obj is LiftSense sense )
985
995
{
986
- if ( sense . GramInfo is null )
987
- {
988
- sense . GramInfo = new LiftGrammaticalInfo { Value = val } ;
989
- }
990
- else
991
- {
992
- sense . GramInfo . Value = val ;
993
- }
996
+ sense . GramInfo = gramInfo ;
997
+ }
998
+ else if ( obj is LiftReversal reversal )
999
+ {
1000
+ reversal . GramInfo = gramInfo ;
994
1001
}
995
1002
}
996
1003
@@ -1024,60 +1031,113 @@ public void ProcessRangeElement(string range, string id, string guid, string par
1024
1031
}
1025
1032
}
1026
1033
1027
- // The following are unused and are not implemented, but may still be called by the Lexicon Merger
1028
- // They may be useful later if we need to add more complex attributes to words in The Combine
1034
+ // The following may be called by the Lexicon Merger.
1035
+ // We don't use this info in The Combine except to know when to protect imported data.
1029
1036
[ ExcludeFromCodeCoverage ]
1030
1037
public LiftExample GetOrMakeExample ( LiftSense sense , Extensible info )
1031
1038
{
1032
- return new LiftExample { Content = new LiftMultiText ( ) } ;
1039
+ var example = new LiftExample
1040
+ {
1041
+ DateCreated = info . CreationTime ,
1042
+ DateModified = info . ModificationTime ,
1043
+ Guid = info . Guid ,
1044
+ Id = info . Id
1045
+ } ;
1046
+ sense . Examples . Add ( example ) ;
1047
+ return example ;
1033
1048
}
1049
+
1034
1050
[ ExcludeFromCodeCoverage ]
1035
1051
public LiftObject GetOrMakeParentReversal ( LiftObject parent , LiftMultiText contents , string type )
1036
1052
{
1037
- return new LiftReversal ( ) ;
1053
+ return new LiftReversal { Form = contents , Main = parent as LiftReversal , Type = type } ;
1038
1054
}
1055
+
1039
1056
[ ExcludeFromCodeCoverage ]
1040
1057
public LiftSense GetOrMakeSubsense ( LiftSense sense , Extensible info , string rawXml )
1041
1058
{
1042
- return new LiftSense ( info , new Guid ( ) , sense )
1043
- {
1044
- Definition = new LiftMultiText ( ) ,
1045
- Gloss = new LiftMultiText ( )
1046
- } ;
1059
+ var subsense = new LiftSense ( info , info . Guid , sense ) ;
1060
+ sense . Subsenses . Add ( subsense ) ;
1061
+ return subsense ;
1047
1062
}
1063
+
1048
1064
[ ExcludeFromCodeCoverage ]
1049
1065
public LiftObject MergeInEtymology ( LiftEntry entry , string source , string type , LiftMultiText form ,
1050
1066
LiftMultiText gloss , string rawXml )
1051
1067
{
1052
- return new LiftEtymology ( ) ;
1068
+ var etymology = new LiftEtymology { Form = form , Gloss = gloss , Source = source , Type = type } ;
1069
+ entry . Etymologies . Add ( etymology ) ;
1070
+ return etymology ;
1053
1071
}
1072
+
1054
1073
[ ExcludeFromCodeCoverage ]
1055
1074
public LiftObject MergeInReversal (
1056
1075
LiftSense sense , LiftObject parent , LiftMultiText contents , string type , string rawXml )
1057
1076
{
1058
- return new LiftReversal ( ) ;
1077
+ var reversal = new LiftReversal { Form = contents , Main = parent as LiftReversal , Type = type } ;
1078
+ sense . Reversals . Add ( reversal ) ;
1079
+ return reversal ;
1059
1080
}
1081
+
1060
1082
[ ExcludeFromCodeCoverage ]
1061
1083
public LiftObject MergeInVariant ( LiftEntry entry , LiftMultiText contents , string rawXml )
1062
1084
{
1063
- return new LiftVariant ( ) ;
1085
+ var variant = new LiftVariant { Form = contents , RawXml = rawXml } ;
1086
+ entry . Variants . Add ( variant ) ;
1087
+ return variant ;
1064
1088
}
1089
+
1065
1090
[ ExcludeFromCodeCoverage ]
1066
- public void EntryWasDeleted ( Extensible info , DateTime dateDeleted ) { }
1067
- [ ExcludeFromCodeCoverage ]
1068
- public void MergeInExampleForm ( LiftExample example , LiftMultiText multiText ) { }
1091
+ public void MergeInExampleForm ( LiftExample example , LiftMultiText multiText )
1092
+ {
1093
+ example . Content ??= [ ] ;
1094
+ foreach ( var ( key , value ) in multiText )
1095
+ {
1096
+ example . Content . Add ( key , value ) ;
1097
+ }
1098
+ }
1099
+
1069
1100
[ ExcludeFromCodeCoverage ]
1070
- public void MergeInPicture ( LiftSense sense , string href , LiftMultiText caption ) { }
1101
+ public void MergeInPicture ( LiftSense sense , string href , LiftMultiText caption )
1102
+ {
1103
+ sense . Illustrations . Add ( new ( ) { Label = caption , Url = href } ) ;
1104
+ }
1105
+
1071
1106
[ ExcludeFromCodeCoverage ]
1072
1107
public void MergeInRelation (
1073
1108
LiftObject extensible , string relationTypeName , string targetId , string rawXml )
1074
- { }
1109
+ {
1110
+ var relation = new LiftRelation { Ref = targetId , Type = relationTypeName } ;
1111
+ if ( extensible is LiftEntry entry )
1112
+ {
1113
+ entry . Relations . Add ( relation ) ;
1114
+ }
1115
+ else if ( extensible is LiftSense sense )
1116
+ {
1117
+ sense . Relations . Add ( relation ) ;
1118
+ }
1119
+ else if ( extensible is LiftVariant variant )
1120
+ {
1121
+ variant . Relations . Add ( relation ) ;
1122
+ }
1123
+ }
1124
+
1075
1125
[ ExcludeFromCodeCoverage ]
1076
- public void MergeInSource ( LiftExample example , string source ) { }
1126
+ public void MergeInSource ( LiftExample example , string source )
1127
+ {
1128
+ example . Source = source ;
1129
+ }
1130
+
1077
1131
[ ExcludeFromCodeCoverage ]
1078
1132
public void MergeInTranslationForm (
1079
- LiftExample example , string type , LiftMultiText multiText , string rawXml )
1080
- { }
1133
+ LiftExample example , string type , LiftMultiText contents , string rawXml )
1134
+ {
1135
+ example . Translations . Add ( new ( ) { Content = contents , Type = type } ) ;
1136
+ }
1137
+
1138
+ // The following are unimplemented, but may still be called by the Lexicon Merger
1139
+ [ ExcludeFromCodeCoverage ]
1140
+ public void EntryWasDeleted ( Extensible info , DateTime dateDeleted ) { }
1081
1141
[ ExcludeFromCodeCoverage ]
1082
1142
public void ProcessFieldDefinition ( string tag , LiftMultiText description ) { }
1083
1143
}
0 commit comments