Example #1
0
        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}");
        }
Example #2
0
 /// <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;
 }
Example #3
0
 /// <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()
 };
Example #4
0
 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,
     });
 }
Example #5
0
            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);
            }
Example #6
0
 /// <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();
Example #7
0
            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);
            }
Example #8
0
        /// <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);
        }
Example #9
0
        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()));
            }
        }
Example #10
0
 /// <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();
 }
Example #11
0
 /// <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;
 }
Example #12
0
 /// <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();
Example #13
0
 /// <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();
Example #14
0
 /// <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;
Example #15
0
        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;
            }
        }
Example #16
0
 /// <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))
 {
 }
Example #17
0
 /// <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;
Example #18
0
 /// <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);
Example #19
0
 /// <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;
 }
Example #20
0
 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);