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);
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()); }
/// <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)); }
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); } }
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); }
/// <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; }
protected virtual Func <bool> ToFunc(ILexical element) => () => Satifies(element);
public static int GetSerializationId(this ILexical element) { Validate.NotNull(element, nameof(element)); return(IdCache.GetOrAdd(element, System.Threading.Interlocked.Increment(ref idGenerator))); }
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);
public override bool Test(ILexical lexical) => Boolean;
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;
/// <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)));
public abstract bool Test(ILexical lexical);
public Pattern(ILexical lexical) { Lexical = lexical; }
public override bool Test(ILexical lexical) => test(lexical);
protected override Func <bool> ToFunc(ILexical element) => () => Satifies(element);
/// <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}") { }
public override bool Test(ILexical lexical) => lexical is T;