Exemple #1
0
        internal override bool IsWordValid(Morpher morpher, Word word)
        {
            if (!base.IsWordValid(morpher, word))
                return false;

            if (IsBound && word.Allomorphs.Count == 1)
            {
                if (morpher.TraceManager.IsTracing)
                    morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.BoundRoot, this, null);
                return false;
            }

            if (StemName != null && !StemName.IsRequiredMatch(word.SyntacticFeatureStruct))
            {
                if (morpher.TraceManager.IsTracing)
                    morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.RequiredStemName, this, StemName);
                return false;
            }

            foreach (RootAllomorph otherAllo in ((LexEntry) Morpheme).Allomorphs.Where(a => a != this && a.StemName != null))
            {
                if (!otherAllo.StemName.IsExcludedMatch(word.SyntacticFeatureStruct, StemName))
                {
                    if (morpher.TraceManager.IsTracing)
                        morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.ExcludedStemName, this, otherAllo.StemName);
                    return false;
                }
            }

            return true;
        }
Exemple #2
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="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));
			}
		/// <summary>
		/// Initializes a new instance of the <see cref="IPACharacterDefinitionTable"/> class.
		/// </summary>
		/// <param name="id">The ID.</param>
		/// <param name="desc">The description.</param>
		/// <param name="morpher">The morpher.</param>
		public IPACharacterDefinitionTable(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
			m_baseChars = new List<SegmentDefinition>();
			m_modifierChars = new List<SegmentDefinition>();
			m_tieBars = new List<SegmentDefinition>();
			m_stops = new List<SegmentDefinition>();
			m_fricatives = new List<SegmentDefinition>();
		}
Exemple #4
0
        public SynthesisStratumRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, Stratum stratum)
        {
            _templatesRule = new SynthesisAffixTemplatesRule(spanFactory, morpher, stratum);
            _mrulesRule    = null;
            IEnumerable <IRule <Word, ShapeNode> > mrules = stratum.MorphologicalRules.Select(mrule => mrule.CompileSynthesisRule(spanFactory, morpher));

            switch (stratum.MorphologicalRuleOrder)
            {
            case MorphologicalRuleOrder.Linear:
                _mrulesRule = new LinearRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default);
                break;

            case MorphologicalRuleOrder.Unordered:
                _mrulesRule = new CombinationRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default);
                break;
            }
            _prulesRule = new LinearRuleCascade <Word, ShapeNode>(stratum.PhonologicalRules.Select(prule => prule.CompileSynthesisRule(spanFactory, morpher)));
            _stratum    = stratum;
            _morpher    = morpher;
        }
Exemple #5
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_lhsTemp.Add(new MarginContext(Direction.RIGHT));
            }
			/// <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));
			}
Exemple #7
0
        internal override bool IsWordValid(Morpher morpher, Word word)
        {
            if (!base.IsWordValid(morpher, word))
            {
                return(false);
            }

            if (IsBound && word.Allomorphs.Count == 1)
            {
                if (morpher.TraceManager.IsTracing)
                {
                    morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.BoundRoot, this, null);
                }
                return(false);
            }

            if (StemName != null && !StemName.IsRequiredMatch(word.SyntacticFeatureStruct))
            {
                if (morpher.TraceManager.IsTracing)
                {
                    morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.RequiredStemName, this, StemName);
                }
                return(false);
            }

            foreach (RootAllomorph otherAllo in ((LexEntry)Morpheme).Allomorphs.Where(a => a != this && a.StemName != null))
            {
                if (!otherAllo.StemName.IsExcludedMatch(word.SyntacticFeatureStruct, StemName))
                {
                    if (morpher.TraceManager.IsTracing)
                    {
                        morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.ExcludedStemName, this, otherAllo.StemName);
                    }
                    return(false);
                }
            }

            return(true);
        }
Exemple #8
0
		public virtual void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
		{
			m_xmlWriter.WriteStartElement("MorphAndLookupWord");
			m_xmlWriter.WriteElementString("Input", word);
			try
			{
				m_trace.WriteInputs = printTraceInputs;
				ICollection<WordSynthesis> results = morpher.MorphAndLookupWord(word, m_trace);
				m_xmlWriter.WriteStartElement("Output");
				foreach (WordSynthesis ws in results)
					Write(ws, prettyPrint);
				m_xmlWriter.WriteEndElement();

				if (m_trace.IsTracing)
					WriteTrace();
				m_trace.Reset();
			}
			catch (MorphException me)
			{
				Write(me);
			}
			m_xmlWriter.WriteEndElement();
		}
