public void TestAddSuggestionGetSuggestionFuzzy() { Client cl = GetClient(); Suggestion suggestion = Suggestion.Builder.String("TOPIC OF WORDS").Score(1).Build(); // test can add a suggestion string Assert.True(cl.AddSuggestion(suggestion, true) > 0, $"{suggestion} insert should of returned at least 1"); // test that the partial part of that string will be returned using fuzzy //Assert.Equal(suggestion.ToString() + " suppose to be returned", suggestion, cl.GetSuggestion(suggestion.String.Substring(0, 3), SuggestionOptions.GetBuilder().Build()).get(0)); Assert.Equal(suggestion.ToString(), cl.GetSuggestions(suggestion.String.Substring(0, 3), SuggestionOptions.Builder.Build())[0].ToString()); }
public void TestAddSuggestionGetSuggestion() { Client cl = GetClient(); Suggestion suggestion = Suggestion.Builder.String("ANOTHER_WORD").Score(1).Build(); Suggestion noMatch = Suggestion.Builder.String("_WORD MISSED").Score(1).Build(); Assert.True(cl.AddSuggestion(suggestion, false) > 0, $"{suggestion.ToString()} should of inserted at least 1"); Assert.True(cl.AddSuggestion(noMatch, false) > 0, $"{noMatch.ToString()} should of inserted at least 1"); // test that with a partial part of that string will have the entire word returned SuggestionOptions.builder().build() Assert.Single(cl.GetSuggestions(suggestion.String.Substring(0, 3), SuggestionOptions.Builder.Fuzzy().Build())); // turn off fuzzy start at second word no hit Assert.Empty(cl.GetSuggestions(noMatch.String.Substring(1, 6), SuggestionOptions.Builder.Build())); // my attempt to trigger the fuzzy by 1 character Assert.Single(cl.GetSuggestions(noMatch.String.Substring(1, 6), SuggestionOptions.Builder.Fuzzy().Build())); }
public void TestAddSuggestionGetSuggestionPayloadScores() { Client cl = GetClient(); Suggestion suggestion = Suggestion.Builder.String("COUNT_ME TOO").Payload("PAYLOADS ROCK ").Score(0.2).Build(); Assert.True(cl.AddSuggestion(suggestion, false) > 0, $"{suggestion.ToString()} insert should of at least returned 1"); Assert.True(cl.AddSuggestion(suggestion.ToBuilder().String("COUNT").Payload("My PAYLOAD is better").Build(), false) > 1, "Count single added should return more than 1"); Assert.True(cl.AddSuggestion(suggestion.ToBuilder().String("COUNT_ANOTHER").Score(1).Payload(null).Build(), false) > 1, "Count single added should return more than 1"); Suggestion noScoreOrPayload = Suggestion.Builder.String("COUNT NO PAYLOAD OR COUNT").Build(); Assert.True(cl.AddSuggestion(noScoreOrPayload, true) > 1, "Count single added should return more than 1"); var payloads = cl.GetSuggestions(suggestion.String.Substring(0, 3), SuggestionOptions.Builder.With(WithOptions.PayloadsAndScores).Build()); Assert.Equal(4, payloads.Length); Assert.True(payloads[2].Payload.Length > 0); Assert.True(payloads[1].Score < .299); }
public bool acceptSuggestion(Suggestion sg) { if (visEl != null) { //update weights in Suggester this.visualiserSuggester.retrieveSuggestion(sg.SuggestionString, "ACCEPT"); if (sg.RHS.Equals(visEl.Data.Name))// map to Visual element { AbstractTreeLatticeNode atln = sourceASTL.getAbstractNodeAtAddress(sg.LHS); if (atln != null) { XmlNode tx = atln.ToXML(); TreeViewViewModel tv = new TreeViewViewModel(tx); visEl.processVisual_TreeNodeDrop(tv.Root, atln.Address); //like dropping a TreeNode on visEl reportMessage("Suggestion \"" + sg.ToString() + "\" applied", ReportIcon.OK); return true; } } else //map to internal elements { AbstractLattice sourceLattice = new AbstractLattice(visEl.ReverseData); AbstractTreeLatticeNode lownode = sourceLattice.Root.findInChildrenByName(sg.LHS); //MessageBox.Show("Source: " + sg.LHS); if (lownode != null) { string lhs = visEl.abstractTree.findRelativeAddress(sourceLattice.Root, lownode); if (!String.IsNullOrEmpty(lhs)) { string rhs = sg.RHS; //if (rhs.StartsWith(visEl.abstractTree.Root.Name)) // rhs = rhs.Substring(visEl.abstractTree.Root.Name.Length+1); //MessageBox.Show("in sugg\n\nSource: " + lhs + "\nTarget: " + rhs); XmlNode tx = sourceLattice.Root.ToXML(); TreeViewViewModel tv = new TreeViewViewModel(tx); TreeNodeViewModel tn = tv.findInTreeByName(sg.LHS); if (tn != null)//which should be //MessageBox.Show("in sugg: " + tv.Root.ToXML().OuterXml); if (visEl.processElement_TreeNodeDrop(lhs, rhs, tn) == true) {//like dropping a tree node on element of the list reportMessage("Suggestion \"" + sg.ToString() + "\" applied", ReportIcon.OK); return true; } //MessageBox.Show("in sugg\n\n"+visEl.templateVM.TemplateXmlNode.OuterXml + "\n\n" + visEl.templateVMR.TemplateXmlNode.OuterXml); } return false; } } reportMessage("Could not find suggestion in source model", ReportIcon.Error); return false; } else//else will never happen { reportMessage("No visual element to apply suggestions to", ReportIcon.Error); return false; } }
public void PickSuggestion(Suggestion suggestion) { Debug.Log("Suggestion Get: " + suggestion.ToString()); Suggestion = suggestion; HasSuggested = true; }