/// <summary> /// Generates a string representing the grammar rule production that the specified parse is starting. /// </summary> /// <param name="p">The parse which stats teh production.</param> /// <param name="includePunctuation">if set to <c>true</c> punctuation will be included in the production.</param> /// <returns>A string representing the grammar rule production that the specified parse is starting</returns> protected string Production(Parse p, bool includePunctuation) { var sb = new StringBuilder(); sb.Append(p.Type).Append("->"); var children = AbstractBottomUpParser.CollapsePunctuation(p.Children, punctSet); for (var ci = 0; ci < children.Length; ci++) { sb.Append(children[ci].Type); if (ci + 1 != children.Length) { sb.Append(","); var nextPunct = children[ci].NextPunctuationSet; if (includePunctuation && nextPunct != null) { //TODO: make sure multiple punctuation comes out the same for (var pit = nextPunct.GetEnumerator(); pit.MoveNext();) { if (pit.Current != null) { sb.Append(pit.Current.Type).Append(","); } } } } } return(sb.ToString()); }
/// <summary> /// Creates events for the provided sample. /// </summary> /// <param name="sample">The sample the sample for which training <see cref="T:Event"/>s are be created.</param> /// <returns>The events enumerator.</returns> protected override IEnumerator <Event> CreateEvents(Parse sample) { var newEvents = new List <Event>(); Parse.PurneParse(sample); if (FixPossesives) { Parse.FixPossessives(sample); } sample.UpdateHeads(Rules); var chunks = GetInitialChunks(sample); switch (Type) { case ParserEventTypeEnum.Chunk: AddChunkEvents(newEvents, chunks); break; case ParserEventTypeEnum.Tag: AddTagEvents(newEvents, chunks); break; default: AddParseEvents(newEvents, AbstractBottomUpParser.CollapsePunctuation(chunks, Punctuation)); break; } return(newEvents.GetEnumerator()); }
/// <summary> /// Creates events for the provided sample. /// </summary> /// <param name="sample">The sample the sample for which training <see cref="T:Event"/>s are be created.</param> /// <returns>The events enumerator.</returns> protected override IEnumerator <Event> CreateEvents(Parse sample) { var newEvents = new List <Event>(); Parse.PurneParse(sample); if (FixPossesives) { Parse.FixPossessives(sample); } sample.UpdateHeads(Rules); var chunks = GetInitialChunks(sample); // I don't want to change the code because the original library has the same warning. #pragma warning disable 618 switch (Type) { case ParserEventTypeEnum.Chunk: AddChunkEvents(newEvents, chunks); break; case ParserEventTypeEnum.Tag: AddTagEvents(newEvents, chunks); break; default: AddParseEvents(newEvents, AbstractBottomUpParser.CollapsePunctuation(chunks, Punctuation)); break; } #pragma warning restore 618 return(newEvents.GetEnumerator()); }
/// <summary> /// Returns true if the specified child is the last child of the specified parent. /// </summary> /// <param name="child">The child.</param> /// <param name="parent">The parent.</param> /// <returns><c>true</c> if the specified child is the last child of the specified parent, <c>false</c> otherwise.</returns> protected bool LastChild(Parse child, Parse parent) { var kids = AbstractBottomUpParser.CollapsePunctuation(parent.Children, Punctuation); return(Equals(kids[kids.Length - 1], child)); }