public override void Write(LoadException le) { m_xmlWriter.WriteStartElement("Error"); switch (le.ErrorType) { case LoadException.LoadErrorType.INVALID_ENTRY_SHAPE: string entryShape = le.Data["shape"] as string; string entryId = le.Data["entry"] as string; SIL.HermitCrab.LexEntry entry = le.Loader.CurrentMorpher.Lexicon.GetEntry(entryId); m_xmlWriter.WriteString(string.Format(ParserCoreStrings.ksHCInvalidEntryShape, entryShape, entry.Description)); break; case LoadException.LoadErrorType.INVALID_RULE_SHAPE: string ruleShape = le.Data["shape"] as string; string ruleId = le.Data["rule"] as string; MorphologicalRule rule = le.Loader.CurrentMorpher.GetMorphologicalRule(ruleId); m_xmlWriter.WriteString(string.Format(ParserCoreStrings.ksHCInvalidRuleShape, ruleShape, rule.Description)); break; default: m_xmlWriter.WriteString(string.Format(ParserCoreStrings.ksHCDefaultErrorMsg, le.Message)); break; } m_xmlWriter.WriteEndElement(); }
/// <summary> /// Initializes a new instance of the <see cref="WordSynthesis"/> class. /// </summary> /// <param name="rootAllomorph">The root allomorph.</param> /// <param name="nonHead">The non-head synthesis.</param> /// <param name="rzFeatures">The realizational features.</param> /// <param name="mrules">The morphological rules to apply.</param> /// <param name="curTrace">The current trace record.</param> internal WordSynthesis(LexEntry.RootAllomorph rootAllomorph, WordSynthesis nonHead, FeatureValues rzFeatures, IEnumerable <MorphologicalRule> mrules, Trace curTrace) { m_root = (LexEntry)rootAllomorph.Morpheme; m_mprFeatures = m_root.MPRFeatures != null?m_root.MPRFeatures.Clone() : new MPRFeatureSet(); m_headFeatures = m_root.HeadFeatures != null?m_root.HeadFeatures.Clone() : new FeatureValues(); m_footFeatures = m_root.FootFeatures != null?m_root.FootFeatures.Clone() : new FeatureValues(); m_pos = m_root.POS; m_stratum = m_root.Stratum; m_nonHead = nonHead; m_morphs = new Morphs(); Morph morph = new Morph(rootAllomorph); morph.Shape.AddMany(rootAllomorph.Shape.Segments); m_morphs.Add(morph); m_shape = new PhoneticShape(); m_shape.Add(new Margin(Direction.LEFT)); m_shape.AddPartition(rootAllomorph.Shape.Segments, morph.Partition); m_shape.Add(new Margin(Direction.RIGHT)); m_obligHeadFeatures = new HCObjectSet <Feature>(); m_mrules = new List <MorphologicalRule>(mrules); m_rzFeatures = rzFeatures; m_curTrace = curTrace; m_mrulesApplied = new Dictionary <MorphologicalRule, int>(); }
/// <summary> /// Adds the lexical entry. /// </summary> /// <param name="entry">The lexical entry.</param> public void AddEntry(LexEntry entry) { entry.Stratum = this; foreach (LexEntry.RootAllomorph allomorph in entry.Allomorphs) { m_entryTrie.Add(allomorph.Shape, allomorph); } }
bool IgnoreEntry(LexEntry entry, string[] selectTraceMorphs) { if (selectTraceMorphs != null) { if (!selectTraceMorphs.Contains(entry.ID)) { return(true); } } return(false); }
void LexicalLookup(WordAnalysis input, ICollection <WordSynthesis> candidates, string[] selectTraceMorphs) { LexLookupTrace lookupTrace = null; if (Morpher.TraceLexLookup) { // create lexical lookup trace record lookupTrace = new LexLookupTrace(this, input.Shape.Clone()); input.CurrentTrace.AddChild(lookupTrace); } foreach (SegmentDefinitionTrie <LexEntry.RootAllomorph> .Match match in m_entryTrie.Search(input.Shape)) { // don't allow a compound where both roots are the same if (input.NonHead == null || input.NonHead.RootAllomorph.Morpheme != match.Value.Morpheme) { LexEntry entry = (LexEntry)match.Value.Morpheme; if (IgnoreEntry(entry, selectTraceMorphs)) { continue; } foreach (LexEntry.RootAllomorph allomorph in entry.Allomorphs) { WordAnalysis wa = input.Clone(); wa.RootAllomorph = allomorph; if (Morpher.TraceLexLookup) { // successful lookup, so create word synthesis trace record WordSynthesisTrace wsTrace = new WordSynthesisTrace(wa.RootAllomorph, wa.UnappliedMorphologicalRules, wa.RealizationalFeatures.Clone()); lookupTrace.AddChild(wsTrace); wa.CurrentTrace = wsTrace; } candidates.Add(new WordSynthesis(wa)); } } } }
/// <summary> /// Copy constructor. /// </summary> /// <param name="ws">The word synthesis.</param> public WordSynthesis(WordSynthesis ws) { m_root = ws.m_root; if (ws.m_nonHead != null) { m_nonHead = ws.m_nonHead.Clone(); } m_shape = ws.m_shape.Clone(); m_morphs = ws.m_morphs.Clone(); m_pos = ws.m_pos; m_mprFeatures = ws.m_mprFeatures.Clone(); m_headFeatures = ws.m_headFeatures.Clone(); m_footFeatures = ws.m_footFeatures.Clone(); m_obligHeadFeatures = new HCObjectSet <Feature>(ws.m_obligHeadFeatures); m_mrules = new List <MorphologicalRule>(ws.m_mrules); m_curRuleIndex = ws.m_curRuleIndex; m_rzFeatures = ws.m_rzFeatures.Clone(); m_curTrace = ws.m_curTrace; m_stratum = ws.m_stratum; m_mrulesApplied = new Dictionary <MorphologicalRule, int>(ws.m_mrulesApplied); }
public override void Blocking(BlockType blockingType, WordSynthesis input, LexEntry blockingEntry) { if (TraceBlocking) ((XElement) input.CurrentTraceObject).Add(new XElement("BlockingTrace", Write("BlockingEntry", blockingEntry))); }
/// <summary> /// Adds the lexical entry. /// </summary> /// <param name="entry">The lexical entry.</param> public void AddEntry(LexEntry entry) { m_entries.Add(entry); }
/// <summary> /// Initializes a new instance of the <see cref="BlockingTrace"/> class. /// </summary> /// <param name="blockingType">Type of the blocking.</param> /// <param name="blockingEntry">The blocking entry.</param> internal BlockingTrace(BlockType blockingType, LexEntry blockingEntry) { m_blockingType = blockingType; m_blockingEntry = blockingEntry; }
void LoadAllomorph(XmlElement alloNode, LexEntry entry, Stratum stratum) { string alloId = alloNode.GetAttribute("id"); string shapeStr = alloNode.SelectSingleNode("PhoneticShape").InnerText; PhoneticShape shape = stratum.CharacterDefinitionTable.ToPhoneticShape(shapeStr, ModeType.SYNTHESIS); if (shape == null) { LoadException le = new LoadException(LoadException.LoadErrorType.INVALID_ENTRY_SHAPE, this, string.Format(HCStrings.kstidInvalidLexEntryShape, shapeStr, entry.ID, stratum.CharacterDefinitionTable.ID)); le.Data["shape"] = shapeStr; le.Data["charDefTable"] = stratum.CharacterDefinitionTable.ID; le.Data["entry"] = entry.ID; throw le; } LexEntry.RootAllomorph allomorph = new LexEntry.RootAllomorph(alloId, shapeStr, m_curMorpher, shape); allomorph.RequiredEnvironments = LoadEnvs(alloNode.SelectSingleNode("RequiredEnvironments")); allomorph.ExcludedEnvironments = LoadEnvs(alloNode.SelectSingleNode("ExcludedEnvironments")); allomorph.Properties = LoadProperties(alloNode.SelectSingleNode("Properties")); entry.AddAllomorph(allomorph); m_curMorpher.AddAllomorph(allomorph); }
void LoadLexEntry(XmlElement entryNode) { string id = entryNode.GetAttribute("id"); LexEntry entry = new LexEntry(id, id, m_curMorpher); string posId = entryNode.GetAttribute("partOfSpeech"); PartOfSpeech pos = m_curMorpher.GetPOS(posId); if (pos == null) throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownPOS, posId), posId); entry.POS = pos; XmlElement glossElem = entryNode.SelectSingleNode("Gloss") as XmlElement; entry.Gloss = new Gloss(glossElem.GetAttribute("id"), glossElem.InnerText, m_curMorpher); entry.MPRFeatures = LoadMPRFeatures(entryNode.GetAttribute("ruleFeatures")); entry.HeadFeatures = LoadSynFeats(entryNode.SelectSingleNode("HeadFeatures"), m_curMorpher.HeadFeatureSystem); entry.FootFeatures = LoadSynFeats(entryNode.SelectSingleNode("FootFeatures"), m_curMorpher.FootFeatureSystem); Stratum stratum = GetStratum(entryNode.GetAttribute("stratum")); string familyId = entryNode.GetAttribute("family"); if (!string.IsNullOrEmpty(familyId)) { LexFamily family = m_curMorpher.Lexicon.GetFamily(familyId); if (family == null) throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownFamily, familyId), familyId); family.AddEntry(entry); } XmlNodeList alloNodes = entryNode.SelectNodes("Allomorphs/Allomorph[@isActive='yes']"); foreach (XmlNode alloNode in alloNodes) { try { LoadAllomorph(alloNode as XmlElement, entry, stratum); } catch (LoadException le) { if (m_quitOnError) throw le; } } if (entry.AllomorphCount > 0) { stratum.AddEntry(entry); m_curMorpher.Lexicon.AddEntry(entry); } }
public void AddEntry(LexEntry entry) { entry.Family = this; m_entries.Add(entry); }
private bool TryLoadLexEntry(XElement entryElem, CharacterDefinitionTable table, out LexEntry entry) { var id = (string) entryElem.Attribute("id"); entry = new LexEntry {Gloss = (string) entryElem.Element("Gloss")}; var fs = new FeatureStruct(); var pos = (string) entryElem.Attribute("partOfSpeech"); if (!string.IsNullOrEmpty(pos)) fs.AddValue(_posFeature, ParsePartsOfSpeech(pos)); XElement headFeatElem = entryElem.Element("AssignedHeadFeatures"); if (headFeatElem != null) fs.AddValue(_headFeature, LoadFeatureStruct(headFeatElem, _language.SyntacticFeatureSystem)); XElement footFeatElem = entryElem.Element("AssignedFootFeatures"); if (footFeatElem != null) fs.AddValue(_footFeature, LoadFeatureStruct(footFeatElem, _language.SyntacticFeatureSystem)); fs.Freeze(); entry.SyntacticFeatureStruct = fs; entry.MprFeatures.UnionWith(LoadMprFeatures((string) entryElem.Attribute("ruleFeatures"))); var familyID = (string) entryElem.Attribute("family"); if (!string.IsNullOrEmpty(familyID)) { LexFamily family = _families[familyID]; family.Entries.Add(entry); } entry.IsPartial = (bool?) entryElem.Attribute("partial") ?? false; LoadProperties(entryElem.Element("Properties"), entry.Properties); foreach (XElement alloElem in entryElem.Elements("Allomorphs").Elements("Allomorph").Where(IsActive)) { try { RootAllomorph allomorph = LoadRootAllomorph(alloElem, table); entry.Allomorphs.Add(allomorph); _allomorphs[(string) alloElem.Attribute("id")] = allomorph; } catch (Exception e) { if (_errorHandler != null) _errorHandler(e, id); else throw; } } if (entry.Allomorphs.Count > 0) { _morphemes[id] = entry; return true; } entry = null; return false; }
public override void Blocking(BlockType blockingType, WordSynthesis input, LexEntry blockingEntry) { if (TraceBlocking) // create blocking trace record, should this become the current trace? ((Trace) input.CurrentTraceObject).AddChild(new BlockingTrace(BlockingTrace.BlockType.TEMPLATE, blockingEntry)); }
public abstract void Blocking(BlockType blockingType, WordSynthesis input, LexEntry blockingEntry);
/// <summary> /// Initializes a new instance of the <see cref="WordSynthesisTrace"/> class. /// </summary> /// <param name="rootAllomorph">The root allomorph.</param> /// <param name="mrules">The morphological rules.</param> /// <param name="rzFeatures">The realizational features.</param> internal WordSynthesisTrace(LexEntry.RootAllomorph rootAllomorph, IEnumerable<MorphologicalRule> mrules, FeatureValues rzFeatures) { m_rootAllomorph = rootAllomorph; m_mrules = new List<MorphologicalRule>(mrules); m_rzFeatures = rzFeatures; }