Example #1
0
        /// <summary>
        /// Unapplies this affix template to specified input word analysis.
        /// </summary>
        /// <param name="input">The input word analysis.</param>
        /// <param name="output">The output word analyses.</param>
        /// <returns>The resulting word analyses.</returns>
        public bool Unapply(WordAnalysis input, out IEnumerable <WordAnalysis> output, string[] selectTraceMorphs)
        {
            Set <WordAnalysis> results = new Set <WordAnalysis>();

            if (Morpher.TraceTemplatesAnalysis)
            {
                // create the template analysis trace input record
                TemplateAnalysisTrace tempTrace = new TemplateAnalysisTrace(this, true, input.Clone());
                input.CurrentTrace.AddChild(tempTrace);
            }
            UnapplySlots(input.Clone(), m_slots.Count - 1, results, selectTraceMorphs);
            foreach (WordAnalysis wa in results)
            {
                foreach (PartOfSpeech pos in m_requiredPOSs)
                {
                    wa.AddPOS(pos);
                }
            }

            if (results.Count > 0)
            {
                output = results;
                return(true);
            }
            else
            {
                output = null;
                return(false);
            }
        }
Example #2
0
        public bool Equals(WordAnalysis other)
        {
            if (other == null)
            {
                return(false);
            }

            if (m_mrulesUnapplied.Count != other.m_mrulesUnapplied.Count)
            {
                return(false);
            }

            foreach (KeyValuePair <MorphologicalRule, int> kvp in m_mrulesUnapplied)
            {
                int numUnapplies;
                if (!other.m_mrulesUnapplied.TryGetValue(kvp.Key, out numUnapplies) || numUnapplies != kvp.Value)
                {
                    return(false);
                }
            }

            if (m_nonHead != null)
            {
                if (!m_nonHead.Equals(other.m_nonHead))
                {
                    return(false);
                }
            }
            else if (other.m_nonHead != null)
            {
                return(false);
            }

            return(m_shape.Equals(other.m_shape) && m_rzFeatures.Equals(other.m_rzFeatures));
        }
Example #3
0
        /// <summary>
        /// Unapplies all of the rules to the specified input word analysis. All matching lexical
        /// entries are added to the <c>candidates</c> parameter.
        /// </summary>
        /// <param name="input">The input word analysis.</param>
        /// <param name="candidates">The set of candidate word synthesis records.</param>
        /// <returns>All word analyses that result from the unapplication of rules.</returns>
        public IEnumerable <WordAnalysis> Unapply(WordAnalysis input, ICollection <WordSynthesis> candidates)
        {
            if (m_isCyclic)
            {
                throw new NotImplementedException(HCStrings.kstidCyclicStratumNotSupported);
            }

            if (m_pruleOrder == PRuleOrder.SIMULTANEOUS)
            {
                throw new NotImplementedException(HCStrings.kstidSimultOrderNotSupported);
            }

            WordAnalysis wa = input.Clone();

            UnapplyPhonologicalRules(wa);

            LexicalLookup(wa, candidates);

            Set <WordAnalysis> tempOutput = new Set <WordAnalysis>();

            tempOutput.Add(wa);
            UnapplyTemplates(wa, tempOutput, candidates);

            Set <WordAnalysis> output = new Set <WordAnalysis>();

            // TODO: handle cyclicity
            foreach (WordAnalysis analysis in tempOutput)
            {
                UnapplyMorphologicalRules(analysis, m_mrules.Count - 1, 0, candidates, output);
            }

            return(output);
        }
		public override void BeginUnapplyPhonologicalRule(PhonologicalRule rule, WordAnalysis input)
		{
			if (IsAnalysisTracingEnabled(rule.ID))
			{
				m_currentAnalysisPruleTrace = new PhonologicalRuleAnalysisTrace(rule, input.Clone());
				((Trace) input.CurrentTraceObject).AddChild(m_currentAnalysisPruleTrace);
			}
		}
Example #5
0
 /// <summary>
 /// Performs any post-processing required after the unapplication of a word analysis. This must
 /// be called after a successful <c>BeginUnapplication</c> call and any <c>Unapply</c> calls.
 /// </summary>
 /// <param name="input">The input word analysis.</param>
 /// <param name="unapplied">if set to <c>true</c> if the input word analysis was successfully unapplied.</param>
 public override void EndUnapplication(WordAnalysis input, bool unapplied)
 {
     if (TraceAnalysis && !unapplied)
     {
         // create the morphological rule analysis trace record for a rule that did not succesfully unapply
         input.CurrentTrace.AddChild(new MorphologicalRuleAnalysisTrace(this, input.Clone()));
     }
 }
Example #6
0
		public override void EndUnapplyPhonologicalRule(PhonologicalRule rule, WordAnalysis output)
		{
			if (m_currentAnalysisPruleTrace != null)
			{
				m_currentAnalysisPruleTrace.Add(Write("Output", output));
				m_currentAnalysisPruleTrace = null;
			}
		}
