private static string FormatVerbalText(IVerbal verbal) { var prepositionalText = verbal.Match((IPrepositionLinkable p) => p.LeftPrepositional?.Text); var adverbialText = string.Join(" ", verbal.AdverbialModifiers.Select(m => m.Text)); return($"{prepositionalText} {verbal.Modality?.Text} {verbal.Text} {adverbialText}"); }
/// <summary> /// Initializes a new instance of the SvoRelationship class. /// </summary> /// <param name="subject">The subject component of the relationship.</param> /// <param name="verbal">The verbal component of the relationship.</param> /// <param name="direct">The direct object component of the relationship.</param> /// <param name="indirect">The indirect object component of the relationship.</param> public SvoRelationship(IEntity subject, IVerbal verbal, IEntity direct, IEntity indirect) { Verbal = verbal; Subject = subject; Direct = direct; Indirect = indirect; }
/// <summary> /// Creates a Newtonsoft.Linq.JObject representation of the Verbal. /// </summary> /// <param name="verbal">The source verbal.</param> /// <returns>A Newtonsoft.Linq.JObject representation of the Verbal.</returns> public static JObject ToJObject(this IVerbal verbal) => new JObject(GetRoleIndependentProperties(verbal)) { ["subjects"] = verbal.Subjects.ToJArray(), ["directObjects"] = verbal.DirectObjects.ToJArray(), ["indirectObjects"] = verbal.IndirectObjects.ToJArray(), ["modality"] = verbal.Modality?.ToJObject(), ["adverbialModifiers"] = verbal.AdverbialModifiers.EmptyIfNull().ToJArray() };
private static ILexicalContextmenu CreateForVerbal(IVerbal verbal) { Validate.NotNull(verbal, nameof(verbal)); return(new LexicalContextmenu { LexicalId = verbal.GetSerializationId(), SubjectIds = verbal.HasSubject() ? verbal.Subjects.Select(e => e.GetSerializationId()).ToArray() : null, DirectObjectIds = verbal.HasDirectObject() ? verbal.DirectObjects.Select(e => e.GetSerializationId()).ToArray() : null, IndirectObjectIds = verbal.HasIndirectObject() ? verbal.IndirectObjects.Select(e => e.GetSerializationId()).ToArray() : null, }); }
public static Item ForSubjects(IVerbal verbal, IEnumerable <TextElement> neighboringElements) { var indicateSubjects = new Item { Header = Text.ViewSubjectsHeader }; indicateSubjects.Click += (s, e) => { ResetUnassociatedLabelBrushes(neighboringElements, verbal); BuildAndExecuteLabelTransformations(neighboringElements, verbal.Subjects); }; return(indicateSubjects); }
/// <summary>e /// Determines if two <see cref="IVerbal"/>s are similar. /// </summary> /// <param name="first">The first IVerbal</param> /// <param name="second">The second IVerbal</param> /// <returns> <c>true</c> if the given IVerbal instances are similar; otherwise, <c>false</c>.</returns> public static Similarity IsSimilarTo(this IVerbal first, IVerbal second) => first.Match() .When(first.Text.EqualsIgnoreCase(second.Text)) .Then(Similarity.Similar) .Case((Verb v1) => second.Match() .Case((Verb v2) => v1.IsSimilarTo(v2)) .Case((VerbPhrase vp2) => v1.IsSimilarTo(vp2)) .Result()) .Case((VerbPhrase vp1) => second.Match() .Case((VerbPhrase vp2) => vp1.IsSimilarTo(vp2)) .Case((Verb v2) => vp1.IsSimilarTo(v2)) .Result()) .Result();
public static Item ForPrepositionalObject(IVerbal verbal, IEnumerable <TextElement> neighboringElements) { var indicatePreopositionalObjects = new Item { Header = Text.ViewObjectOfThePrepositionHeader }; indicatePreopositionalObjects.Click += (s, e) => { ResetUnassociatedLabelBrushes(neighboringElements, verbal); var associatedElements = from element in neighboringElements where element.Tag?.Equals(verbal.ObjectOfThePreposition) ?? false select(element, background : colorMapping[verbal.ObjectOfThePreposition], foreground : Red); foreach (var(element, background, foreground) in associatedElements) { element.Foreground = foreground; element.Background = background; } }; return(indicatePreopositionalObjects); }
/// <summary> /// Creates a context menu specific to the given IVerbal element with context determined by /// the provided labels. /// </summary> /// <param name="verbal">The <see cref="IVerbal"/> for which to create a menu.</param> /// <param name="neighboringElements"> /// The labels which determine the context in which the menu is to be created. /// </param> /// <returns> /// A context menu based on the provided IVerbal in the context of the provided labels. /// </returns> private static ContextMenu ForVerbal(IVerbal verbal, IEnumerable <TextElement> neighboringElements) { var result = new ContextMenu(); if (verbal.Subjects.Any()) { result.Items.Add(VerbalMenuItemFactory.ForSubjects(verbal, neighboringElements)); } if (verbal.DirectObjects.Any()) { result.Items.Add(VerbalMenuItemFactory.ForDirectObjects(verbal, neighboringElements)); } if (verbal.IndirectObjects.Any()) { result.Items.Add(VerbalMenuItemFactory.ForIndirectObjects(verbal, neighboringElements)); } if (verbal.ObjectOfThePreposition != null) { result.Items.Add(VerbalMenuItemFactory.ForPrepositionalObject(verbal, neighboringElements)); } return(result); }
public void GetVerbalsTest() { var target = CreateUnboundUnweightedTestDocument(); IEnumerable <IVerbal> expected = new IVerbal[] { new VerbPhrase( new ModalAuxilary("must"), new BaseVerb("attack") ), new BaseVerb("attack"), new VerbPhrase( new ModalAuxilary("must"), new BaseVerb("do") ), new BaseVerb("do"), new VerbPhrase(new BaseVerb("are") ), }; IEnumerable <IVerbal> actual; actual = target.Verbals; foreach (var e in expected) { Assert.Contains(e, actual, LASI.Utilities.Equality.Create <IVerbal>((a, b) => a.Text == b.Text && a.GetType() == b.GetType())); } }
/// <summary> /// Binds the <see cref="LiftedEntity"/> as a direct object of the <see cref="IVerbal"/>. /// </summary> /// <param name="verbal">The <see cref="IVerbal"/> to which to bind.</param> public void BindAsDirectObjectOf(IVerbal verbal) { directObjectsOfVerbals = directObjectsOfVerbals.Append(verbal).ToAggregate(); }
/// <summary> /// Binds the <see cref="RelativePronoun"/> as an indirect object of the <see cref="IVerbal"/>. /// </summary> /// <param name="verbal">The <see cref="IVerbal"/> to which to bind.</param> public void BindAsIndirectObjectOf(IVerbal verbal) { IndirectObjectOf = verbal; }
/// <summary> /// Gets a value indicating if the Verbal has at least one subject, direct object, or indirect object. /// </summary> /// <param name="verbal">The verbal to test.</param> /// <returns><c>true</c> if the Verbal has at least one subject, direct object, or indirect object; otherwise, <c>false</c>.</returns> public static bool HasSubjectOrObject(this IVerbal verbal) => verbal.HasObject() || verbal.HasSubject();
/// <summary> /// Return a value indicating if the Verbal has any direct OR indirect objects bound to it. /// </summary> /// <param name="verbal">The verbal to test.</param> /// <returns><c>true</c> if the Verbal has any direct OR indirect objects bound to it; otherwise, <c>false</c>.</returns> public static bool HasObject(this IVerbal verbal) => verbal.HasDirectObject() || verbal.HasIndirectObject();
/// <summary> /// Determines if the Given ActionsRelatedOn object contains the provided IVerbal. /// </summary> /// <param name="relatorSet">The object whose contents are to be searched. This parameter can be null. If it is null, false is returned.</param> /// <param name="relator">The IVerbal for which to search.</param> /// <returns> <c>true</c> if the given ActionsRelatedOn set contains the provided IVerbal, false if theActionsRelatedOn set does not contain the provided IVerbal or is null.</returns> public static bool On(this ActionsRelatedOn?relatorSet, IVerbal relator) => relatorSet?.RelatedOn.Contains(relator, (l, r) => l.Text == r.Text) == true;
private static void ResetUnassociatedLabelBrushes(IEnumerable <TextElement> neighboringElements, IVerbal verbal) { var elements = from element in neighboringElements where !verbal.HasSubjectOrObject(i => i == element.Tag) select element; foreach (var element in elements) { element.Foreground = colorMapping[element.Tag as ILexical]; element.Background = White; } }
/// <summary> /// Initializes a new instance of the AggregateVerbal class. /// </summary> /// <param name="first">The first verbal of the aggregate.</param> /// <param name="rest">The remaining verbals which form the aggregate.</param> public AggregateVerbal(IVerbal first, params IVerbal[] rest) : this(rest.Prepend(first)) { }
/// <summary> /// Binds the <see cref="RelativePronoun"/> as a direct object of the <see cref="IVerbal"/>. /// </summary> /// <param name="verbal">The <see cref="IVerbal"/> to which to bind.</param> public void BindAsDirectObjectOf(IVerbal verbal) => DirectObjectOf = verbal;
/// <summary> /// Gets a value indicating if the Verbal has at least one subject, direct object, or indirect object matching the provided predicate. /// </summary> /// <param name="predicate">A predicate to test each associated subject, direct object, or indirect object.</param> /// <param name="verbal">The Verbal to test.</param> /// <returns><c>true</c> if the Verbal has at least one subject, direct object, or indirect object matching the provided predicate; otherwise, <c>false</c>.</returns> public static bool HasSubjectOrObject(this IVerbal verbal, Func <IEntity, bool> predicate) => verbal.HasObject(predicate) || verbal.HasSubject(predicate);
/// <summary> /// Binds the <see cref="RelativePronoun"/> as a subject of the <see cref="IVerbal"/>. /// </summary> /// <param name="verbal">The <see cref="IVerbal"/> to which to bind.</param> public void BindAsSubjectOf(IVerbal verbal) { SubjectOf = verbal; }
public void Deconstruct(out IEntity subject, out IVerbal verbal, out IEntity direct, out IEntity indirect, out ILexical prepositional) => (subject, verbal, direct, indirect, prepositional) = (Subject, Verbal, Direct, Indirect, Prepositional);