Пример #1
0
		void LoadCompoundSubrule(XmlElement compSubruleNode, CompoundingRule compRule)
		{
			string id = compSubruleNode.GetAttribute("id");
			Dictionary<string, string> varFeatIds;
			AlphaVariables varFeats = LoadAlphaVars(compSubruleNode.SelectSingleNode("VariableFeatures"), out varFeatIds);

			XmlElement headElem = compSubruleNode.SelectSingleNode("HeadRecordStructure") as XmlElement;

			Dictionary<string, int> partIds = new Dictionary<string, int>();
			List<PhoneticPattern> headLhsList = LoadReqPhoneticInput(headElem.SelectSingleNode("RequiredPhoneticInput"), 0,
				varFeats, varFeatIds, partIds);

			List<PhoneticPattern> nonHeadLhsList = LoadReqPhoneticInput(compSubruleNode.SelectSingleNode("NonHeadRecordStructure/RequiredPhoneticInput"),
				headLhsList.Count, varFeats, varFeatIds, partIds);

			XmlElement outputElem = compSubruleNode.SelectSingleNode("OutputSideRecordStructure") as XmlElement;

			List<MorphologicalOutput> rhsList = LoadPhoneticOutput(outputElem.SelectSingleNode("MorphologicalPhoneticOutput"), varFeats,
				varFeatIds, partIds, compRule.ID);

			CompoundingRule.Subrule sr = new CompoundingRule.Subrule(id, id, m_curMorpher,
				headLhsList, nonHeadLhsList, rhsList, varFeats);

			sr.RequiredMPRFeatures = LoadMPRFeatures(headElem.GetAttribute("requiredMPRFeatures"));
			sr.ExcludedMPRFeatures = LoadMPRFeatures(headElem.GetAttribute("excludedMPRFeatures"));
			sr.OutputMPRFeatures = LoadMPRFeatures(outputElem.GetAttribute("MPRFeatures"));

			sr.Properties = LoadProperties(compSubruleNode.SelectSingleNode("Properties"));

			compRule.AddSubrule(sr);
		}
Пример #2
0
		void LoadCompoundRule(XmlElement compRuleNode)
		{
			string id = compRuleNode.GetAttribute("id");
			string name = compRuleNode.SelectSingleNode("Name").InnerText;
			CompoundingRule compRule = new CompoundingRule(id, name, m_curMorpher);
			XmlElement glossElem = compRuleNode.SelectSingleNode("Gloss") as XmlElement;
			if (glossElem != null)
				compRule.Gloss = new Gloss(glossElem.GetAttribute("id"), glossElem.InnerText, m_curMorpher);

			string multApp = compRuleNode.GetAttribute("multipleApplication");
			if (!string.IsNullOrEmpty(multApp))
				compRule.MaxNumApps = Convert.ToInt32(multApp);

			compRule.HeadRequiredPOSs = LoadPOSs(compRuleNode.GetAttribute("headPartsOfSpeech"));

			compRule.NonHeadRequiredPOSs = LoadPOSs(compRuleNode.GetAttribute("nonheadPartsOfSpeech"));

			string outPOSId = compRuleNode.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);
			}
			compRule.OutPOS = outPOS;

			compRule.HeadRequiredHeadFeatures = LoadSynFeats(compRuleNode.SelectSingleNode("HeadRequiredHeadFeatures"),
				m_curMorpher.HeadFeatureSystem);
			compRule.HeadRequiredFootFeatures = LoadSynFeats(compRuleNode.SelectSingleNode("HeadRequiredFootFeatures"),
				m_curMorpher.FootFeatureSystem);

			compRule.NonHeadRequiredHeadFeatures = LoadSynFeats(compRuleNode.SelectSingleNode("NonHeadRequiredHeadFeatures"),
				m_curMorpher.HeadFeatureSystem);
			compRule.NonHeadRequiredFootFeatures = LoadSynFeats(compRuleNode.SelectSingleNode("NonHeadRequiredFootFeatures"),
				m_curMorpher.FootFeatureSystem);

			compRule.OutHeadFeatures = LoadSynFeats(compRuleNode.SelectSingleNode("OutputHeadFeatures"),
				m_curMorpher.HeadFeatureSystem);
			compRule.OutFootFeatures = LoadSynFeats(compRuleNode.SelectSingleNode("OutputFootFeatures"),
				m_curMorpher.FootFeatureSystem);

			HCObjectSet<Feature> obligHeadFeats = new HCObjectSet<Feature>();
			string obligHeadIdsStr = compRuleNode.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);
				}
			}
			compRule.ObligatoryHeadFeatures = obligHeadFeats;

			compRule.IsBlockable = compRuleNode.GetAttribute("blockable") == "true";

			XmlNodeList subruleList = compRuleNode.SelectNodes("CompoundSubrules/CompoundSubruleStructure[@isActive='yes']");
			foreach (XmlNode subruleNode in subruleList)
			{
				try
				{
					LoadCompoundSubrule(subruleNode as XmlElement, compRule);
				}
				catch (LoadException le)
				{
					if (m_quitOnError)
						throw le;
				}
			}

			if (compRule.SubruleCount > 0)
				m_curMorpher.AddMorphologicalRule(compRule);
		}