Beispiel #1
0
 public TResult Apply <TCase, TResult>(Predicate <TCase> accumulated, ILexical element, Func <TCase, TResult> apply) where TCase : class, ILexical
 {
     if (accumulated.Satifies(element))
     {
         return(apply(element as TCase));
     }
     return(default);
Beispiel #2
0
 public static ILexicalContextmenu Create(this ILexical lexical)
 {
     Validate.NotNull(lexical, nameof(lexical));
     return(lexical.Match()
            .Case((IReferencer r) => CreateForReferencer(r))
            .Case((IVerbal v) => CreateForVerbal(v))
            .Result());
 }
Beispiel #3
0
        /// <summary>
        /// Gets common properties serialized for all lexical types.
        /// </summary>
        /// <param name="element">The element whose properties are to be serialized.</param>
        /// <returns>The common properties serialized for all lexical types.</returns>
        private static IEnumerable <JProperty> GetCommonProperties(ILexical element)
        {
            yield return(new JProperty("text", element.Text));

            yield return(new JProperty("name", ElementNameMappingProvider[element]));

            yield return(new JProperty("weight", element.Weight));

            yield return(new JProperty("metaWeight", element.MetaWeight));
        }
Beispiel #4
0
 private static IEnumerable <JProperty> GetRoleIndependentProperties(ILexical element)
 {
     foreach (var property in GetCommonProperties(element))
     {
         yield return(property);
     }
     foreach (var property in GetStructuralProperties(element))
     {
         yield return(property);
     }
 }
Beispiel #5
0
        static void Test(ILexical value)
        {
            var pred = Verbal.Combine(When(true)).Combine(Text("dogged")).Combine(When(true));
            var prec = Verbal
                       & When(true)
                       & "dogged"
                       & When(x => x.Text == "true")
                       & "abc"
                       & When(x => true);
            var applicator  = new Applicator();
            var applicator2 = new Applicator <IVerbal, IEntity>();

            var res = applicator.Apply(pred, value, v => v);
            var rec = applicator.Apply(prec, value, v => v.Subjects);

            //var red = prec | applicator2 | (v => v.AggregateDirectObject);

            var ree = applicator2.SetTarget(value)
                      | Verbal & When(value.Text == "true") & Text("")
                      | (v => v.AggregateDirectObject)
                      | Verbal & Text("dogged")
                      | (x => x.AggregateDirectObject);
        }
Beispiel #6
0
 /// <summary>
 /// Binds an ILexical construct as the object of the Preposition.
 /// Lexical constructs include word, Phrase, and Clause Types.
 /// </summary>
 /// <param name="prepositionalObject">The ILexical construct as the object of the Preposition.</param>
 public void BindObject(ILexical prepositionalObject)
 {
     BoundObject = prepositionalObject;
 }
Beispiel #7
0
 protected virtual Func <bool> ToFunc(ILexical element) => () => Satifies(element);
Beispiel #8
0
 public static int GetSerializationId(this ILexical element)
 {
     Validate.NotNull(element, nameof(element));
     return(IdCache.GetOrAdd(element, System.Threading.Interlocked.Increment(ref idGenerator)));
 }
Beispiel #9
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);
Beispiel #10
0
 public override bool Test(ILexical lexical) => Boolean;
Beispiel #11
0
 private static IEnumerable <JProperty> GetStructuralProperties(ILexical element) =>
 from result in element.Match()
 .Case((Phrase p) => new JProperty("words", p.Words.ToJArray()))
 .Case((Clause c) => new JProperty("phrases", c.Phrases.ToJArray()))
 select result;
Beispiel #12
0
 /// <summary>
 /// Creates a Newtonsoft.Linq.JObject representation of the lexical.
 /// </summary>
 /// <param name="lexical">The source entity.</param>
 /// <returns>A Newtonsoft.Linq.JObject representation of the lexical.</returns>
 public static JObject ToJObject(this ILexical lexical) => lexical.Match()
 .Case((IEntity e) => e.ToJObject())
 .Case((IVerbal v) => v.ToJObject())
 .Case((IAdverbial a) => a.ToJObject())
 .Result(new JObject(GetRoleIndependentProperties(lexical)));
Beispiel #13
0
 public abstract bool Test(ILexical lexical);
Beispiel #14
0
 public Pattern(ILexical lexical)
 {
     Lexical = lexical;
 }
Beispiel #15
0
 public override bool Test(ILexical lexical) => test(lexical);
Beispiel #16
0
 protected override Func <bool> ToFunc(ILexical element) => () => Satifies(element);
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the InvalidStateTransitionException with a message indicating the state where the error occurred and the ILexical instance which caused the error.
 /// </summary>
 /// <param name="stateName">The number representing the State where the error occurred.</param>
 /// <param name="errorOn">The ILeixcal instance which caused the error.</param>
 public InvalidStateTransitionException(string stateName, ILexical errorOn)
     : base($"Invalid Transition\nAt State {stateName}\nOn {errorOn}")
 {
 }
Beispiel #18
0
 public override bool Test(ILexical lexical) => lexical is T;