Exemple #9
0
        internal virtual bool IsWordValid(Morpher morpher, Word word)
        {
            AllomorphEnvironment env = Environments.FirstOrDefault(e => !e.IsWordValid(word));

            if (env != null)
            {
                if (morpher.TraceManager.IsTracing)
                {
                    morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.Environments, this, env);
                }
                return(false);
            }

            AllomorphCoOccurrenceRule alloRule = AllomorphCoOccurrenceRules.FirstOrDefault(r => !r.IsWordValid(word));

            if (alloRule != null)
            {
                if (morpher.TraceManager.IsTracing)
                {
                    morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.AllomorphCoOccurrenceRules, this, alloRule);
                }
                return(false);
            }

            MorphemeCoOccurrenceRule morphemeRule = Morpheme.MorphemeCoOccurrenceRules.FirstOrDefault(r => !r.IsWordValid(word));

            if (morphemeRule != null)
            {
                if (morpher.TraceManager.IsTracing)
                {
                    morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.MorphemeCoOccurrenceRules, this, morphemeRule);
                }
                return(false);
            }

            return(true);
        }
        public AnalysisStratumRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, Stratum stratum)
        {
            _stratum       = stratum;
            _morpher       = morpher;
            _prulesRule    = new LinearRuleCascade <Word, ShapeNode>(stratum.PhonologicalRules.Select(prule => prule.CompileAnalysisRule(spanFactory, morpher)).Reverse());
            _templatesRule = new RuleBatch <Word, ShapeNode>(stratum.AffixTemplates.Select(template => template.CompileAnalysisRule(spanFactory, morpher)), false, FreezableEqualityComparer <Word> .Default);
            _mrulesRule    = null;
            IEnumerable <IRule <Word, ShapeNode> > mrules = stratum.MorphologicalRules.Select(mrule => mrule.CompileAnalysisRule(spanFactory, morpher)).Reverse();

            switch (stratum.MorphologicalRuleOrder)
            {
            case MorphologicalRuleOrder.Linear:
                _mrulesRule = new LinearRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default);
                break;

            case MorphologicalRuleOrder.Unordered:
#if SINGLE_THREADED
                _mrulesRule = new CombinationRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default);
#else
                _mrulesRule = new ParallelCombinationRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default);
#endif
                break;
            }
        }
Exemple #11
0
		public virtual void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
		{
			m_out.WriteLine("Morph and Lookup: " + word);
			ICollection<WordSynthesis> results = morpher.MorphAndLookupWord(word, m_trace);
			m_out.WriteLine("*Results*");
			if (results.Count == 0)
			{
				m_out.WriteLine("None found");
				m_out.WriteLine();
			}
			else
			{
				foreach (WordSynthesis ws in results)
					Write(ws, prettyPrint);
			}

			if (prettyPrint && m_trace.IsTracing)
			{
				m_out.WriteLine("*Trace*");
				WriteTrace(printTraceInputs);
				m_out.WriteLine();
			}
			m_trace.Reset();
		}
Exemple #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Morpheme"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="desc">The description.</param>
 /// <param name="morpher">The morpher.</param>
 public Morpheme(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
 }
Exemple #13
0
 public Gloss(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
 }
Exemple #14
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MetathesisRule"/> class.
		/// </summary>
		/// <param name="featId">The ID.</param>
		/// <param name="desc">The description.</param>
		/// <param name="morpher">The morpher.</param>
		public MetathesisRule(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
		}
Exemple #15
0
 public PhonologicalRule(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
 }
		protected MorphologicalRule(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
		}
