Esempio n. 1
0
 /// <summary>
 /// Creates a context menu specific to the given IReferencer element with context
 /// determined by the provided labels.
 /// </summary>
 /// <param name="referencer">The <see cref="IReferencer"/> 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 IReferencer in the context of the provided labels.
 /// </returns>
 private static ContextMenu ForReferencer(IReferencer referencer, IEnumerable <TextElement> neighboringElements) => new ContextMenu
 {
     Items =
     {
         ReferencerMenuItemFactory.ForReferredTo(referencer, neighboringElements)
     }
 };
Esempio n. 2
0
 private static ILexicalContextmenu CreateForReferencer(IReferencer referencer)
 {
     Validate.NotNull(referencer, nameof(referencer));
     return(new LexicalContextmenu
     {
         LexicalId = referencer.GetSerializationId(),
         RefersToIds = referencer.RefersTo.Any() ? referencer.RefersTo.OfPhrase().Select(e => e.GetSerializationId()).ToArray() : null
     });
 }
Esempio n. 3
0
        public void RefereesTest()
        {
            var target = new NounPhrase(new Determiner("the"), new Adjective("large"), new CommonSingularNoun("elephants"));
            IEnumerable <IReferencer> expected = new IReferencer[] { new RelativePronoun("that"), new PersonalPronoun("it") };
            IEnumerable <IReferencer> actual;

            foreach (var r in expected)
            {
                target.BindReferencer(r);
            }
            actual = target.Referencers;
            Check.That(actual).Contains(expected);
        }
Esempio n. 4
0
 /// <summary>
 /// Returns a NameGender value indicating the likely gender of the Pronoun based on its
 /// referent if known, or else its PronounKind.
 /// </summary>
 /// <param name="referencer">The Pronoun whose gender to lookup.</param>
 /// <returns>A NameGender value indicating the likely gender of the Pronoun.</returns>
 private static Gender GetGender(IReferencer referencer) => referencer.Match()
 .Case((PronounPhrase p) => DeterminePronounPhraseGender(p))
 .When(referencer.RefersTo != null)
 .Then((from referrenced in referencer.RefersTo
        let gender = referrenced.Match()
                     .Case((NounPhrase n) => DetermineNounPhraseGender(n))
                     .Case((Pronoun r) => r.Gender)
                     .Case((ProperSingularNoun r) => r.Gender)
                     .Case((CommonNoun n) => Gender.Neutral)
                     .Result()
                     group gender by gender into byGender
                         where byGender.Count() == referencer.RefersTo.Count()
                     select byGender.Key).FirstOrDefault())
 .Case((ISimpleGendered p) => p.Gender)
 .Result();
Esempio n. 5
0
            public static Item ForReferredTo(IReferencer referencer, IEnumerable <TextElement> neighboringElements)
            {
                var indicateReferredTo = new Item {
                    Header = "View Referred To"
                };

                indicateReferredTo.Click += (s, e) =>
                {
                    ResetLabelBrushes(neighboringElements);
                    var associatedElements = from element in neighboringElements
                                             where referencer.RefersTo == element.Tag || element.Tag is NounPhrase &&
                                             referencer.RefersTo.Intersect((element.Tag as NounPhrase).Words.OfEntity()).Any()
                                             select element;
                    foreach (var a in associatedElements)
                    {
                        a.Foreground = White;
                        a.Background = Black;
                    }
                };
                return(indicateReferredTo);
            }
Esempio n. 6
0
 /// <summary>
 /// Binds an EntityReferencer, generally a Pronoun or PronounPhrase to refer to the RelativePronoun.
 /// </summary>
 /// <param name="referencer">The EntityReferency to Bind.</param>
 public void BindReferencer(IReferencer referencer)
 {
     referencers = referencers.Add(referencer);
     referencer.BindAsReferringTo(this);
 }
Esempio n. 7
0
 /// <summary>
 /// Binds another IReferencer, generally another Pronoun but possibly a PronounPhrase, to refer to the Pronoun.
 /// </summary>
 /// <param name="referencer">An IReferencer which will be bound to refer to the Pronoun.</param>
 public virtual void BindReferencer(IReferencer referencer)
 {
     boundPronouns.Add(referencer);
     referencer.BindAsReferringTo(new AggregateEntity(this, this.RefersTo));
 }
Esempio n. 8
0
 public void BindReferencer(IReferencer referencer)
 {
     boundPronouns.Add(referencer);
 }
Esempio n. 9
0
 /// <summary>
 /// Removes from the stored content a single value indicated by an <code>IReferencer</code>.
 /// </summary>
 /// <returns>Indicates if the removal was the successful</returns>
 public static bool Unregister(IReferencer referencer)
 {
     return(referencers.Remove(referencer.Token) && Unregister(referencer.Token));
 }
Esempio n. 10
0
 /// <summary>
 /// Binds the <see cref="IReferencer"/> as referencing this.
 /// </summary>
 /// <param name="referencer">The <see cref="IReferencer"/> to which to bind.</param>
 public override void BindReferencer(IReferencer referencer)
 {
     base.BindReferencer(referencer);
     referencer.BindAsReferringTo(this.RefersTo);
 }