Example #7
0
 void UnapplyPhonologicalRules(WordAnalysis input)
 {
     // TODO: handle ordering properly
     for (int i = m_prules.Count - 1; i >= 0; i--)
     {
         m_prules[i].Unapply(input);
     }
 }
		public override void EndUnapplyPhonologicalRule(PhonologicalRule rule, WordAnalysis output)
		{
			if (m_currentAnalysisPruleTrace != null)
			{
				m_currentAnalysisPruleTrace.Output = output.Clone();
				m_currentAnalysisPruleTrace = null;
			}
		}
Example #9
0
		public override void EndUnapplyStratum(Stratum stratum, WordAnalysis output)
		{
			if (TraceStrataAnalysis)
			{
				((XElement) output.CurrentTraceObject).Add(new XElement("StratumAnalysisTraceOut",
					Write("Stratum", stratum),
					Write("Output", output)));
			}
		}
Example #10
0
		public override void BeginUnapplyStratum(Stratum stratum, WordAnalysis input)
		{
			if (TraceStrataAnalysis)
			{
				((XElement) input.CurrentTraceObject).Add(new XElement("StratumAnalysisTraceIn",
					Write("Stratum", stratum),
					Write("Input", input)));
			}
		}
Example #11
0
		public override void BeginAnalyzeWord(string inputWord, WordAnalysis input)
		{
			if (IsTracing)
			{
				var trace = new WordAnalysisTrace(inputWord, input.Shape.Clone());
				m_traces.Add(trace);
				input.CurrentTraceObject = trace;
			}
		}
Example #12
0
		public override void BeginUnapplyTemplate(AffixTemplate template, WordAnalysis input)
		{
			if (TraceTemplatesAnalysis)
			{
				((XElement) input.CurrentTraceObject).Add(new XElement("TemplateAnalysisTraceIn",
					Write("AffixTemplate", template),
					Write("Input", input)));
			}
		}
Example #13
0
		public override void BeginAnalyzeWord(string inputWord, WordAnalysis input)
		{
			if (IsTracing)
			{
				var trace = new XElement("WordAnalysisTrace", new XElement("InputWord", inputWord));
				m_traces.Add(trace);
				input.CurrentTraceObject = trace;
			}
		}
Example #14
0
 public bool IsUnapplicable(WordAnalysis input)
 {
     foreach (PartOfSpeech pos in m_requiredPOSs)
     {
         if (input.MatchPOS(pos))
         {
             return(true);
         }
     }
     return(false);
 }
Example #15
0
            /// <summary>
            /// Unapplies this subrule to the input word analysis.
            /// </summary>
            /// <param name="input">The input word analysis.</param>
            /// <param name="output">The output word analyses.</param>
            /// <returns><c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c></returns>
            public bool Unapply(WordAnalysis input, out ICollection <WordAnalysis> output)
            {
                VariableValues instantiatedVars = new VariableValues(m_alphaVars);
                IList <Match>  matches;

                m_transform.RHSTemplate.IsMatch(input.Shape.First, Direction.RIGHT, ModeType.ANALYSIS, instantiatedVars, out matches);

                List <WordAnalysis> outputList = new List <WordAnalysis>();

                output = outputList;
                foreach (Match match in matches)
                {
                    PhoneticShape headShape;
                    PhoneticShape nonHeadShape;
                    UnapplyRHS(match, out headShape, out nonHeadShape);

                    // for computational complexity reasons, we ensure that the non-head is a root, otherwise we assume it is not
                    // a valid analysis and throw it away
                    foreach (LexEntry.RootAllomorph allo in Morpheme.Stratum.SearchEntries(nonHeadShape))
                    {
                        // check to see if this is a duplicate of another output analysis, this is not strictly necessary, but
                        // it helps to reduce the search space
                        bool add = true;
                        for (int i = 0; i < output.Count; i++)
                        {
                            if (headShape.Duplicates(outputList[i].Shape) && allo == outputList[i].NonHead.RootAllomorph)
                            {
                                if (headShape.Count > outputList[i].Shape.Count)
                                {
                                    // if this is a duplicate and it is longer, then use this analysis and remove the previous one
                                    outputList.RemoveAt(i);
                                }
                                else
                                {
                                    // if it is shorter, then do not add it to the output list
                                    add = false;
                                }
                                break;
                            }
                        }

                        if (add)
                        {
                            WordAnalysis wa = input.Clone();
                            wa.Shape   = headShape;
                            wa.NonHead = new WordAnalysis(nonHeadShape, wa.Stratum, null);
                            wa.NonHead.RootAllomorph = allo;
                            output.Add(wa);
                        }
                    }
                }

                return(outputList.Count > 0);
            }
Example #16
0
		public override void BeginUnapplyPhonologicalRule(PhonologicalRule rule, WordAnalysis input)
		{
			if (IsAnalysisTracingEnabled(rule.ID))
			{
				m_currentAnalysisPruleTrace = new XElement("PhonologicalRuleAnalysisTrace",
					Write("PhonologicalRule", rule));
				if (WriteInputs)
					m_currentAnalysisPruleTrace.Add(Write("Input", input));
				((XElement) input.CurrentTraceObject).Add(m_currentAnalysisPruleTrace);
			}
		}