Exemple #17
0
		private void LoadParser()
		{
			m_morpher = null;

			int delReapps = 0;
			string loadErrorsFile = Path.Combine(m_outputDirectory, m_cache.ProjectId.Name + "HCLoadErrors.xml");
			using (XmlWriter writer = XmlWriter.Create(loadErrorsFile))
			using (new WorkerThreadReadHelper(m_cache.ServiceLocator.GetInstance<IWorkerThreadReadHandler>()))
			{
				m_language = HCLoader.Load(m_spanFactory, m_cache, writer);
				XElement parserParamsElem = XElement.Parse(m_cache.LanguageProject.MorphologicalDataOA.ParserParameters);
				XElement delReappsElem = parserParamsElem.Elements("ParserParameters").Elements("HC").Elements("DelReapps").FirstOrDefault();
				if (delReappsElem != null)
					delReapps = (int) delReappsElem;
			}
			m_morpher = new Morpher(m_spanFactory, m_traceManager, m_language) { DeletionReapplications = delReapps };
		}
Exemple #18
0
 public override IRule <Word, ShapeNode> CompileAnalysisRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher)
 {
     return(new AnalysisLanguageRule(spanFactory, morpher, this));
 }
Exemple #19
0
		/// <summary>
		/// Initializes a new instance of the <see cref="NaturalClass"/> class.
		/// </summary>
		/// <param name="featId">The ID.</param>
		/// <param name="desc">The description.</param>
		/// <param name="morpher">The morpher.</param>
		public NaturalClass(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
			m_segDefs = new Set<SegmentDefinition>();
		}
Exemple #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LexEntry"/> class.
 /// </summary>
 /// <param name="id">The ID.</param>
 /// <param name="desc">The description.</param>
 /// <param name="morpher">The morpher.</param>
 public LexEntry(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_allomorphs = new List <RootAllomorph>();
 }
Exemple #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RootAllomorph"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="desc">The description.</param>
 /// <param name="morpher">The morpher.</param>
 /// <param name="shape">The shape.</param>
 public RootAllomorph(string id, string desc, Morpher morpher, PhoneticShape shape)
     : base(id, desc, morpher)
 {
     m_shape = shape;
 }
Exemple #22
0
 public LexFamily(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_entries = new HCObjectSet <LexEntry>();
 }
Exemple #23
0
 public PartOfSpeech(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
 }
Exemple #24
0
			public override void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
			{
				try
				{
					ICollection<WordGrammarTrace> wordGrammarTraces = null;
					if (m_fDotrace)
						wordGrammarTraces = new Set<WordGrammarTrace>();
					morpher.TraceAll = m_fDotrace;
					WordAnalysisTrace trace;
					ICollection<WordSynthesis> synthesisRecs = morpher.MorphAndLookupWord(word, out trace);
					foreach (WordSynthesis ws in synthesisRecs)
					{
						WordGrammarTrace wordGrammarTrace = null;
						IEnumerable<PcPatrMorph> morphs = GetMorphs(ws);
						if (m_fDotrace)
						{
							wordGrammarTrace = new WordGrammarTrace(((uint)ws.GetHashCode()).ToString(), morphs);
							wordGrammarTraces.Add(wordGrammarTrace);
						}

						WritePcPatrLexiconFile(m_patrlexPath, morphs);
						m_patr.LoadLexiconFile(m_patrlexPath, 0);
						string sentence = BuildPcPatrInputSentence(morphs);
						try
						{
							if (m_patr.ParseString(sentence) != null)
							{
								BuildXmlOutput(morphs);
								if (m_fDotrace)
									wordGrammarTrace.Success = true;
							}
							else if (m_fDotrace)
							{
								wordGrammarTrace.Success = false;
							}
						}
						catch (Exception)
						{
						}
					}
					if (m_fDotrace)
					{
						Write(trace, prettyPrint, printTraceInputs);
						ConvertWordGrammarTraceToXml(wordGrammarTraces);
					}
				}
				catch (MorphException exc)
				{
					Write(exc);
				}
			}
Exemple #25
0
 public HCObject(HCObject obj)
 {
     m_id      = obj.m_id;
     m_desc    = obj.m_desc;
     m_morpher = obj.m_morpher;
 }
Exemple #26
0
 public virtual void Reset()
 {
     m_curMorpher = null;
     m_morphers.Clear();
     m_isLoaded = false;
 }
