Esempio n. 1
0
        protected bool Filter(Tweet tweet)
        {
            if (Predicates.Count() == 0)
            {
                return(true);
            }

            if (IsOrSearch.Value)
            {
                return(Predicates.Any(predicate => predicate(tweet)));
            }
            else
            {
                return(Predicates.All(predicate => predicate(tweet)));
            }
        }
        public void Evaluate()
        {
            if (Evaluated) return;

            foreach (var predicate in Predicates)
            {
                if (predicate.GetMissingVariableId() != null) continue;

                predicate.Evaluate();

                if (predicate.Result) continue;

                Result = false;
                Evaluated = true;
                return;
            }

            if (Predicates.Any(_ => _.Evaluated && !_.Result) || Predicates.All(_ => _.Evaluated))
            {
                Result = true;
                Evaluated = true;
            }
        }
 /// <summary>
 /// Evaluate this predicate for the given loc.
 /// </summary>
 public override bool Evaluate(ILoc loc)
 {
     return(Predicates.All(x => x.Evaluate(loc)));
 }
Esempio n. 4
0
        public List <string> ToTokenList(string format, IFormatProvider formatProvider)
        {
            List <string> sb = new List <string>();

            //Degenerate case
            if (nullOrSymbols != null)
            {
                sb.Add(nullOrSymbols.Text);
                return(sb);
            }

            if (tagConjunction != null)
            {
                sb.AddIfNeeded("|", format);
                if (format == "html")
                {
                    sb.Add(HtmlTagHelper.SpanWrap("conjunction", tagConjunction.Text));
                }
                else
                {
                    sb.Add(tagConjunction.Text);
                }

                sb.AddIfNeeded("|", format);
            }

            //TODO Vocative sentences
            //[chain]o[!.?]
            if (degenerateVocative != null)
            {
                sb.AddRange(degenerateVocative.ToTokenList(format, formatProvider));
                sb.Add(Particles.o.ToString(format, formatProvider)); //Seems dodgy. Why not a property of the chain or sentence?
            }
            else if (degenerateFragment != null)
            {
                sb.AddRange(degenerateFragment.ToTokenList(format, formatProvider));
                sb.Add(Particles.la.ToString(format, formatProvider));
            }
            else if (degenerateExclamation != null)
            {
                sb.AddRange(degenerateExclamation.ToTokenList(format, formatProvider));
            }
            else
            {
                if (HeadVocatives != null)
                {
                    foreach (Vocative vocative in HeadVocatives)
                    {
                        sb.AddIfNeeded("{", format);
                        sb.AddRange(vocative.ToTokenList(format, formatProvider));
                        sb.Add(Particles.o.ToString(format, formatProvider));
                        //Do we really need a comma? Nope. Not yet.
                        sb.AddIfNeeded("}", format);
                    }
                }

                if (LaFragment != null)
                {
                    foreach (Fragment chain in LaFragment.ToArray().Reverse())
                    {
                        sb.AddIfNeeded("{", format);
                        sb.AddRange(chain.ToTokenList(format, formatProvider));
                        sb.Add(Particles.la.ToString(format, formatProvider));
                        sb.AddIfNeeded("}", format);
                    }
                }

                //Unless it is an array, delegate to member ToString();
                if (subjects != null)
                {
                    if (isHortative)
                    {
                        sb.Add(Particles.o.ToString(format, formatProvider));
                    }

                    //Should only happen for imperatives
                    sb.AddIfNeeded("[", format);

                    //HACK: Remove dummy subject. jan Sanwan
                    string likelySubject = subjects == null ? "[NULL]" : subjects.ToString(format, formatProvider);
                    bool   isDummy       = likelySubject.ContainsCheck("jan") && likelySubject.ContainsCheck("Sanwan");
                    if (!isDummy)
                    {
                        sb.Add(likelySubject);
                    }
                    //subjects.Select(x => x == null ? "[NULL]" : x.ToString(format, formatProvider)), format, formatProvider, false);
                    sb.AddIfNeeded("]", format);
                }
                else
                {
                    //Not surprising if it is an imperative.
                    if (Predicates.All(x => x.Particle.Text != Particles.o.Text))
                    {
                        Console.WriteLine("This was surprising.. no subjects and AFAIK, this is not an imperative of any sort.");
                    }
                }

                sb.AddIfNeeded("<", format);
                bool suppressFirstLi = false;
                if (subjects != null)
                {
                    string test = subjects.ToString("g", formatProvider);
                    if (test == "mi" || test == "sina")
                    {
                        suppressFirstLi = true;
                    }
                }

                sb.AddRange(Predicates.ToTokenList(format, formatProvider, suppressFirstLi));

                sb.AddIfNeeded(">", format);
            }


            if (tagQuestion != null)
            {
                if (format == "html")
                {
                    sb.Add(HtmlTagHelper.SpanWrap("conjunction", tagQuestion.Text));
                }
                else
                {
                    sb.AddIfNeeded("|", format);
                    sb.Add(tagQuestion.Text);
                    sb.AddIfNeeded("|", format);
                }
            }
            return(sb);
        }
Esempio n. 5
0
 /// <summary>Check if all predicates are true</summary>
 public bool CheckAll(T item)
 {
     return(Predicates.All(predicate => predicate(item)));
 }
 public bool IsValid()
 {
     return Predicates.All(predicate => predicate.GetMissingVariableId() == null);
 }