Example #17
0
		public override void MorphologicalRuleUnapplied(MorphologicalRule rule, WordAnalysis input, WordAnalysis output, Allomorph allomorph)
		{
			if (IsAnalysisTracingEnabled(rule.ID))
			{
				// create the morphological rule analysis trace record for each output analysis
				var trace = new MorphologicalRuleAnalysisTrace(rule, input.Clone()) {RuleAllomorph = allomorph, Output = output.Clone()};
				((Trace) output.CurrentTraceObject).AddChild(trace);
				// set current trace record to the morphological rule trace record for each
				// output analysis
				output.CurrentTraceObject = trace;
			}
		}
Example #18
0
        void UnapplyMorphologicalRulesAndTemplates(WordAnalysis wa, Set <WordAnalysis> output, ICollection <WordSynthesis> candidates, string[] selectTraceMorphs)
        {
            Set <WordAnalysis> tempOutput = new Set <WordAnalysis>();

            tempOutput.Add(wa);
            UnapplyTemplates(wa, tempOutput, candidates, selectTraceMorphs);
            foreach (WordAnalysis analysis in tempOutput)
            {
                // start over from the very beginning
                UnapplyMorphologicalRules(analysis, m_mrules.Count - 1, 0, candidates, output, selectTraceMorphs);
            }
        }
Example #19
0
		/// <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;
		}
Example #20
0
		public override bool Unapply(WordAnalysis input, int srIndex, out ICollection<WordAnalysis> output)
		{
			output = null;
			FeatureValues rzFeats;
			if (!RealizationalFeatures.Unify(input.RealizationalFeatures, out rzFeats))
				return false;

			if (base.Unapply(input, srIndex, out output))
			{
				foreach (WordAnalysis wa in output)
					wa.RealizationalFeatures = rzFeats;
				return true;
			}
			return false;
		}
Example #21
0
 /// <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;
 }
Example #22
0
            /// <summary>
            /// Unapplies this subrule to the input word analysis.
            /// </summary>
            /// <param name="input">The input word analysis.</param>
            /// <param name="output">The output word analyses.</param>
            /// <returns><c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c></returns>
            public bool Unapply(WordAnalysis input, out ICollection <WordAnalysis> output)
            {
                VariableValues instantiatedVars = new VariableValues(m_alphaVars);
                IList <Match>  matches;

                m_transform.RHSTemplate.IsMatch(input.Shape.First, Direction.RIGHT, ModeType.ANALYSIS, instantiatedVars, out matches);

                List <WordAnalysis> outputList = new List <WordAnalysis>();

                output = outputList;
                foreach (Match match in matches)
                {
                    PhoneticShape shape = UnapplyRHS(match);

                    if (shape.Count > 2)
                    {
                        // check to see if this is a duplicate of another output analysis, this is not strictly necessary, but
                        // it helps to reduce the search space
                        bool add = true;
                        for (int i = 0; i < output.Count; i++)
                        {
                            if (shape.Duplicates(outputList[i].Shape))
                            {
                                if (shape.Count > outputList[i].Shape.Count)
                                {
                                    // if this is a duplicate and it is longer, then use this analysis and remove the previous one
                                    outputList.RemoveAt(i);
                                }
                                else
                                {
                                    // if it is shorter, then do not add it to the output list
                                    add = false;
                                }
                                break;
                            }
                        }

                        if (add)
                        {
                            WordAnalysis wa = input.Clone();
                            wa.Shape = shape;
                            output.Add(wa);
                        }
                    }
                }

                return(outputList.Count > 0);
            }
Example #23
0
        /// <summary>
        /// Unapplies the specified subrule to the specified word analysis.
        /// </summary>
        /// <param name="input">The input word analysis.</param>
        /// <param name="srIndex">Index of the subrule.</param>
        /// <param name="output">All resulting word analyses.</param>
        /// <returns>
        ///     <c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c>
        /// </returns>
        public override bool Unapply(WordAnalysis input, int srIndex, out ICollection <WordAnalysis> output)
        {
            if (m_subrules[srIndex].Unapply(input, out output))
            {
                foreach (WordAnalysis wa in output)
                {
                    if (m_headRequiredPOSs != null && m_headRequiredPOSs.Count > 0)
                    {
                        foreach (PartOfSpeech pos in m_headRequiredPOSs)
                        {
                            wa.AddPOS(pos);
                        }
                    }
                    else if (m_outPOS == null)
                    {
                        wa.UninstantiatePOS();
                    }

                    if (m_nonHeadRequiredPOSs != null)
                    {
                        foreach (PartOfSpeech pos in m_nonHeadRequiredPOSs)
                        {
                            wa.NonHead.AddPOS(pos);
                        }
                    }

                    wa.MorphologicalRuleUnapplied(this);

                    if (TraceAnalysis)
                    {
                        // create the morphological rule analysis trace record for each output analysis
                        MorphologicalRuleAnalysisTrace trace = new MorphologicalRuleAnalysisTrace(this, input.Clone());
                        trace.RuleAllomorph = m_subrules[srIndex];
                        trace.Output        = wa.Clone();
                        wa.CurrentTrace.AddChild(trace);
                        // set current trace record to the morphological rule trace record for each
                        // output analysis
                        wa.CurrentTrace = trace;
                    }
                }
                return(true);
            }

            output = null;
            return(false);
        }
