コード例 #1
0
ファイル: CompoundingRule.cs プロジェクト: sillsdev/WorldPad
            /// <summary>
            /// Initializes a new instance of the <see cref="Subrule"/> class.
            /// </summary>
            /// <param name="id">The id.</param>
            /// <param name="desc">The description.</param>
            /// <param name="morpher">The morpher.</param>
            /// <param name="headLhs">The head LHS.</param>
            /// <param name="nonHeadLhs">The non-head LHS.</param>
            /// <param name="rhs">The RHS.</param>
            /// <param name="alphaVars">The alpha variables.</param>
            public Subrule(string id, string desc, Morpher morpher, IEnumerable <PhoneticPattern> headLhs,
                           IEnumerable <PhoneticPattern> nonHeadLhs, IEnumerable <MorphologicalOutput> rhs, AlphaVariables alphaVars)
                : base(id, desc, morpher)
            {
                m_alphaVars = alphaVars;

                List <PhoneticPattern> lhs = new List <PhoneticPattern>();

                lhs.AddRange(headLhs);
                lhs.AddRange(nonHeadLhs);

                m_transform = new MorphologicalTransform(lhs, rhs, MorphologicalTransform.RedupMorphType.IMPLICIT);

                // the LHS template is generated by simply concatenating all of the
                // LHS partitions; it matches the entire word, so we check for both the
                // left and right margins.
                m_headLhsTemp = new PhoneticPattern();
                m_headLhsTemp.Add(new MarginContext(Direction.LEFT));
                int partition = 0;

                foreach (PhoneticPattern pat in headLhs)
                {
                    m_headLhsTemp.AddPartition(pat, partition++);
                }
                m_headLhsTemp.Add(new MarginContext(Direction.RIGHT));

                m_firstNonHeadPartition = partition;
                m_nonHeadLhsTemp        = new PhoneticPattern();
                m_nonHeadLhsTemp.Add(new MarginContext(Direction.LEFT));
                foreach (PhoneticPattern pat in nonHeadLhs)
                {
                    m_nonHeadLhsTemp.AddPartition(pat, partition++);
                }
                m_nonHeadLhsTemp.Add(new MarginContext(Direction.RIGHT));
            }
コード例 #2
0
 public void Reset()
 {
     m_multApplication = MultAppOrder.LR_ITERATIVE;
     m_alphaVars       = null;
     m_lhs             = null;
     m_subrules.Clear();
 }
コード例 #3
0
ファイル: CompoundingRule.cs プロジェクト: sillsdev/WorldPad
			/// <summary>
			/// Initializes a new instance of the <see cref="Subrule"/> class.
			/// </summary>
			/// <param name="id">The id.</param>
			/// <param name="desc">The description.</param>
			/// <param name="morpher">The morpher.</param>
			/// <param name="headLhs">The head LHS.</param>
			/// <param name="nonHeadLhs">The non-head LHS.</param>
			/// <param name="rhs">The RHS.</param>
			/// <param name="alphaVars">The alpha variables.</param>
			public Subrule(string id, string desc, Morpher morpher, IEnumerable<PhoneticPattern> headLhs,
				IEnumerable<PhoneticPattern> nonHeadLhs, IEnumerable<MorphologicalOutput> rhs, AlphaVariables alphaVars)
				: base (id, desc, morpher)
			{
				m_alphaVars = alphaVars;

				List<PhoneticPattern> lhs = new List<PhoneticPattern>();
				lhs.AddRange(headLhs);
				lhs.AddRange(nonHeadLhs);

				m_transform = new MorphologicalTransform(lhs, rhs, MorphologicalTransform.RedupMorphType.IMPLICIT);

				// the LHS template is generated by simply concatenating all of the
				// LHS partitions; it matches the entire word, so we check for both the
				// left and right margins.
				m_headLhsTemp = new PhoneticPattern();
				m_headLhsTemp.Add(new MarginContext(Direction.LEFT));
				int partition = 0;
				foreach (PhoneticPattern pat in headLhs)
					m_headLhsTemp.AddPartition(pat, partition++);
				m_headLhsTemp.Add(new MarginContext(Direction.RIGHT));

				m_firstNonHeadPartition = partition;
				m_nonHeadLhsTemp = new PhoneticPattern();
				m_nonHeadLhsTemp.Add(new MarginContext(Direction.LEFT));
				foreach (PhoneticPattern pat in nonHeadLhs)
					m_nonHeadLhsTemp.AddPartition(pat, partition++);
				m_nonHeadLhsTemp.Add(new MarginContext(Direction.RIGHT));
			}
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VariableValues"/> class.
 /// </summary>
 /// <param name="alphaVars">The alpha variables.</param>
 public VariableValues(AlphaVariables alphaVars)
 {
     m_values = new Dictionary <string, List <FeatureValue> >();
     foreach (string variableName in alphaVars.Variables)
     {
         m_values[variableName] = new List <FeatureValue>();
     }
 }
