/// <summary> /// Initializes a new instance of the <see cref="WordAnalysis"/> class. /// </summary> /// <param name="shape">The shape.</param> /// <param name="stratum"></param> internal WordAnalysis(PhoneticShape shape, Stratum stratum) { m_shape = shape; m_pos = new HCObjectSet<PartOfSpeech>(); m_mrules = new List<MorphologicalRule>(); m_mrulesUnapplied = new Dictionary<MorphologicalRule, int>(); m_rzFeatures = new FeatureValues(); m_stratum = stratum; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="wa">The word analysis.</param> public WordAnalysis(WordAnalysis wa) { m_shape = wa.m_shape.Clone(); m_pos = new HCObjectSet<PartOfSpeech>(wa.m_pos); m_rootAllomorph = wa.m_rootAllomorph; if (wa.m_nonHead != null) m_nonHead = wa.m_nonHead.Clone(); m_mrules = new List<MorphologicalRule>(wa.m_mrules); m_mrulesUnapplied = new Dictionary<MorphologicalRule, int>(wa.m_mrulesUnapplied); m_rzFeatures = wa.m_rzFeatures.Clone(); m_curTrace = wa.m_curTrace; m_stratum = wa.m_stratum; }
/// <summary> /// Initializes a new instance of the <see cref="Morpher"/> class. /// </summary> /// <param name="id">The id.</param> /// <param name="language">The language.</param> public Morpher(string id, string language) : base(id, language, null) { m_strata = new HCObjectSet<Stratum>(); m_phoneticFeatSys = new FeatureSystem(); m_headFeatSys = new FeatureSystem(); m_footFeatSys = new FeatureSystem(); m_charDefTables = new HCObjectSet<CharacterDefinitionTable>(); m_natClasses = new HCObjectSet<NaturalClass>(); m_prules = new HCObjectSet<PhonologicalRule>(); m_mrules = new HCObjectSet<MorphologicalRule>(); m_lexicon = new Lexicon(); m_templates = new HCObjectSet<AffixTemplate>(); m_mprFeatGroups = new HCObjectSet<MPRFeatureGroup>(); m_mprFeatures = new HCObjectSet<MPRFeature>(); m_pos = new HCObjectSet<PartOfSpeech>(); m_allomorphs = new HCObjectSet<Allomorph>(); }
void LoadAffixTemplate(XmlElement tempNode, HCObjectSet<MorphologicalRule> templateRules) { string id = tempNode.GetAttribute("id"); string name = tempNode.SelectSingleNode("Name").InnerText; AffixTemplate template = new AffixTemplate(id, name, m_curMorpher); string posIdsStr = tempNode.GetAttribute("requiredPartsOfSpeech"); template.RequiredPOSs = LoadPOSs(posIdsStr); XmlNodeList slotList = tempNode.SelectNodes("Slot[@isActive='yes']"); foreach (XmlNode slotNode in slotList) { XmlElement slotElem = slotNode as XmlElement; string slotId = slotElem.GetAttribute("id"); string slotName = slotElem.SelectSingleNode("Name").InnerText; Slot slot = new Slot(slotId, slotName, m_curMorpher); string ruleIdsStr = slotElem.GetAttribute("morphologicalRules"); string[] ruleIds = ruleIdsStr.Split(' '); MorphologicalRule lastRule = null; foreach (string ruleId in ruleIds) { MorphologicalRule rule = m_curMorpher.GetMorphologicalRule(ruleId); if (rule != null) { slot.AddRule(rule); lastRule = rule; templateRules.Add(rule); } else { if (m_quitOnError) throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownMRule, ruleId), ruleId); } } string optionalStr = slotElem.GetAttribute("optional"); if (string.IsNullOrEmpty(optionalStr) && lastRule is RealizationalRule) slot.IsOptional = (lastRule as RealizationalRule).RealizationalFeatures.NumFeatures > 0; else slot.IsOptional = optionalStr == "true"; template.AddSlot(slot); } m_curMorpher.AddAffixTemplate(template); }
void LoadMRule(XmlElement mruleNode) { string id = mruleNode.GetAttribute("id"); string name = mruleNode.SelectSingleNode("Name").InnerText; AffixalMorphologicalRule mrule = new AffixalMorphologicalRule(id, name, m_curMorpher); XmlElement glossElem = mruleNode.SelectSingleNode("Gloss") as XmlElement; if (glossElem != null) mrule.Gloss = new Gloss(glossElem.GetAttribute("id"), glossElem.InnerText, m_curMorpher); string multApp = mruleNode.GetAttribute("multipleApplication"); if (!string.IsNullOrEmpty(multApp)) mrule.MaxNumApps = Convert.ToInt32(multApp); mrule.RequiredPOSs = LoadPOSs(mruleNode.GetAttribute("requiredPartsOfSpeech")); string outPOSId = mruleNode.GetAttribute("outputPartOfSpeech"); PartOfSpeech outPOS = null; if (!string.IsNullOrEmpty(outPOSId)) { outPOS = m_curMorpher.GetPOS(outPOSId); if (outPOS == null) throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownPOS, outPOSId), outPOSId); } mrule.OutPOS = outPOS; mrule.RequiredHeadFeatures = LoadSynFeats(mruleNode.SelectSingleNode("RequiredHeadFeatures"), m_curMorpher.HeadFeatureSystem); mrule.RequiredFootFeatures = LoadSynFeats(mruleNode.SelectSingleNode("RequiredFootFeatures"), m_curMorpher.FootFeatureSystem); mrule.OutHeadFeatures = LoadSynFeats(mruleNode.SelectSingleNode("OutputHeadFeatures"), m_curMorpher.HeadFeatureSystem); mrule.OutFootFeatures = LoadSynFeats(mruleNode.SelectSingleNode("OutputFootFeatures"), m_curMorpher.FootFeatureSystem); HCObjectSet<Feature> obligHeadFeats = new HCObjectSet<Feature>(); string obligHeadIdsStr = mruleNode.GetAttribute("outputObligatoryFeatures"); if (!string.IsNullOrEmpty(obligHeadIdsStr)) { string[] obligHeadIds = obligHeadIdsStr.Split(' '); foreach (string obligHeadId in obligHeadIds) { Feature feature = m_curMorpher.HeadFeatureSystem.GetFeature(obligHeadId); if (feature == null) throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownFeat, obligHeadId), obligHeadId); obligHeadFeats.Add(feature); } } mrule.ObligatoryHeadFeatures = obligHeadFeats; mrule.IsBlockable = mruleNode.GetAttribute("blockable") == "true"; XmlNodeList subruleList = mruleNode.SelectNodes("MorphologicalSubrules/MorphologicalSubruleStructure[@isActive='yes']"); foreach (XmlNode subruleNode in subruleList) { try { LoadMSubrule(subruleNode as XmlElement, mrule); } catch (LoadException le) { if (m_quitOnError) throw le; } } if (mrule.SubruleCount > 0) m_curMorpher.AddMorphologicalRule(mrule); }
public abstract void PhonologicalRuleNotApplicablePOS(WordSynthesis input, HCObjectSet<PartOfSpeech> requiredPOSs);
public ClosedValueInstance(IEnumerable<FeatureValue> values) { m_values = new HCObjectSet<FeatureValue>(values); }
MorphCoOccurrence LoadAlloCoOccur(XmlElement coOccurNode) { MorphCoOccurrence.AdjacencyType adjacency = GetAdjacencyType(coOccurNode.GetAttribute("adjacency")); string[] allomorphIds = coOccurNode.GetAttribute("allomorphs").Split(' '); HCObjectSet<HCObject> allomorphs = new HCObjectSet<HCObject>(); foreach (string allomorphId in allomorphIds) { Allomorph allomorph = m_curMorpher.GetAllomorph(allomorphId); if (allomorph == null) throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownAllo, allomorphId), allomorphId); allomorphs.Add(allomorph); } return new MorphCoOccurrence(allomorphs, MorphCoOccurrence.ObjectType.ALLOMORPH, adjacency); }
public override void PhonologicalRuleNotApplicablePOS(WordSynthesis input, HCObjectSet<PartOfSpeech> requiredPOSs) { if (m_currentSynthesisPruleTrace != null) m_currentSynthesisPruleTrace.AddChild(new PhonologicalRuleSynthesisRequiredPOSTrace(input.POS, requiredPOSs)); }
/// <summary> /// Initializes a new instance of the <see cref="BlockingTrace"/> class. /// </summary> /// <param name="pos">The part of speech of the stem.</param> /// <param name="requiredPOSs">The set of parts of speech this rule requires.</param> internal PhonologicalRuleSynthesisRequiredPOSTrace(PartOfSpeech pos, HCObjectSet<PartOfSpeech> requiredPOSs) { PartOfSpeech = pos; RequiredPOSs = requiredPOSs; }
/// <summary> /// Initializes a new instance of the <see cref="AffixTemplate"/> class. /// </summary> /// <param name="id">The ID.</param> /// <param name="desc">The description.</param> /// <param name="morpher">The morpher.</param> public AffixTemplate(string id, string desc, Morpher morpher) : base(id, desc, morpher) { m_slots = new HCObjectSet<Slot>(); }
public Loader() { m_morphers = new HCObjectSet<Morpher>(); }
/// <summary> /// Initializes a new instance of the <see cref="Slot"/> class. /// </summary> /// <param name="id">The ID.</param> /// <param name="desc">The description.</param> /// <param name="morpher">The morpher.</param> public Slot(string id, string desc, Morpher morpher) : base(id, desc, morpher) { m_rules = new HCObjectSet<MorphologicalRule>(); }
public Lexicon() { m_entries = new HCObjectSet<LexEntry>(); m_families = new HCObjectSet<LexFamily>(); }
public LexFamily(string id, string desc, Morpher morpher) : base(id, desc, morpher) { m_entries = new HCObjectSet<LexEntry>(); }
/// <summary> /// Initializes a new instance of the <see cref="Feature"/> class. /// </summary> /// <param name="id">The id.</param> /// <param name="desc">The description.</param> /// <param name="morpher">The morpher.</param> public Feature(string id, string desc, Morpher morpher) : base(id, desc, morpher) { m_possibleValues = new HCObjectSet<FeatureValue>(); m_subFeatures = new HCObjectSet<Feature>(); }
public ClosedValueInstance(FeatureValue value) { m_values = new HCObjectSet<FeatureValue>(); m_values.Add(value); }
public override void PhonologicalRuleNotApplicablePOS(WordSynthesis input, HCObjectSet<PartOfSpeech> requiredPOSs) { if (m_currentSynthesisPruleTrace != null) { m_currentSynthesisPruleTrace.Add(new XElement("PhonologicalRuleSynthesisRequiredPOSTrace", Write("PhonologicalRuleStemPOS", input.POS), new XElement("PhonologicalRuleRequiredPOSes", requiredPOSs.Select(pos => Write("PhonologicalRuleRequiredPOS", pos))))); } }
IEnumerable<PartOfSpeech> LoadPOSs(string posIdsStr) { HCObjectSet<PartOfSpeech> result = new HCObjectSet<PartOfSpeech>(); if (!string.IsNullOrEmpty(posIdsStr)) { string[] posIds = posIdsStr.Split(' '); foreach (string posId in posIds) { PartOfSpeech pos = m_curMorpher.GetPOS(posId); if (pos == null) throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownPOS, posId), posId); result.Add(pos); } } return result; }
void LoadLanguage(XmlElement langElem) { string id = langElem.GetAttribute("id"); m_curMorpher = new Morpher(id, langElem.SelectSingleNode("Name").InnerText); m_morphers.Add(m_curMorpher); XmlNodeList posList = langElem.SelectNodes("PartsOfSpeech/PartOfSpeech"); foreach (XmlNode posNode in posList) { XmlElement posElem = posNode as XmlElement; string posId = posElem.GetAttribute("id"); m_curMorpher.AddPOS(new PartOfSpeech(posId, posElem.InnerText, m_curMorpher)); } XmlNodeList mprFeatList = langElem.SelectNodes("MorphologicalPhonologicalRuleFeatures/MorphologicalPhonologicalRuleFeature[@isActive='yes']"); foreach (XmlNode mprFeatNode in mprFeatList) { XmlElement mprFeatElem = mprFeatNode as XmlElement; string mprFeatId = mprFeatElem.GetAttribute("id"); m_curMorpher.AddMPRFeature(new MPRFeature(mprFeatId, mprFeatElem.InnerText, m_curMorpher)); } XmlNodeList mprFeatGroupList = langElem.SelectNodes("MorphologicalPhonologicalRuleFeatures/MorphologicalPhonologicalRuleFeatureGroup[@isActive='yes']"); foreach (XmlNode mprFeatGroupNode in mprFeatGroupList) LoadMPRFeatGroup(mprFeatGroupNode as XmlElement); XmlNode phonFeatSysNode = langElem.SelectSingleNode("PhonologicalFeatureSystem[@isActive='yes']"); if (phonFeatSysNode != null) LoadFeatureSystem(phonFeatSysNode as XmlElement, m_curMorpher.PhoneticFeatureSystem); XmlNode headFeatsNode = langElem.SelectSingleNode("HeadFeatures"); if (headFeatsNode != null) LoadFeatureSystem(headFeatsNode as XmlElement, m_curMorpher.HeadFeatureSystem); XmlNode footFeatsNode = langElem.SelectSingleNode("FootFeatures"); if (footFeatsNode != null) LoadFeatureSystem(footFeatsNode as XmlElement, m_curMorpher.FootFeatureSystem); XmlNodeList charDefTableList = langElem.SelectNodes("CharacterDefinitionTable[@isActive='yes']"); foreach (XmlNode charDefTableNode in charDefTableList) LoadCharDefTable(charDefTableNode as XmlElement); XmlNodeList featNatClassList = langElem.SelectNodes("NaturalClasses/FeatureNaturalClass[@isActive='yes']"); foreach (XmlNode natClassNode in featNatClassList) LoadFeatNatClass(natClassNode as XmlElement); XmlNodeList segNatClassList = langElem.SelectNodes("NaturalClasses/SegmentNaturalClass[@isActive='yes']"); foreach (XmlNode natClassNode in segNatClassList) LoadSegNatClass(natClassNode as XmlElement); XmlNodeList mrulesNodeList = langElem.SelectNodes("MorphologicalRules/*[@isActive='yes']"); if (mrulesNodeList != null) { foreach (XmlNode mruleNode in mrulesNodeList) { XmlElement mruleElem = mruleNode as XmlElement; try { switch (mruleElem.Name) { case "MorphologicalRule": LoadMRule(mruleNode as XmlElement); break; case "RealizationalRule": LoadRealRule(mruleNode as XmlElement); break; case "CompoundingRule": LoadCompoundRule(mruleNode as XmlElement); break; } } catch (LoadException le) { if (m_quitOnError) throw le; } } } HCObjectSet<MorphologicalRule> templateRules = new HCObjectSet<MorphologicalRule>(); XmlNodeList tempList = langElem.SelectNodes("Strata/AffixTemplate[@isActive='yes']"); foreach (XmlNode tempNode in tempList) LoadAffixTemplate(tempNode as XmlElement, templateRules); XmlNodeList stratumList = langElem.SelectNodes("Strata/Stratum[@isActive='yes']"); XmlElement surfaceElem = null; foreach (XmlNode stratumNode in stratumList) { XmlElement stratumElem = stratumNode as XmlElement; if (stratumElem.GetAttribute("id") == Stratum.SURFACE_STRATUM_ID) surfaceElem = stratumElem; else LoadStratum(stratumElem); } if (surfaceElem == null) throw CreateUndefinedObjectException(HCStrings.kstidNoSurfaceStratum, Stratum.SURFACE_STRATUM_ID); LoadStratum(surfaceElem); if (mrulesNodeList != null) { foreach (XmlNode mruleNode in mrulesNodeList) { XmlElement mruleElem = mruleNode as XmlElement; string ruleId = mruleElem.GetAttribute("id"); if (!templateRules.Contains(ruleId)) { MorphologicalRule mrule = m_curMorpher.GetMorphologicalRule(ruleId); if (mrule != null) { Stratum stratum = m_curMorpher.GetStratum(mruleElem.GetAttribute("stratum")); stratum.AddMorphologicalRule(mrule); } } } } XmlNodeList familyList = langElem.SelectNodes("Lexicon/Families/Family[@isActive='yes']"); foreach (XmlNode familyNode in familyList) { XmlElement familyElem = familyNode as XmlElement; LexFamily family = new LexFamily(familyElem.GetAttribute("id"), familyElem.InnerText, m_curMorpher); m_curMorpher.Lexicon.AddFamily(family); } XmlNodeList entryList = langElem.SelectNodes("Lexicon/LexicalEntry[@isActive='yes']"); foreach (XmlNode entryNode in entryList) { try { LoadLexEntry(entryNode as XmlElement); } catch (LoadException le) { if (m_quitOnError) throw le; } } // co-occurrence rules cannot be loaded until all of the morphemes and their allomorphs have been loaded XmlNodeList morphemeList = langElem.SelectNodes("Lexicon/LexicalEntry[@isActive='yes'] | MorphologicalRules/*[@isActive='yes']"); foreach (XmlNode morphemeNode in morphemeList) { XmlElement morphemeElem = morphemeNode as XmlElement; string morphemeId = morphemeElem.GetAttribute("id"); Morpheme morpheme = m_curMorpher.GetMorpheme(morphemeId); if (morpheme != null) { try { morpheme.RequiredMorphemeCoOccurrences = LoadMorphCoOccurs(morphemeElem.SelectSingleNode("RequiredMorphemeCoOccurrences")); } catch (LoadException le) { if (m_quitOnError) throw le; } try { morpheme.ExcludedMorphemeCoOccurrences = LoadMorphCoOccurs(morphemeElem.SelectSingleNode("ExcludedMorphemeCoOccurrences")); } catch (LoadException le) { if (m_quitOnError) throw le; } } XmlNodeList allomorphList = morphemeNode.SelectNodes("Allomorphs/Allomorph[@isActive='yes'] | MorphologicalSubrules/MorphologicalSubruleStructure[@isActive='yes']"); foreach (XmlNode alloNode in allomorphList) { XmlElement alloElem = alloNode as XmlElement; string alloId = alloElem.GetAttribute("id"); Allomorph allomorph = m_curMorpher.GetAllomorph(alloId); if (allomorph != null) { try { allomorph.RequiredAllomorphCoOccurrences = LoadAlloCoOccurs(alloElem.SelectSingleNode("RequiredAllomorphCoOccurrences")); } catch (LoadException le) { if (m_quitOnError) throw le; } try { allomorph.ExcludedAllomorphCoOccurrences = LoadAlloCoOccurs(alloElem.SelectSingleNode("ExcludedAllomorphCoOccurrences")); } catch (LoadException le) { if (m_quitOnError) throw le; } } } } XmlNodeList prules = langElem.SelectNodes("PhonologicalRules/*[@isActive='yes']"); foreach (XmlNode pruleNode in prules) { XmlElement pruleElem = pruleNode as XmlElement; try { switch (pruleElem.Name) { case "MetathesisRule": LoadMetathesisRule(pruleElem); break; case "PhonologicalRule": LoadPRule(pruleElem); break; } } catch (LoadException le) { if (m_quitOnError) throw le; } } }
MorphCoOccurrence LoadMorphCoOccur(XmlElement coOccurNode) { MorphCoOccurrence.AdjacencyType adjacency = GetAdjacencyType(coOccurNode.GetAttribute("adjacency")); string[] morphemeIds = coOccurNode.GetAttribute("morphemes").Split(' '); HCObjectSet<HCObject> morphemes = new HCObjectSet<HCObject>(); foreach (string morphemeId in morphemeIds) { Morpheme morpheme = m_curMorpher.GetMorpheme(morphemeId); if (morpheme == null) throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownMorpheme, morphemeId), morphemeId); morphemes.Add(morpheme); } return new MorphCoOccurrence(morphemes, MorphCoOccurrence.ObjectType.MORPHEME, adjacency); }
public override void Reset() { base.Reset(); m_headRequiredPOSs = null; m_nonHeadRequiredPOSs = null; m_outPOS = null; m_maxNumApps = 1; m_headRequiredHeadFeatures = null; m_headRequiredFootFeatures = null; m_nonHeadRequiredHeadFeatures = null; m_nonHeadRequiredFootFeatures = null; m_outHeadFeatures = null; m_outFootFeatures = null; m_obligHeadFeatures = null; m_subrules.Clear(); }
/// <summary> /// Initializes a new instance of the <see cref="FeatureSystem"/> class. /// </summary> public FeatureSystem() { m_features = new HCObjectSet<Feature>(); m_values = new HCObjectSet<FeatureValue>(); }