Example #24
0
        void UnapplySlots(WordAnalysis input, int sIndex, Set <WordAnalysis> output, string[] selectTraceMorphs)
        {
            for (int i = sIndex; i >= 0; i--)
            {
                foreach (MorphologicalRule rule in m_slots[i].MorphologicalRules)
                {
                    if (rule.BeginUnapplication(input))
                    {
                        bool ruleUnapplied = false;
                        for (int j = 0; j < rule.SubruleCount; j++)
                        {
                            ICollection <WordAnalysis> analyses;
                            if (rule.Unapply(input, j, out analyses, selectTraceMorphs))
                            {
                                ruleUnapplied = true;
                                foreach (WordAnalysis wa in analyses)
                                {
                                    if (wa.Shape.Count > 2)
                                    {
                                        UnapplySlots(wa, i - 1, output, selectTraceMorphs);
                                    }
                                }
                            }
                        }
                        rule.EndUnapplication(input, ruleUnapplied);
                    }
                }
                // we can skip this slot if it is optional
                if (!m_slots[i].IsOptional)
                {
                    if (Morpher.TraceTemplatesAnalysis)
                    {
                        input.CurrentTrace.AddChild(new TemplateAnalysisTrace(this, false, null));
                    }
                    return;
                }
            }

            if (Morpher.TraceTemplatesAnalysis)
            {
                input.CurrentTrace.AddChild(new TemplateAnalysisTrace(this, false, input.Clone()));
            }
            output.Add(input);
        }
Example #25
0
        public override bool Unapply(WordAnalysis input, int srIndex, out ICollection <WordAnalysis> output)
        {
            output = null;
            FeatureValues rzFeats;

            if (!RealizationalFeatures.Unify(input.RealizationalFeatures, out rzFeats))
            {
                return(false);
            }

            if (base.Unapply(input, srIndex, out output))
            {
                foreach (WordAnalysis wa in output)
                {
                    wa.RealizationalFeatures = rzFeats;
                }
                return(true);
            }
            return(false);
        }
Example #26
0
        /// <summary>
        /// Unapplies the rule to the specified word analysis.
        /// </summary>
        /// <param name="input">The input word analysis.</param>
        public override void Unapply(WordAnalysis input)
        {
            // I don't think there is any difference between iterative and
            // simultaneous application
            Direction dir = Direction.RIGHT;

            switch (m_multApplication)
            {
            case MultAppOrder.LR_ITERATIVE:
            case MultAppOrder.SIMULTANEOUS:
                dir = Direction.LEFT;
                break;

            case MultAppOrder.RL_ITERATIVE:
                dir = Direction.RIGHT;
                break;
            }

            ProcessIterative(input.Shape, dir, m_rhsTemp, ModeType.ANALYSIS);
        }
Example #27
0
        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));
                    }
                }
            }
        }
Example #28
0
        void MorphologicalRuleUnapplied(WordAnalysis ruleOutput, int rIndex, int srIndex, ICollection <WordSynthesis> candidates,
                                        Set <WordAnalysis> output, string[] selectTraceMorphs)
        {
            if (ruleOutput.Shape.Count > 2)
            {
                // lookup resulting phonetic shape in lexicon
                LexicalLookup(ruleOutput, candidates, selectTraceMorphs);

                // recursive call so that we can cover every permutation of rule unapplication
                switch (m_mruleOrder)
                {
                case MRuleOrder.LINEAR:
                    UnapplyMorphologicalRules(ruleOutput, rIndex, srIndex, candidates, output, selectTraceMorphs);
                    break;

                case MRuleOrder.UNORDERED:
                    UnapplyMorphologicalRulesAndTemplates(ruleOutput, output, candidates, selectTraceMorphs);
                    break;
                }
            }
        }
Example #29
0
        void MorphologicalRuleUnapplied(WordAnalysis ruleOutput, int rIndex, int srIndex, ICollection <WordSynthesis> candidates,
                                        Set <WordAnalysis> output)
        {
            if (ruleOutput.Shape.Count > 2)
            {
                // lookup resulting phonetic shape in lexicon
                LexicalLookup(ruleOutput, candidates);

                // recursive call so that we can cover every permutation of rule unapplication
                switch (m_mruleOrder)
                {
                case MRuleOrder.LINEAR:
                    UnapplyMorphologicalRules(ruleOutput, rIndex, srIndex, candidates, output);
                    break;

                case MRuleOrder.UNORDERED:
                    // start over from the very beginning
                    UnapplyMorphologicalRules(ruleOutput, m_mrules.Count - 1, 0, candidates, output);
                    break;
                }
            }
        }