Exemple #27
0
		private void MorphAndLookupWord(XmlWriter writer, Morpher morpher, string word, bool printTraceInputs, string[] selectTraceMorphs, string patrlexPath, bool doTrace)
		{
			try
			{
				ICollection<WordGrammarTrace> wordGrammarTraces = null;
				if (doTrace)
					wordGrammarTraces = new HashSet<WordGrammarTrace>();
				var traceManager = new FwXmlTraceManager(m_cache) { WriteInputs = printTraceInputs, TraceAll = doTrace };
				ICollection<WordSynthesis> synthesisRecs = morpher.MorphAndLookupWord(word, traceManager, selectTraceMorphs);

				IEnumerable<PatrResult> patrResults = ProcessPatr(synthesisRecs, patrlexPath, doTrace);
				foreach (PatrResult patrResult in patrResults)
				{
					if (patrResult.PassedPatr)
						BuildXmlOutput(writer, patrResult.Morphs);
					if (wordGrammarTraces != null)
						wordGrammarTraces.Add(patrResult.WordGrammarTrace);
				}

				if (doTrace)
				{
					WriteTrace(writer, traceManager);
					ConvertWordGrammarTraceToXml(writer, wordGrammarTraces);
				}
				traceManager.Reset();
			}
			catch (MorphException exc)
			{
				Write(writer, exc);
			}
		}
Exemple #28
0
		public MorphException(MorphErrorType errorType, Morpher morpher)
		{
			m_errorType = errorType;
			m_morpher = morpher;
		}
		// TODO: add subcats

		/// <summary>
		/// Initializes a new instance of the <see cref="MorphologicalRule"/> class.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <param name="desc">The description.</param>
		/// <param name="morpher">The morpher.</param>
		public AffixalMorphologicalRule(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
			m_subrules = new List<Subrule>();
		}
Exemple #30
0
		public MorphException(MorphErrorType errorType, Morpher morpher, string message, Exception inner)
			: base(message, inner)
		{
			m_errorType = errorType;
			m_morpher = morpher;
		}
Exemple #31
0
		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;
				}
			}
		}
		public PhonologicalRule(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
		}
Exemple #33
0
        // TODO: add subcats

        /// <summary>
        /// Initializes a new instance of the <see cref="MorphologicalRule"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="desc">The description.</param>
        /// <param name="morpher">The morpher.</param>
        public AffixalMorphologicalRule(string id, string desc, Morpher morpher)
            : base(id, desc, morpher)
        {
            m_subrules = new List <Subrule>();
        }
 public abstract IRule<Word, ShapeNode> CompileSynthesisRule(SpanFactory<ShapeNode> spanFactory, Morpher morpher);
 protected MorphologicalRule(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
 }
Exemple #36
0
		public virtual void Reset()
		{
			m_curMorpher = null;
			m_morphers.Clear();
			m_isLoaded = false;
		}
Exemple #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModifyFromInput"/> class.
 /// </summary>
 /// <param name="partition">The partition to modify.</param>
 /// <param name="ctxt">The simple context.</param>
 /// <param name="morpher">The morpher.</param>
 public ModifyFromInput(int partition, SimpleContext ctxt, Morpher morpher)
 {
     m_partition = partition;
     m_ctxt      = ctxt;
     m_morpher   = morpher;
 }
Exemple #38
0
 public override IRule <Word, ShapeNode> CompileSynthesisRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher)
 {
     return(new SynthesisStratumRule(spanFactory, morpher, this));
 }
Exemple #39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Allomorph"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="desc">The description.</param>
 /// <param name="morpher">The morpher.</param>
 protected Allomorph(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_properties = new Dictionary <string, string>();
 }
Exemple #40
0
 public HCObject(string id, string desc, Morpher morpher)
 {
     m_id      = id;
     m_desc    = desc;
     m_morpher = morpher;
 }
Exemple #41
0
        // TODO: add subcats

        /// <summary>
        /// Initializes a new instance of the <see cref="MorphologicalRule"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="desc">The description.</param>
        /// <param name="morpher">The morpher.</param>
        public CompoundingRule(string id, string desc, Morpher morpher)
            : base(id, desc, morpher)
        {
            m_subrules = new List <Subrule>();
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="ModifyFromInput"/> class.
		/// </summary>
		/// <param name="partition">The partition to modify.</param>
		/// <param name="ctxt">The simple context.</param>
		/// <param name="morpher">The morpher.</param>
		public ModifyFromInput(int partition, SimpleContext ctxt, Morpher morpher)
		{
			m_partition = partition;
			m_ctxt = ctxt;
			m_morpher = morpher;
		}
Exemple #43
0
		/// <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>();
		}