コード例 #5
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="ctxt">The simple context.</param>
 public NaturalClassContext(NaturalClassContext ctxt)
     : base(ctxt)
 {
     m_natClass = ctxt.m_natClass;
     if (ctxt.m_variables != null)
     {
         m_variables     = new Dictionary <string, bool>(ctxt.m_variables);
         m_antiVariables = new Dictionary <string, bool>(ctxt.m_antiVariables);
         m_alphaVars     = ctxt.m_alphaVars;
     }
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleContext"/> class from a natural class.
 /// </summary>
 /// <param name="natClass">The natural class.</param>
 /// <param name="variables">The variables.</param>
 /// <param name="alphaVars">The alpha variables.</param>
 public NaturalClassContext(NaturalClass natClass, IDictionary <string, bool> variables, AlphaVariables alphaVars)
     : base(natClass.Features.Clone(), natClass.AntiFeatures.Clone())
 {
     m_natClass      = natClass;
     m_variables     = variables;
     m_alphaVars     = alphaVars;
     m_antiVariables = new Dictionary <string, bool>(variables.Count);
     foreach (KeyValuePair <string, bool> kvp in variables)
     {
         m_antiVariables[kvp.Key] = !kvp.Value;
     }
 }
コード例 #7
0
			/// <summary>
			/// Initializes a new instance of the <see cref="Subrule"/> class.
			/// </summary>
			/// <param name="id">The id.</param>
			/// <param name="desc">The description.</param>
			/// <param name="morpher">The morpher.</param>
			/// <param name="lhs">The LHS.</param>
			/// <param name="rhs">The RHS.</param>
			/// <param name="alphaVars">The alpha variables.</param>
			/// <param name="redupMorphType">The full reduplication type.</param>
			public Subrule(string id, string desc, Morpher morpher, IEnumerable<PhoneticPattern> lhs,
				IEnumerable<MorphologicalOutput> rhs, AlphaVariables alphaVars, MorphologicalTransform.RedupMorphType redupMorphType)
				: base (id, desc, morpher)
			{
				m_alphaVars = alphaVars;

				m_transform = new MorphologicalTransform(lhs, rhs, redupMorphType);

				// the LHS template is generated by simply concatenating all of the
				// LHS partitions; it matches the entire word, so we check for both the
				// left and right margins.
				m_lhsTemp = new PhoneticPattern();
				m_lhsTemp.Add(new MarginContext(Direction.LEFT));
				int partition = 0;
				foreach (PhoneticPattern pat in lhs)
				{
					m_lhsTemp.AddPartition(pat, partition, m_transform.IsGreedy(partition));
					partition++;
				}
				m_lhsTemp.Add(new MarginContext(Direction.RIGHT));
			}
コード例 #8
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Subrule"/> class.
            /// </summary>
            /// <param name="id">The id.</param>
            /// <param name="desc">The description.</param>
            /// <param name="morpher">The morpher.</param>
            /// <param name="lhs">The LHS.</param>
            /// <param name="rhs">The RHS.</param>
            /// <param name="alphaVars">The alpha variables.</param>
            /// <param name="redupMorphType">The full reduplication type.</param>
            public Subrule(string id, string desc, Morpher morpher, IEnumerable <PhoneticPattern> lhs,
                           IEnumerable <MorphologicalOutput> rhs, AlphaVariables alphaVars, MorphologicalTransform.RedupMorphType redupMorphType)
                : base(id, desc, morpher)
            {
                m_alphaVars = alphaVars;

                m_transform = new MorphologicalTransform(lhs, rhs, redupMorphType);

                // the LHS template is generated by simply concatenating all of the
                // LHS partitions; it matches the entire word, so we check for both the
                // left and right margins.
                m_lhsTemp = new PhoneticPattern();
                m_lhsTemp.Add(new MarginContext(Direction.LEFT));
                int partition = 0;

                foreach (PhoneticPattern pat in lhs)
                {
                    m_lhsTemp.AddPartition(pat, partition, m_transform.IsGreedy(partition));
                    partition++;
                }
                m_lhsTemp.Add(new MarginContext(Direction.RIGHT));
            }
コード例 #9
0
ファイル: XmlLoader.cs プロジェクト: sillsdev/WorldPad
		Environment LoadEnv(XmlNode envNode, AlphaVariables varFeats, Dictionary<string, string> varFeatIds)
		{
			if (envNode == null)
				return new Environment();

			PhoneticPattern leftEnv = LoadPTemp(envNode.SelectSingleNode("LeftEnvironment/PhoneticTemplate") as XmlElement,
				varFeats, varFeatIds, null);
			PhoneticPattern rightEnv = LoadPTemp(envNode.SelectSingleNode("RightEnvironment/PhoneticTemplate") as XmlElement,
				varFeats, varFeatIds, null);
			return new Environment(leftEnv, rightEnv);
		}
コード例 #10
0
ファイル: XmlLoader.cs プロジェクト: sillsdev/WorldPad
		List<PhoneticPattern> LoadReqPhoneticInput(XmlNode reqPhonInputNode, int partition, AlphaVariables varFeats, Dictionary<string, string> varFeatIds,
			Dictionary<string, int> partIds)
		{
			List<PhoneticPattern> lhsList = new List<PhoneticPattern>();
			XmlNodeList pseqList = reqPhonInputNode.SelectNodes("PhoneticSequence");
			foreach (XmlNode pseqNode in pseqList)
			{
				XmlElement pseqElem = pseqNode as XmlElement;
				PhoneticPattern pattern = new PhoneticPattern();
				LoadPSeq(pattern, pseqElem, varFeats, varFeatIds, null);
				lhsList.Add(pattern);
				partIds[pseqElem.GetAttribute("id")] = partition++;
			}
			return lhsList;
		}
コード例 #11
0
		public void Reset()
		{
			m_multApplication = MultAppOrder.LR_ITERATIVE;
			m_alphaVars = null;
			m_lhs = null;
			m_subrules.Clear();
		}
コード例 #12
0
ファイル: XmlLoader.cs プロジェクト: sillsdev/WorldPad
		List<MorphologicalOutput> LoadPhoneticOutput(XmlNode phonOutputNode, AlphaVariables varFeats, Dictionary<string, string> varFeatIds,
			Dictionary<string, int> partIds, string ruleId)
		{
			List<MorphologicalOutput> rhsList = new List<MorphologicalOutput>();
			foreach (XmlNode partNode in phonOutputNode.ChildNodes)
			{
				if (partNode.NodeType != XmlNodeType.Element)
					continue;
				XmlElement partElem = partNode as XmlElement;
				switch (partElem.Name)
				{
					case "CopyFromInput":
						rhsList.Add(new CopyFromInput(partIds[partElem.GetAttribute("index")]));
						break;

					case "InsertSimpleContext":
						SimpleContext insCtxt = LoadNatClassCtxt(partElem.SelectSingleNode("SimpleContext") as XmlElement,
							varFeats, varFeatIds);
						rhsList.Add(new InsertSimpleContext(insCtxt));
						break;

					case "ModifyFromInput":
						SimpleContext modCtxt = LoadNatClassCtxt(partElem.SelectSingleNode("SimpleContext") as XmlElement,
							varFeats, varFeatIds);
						rhsList.Add(new ModifyFromInput(partIds[partElem.GetAttribute("index")], modCtxt, m_curMorpher));
						break;

					case "InsertSegments":
						CharacterDefinitionTable charDefTable = GetCharDefTable(partElem.GetAttribute("characterTable"));
						string shapeStr = partElem.SelectSingleNode("PhoneticShape").InnerText;
						PhoneticShape pshape = charDefTable.ToPhoneticShape(shapeStr, ModeType.SYNTHESIS);
						if (pshape == null)
						{
							LoadException le = new LoadException(LoadException.LoadErrorType.INVALID_RULE_SHAPE, this,
								string.Format(HCStrings.kstidInvalidRuleShape, shapeStr, ruleId, charDefTable.ID));
							le.Data["shape"] = shapeStr;
							le.Data["charDefTable"] = charDefTable.ID;
							le.Data["rule"] = ruleId;
							throw le;
						}
						rhsList.Add(new InsertSegments(pshape));
						break;
				}
			}
			return rhsList;
		}
コード例 #13
0
ファイル: AlphaVariables.cs プロジェクト: bbriggs/FieldWorks
		/// <summary>
		/// Initializes a new instance of the <see cref="VariableValues"/> class.
		/// </summary>
		/// <param name="alphaVars">The alpha variables.</param>
		public VariableValues(AlphaVariables alphaVars)
		{
			m_values = new Dictionary<string, List<FeatureValue>>();
			foreach (string variableName in alphaVars.Variables)
				m_values[variableName] = new List<FeatureValue>();
		}
コード例 #14
0
ファイル: NaturalClass.cs プロジェクト: bbriggs/FieldWorks
		/// <summary>
		/// Initializes a new instance of the <see cref="SimpleContext"/> class from a natural class.
		/// </summary>
		/// <param name="natClass">The natural class.</param>
		/// <param name="variables">The variables.</param>
		/// <param name="alphaVars">The alpha variables.</param>
		public NaturalClassContext(NaturalClass natClass, IDictionary<string, bool> variables, AlphaVariables alphaVars)
			: base(natClass.Features.Clone(), natClass.AntiFeatures.Clone())
		{
			m_natClass = natClass;
			m_variables = variables;
			m_alphaVars = alphaVars;
			m_antiVariables = new Dictionary<string, bool>(variables.Count);
			foreach (KeyValuePair<string, bool> kvp in variables)
				m_antiVariables[kvp.Key] = !kvp.Value;
		}
コード例 #15
0
ファイル: NaturalClass.cs プロジェクト: bbriggs/FieldWorks
		/// <summary>
		/// Copy constructor.
		/// </summary>
		/// <param name="ctxt">The simple context.</param>
		public NaturalClassContext(NaturalClassContext ctxt)
			: base(ctxt)
		{
			m_natClass = ctxt.m_natClass;
			if (ctxt.m_variables != null)
			{
				m_variables = new Dictionary<string, bool>(ctxt.m_variables);
				m_antiVariables = new Dictionary<string, bool>(ctxt.m_antiVariables);
				m_alphaVars = ctxt.m_alphaVars;
			}
		}
コード例 #16
0
ファイル: XmlLoader.cs プロジェクト: sillsdev/WorldPad
		void LoadPSeq(PhoneticPattern pattern, XmlElement pseqNode, AlphaVariables alphaVars, Dictionary<string, string> varFeatIds,
			Dictionary<string, int> partIds)
		{
			if (pseqNode == null)
				return;

			foreach (XmlNode recNode in pseqNode.ChildNodes)
			{
				if (recNode.NodeType != XmlNodeType.Element)
					continue;

				XmlElement recElem = recNode as XmlElement;
				IEnumerable<PhoneticPatternNode> nodes = null;
				switch (recElem.Name)
				{
					case "SimpleContext":
						nodes = LoadNatClassCtxtPSeq(recElem, alphaVars, varFeatIds);
						break;

					case "BoundaryMarker":
						nodes = LoadBdryCtxt(recElem);
						break;

					case "Segment":
						nodes = LoadSegCtxt(recElem);
						break;

					case "OptionalSegmentSequence":
						nodes = LoadOptSeq(recElem, alphaVars, varFeatIds, pattern.IsTarget);
						break;

					case "Segments":
						nodes = LoadSegCtxts(recElem);
						break;
				}

				int partition = -1;
				string id = recElem.GetAttribute("id");
				if (partIds != null && !string.IsNullOrEmpty(id))
					partition = partIds[id];
				pattern.AddPartition(nodes, partition);
			}
		}
コード例 #17
0
ファイル: XmlLoader.cs プロジェクト: sillsdev/WorldPad
		IEnumerable<PhoneticPatternNode> LoadNatClassCtxtPSeq(XmlElement ctxtNode, AlphaVariables alphaVars,
			Dictionary<string, string> varFeatIds)
		{
			yield return LoadNatClassCtxt(ctxtNode, alphaVars, varFeatIds);
		}
コード例 #18
0
ファイル: XmlLoader.cs プロジェクト: sillsdev/WorldPad
		NaturalClassContext LoadNatClassCtxt(XmlElement ctxtNode, AlphaVariables alphaVars,
			Dictionary<string, string> varFeatIds)
		{
			string classId = ctxtNode.GetAttribute("naturalClass");
			NaturalClass natClass = m_curMorpher.GetNaturalClass(classId);
			if (natClass == null)
				throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownNatClass, classId), classId);

			Dictionary<string, bool> vars = new Dictionary<string, bool>();
			XmlNodeList varsList = ctxtNode.SelectNodes("AlphaVariables/AlphaVariable");
			foreach (XmlNode varNode in varsList)
			{
				XmlElement varElem = varNode as XmlElement;

				string varStr = varFeatIds[varElem.GetAttribute("variableFeature")];
				vars[varStr] = varElem.GetAttribute("polarity") == "plus";
			}
			return new NaturalClassContext(natClass, vars, alphaVars);
		}
