public void SynthesizeWord(Language lang, Word input)
		{
			var trace = new XElement("WordSynthesisTrace",
				CreateAllomorphElement(input.RootAllomorph),
				new XElement("MorphologicalRules", input.MorphologicalRules.Select(CreateMorphologicalRuleElement)));
			var curTrace = (XElement) input.CurrentTrace;
			var lookupTrace = (XElement) curTrace.LastNode;
			lookupTrace.Add(trace);
			input.CurrentTrace = trace;
		}
		public void AnalyzeWord(Language lang, Word input)
		{
			input.CurrentTrace = new XElement("WordAnalysisTrace", new XElement("InputWord", input.Shape.ToString(lang.SurfaceStratum.SymbolTable, true)));
		}
		public void ParseSuccessful(Language lang, Word output)
		{
			((XElement) output.CurrentTrace).Add(new XElement("ParseCompleteTrace", new XAttribute("success", true),
				CreateWordElement("Result", output, false)));
		}
		public void ParseFailed(Language lang, Word word, FailureReason reason, Allomorph allomorph, object failureObj)
		{
			XElement trace;
			switch (reason)
			{
				case FailureReason.ExcludedAllomorphCoOccurrences:
					var alloRule = (AllomorphCoOccurrenceRule) failureObj;
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "adhocProhibitionRule"),
							new XElement("RuleType", "Allomorph"),
							CreateAllomorphElement(allomorph),
							new XElement("Others", alloRule.Others.Select(CreateAllomorphElement)),
							new XElement("Adjacency", alloRule.Adjacency)));
					break;

				case FailureReason.ExcludedMorphemeCoOccurrences:
					var morphemeRule = (MorphemeCoOccurrenceRule) failureObj;
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "adhocProhibitionRule"),
							new XElement("RuleType", "Morpheme"),
							CreateMorphemeElement(allomorph.Morpheme),
							new XElement("Others", morphemeRule.Others.Select(CreateMorphemeElement)),
							new XElement("Adjacency", morphemeRule.Adjacency)));
					break;

				case FailureReason.RequiredEnvironments:
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "environment"),
							CreateAllomorphElement(allomorph),
							new XElement("Environment", failureObj)));
					break;

				case FailureReason.SurfaceFormMismatch:
					trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "formMismatch")));
					break;

				case FailureReason.RequiredSyntacticFeatureStruct:
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "affixInflFeats"),
							CreateAllomorphElement(allomorph),
							CreateInflFeaturesElement("InflFeatures", word.SyntacticFeatureStruct),
							CreateInflFeaturesElement("RequiredInflFeatures", (FeatureStruct) failureObj)));
					break;

				case FailureReason.StemName:
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "stemName"),
							CreateAllomorphElement(allomorph),
							new XElement("StemName", failureObj)));
					break;

				case FailureReason.BoundRoot:
					trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "boundStem")));
					break;

				case FailureReason.DisjunctiveAllomorph:
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "disjunctiveAllomorph"),
							CreateWordElement("Word", (Word) failureObj, false)));
					break;

				case FailureReason.PartialParse:
					trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "partialParse")));
					break;

				default:
					return;
			}
			((XElement) word.CurrentTrace).Add(trace);
		}
Exemple #5
0
 public HCContext(Language language, TextWriter outWriter)
 {
     _language = language;
     _outWriter = outWriter;
 }