public AndPredicate(TextPredicate a, TextPredicate b) { this.components = new List <TextPredicate>() { a, b }; }
public string ConvertToString(TextPredicate predicate) { ContainsPhrase_Predicate contains = predicate as ContainsPhrase_Predicate; if (contains != null) { return(this.ConvertToString(contains)); } AndPredicate and = predicate as AndPredicate; if (and != null) { return(this.ConvertToString(and)); } OrPredicate or = predicate as OrPredicate; if (or != null) { return(this.ConvertToString(or)); } NotPredicate not = predicate as NotPredicate; if (not != null) { return(this.ConvertToString(not)); } throw new Exception("Unrecognized predicate: " + predicate); }
public TextRule ReadScoringRule(XmlNode nodeRepresentation) { TextPredicate criteria = null; double score = 0; foreach (XmlNode child in nodeRepresentation.ChildNodes) { if (child.Name == ScoringRulePredicate_Tag) { foreach (XmlNode grandchild in child.ChildNodes) { criteria = this.ReadTextPredicate(grandchild); continue; } } if (child.Name == this.ScoreTag) { score = this.ReadDouble(child); continue; } } TextRule rule = new TextRule(criteria, score); return(rule); }
private TextPredicate getPendingChildPredicate() { if (this.openPredicates.Count > 0) { TextPredicate predicate = this.openPredicates.Last(); this.openPredicates.RemoveAt(this.openPredicates.Count - 1); return(predicate); } return(null); }
public NotPredicate Read_NotPredicate(XmlNode nodeRepresentation) { NotPredicate predicate = new NotPredicate(); foreach (XmlNode childNode in nodeRepresentation.ChildNodes) { TextPredicate child = this.ReadTextPredicate(childNode); predicate.Child = child;; } return(predicate); }
public OrPredicate Read_OrPredicate(XmlNode nodeRepresentation) { OrPredicate predicate = new OrPredicate(); foreach (XmlNode childNode in nodeRepresentation.ChildNodes) { TextPredicate child = this.ReadTextPredicate(childNode); predicate.AddChild(child); } return(predicate); }
private void closeParen() { if (this.openPredicates.Count > 0) { // Remove this pending child and attach it to its parent. // This indicates that from now on we won't make any more changes to this child. // Instead, any subsequent changes will apply to its parent. TextPredicate predicate = this.openPredicates.Last(); this.openPredicates.RemoveAt(this.openPredicates.Count - 1); this.addChild(predicate); } }
private void AndButton_Clicked(object sender, EventArgs e) { AndPredicate and = new AndPredicate(); TextPredicate child = this.getPendingChildPredicate(); if (child != null) { and.AddChild(child); this.openPredicates.Add(and); } else { this.addChild(and); } this.updateLayout(); }
private void OrButton_Clicked(object sender, EventArgs e) { OrPredicate or = new OrPredicate(); TextPredicate child = this.getPendingChildPredicate(); if (child != null) { or.AddChild(child); this.openPredicates.Add(or); } else { this.addChild(or); } this.updateLayout(); }
// add the given predicate as a child of the leafmost existing predicate private void addChild(TextPredicate predicate) { if (this.openPredicates.Count < 1) { // no predicates already exist, this one becomes the primary one this.openPredicates.Add(predicate); return; } TextPredicate last = this.openPredicates.Last(); OrPredicate or = last as OrPredicate; if (or != null) { // we have a pending 'or'; add it here or.AddChild(predicate); return; } AndPredicate and = last as AndPredicate; if (and != null) { // we have a pending 'and'; add it here and.AddChild(predicate); return; } NotPredicate not = last as NotPredicate; if (not != null) { // we have a pending 'not'; add it here not.Child = predicate; return; } if (last == null) { // We have an empty spot to add this predicate to // This user is expected to attach this to a parent later // If the user doesn't attach this to a parent later, we will for them this.openPredicates.RemoveAt(this.openPredicates.Count - 1); this.openPredicates.Add(predicate); return; } // error; do nothing }
public TextRule GetRule() { TextPredicate predicate = this.getPredicate(); if (predicate == null) { return(null); } double score = this.getScore(); if (score == 0) { return(null); } this.openPredicates.Clear(); this.newWord_box.Text = ""; this.scoreBox.Text = ""; TextRule rule = new TextRule(predicate, score); return(rule); }
public TextRule(TextPredicate criteria, double score) { this.criteria = criteria; this.score = score; }
public NotPredicate(TextPredicate child) { this.child = child; }
public void AddChild(TextPredicate child) { this.components.Add(child); }