Example #30
0
        /// <summary>
        /// Unapplies the rule to the specified word analysis.
        /// </summary>
        /// <param name="input">The input word analysis.</param>
        public override void Unapply(WordAnalysis input)
        {
            PhonologicalRuleAnalysisTrace trace = null;

            if (TraceAnalysis)
            {
                // create phonological rule analysis trace record
                trace = new PhonologicalRuleAnalysisTrace(this, input.Clone());
                input.CurrentTrace.AddChild(trace);
            }

            foreach (Subrule sr in m_subrules)
            {
                sr.Unapply(input.Shape);
            }

            if (trace != null)
            {
                // add output to trace record
                trace.Output = input.Clone();
            }
        }
Example #31
0
 void UnapplyTemplates(WordAnalysis input, Set <WordAnalysis> output, ICollection <WordSynthesis> candidates, string[] selectTraceMorphs)
 {
     foreach (AffixTemplate template in m_templates)
     {
         if (template.IsUnapplicable(input))
         {
             IEnumerable <WordAnalysis> tempOutput;
             if (template.Unapply(input, out tempOutput, selectTraceMorphs))
             {
                 foreach (WordAnalysis tempAnalysis in tempOutput)
                 {
                     // don't bother to do a lookup if this analysis already exists
                     if (!output.Contains(tempAnalysis))
                     {
                         output.Add(tempAnalysis);
                         // lookup resulting phonetic shape in lexicon
                         LexicalLookup(tempAnalysis, candidates, selectTraceMorphs);
                     }
                 }
             }
         }
     }
 }
Example #32
0
        /// <summary>
        /// Unapplies all of the rules to the specified input word analysis. All matching lexical
        /// entries are added to the <c>candidates</c> parameter.
        /// </summary>
        /// <param name="input">The input word analysis.</param>
        /// <param name="candidates">The set of candidate word synthesis records.</param>
        /// <returns>All word analyses that result from the unapplication of rules.</returns>
        public IEnumerable <WordAnalysis> Unapply(WordAnalysis input, ICollection <WordSynthesis> candidates, string[] selectTraceMorphs)
        {
            if (m_isCyclic)
            {
                throw new NotImplementedException(HCStrings.kstidCyclicStratumNotSupported);
            }

            if (m_pruleOrder == PRuleOrder.SIMULTANEOUS)
            {
                throw new NotImplementedException(HCStrings.kstidSimultOrderNotSupported);
            }

            WordAnalysis wa = input.Clone();

            UnapplyPhonologicalRules(wa);

            LexicalLookup(wa, candidates, selectTraceMorphs);

            Set <WordAnalysis> output = new Set <WordAnalysis>();

            UnapplyMorphologicalRulesAndTemplates(wa, output, candidates, selectTraceMorphs);

            return(output);
        }
Example #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MorphologicalRuleAnalysisTrace"/> class.
 /// </summary>
 /// <param name="rule">The rule.</param>
 /// <param name="input">The input.</param>
 internal MorphologicalRuleAnalysisTrace(MorphologicalRule rule, WordAnalysis input)
     : base(rule)
 {
     m_input = input;
 }
		/// <summary>
		/// Performs any post-processing required after the unapplication of a word analysis. This must
		/// be called after a successful <c>BeginUnapplication</c> call and any <c>Unapply</c> calls.
		/// </summary>
		/// <param name="input">The input word analysis.</param>
		/// <param name="trace"></param>
		/// <param name="unapplied">if set to <c>true</c> if the input word analysis was successfully unapplied.</param>
		public override void EndUnapplication(WordAnalysis input, TraceManager trace, bool unapplied)
		{
			if (trace != null && !unapplied)
				trace.MorphologicalRuleNotUnapplied(this, input);
		}
Example #35
0
		public override void BeginUnapplyTemplate(AffixTemplate template, WordAnalysis input)
		{
			if (TraceTemplatesAnalysis)
				((Trace) input.CurrentTraceObject).AddChild(new TemplateAnalysisTrace(template, true, input.Clone()));
		}
Example #36
0
		/// <summary>
		/// Initializes a new instance of the <see cref="PhonologicalRuleAnalysisTrace"/> class.
		/// </summary>
		/// <param name="rule">The rule.</param>
		/// <param name="input">The input.</param>
		internal PhonologicalRuleAnalysisTrace(PhonologicalRule rule, WordAnalysis input)
			: base(rule)
		{
			m_input = input;
		}
Example #37
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MorphologicalRuleAnalysisTrace"/> class.
		/// </summary>
		/// <param name="rule">The rule.</param>
		/// <param name="input">The input.</param>
		internal MorphologicalRuleAnalysisTrace(MorphologicalRule rule, WordAnalysis input)
			: base(rule)
		{
			m_input = input;
		}
Example #38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TemplateAnalysisTrace"/> class.
 /// </summary>
 /// <param name="template">The template.</param>
 /// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
 /// <param name="analysis">The input or output word analysis.</param>
 internal TemplateAnalysisTrace(AffixTemplate template, bool input, WordAnalysis analysis)
     : base(template, input)
 {
     m_analysis = analysis;
 }
