Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interlinear flextext importing #154

Merged
merged 7 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 89 additions & 11 deletions Src/LexText/Interlinear/BIRDInterlinearImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.Infrastructure;
using SIL.LCModel.Utils;
using Gecko.WebIDL;
using SIL.FieldWorks.Common.Framework.DetailControls;
using SIL.Extensions;
using SIL.Machine.DataStructures;

namespace SIL.FieldWorks.IText
{
Expand Down Expand Up @@ -723,6 +727,8 @@ private static IAnalysis CreateWordAnalysisStack(LcmCache cache, Word word)
IAnalysis analysis = null;
var wsFact = cache.WritingSystemFactory;
ILgWritingSystem wsMainVernWs = null;
IWfiMorphBundle bundle = null;

foreach (var wordItem in word.Items)
{
ITsString wordForm = null;
Expand Down Expand Up @@ -757,19 +763,91 @@ private static IAnalysis CreateWordAnalysisStack(LcmCache cache, Word word)
{
Debug.Assert(analysis != null, "What else could this do?");
}
//Add any morphemes to the thing

// Fill in morphemes, lex. entries, lex. gloss, and lex.gram.info
if (word.morphemes != null && word.morphemes.morphs.Length > 0)
{
//var bundle = newSegment.Cache.ServiceLocator.GetInstance<IWfiMorphBundleFactory>().Create();
//analysis.Analysis.MorphBundlesOS.Add(bundle);
//foreach (var morpheme in word.morphemes)
//{
// //create a morpheme
// foreach(item item in morpheme.items)
// {
// //fill in morpheme's stuff
// }
//}
int morphIdx = 0;
foreach (var morpheme in word.morphemes.morphs)
{
ILexEntryRepository lex_entry_repo = cache.ServiceLocator.GetInstance<ILexEntryRepository>();
IMoMorphSynAnalysisRepository msa_repo = cache.ServiceLocator.GetInstance<IMoMorphSynAnalysisRepository>();
var itemDict = new Dictionary<string, Tuple<string, string>>();
if (analysis.Analysis == null)
{
break;
}

foreach (item item in morpheme.items)
{
itemDict[item.type] = new Tuple<string, string>(item.lang, item.Value);
}

if (itemDict.ContainsKey("txt")) // Morphemes
{
int ws = GetWsEngine(wsFact, itemDict["txt"].Item1).Handle;
ITsString wf = TsStringUtils.MakeString(itemDict["txt"].Item2, ws);

// If we already have a bundle use that one
bundle =
analysis.Analysis.MorphBundlesOS.FirstOrDefault(b => b.Form.get_String(ws).Text == itemDict["txt"].Item2);
if (bundle == null)
{
// Otherwise create a new bundle and add it to analysis
bundle = cache.ServiceLocator.GetInstance<IWfiMorphBundleFactory>().Create();
if (analysis.Analysis.MorphBundlesOS.Count >= word.morphemes.morphs.Length)
{
analysis.Analysis.MorphBundlesOS.RemoveAt(morphIdx);
}
analysis.Analysis.MorphBundlesOS.Insert(morphIdx, bundle);
}
bundle.Form.set_String(ws, wf);
}

if (itemDict.ContainsKey("cf")) // Lex. Entries
{
int ws_cf = GetWsEngine(wsFact, itemDict["cf"].Item1).Handle;
var entries = lex_entry_repo.AllInstances().Where(
m => StringServices.CitationFormWithAffixTypeStaticForWs(m, ws_cf, string.Empty) == itemDict["cf"].Item2);
if (entries != null)
{
ILexEntry entry = null;
if (entries.Count() == 1)
{
entry = entries.First();
}
else if (itemDict.ContainsKey("hn")) // Homograph Number
{
entry = entries.FirstOrDefault(m => m.HomographNumber.ToString() == itemDict["hn"].Item2);
}
else // Didn't find a match
{
break;
}
bundle.MorphRA = entry.LexemeFormOA;

if (itemDict.ContainsKey("gls")) // Lex. Gloss
{
int ws_gls = GetWsEngine(wsFact, itemDict["gls"].Item1).Handle;
ILexSense sense = entry.SensesOS.FirstOrDefault(s => s.Gloss.get_String(ws_gls).Text == itemDict["gls"].Item2);
if (sense != null)
{
bundle.SenseRA = sense;
}
}
}
}

if (itemDict.ContainsKey("msa")) // Lex. Gram. Info
{
IMoMorphSynAnalysis match = msa_repo.AllInstances().FirstOrDefault(m => m.InterlinearAbbr == itemDict["msa"].Item2);
if (match != null)
{
bundle.MsaRA = match;
}
}
morphIdx++;
}
}
return analysis;
}
Expand Down
9 changes: 4 additions & 5 deletions Src/LexText/Interlinear/FlexInterlinModel/FlexInterlinear.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool - however, it has been heavily massaged, since the tool is kind of broken -NaylorJ
// Runtime Version:2.0.50727.5446
Expand Down Expand Up @@ -602,7 +602,7 @@ public string type
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, TypeName = "morphemes")]
public partial class Morphemes
{

Expand Down Expand Up @@ -660,10 +660,9 @@ public bool analysisStatusSpecified
[System.SerializableAttribute()]
// [System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, TypeName = "morph")]
public partial class Morph
{

private item[] itemField;

private morphTypes typeField;
Expand All @@ -674,7 +673,7 @@ public partial class Morph
public string guid;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("item", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)]
[System.Xml.Serialization.XmlElementAttribute("item", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)]
public item[] items
{
get
Expand Down
Loading