Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 0 additions & 19 deletions Src/FwParatextLexiconPlugin/FdoLexicon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,6 @@ private bool TryGetWordAnalysis(IWfiAnalysis analysis, out WordAnalysisV2 lexeme
private ILexEntry GetMatchingEntryFromParser(string wordForm)
{
ILexEntry matchingEntry = null;
if (m_parser == null)
InstantiateParser();

if (m_parser == null)
return null;

Expand All @@ -640,22 +637,6 @@ private ILexEntry GetMatchingEntryFromParser(string wordForm)
return matchingEntry;
}

private void InstantiateParser()
{
string parserDataDir = Path.Combine(ParatextLexiconPluginDirectoryFinder.CodeDirectory, "Language Explorer");
switch (m_cache.LanguageProject.MorphologicalDataOA.ActiveParser)
{
case "XAmple":
m_parser = new XAmpleParser(m_cache, parserDataDir);
break;
case "HC":
m_parser = new HCParser(m_cache);
break;
default:
throw new InvalidOperationException("The language project is set to use an unrecognized parser.");
}
}

private ILexEntry GetMatchingEntryFromStemmer(string wordForm)
{
var repo = m_cache.ServiceLocator.GetInstance<ILexEntryRepository>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,6 @@ public void FindClosestMatchingLexeme()
matchingLexeme = m_lexicon.FindClosestMatchingLexeme("a");
Assert.That(matchingLexeme.LexicalForm == "a", Is.True);

// Found by parser
lexeme = m_lexicon.CreateLexeme(LexemeType.Prefix, "pre");
m_lexicon.AddLexeme(lexeme);
matchingLexeme = m_lexicon.FindClosestMatchingLexeme("prea");
Assert.That(matchingLexeme.LexicalForm == "a", Is.True);

// Found by unsupervised stemmer
m_lexicon.AddLexeme(m_lexicon.CreateLexeme(LexemeType.Stem, "b"));
m_lexicon.AddLexeme(m_lexicon.CreateLexeme(LexemeType.Stem, "c"));
Expand Down
13 changes: 10 additions & 3 deletions Src/LexText/ParserCore/ParserCoreTests/ParseWorkerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ParseWorkerTests : MemoryOnlyBackendProviderTestBase
private String m_taskDetailsString;
private IdleQueue m_idleQueue;
private CoreWritingSystemDefinition m_vernacularWS;
Mediator Mediator { get; set; }
PropertyTable PropertyTable { get; set; }
#endregion Data Members

#region Non-test methods
Expand Down Expand Up @@ -67,14 +69,19 @@ public override void FixtureSetup()
base.FixtureSetup();
m_vernacularWS = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem;
m_idleQueue = new IdleQueue {IsPaused = true};
Mediator = new Mediator();
PropertyTable = new PropertyTable(Mediator);
}

public override void FixtureTeardown()
{
m_vernacularWS = null;
m_idleQueue.Dispose();
m_idleQueue = null;

Mediator.Dispose();
Mediator = null;
PropertyTable.Dispose();
PropertyTable = null;
base.FixtureTeardown();
}

Expand Down Expand Up @@ -106,7 +113,7 @@ protected void UndoAll()
public void TryAWord()
{
XDocument lowerXDoc = new XDocument(new XComment("cats"));
var parserWorker = new ParserWorker(Cache, null, HandleTaskUpdate, m_idleQueue, null);
var parserWorker = new ParserWorker(Cache, PropertyTable, HandleTaskUpdate, m_idleQueue, null);
parserWorker.Parser = new TestParserClass(null, lowerXDoc);

// SUT
Expand Down Expand Up @@ -141,7 +148,7 @@ public void UpdateWordform()
});
});

var parserWorker = new ParserWorker(Cache, null, HandleTaskUpdate, m_idleQueue, null);
var parserWorker = new ParserWorker(Cache, PropertyTable, HandleTaskUpdate, m_idleQueue, null);
parserWorker.Parser = new TestParserClass(lowerResult, null);