Example #39
0
		/// <summary>
		/// Unapplies the rule to the specified word analysis.
		/// </summary>
		/// <param name="input">The input word analysis.</param>
		public override void Unapply(WordAnalysis input)
		{
			// I don't think there is any difference between iterative and
			// simultaneous application
			Direction dir = Direction.RIGHT;
			switch (m_multApplication)
			{
				case MultAppOrder.LR_ITERATIVE:
				case MultAppOrder.SIMULTANEOUS:
					dir = Direction.LEFT;
					break;

				case MultAppOrder.RL_ITERATIVE:
					dir = Direction.RIGHT;
					break;
			}

			ProcessIterative(input.Shape, dir, m_rhsTemp, ModeType.ANALYSIS);
		}
Example #40
0
		public bool Equals(WordAnalysis other)
		{
			if (other == null)
				return false;

			if (m_mrulesUnapplied.Count != other.m_mrulesUnapplied.Count)
				return false;

			foreach (KeyValuePair<MorphologicalRule, int> kvp in m_mrulesUnapplied)
			{
				int numUnapplies;
				if (!other.m_mrulesUnapplied.TryGetValue(kvp.Key, out numUnapplies) || numUnapplies != kvp.Value)
					return false;
			}

			if (m_nonHead != null)
			{
				if (!m_nonHead.Equals(other.m_nonHead))
					return false;
			}
			else if (other.m_nonHead != null)
			{
				return false;
			}

			return m_shape.Equals(other.m_shape) && m_rzFeatures.Equals(other.m_rzFeatures);
		}
Example #41
0
		public override void EndUnapplyTemplate(AffixTemplate template, WordAnalysis output, bool unapplied)
		{
			if (TraceTemplatesAnalysis)
				((Trace) output.CurrentTraceObject).AddChild(new TemplateAnalysisTrace(template, false, unapplied ? output.Clone() : null));
		}
 /// <summary>
 /// Unapplies the specified subrule to the specified word analysis.
 /// </summary>
 /// <param name="input">The input word analysis.</param>
 /// <param name="srIndex">Index of the subrule.</param>
 /// <param name="output">All resulting word analyses.</param>
 /// <param name="selectTraceMorphs">list of ids to be used in a selective trace</param>
 /// <returns><c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c></returns>
 public abstract bool Unapply(WordAnalysis input, int srIndex, out ICollection <WordAnalysis> output, string[] selectTraceMorphs);
 /// <summary>
 /// Performs any pre-processing required for unapplication of a word analysis. This must
 /// be called before <c>Unapply</c>. <c>Unapply</c> and <c>EndUnapplication</c> should only
 /// be called if this method returns <c>true</c>.
 /// </summary>
 /// <param name="input">The input word analysis.</param>
 /// <returns><c>true</c> if the specified input is unapplicable, otherwise <c>false</c>.</returns>
 public abstract bool BeginUnapplication(WordAnalysis input);
 /// <summary>
 /// Performs any post-processing required after the unapplication of a word analysis. This must
 /// be called after a successful <c>BeginUnapplication</c> call and any <c>Unapply</c> calls.
 /// </summary>
 /// <param name="input">The input word analysis.</param>
 /// <param name="unapplied">if set to <c>true</c> if the input word analysis was successfully unapplied.</param>
 public abstract void EndUnapplication(WordAnalysis input, bool unapplied);
Example #45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StratumAnalysisTrace"/> class.
 /// </summary>
 /// <param name="stratum">The stratum.</param>
 /// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
 /// <param name="analysis">The input or output word analysis.</param>
 internal StratumAnalysisTrace(Stratum stratum, bool input, WordAnalysis analysis)
     : base(stratum, input)
 {
     m_analysis = analysis;
 }
Example #46
0
 /// <summary>
 /// Performs any pre-processing required for unapplication of a word analysis. This must
 /// be called before <c>Unapply</c>. <c>Unapply</c> and <c>EndUnapplication</c> should only
 /// be called if this method returns <c>true</c>.
 /// </summary>
 /// <param name="input">The input word analysis.</param>
 /// <returns>
 ///     <c>true</c> if the specified input is unapplicable, otherwise <c>false</c>.
 /// </returns>
 public override bool BeginUnapplication(WordAnalysis input)
 {
     return(input.GetNumUnappliesForMorphologicalRule(this) < m_maxNumApps && input.NonHead == null &&
            (m_outPOS == null || input.MatchPOS(m_outPOS)));
 }
Example #47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhonologicalRuleAnalysisTrace"/> class.
 /// </summary>
 /// <param name="rule">The rule.</param>
 /// <param name="input">The input.</param>
 internal PhonologicalRuleAnalysisTrace(PhonologicalRule rule, WordAnalysis input)
     : base(rule)
 {
     m_input = input;
 }