Exemple #44
0
 public MorphException(MorphErrorType errorType, Morpher morpher)
 {
     m_errorType = errorType;
     m_morpher   = morpher;
 }
Exemple #45
0
		/// <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>();
		}
Exemple #46
0
 public override IRule<Word, ShapeNode> CompileSynthesisRule(SpanFactory<ShapeNode> spanFactory, Morpher morpher)
 {
     return new SynthesisStratumRule(spanFactory, morpher, this);
 }
Exemple #47
0
 public override IRule <Word, ShapeNode> CompileSynthesisRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher)
 {
     return(new PipelineRuleCascade <Word, ShapeNode>(_strata.Select(stratum => stratum.CompileSynthesisRule(spanFactory, morpher)),
                                                      FreezableEqualityComparer <Word> .Default));
 }
 public AnalysisLanguageRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, Language language)
 {
     _morpher = morpher;
     _strata  = language.Strata.Reverse().ToList();
     _rules   = _strata.Select(stratum => stratum.CompileAnalysisRule(spanFactory, morpher)).ToList();
 }
Exemple #49
0
		// TODO: add subcats

		/// <summary>
		/// Initializes a new instance of the <see cref="MorphologicalRule"/> class.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <param name="desc">The description.</param>
		/// <param name="morpher">The morpher.</param>
		public CompoundingRule(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
			m_subrules = new List<Subrule>();
		}
Exemple #50
0
 public override IRule<Word, ShapeNode> CompileAnalysisRule(SpanFactory<ShapeNode> spanFactory, Morpher morpher)
 {
     return new AnalysisAffixTemplateRule(spanFactory, morpher, this);
 }
Exemple #51
0
 public MorphException(MorphErrorType errorType, Morpher morpher, string message, Exception inner)
     : base(message, inner)
 {
     m_errorType = errorType;
     m_morpher   = morpher;
 }
Exemple #52
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CharacterDefinitionTable"/> class.
 /// </summary>
 /// <param name="featId">The ID.</param>
 /// <param name="desc">The description.</param>
 /// <param name="morpher">The morpher.</param>
 public CharacterDefinitionTable(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_segDefs  = new Dictionary <string, SegmentDefinition>();
     m_bdryDefs = new Dictionary <string, BoundaryDefinition>();
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="PhonologicalRule"/> class.
		/// </summary>
		/// <param name="featId">The ID.</param>
		/// <param name="desc">The description.</param>
		/// <param name="morpher">The morpher.</param>
		public StandardPhonologicalRule(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
			m_subrules = new List<Subrule>();
		}
		public RealizationalRule(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
		}
 public abstract IRule <Word, ShapeNode> CompileSynthesisRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher);
Exemple #56
0
 public void Compile()
 {
     _morpher = new Morpher(new ShapeSpanFactory(), new TraceManager(), _language);
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="CharacterDefinitionTable"/> class.
		/// </summary>
		/// <param name="featId">The ID.</param>
		/// <param name="desc">The description.</param>
		/// <param name="morpher">The morpher.</param>
		public CharacterDefinitionTable(string id, string desc, Morpher morpher)
			: base(id, desc, morpher)
		{
			m_segDefs = new Dictionary<string, SegmentDefinition>();
			m_bdryDefs = new Dictionary<string, BoundaryDefinition>();
		}
Exemple #58
0
 public void Compile()
 {
     _morpher = new Morpher(new ShapeSpanFactory(), new TraceManager(), _language);
 }
Exemple #59
0
 public RealizationalRule(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
 }
Exemple #60
0
		/// <summary>
		/// Initializes a new instance of the <see cref="LexEntry"/> class.
		/// </summary>
		/// <param name="id">The ID.</param>
		/// <param name="desc">The description.</param>
		/// <param name="morpher">The morpher.</param>
		public LexEntry(string id, string desc, Morpher morpher)
			: base (id, desc, morpher)
		{
			m_allomorphs = new List<RootAllomorph>();
		}