public static void Add(SetOfPrimitives data) { if (samples == null) { samples = new List<SetOfPrimitives>(); } samples.Add(data); }
public static void checkRules() { if ((samples == null) || (samples.Count < 1)) { return; } else if (samples.Count == 1) { if (solution != null) solution.Clear(); solution = samples[0]; return; } // Always create a new solution based on the gestures solution = new SetOfPrimitives(); // All the samples will be compared to the first as // the anti-unification will look for all the elements that // are common through all the samples SetOfPrimitives firstSample = samples[0]; foreach (PrimitiveData primitive in firstSample) { checkProportionforPrimitive(primitive); PrimitiveData antiUnifiedString = checkStringListPrimitives(primitive); if (antiUnifiedString != null) solution.Add(antiUnifiedString); PrimitiveData antiUnifiedComplex = checkValueComplexPrimitives(primitive); if (antiUnifiedComplex != null) solution.Add(antiUnifiedComplex); } }
private static List<String> PrimitiveToGDL(SetOfPrimitives primitives) { if (primitives == null) throw new ArgumentNullException(); string name = "";// "name:" + GestureName + Environment.NewLine; List<String> result = new List<String>(); const string SPACE = " "; List<string> steps = new List<string>(); List<string> complexSteps = new List<string>(); int step = 1; IdComparer comparer = new IdComparer(); for (int i = 0; i < primitives.Count; i++) { if (primitives[i] == null) primitives[i] = new PrimitiveData(); } primitives.Sort(comparer); foreach (PrimitiveData primitive in primitives) { if ((primitive.ID.Count == 1)) // Simple primitives { if (primitive.ID[0] != step) { steps.Add("validate as step" + primitive.ID[0]); step++; } if (primitive.ListValue.Count == 0) { if (primitive.Value != 0) steps.Add(SPACE + primitive.Name + ":" + Math.Round(primitive.Value, 2)); else steps.Add(SPACE + primitive.Name); } else { steps.Add(SPACE + primitive.Name + ":" + string.Join(",", primitive.ListValue)); } } else { string primitiveID = primitive.IDtoString(); if (primitiveID != "") primitiveID = " " + primitiveID; if (primitive.ListValue.Count == 0) { complexSteps.Add(SPACE + primitive.Name + primitiveID + ":" + Math.Round(primitive.Value, 2)); } else { complexSteps.Add(SPACE + primitive.Name + primitiveID + ":" + string.Join(",", primitive.ListValue)); } } } if (step == 1) result.Insert(0, "validate"); else result.Insert(0, "validate as step1"); result.AddRange(steps); if (complexSteps.Count > 1) { if (step > 1) result.Add("validate"); result.AddRange(complexSteps); } result.Add("return" + Environment.NewLine + SPACE + "Touch points"); return result; }
private static SetOfPrimitives loadPrimitives(List<TouchPoint2> simplegestures, IEnumerable<IPrimitiveConditionData> primitives) { List<IPrimitiveConditionData> returnList; SetOfPrimitives output = new SetOfPrimitives(); foreach (IPrimitiveConditionData primitive in primitives) { returnList = null; IPrimitiveConditionValidator ruleValidator = GestureLanguageProcessor.GetPrimitiveConditionValidator(primitive); returnList = ruleValidator.GenerateRules(simplegestures); if (returnList != null) { int index = 1; foreach (IPrimitiveConditionData resultData in returnList) { if (resultData != null) { PrimitiveData primitiveData = new PrimitiveData(); if (primitive.isComplex()) { primitiveData.ID = getIDsFromGDL(resultData.ToGDL()); } else { primitiveData.IDadd(index++); } primitiveData.Name = getPrimitiveName(primitive); string strValue = getStrValueFromGDL(resultData.ToGDL()); double value; bool isDouble = double.TryParse(strValue, out value); if (isDouble) primitiveData.Value = value; else { int idx = strValue.IndexOf(","); if (idx >= 0) primitiveData.ListValue = new List<string>(strValue.Split(',')); else primitiveData.ListValue.Add(strValue); } output.Add(primitiveData); } else index++; } } } return output; }
/* Check a way so that the proportion: * Compares the data with all the data in the same gesture with the same name. * Find the alpha between the first found * add alpha to alphas * Then it has to do the same for all the other gestures */ private static PrimitiveData getPrimitiveWithSameName(PrimitiveData data, SetOfPrimitives gesture) { foreach (PrimitiveData result in gesture) { if ((data.Name == result.Name) && (data.IDcompare(result.ID))) return result; } return null; }
public static List<String> TouchPointsToGDL(ValidSetOfTouchPoints allpoints) { if (allpoints == null) return null; List<IPrimitiveConditionData> primitives; SetOfPrimitives setOfPrimitives = new SetOfPrimitives(); List<TouchPoint2> simplegestures = new List<TouchPoint2>(); primitives = GestureLanguageProcessor.GetAllPrimitives(); SetOfPrimitives sample = new SetOfPrimitives(); if ((allpoints.Count == 1) && (PointTranslator.BreakIntoSteps)) simplegestures = PointTranslator.FindLines(allpoints[0]); else { simplegestures = PointTranslator.analyzeTags(allpoints); simplegestures = PointTranslator.removeHandRedundancy(simplegestures); } //============================= var simplePrimitives = from p in primitives where p.isComplex() == false select p; var complexPrimitives = from p in primitives where p.isComplex() == true select p; sample.AddRange(loadPrimitives(simplegestures, simplePrimitives)); sample.AddRange(loadPrimitives(simplegestures, complexPrimitives)); Add(sample); return PrimitiveToGDL(sample); }