Example #48
0
			/// <summary>
			/// Unapplies this subrule to the input word analysis.
			/// </summary>
			/// <param name="input">The input word analysis.</param>
			/// <param name="output">The output word analyses.</param>
			/// <returns><c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c></returns>
			public bool Unapply(WordAnalysis input, out ICollection<WordAnalysis> output)
			{
				VariableValues instantiatedVars = new VariableValues(m_alphaVars);
				IList<Match> matches;
				m_transform.RHSTemplate.IsMatch(input.Shape.First, Direction.RIGHT, ModeType.ANALYSIS, instantiatedVars, out matches);

				List<WordAnalysis> outputList = new List<WordAnalysis>();
				output = outputList;
				foreach (Match match in matches)
				{
					PhoneticShape headShape;
					PhoneticShape nonHeadShape;
					UnapplyRHS(match, out headShape, out nonHeadShape);

					// for computational complexity reasons, we ensure that the non-head is a root, otherwise we assume it is not
					// a valid analysis and throw it away
					foreach (LexEntry.RootAllomorph allo in Morpheme.Stratum.SearchEntries(nonHeadShape))
					{
						// check to see if this is a duplicate of another output analysis, this is not strictly necessary, but
						// it helps to reduce the search space
						bool add = true;
						for (int i = 0; i < output.Count; i++)
						{
							if (headShape.Duplicates(outputList[i].Shape) && allo == outputList[i].NonHead.RootAllomorph)
							{
								if (headShape.Count > outputList[i].Shape.Count)
									// if this is a duplicate and it is longer, then use this analysis and remove the previous one
									outputList.RemoveAt(i);
								else
									// if it is shorter, then do not add it to the output list
									add = false;
								break;
							}
						}

						if (add)
						{
							WordAnalysis wa = input.Clone();
							wa.Shape = headShape;
							wa.NonHead = new WordAnalysis(nonHeadShape, wa.Stratum, null);
							wa.NonHead.RootAllomorph = allo;
							output.Add(wa);
						}
					}
				}

				return outputList.Count > 0;
			}
		/// <summary>
		/// Unapplies the rule to the specified word analysis.
		/// </summary>
		/// <param name="input">The input word analysis.</param>
		public override void Unapply(WordAnalysis input)
		{
			PhonologicalRuleAnalysisTrace trace = null;
			if (TraceAnalysis)
			{
				// create phonological rule analysis trace record
				trace = new PhonologicalRuleAnalysisTrace(this, input.Clone());
				input.CurrentTrace.AddChild(trace);
			}

			foreach (Subrule sr in m_subrules)
				sr.Unapply(input.Shape);

			if (trace != null)
				// add output to trace record
				trace.Output = input.Clone();
		}
Example #50
0
		/// <summary>
		/// Unapplies the specified subrule to the specified word analysis.
		/// </summary>
		/// <param name="input">The input word analysis.</param>
		/// <param name="srIndex">Index of the subrule.</param>
		/// <param name="output">All resulting word analyses.</param>
		/// <returns>
		/// 	<c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c>
		/// </returns>
		public override bool Unapply(WordAnalysis input, int srIndex, out ICollection<WordAnalysis> output)
		{
			if (m_subrules[srIndex].Unapply(input, out output))
			{
				foreach (WordAnalysis wa in output)
				{
					if (m_headRequiredPOSs != null && m_headRequiredPOSs.Count > 0)
					{
						foreach (PartOfSpeech pos in m_headRequiredPOSs)
							wa.AddPOS(pos);
					}
					else if (m_outPOS == null)
					{
						wa.UninstantiatePOS();
					}

					if (m_nonHeadRequiredPOSs != null)
					{
						foreach (PartOfSpeech pos in m_nonHeadRequiredPOSs)
							wa.NonHead.AddPOS(pos);
					}

					wa.MorphologicalRuleUnapplied(this);

					if (TraceAnalysis)
					{
						// create the morphological rule analysis trace record for each output analysis
						MorphologicalRuleAnalysisTrace trace = new MorphologicalRuleAnalysisTrace(this, input.Clone());
						trace.RuleAllomorph = m_subrules[srIndex];
						trace.Output = wa.Clone();
						wa.CurrentTrace.AddChild(trace);
						// set current trace record to the morphological rule trace record for each
						// output analysis
						wa.CurrentTrace = trace;
					}
				}
				return true;
			}

			output = null;
			return false;
		}
Example #51
0
		/// <summary>
		/// Initializes a new instance of the <see cref="StratumAnalysisTrace"/> class.
		/// </summary>
		/// <param name="stratum">The stratum.</param>
		/// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
		/// <param name="analysis">The input or output word analysis.</param>
		internal StratumAnalysisTrace(Stratum stratum, bool input, WordAnalysis analysis)
			: base(stratum, input)
		{
			m_analysis = analysis;
		}
Example #52
0
 public override bool BeginUnapplication(WordAnalysis input)
 {
     return(true);
 }
Example #53
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TemplateAnalysisTrace"/> class.
		/// </summary>
		/// <param name="template">The template.</param>
		/// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
		/// <param name="analysis">The input or output word analysis.</param>
		internal TemplateAnalysisTrace(AffixTemplate template, bool input, WordAnalysis analysis)
			: base(template, input)
		{
			m_analysis = analysis;
		}