// SUT
Expand Down
2 changes: 1 addition & 1 deletion Src/LexText/ParserCore/ParserWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ParserWorker(LcmCache cache, PropertyTable propertyTable, Action<TaskRepo
switch (m_cache.LanguageProject.MorphologicalDataOA.ActiveParser)
{
case "XAmple":
m_parser = new XAmpleParser(cache, dataDir);
m_parser = new XAmpleParser(cache, dataDir, m_propertyTable);
agent = cache.ServiceLocator.GetInstance<ICmAgentRepository>().GetObject(CmAgentTags.kguidAgentXAmpleParser);
break;
case "HC":
Expand Down
22 changes: 15 additions & 7 deletions Src/LexText/ParserCore/XAmpleParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using SIL.FieldWorks.Common.FwUtils;
using SIL.LCModel;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.ObjectModel;
using SIL.Xml;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -11,12 +17,8 @@
using System.Text;
using System.Xml;
using System.Xml.Linq;
using SIL.LCModel;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.ObjectModel;
using SIL.Xml;
using XAmpleManagedWrapper;
using XCore;

namespace SIL.FieldWorks.WordWorks.Parser
{
Expand All @@ -25,6 +27,7 @@ public class XAmpleParser : DisposableBase, IParser
private static readonly char[] Digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

private XAmpleWrapper m_xample;
private PropertyTable m_propTable;
private readonly string m_dataDir;
private readonly LcmCache m_cache;
private ParserModelChangeListener m_changeListener;
Expand All @@ -33,7 +36,7 @@ public class XAmpleParser : DisposableBase, IParser
private bool m_forceUpdate;
private XElement xampleAddonFileRoot;

public XAmpleParser(LcmCache cache, string dataDir)
public XAmpleParser(LcmCache cache, string dataDir, PropertyTable propertyTable)
{
m_cache = cache;
m_xample = new XAmpleWrapper();
Expand All @@ -43,6 +46,7 @@ public XAmpleParser(LcmCache cache, string dataDir)
m_database = ConvertNameToUseAnsiCharacters(m_cache.ProjectId.Name);
m_transformer = new M3ToXAmpleTransformer(m_database);
m_forceUpdate = true;
m_propTable = propertyTable;
InitXAmpleAddonDataInfo();
}
private void InitXAmpleAddonDataInfo()
Expand All @@ -58,7 +62,11 @@ private void InitXAmpleAddonDataInfo()
{
xampleAddonFileRoot = doc.Root;
var preparer = new XAmplePropertiesPreparer(m_cache, xampleAddonFileRoot, false);
preparer.AddListsAndFields();
if (!preparer.ListsAlreadyAdded())
{
preparer.AddListsAndFields();
FwUtils.Publisher.Publish(new PublisherParameterObject(EventConstants.ReloadAreaTools, "lists", m_propTable.GetWindow()));
Comment thread
AndyBlack marked this conversation as resolved.
}
}
}
}
Expand Down
29 changes: 16 additions & 13 deletions Src/LexText/ParserCore/XAmplePropertiesPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Xml.XPath;
using XCore;

namespace SIL.FieldWorks.WordWorks.Parser
{
Expand Down Expand Up @@ -57,13 +57,24 @@ where fd.IsCustomField
select fd).ToList();
}

public Boolean ListsAlreadyAdded()
{
var possListRepository = Cache.ServiceLocator.GetInstance<ICmPossibilityListRepository>();
return possListRepository.AllInstances().Any(list => list.Name.BestAnalysisAlternative.Text == customListName);
}

public Boolean XAmplePropertiesCustomFieldAlreadyAdded(string fieldName, int fieldClassId)
Comment thread
AndyBlack marked this conversation as resolved.
{
var customFields = GetListOfCustomFields();
return customFields.Any(fd => fd.Name == fieldName && fd.Class == fieldClassId);
}

public void AddListsAndFields()
{
if (Root == null)
{
return;
}

AddXAmplePropertiesList();
var customFields = GetListOfCustomFields();
AddXAmplePropertiesCustomField(entryCustomFieldName, LexEntryTags.kClassId);
Expand All @@ -75,8 +86,7 @@ public void AddListsAndFields()
/// </summary>
public void AddXAmplePropertiesCustomField(string fieldName, int fieldClassId)
{
var customFields = GetListOfCustomFields();
if (customFields.Find(fd => fd.Name == fieldName) != null)
if (XAmplePropertiesCustomFieldAlreadyAdded(fieldName, fieldClassId))
{
// already done; quit
return;
Expand Down Expand Up @@ -117,22 +127,15 @@ public void AddXAmplePropertiesCustomField(string fieldName, int fieldClassId)
/// </summary>
public void AddXAmplePropertiesList()
{
if (Root == null)
if (Root == null || ListsAlreadyAdded())
{
// nothing to do
return;
}
var possListRepository = Cache.ServiceLocator.GetInstance<ICmPossibilityListRepository>();
var customList = possListRepository.AllInstances().FirstOrDefault(list => list.Name.BestAnalysisAlternative.Text == customListName);
if (customList != null)
{
return;
}
NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
{
int ws = WritingSystemServices.kwsAnal;
Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>().CreateUnowned(customListName, ws);
customList = possListRepository.AllInstances().Last();
var customList = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>().CreateUnowned(customListName, ws);
var propPoss = Cache.ServiceLocator.GetInstance<ICmCustomItemFactory>();
ws = Cache.DefaultAnalWs;
var elements = Root.XPathSelectElements("CustomList/Contents/Element");
Expand Down
3 changes: 2 additions & 1 deletion Src/Utilities/pcpatrflex/ToneParsFLExDll/ToneParsFLExForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ private bool XAmpleFilesAreUpToDate()
Path.Combine(
FwDirectoryFinder.CodeDirectory,
FwDirectoryFinder.ksFlexFolderName
)
),
PropTable
);
}
return m_XAmpleParser.IsUpToDate();
Expand Down
Loading