public void Init(Dictionary <string, object> parameters) { intent = (IRuntimeStorage)parameters["intent"]; shared = (Dictionary <string, object>)parameters["shared"]; libraries = new List <string>(); if (parameters.ContainsKey("library")) { libraries.Add((string)parameters["library"]); } try{ ptypeUtil = new PtypeSerializationUtility(); List <Ptype> lib = ptypeUtil.LoadPtypes(intent); shared[SHARED_PTYPES_KEY] = lib; this.featureTree = FeatureTree.FeatureTree.BuildTree(GetFeatures(lib)); }catch (Exception e) { Console.Error.WriteLine(e.StackTrace); } }
public void AddPtypes(string library, IEnumerable <Ptype> ptypesadded) { PrototypeItems.RaiseListChangedEvents = false; foreach (Ptype ptype in ptypesadded) { ViewablePrototypeItem prev = PrototypeItems.FirstOrDefault((i) => i.Guid.Equals(ptype.Id)); var examples = PtypeSerializationUtility.GetTrainingExamples(library, ptype.Id); if (prev == null) { PrototypeItems.Insert(0, new ViewablePrototypeItem(ptype, library, examples.Positives, examples.Negatives)); } else { int index = PrototypeItems.IndexOf(prev); PrototypeItems.Remove(prev); PrototypeItems.Insert(index, new ViewablePrototypeItem(ptype, library, examples.Positives, examples.Negatives)); } } PrototypeItems.RaiseListChangedEvents = true; PrototypeItems.ResetBindings(); }
public void SetProperties(Tree node, Tree root, Bitmap wholeScreenshot, string ptypeLib, PrefabInterpretationLogic interpLogic, Bitmap image = null, IEnumerable <string> annotationLibs = null) { Annotations.Clear(); AnnotationLibraries.Clear(); List <string> keys = new List <string>(node.GetTags().Select(kvp => kvp.Key)); foreach (string key in keys) { if (!key.Equals("ptype") && !key.Equals("invalidated")) { object attribute = node[key]; if (attribute == null) { attribute = ""; } AnnotationKeyValuePair annotation = new AnnotationKeyValuePair(key, attribute.ToString()); annotation.IsEditingChanged += new DependencyPropertyChangedEventHandler(annotation_IsEditingChanged); Annotations.Add(annotation); } } Node = node; if (node.HasTag("type")) { switch (node["type"].ToString()) { case "ptype": Ptype ptype = (Ptype)node["ptype"]; var exs = PtypeSerializationUtility.GetTrainingExamples(ptypeLib, ptype.Id); Prototype = new ViewablePrototypeItem(ptype, ptypeLib, exs.Positives, exs.Negatives, image); break; case "content": case "feature": Prototype = new ViewablePrototypeItem(null, ptypeLib, new List <ImageAnnotation>(), new List <ImageAnnotation>(), image); break; default: break; } } SetAnnotationLibraries(annotationLibs); StaticMetadata = "x=" + node.Left + ", y=" + node.Top + ", width=" + node.Width + ", height=" + node.Height; NodePath = PathDescriptor.GetPath(node, root); if (image != null) { //string bitmapid = wholeScreenshot.GetHashCode().ToString(); //var annotations = interpLogic.GetAnnotationsMatchingNode(node, root, bitmapid); //string annotationsStr = "[\n"; //foreach (string lib in annotations.Keys) //{ // foreach (IAnnotation ia in annotations[lib]) // { // annotationsStr += "{\"library\" : \"" + lib + "\"\n"; // annotationsStr += "\"id\" : \"" + ia.Id + "\"\n"; // annotationsStr += ", \"data\"" + JsonConvert.SerializeObject(ia.Data) + "\n"; // annotationsStr += "}"; // annotationsStr += ","; // } //} //annotationsStr.Remove(annotationsStr.Length - 1); //annotationsStr += "\n]"; //AnnotationValueBox.Text = annotationsStr; } }