Example #54
0
 void LexicalLookup(WordAnalysis input, ICollection <WordSynthesis> candidates)
 {
     LexicalLookup(input, candidates, null);
 }
Example #55
0
		/// <summary>
		/// Performs any pre-processing required for unapplication of a word analysis. This must
		/// be called before <c>Unapply</c>. <c>Unapply</c> and <c>EndUnapplication</c> should only
		/// be called if this method returns <c>true</c>.
		/// </summary>
		/// <param name="input">The input word analysis.</param>
		/// <returns>
		/// 	<c>true</c> if the specified input is unapplicable, otherwise <c>false</c>.
		/// </returns>
		public override bool BeginUnapplication(WordAnalysis input)
		{
			return input.GetNumUnappliesForMorphologicalRule(this) < m_maxNumApps && input.NonHead == null
				&& (m_outPOS == null || input.MatchPOS(m_outPOS));
		}
			/// <summary>
			/// Unapplies this subrule to the input word analysis.
			/// </summary>
			/// <param name="input">The input word analysis.</param>
			/// <param name="output">The output word analyses.</param>
			/// <returns><c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c></returns>
			public bool Unapply(WordAnalysis input, out ICollection<WordAnalysis> output)
			{
				VariableValues instantiatedVars = new VariableValues(m_alphaVars);
				IList<Match> matches;
				m_transform.RHSTemplate.IsMatch(input.Shape.First, Direction.RIGHT, ModeType.ANALYSIS, instantiatedVars, out matches);

				List<WordAnalysis> outputList = new List<WordAnalysis>();
				output = outputList;
				foreach (Match match in matches)
				{
					PhoneticShape shape = UnapplyRHS(match);

					if (shape.Count > 2)
					{
						// check to see if this is a duplicate of another output analysis, this is not strictly necessary, but
						// it helps to reduce the search space
						bool add = true;
						for (int i = 0; i < output.Count; i++)
						{
							if (shape.Duplicates(outputList[i].Shape))
							{
								if (shape.Count > outputList[i].Shape.Count)
									// if this is a duplicate and it is longer, then use this analysis and remove the previous one
									outputList.RemoveAt(i);
								else
									// if it is shorter, then do not add it to the output list
									add = false;
								break;
							}
						}

						if (add)
						{
							WordAnalysis wa = input.Clone();
							wa.Shape = shape;
							output.Add(wa);
						}
					}
				}

				return outputList.Count > 0;
			}
Example #57
0
		/// <summary>
		/// Performs any post-processing required after the unapplication of a word analysis. This must
		/// be called after a successful <c>BeginUnapplication</c> call and any <c>Unapply</c> calls.
		/// </summary>
		/// <param name="input">The input word analysis.</param>
		/// <param name="unapplied">if set to <c>true</c> if the input word analysis was successfully unapplied.</param>
		public override void EndUnapplication(WordAnalysis input, bool unapplied)
		{
			if (TraceAnalysis && !unapplied)
				// create the morphological rule analysis trace record for a rule that did not succesfully unapply
				input.CurrentTrace.AddChild(new MorphologicalRuleAnalysisTrace(this, input.Clone()));
		}
		/// <summary>
		/// Unapplies the specified subrule to the specified word analysis.
		/// </summary>
		/// <param name="input">The input word analysis.</param>
		/// <param name="srIndex">Index of the subrule.</param>
		/// <param name="output">All resulting word analyses.</param>
		/// <param name="selectTraceMorphs">list of ids to be used in a selective trace</param>
		/// <returns>
		/// 	<c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c>
		/// </returns>
		public override bool Unapply(WordAnalysis input, int srIndex, TraceManager trace, string[] selectTraceMorphs, out ICollection<WordAnalysis> output)
		{
			if (UseThisRule(selectTraceMorphs) && m_subrules[srIndex].Unapply(input, out output))
			{
				foreach (WordAnalysis wa in output)
				{
					if (m_requiredPOSs != null && m_requiredPOSs.Count > 0)
					{
						foreach (PartOfSpeech pos in m_requiredPOSs)
							wa.AddPOS(pos);
					}
					else if (m_outPOS == null)
					{
						wa.UninstantiatePOS();
					}

					wa.MorphologicalRuleUnapplied(this);

					if (trace != null)
						trace.MorphologicalRuleUnapplied(this, input, wa, m_subrules[srIndex]);
				}
				return true;
			}

			output = null;
			return false;
		}
Example #59
0
		public override void MorphologicalRuleNotUnapplied(MorphologicalRule rule, WordAnalysis input)
		{
			if (IsAnalysisTracingEnabled(rule.ID))
			{
				// create the morphological rule analysis trace record for a rule that did not succesfully unapply
				((Trace) input.CurrentTraceObject).AddChild(new MorphologicalRuleAnalysisTrace(rule, input.Clone()));
			}
		}
Example #60
0
		public override void EndUnapplyStratum(Stratum stratum, WordAnalysis output)
		{
			if (TraceStrataAnalysis)
				((Trace) output.CurrentTraceObject).AddChild(new StratumAnalysisTrace(stratum, false, output.Clone()));
		}