コード例 #19
0
ファイル: XmlLoader.cs プロジェクト: sillsdev/WorldPad
		PhoneticPattern LoadPTemp(XmlElement ptempNode, AlphaVariables varFeats, Dictionary<string, string> varFeatIds,
			Dictionary<string, int> partIds)
		{
			if (ptempNode == null)
				return null;

			bool initial = ptempNode.GetAttribute("initialBoundaryCondition") == "true";
			bool final = ptempNode.GetAttribute("finalBoundaryCondition") == "true";
			PhoneticPattern pattern = new PhoneticPattern();
			if (initial)
				pattern.Add(new MarginContext(Direction.LEFT));
			LoadPSeq(pattern, ptempNode.SelectSingleNode("PhoneticSequence") as XmlElement, varFeats,
				varFeatIds, partIds);
			if (final)
				pattern.Add(new MarginContext(Direction.RIGHT));

			return pattern;
		}
コード例 #20
0
ファイル: XmlLoader.cs プロジェクト: sillsdev/WorldPad
		IEnumerable<PhoneticPatternNode> LoadOptSeq(XmlElement optSeqNode, AlphaVariables varFeats,
			Dictionary<string, string> varFeatIds, bool isTarget)
		{
			string minStr = optSeqNode.GetAttribute("min");
			int min = string.IsNullOrEmpty(minStr) ? 0 : Convert.ToInt32(minStr);
			string maxStr = optSeqNode.GetAttribute("max");
			int max = string.IsNullOrEmpty(maxStr) ? -1 : Convert.ToInt32(maxStr);
			PhoneticPattern pattern = new PhoneticPattern(isTarget);
			LoadPSeq(pattern, optSeqNode, varFeats, varFeatIds, null);
			yield return new NestedPhoneticPattern(pattern, min, max);
		}