public static string[] ParseStringArray(string x) { var result = new List<StringPair>(); var arrays = x.Split(','); foreach (var array in arrays) { var a = array.Split(';'); var b = new StringPair { name = a[0].Trim(), q = a.Length >= 2 ? a[1].Trim().ConvertToFloat(1, 0, 1) : 1 }; result.Add(b); } result.Sort((x1, x2) => (x1.q > x2.q ? 1 : -1)); return result.Select((xx) => (xx.name)).ToArray(); }
public int GetSimilarity(FuzzyString other) { var key = new StringPair(this.CleanString, other.CleanString); int value; if (!CachedComparisons.TryGetValue(key, out value)) { var similarity = SiftStringSimilarity.StringMetrics.SiftSimilarity(this.CleanString, other.CleanString); value = (int)(similarity * 100); CachedComparisons.Add(key, value); } return value; }
/// <summary> /// Deserialize XmlQueryStaticData object from a byte array. /// </summary> public XmlQueryStaticData(byte[] data, Type[] ebTypes) { MemoryStream dataStream = new MemoryStream(data, /*writable:*/false); XmlQueryDataReader dataReader = new XmlQueryDataReader(dataStream); int length; // Read a format version int formatVersion = dataReader.ReadInt32Encoded(); // Changes in the major part of version are not supported if ((formatVersion & ~0xff) > CurrentFormatVersion) throw new NotSupportedException(); // XmlWriterSettings defaultWriterSettings; _defaultWriterSettings = new XmlWriterSettings(dataReader); // IList<WhitespaceRule> whitespaceRules; length = dataReader.ReadInt32(); if (length != 0) { _whitespaceRules = new WhitespaceRule[length]; for (int idx = 0; idx < length; idx++) { _whitespaceRules[idx] = new WhitespaceRule(dataReader); } } // string[] names; length = dataReader.ReadInt32(); if (length != 0) { _names = new string[length]; for (int idx = 0; idx < length; idx++) { _names[idx] = dataReader.ReadString(); } } // StringPair[][] prefixMappingsList; length = dataReader.ReadInt32(); if (length != 0) { _prefixMappingsList = new StringPair[length][]; for (int idx = 0; idx < length; idx++) { int length2 = dataReader.ReadInt32(); _prefixMappingsList[idx] = new StringPair[length2]; for (int idx2 = 0; idx2 < length2; idx2++) { _prefixMappingsList[idx][idx2] = new StringPair(dataReader.ReadString(), dataReader.ReadString()); } } } // Int32Pair[] filters; length = dataReader.ReadInt32(); if (length != 0) { _filters = new Int32Pair[length]; for (int idx = 0; idx < length; idx++) { _filters[idx] = new Int32Pair(dataReader.ReadInt32Encoded(), dataReader.ReadInt32Encoded()); } } // XmlQueryType[] types; length = dataReader.ReadInt32(); if (length != 0) { _types = new XmlQueryType[length]; for (int idx = 0; idx < length; idx++) { _types[idx] = XmlQueryTypeFactory.Deserialize(dataReader); } } // XmlCollation[] collations; length = dataReader.ReadInt32(); if (length != 0) { _collations = new XmlCollation[length]; for (int idx = 0; idx < length; idx++) { _collations[idx] = new XmlCollation(dataReader); } } // string[] globalNames; length = dataReader.ReadInt32(); if (length != 0) { _globalNames = new string[length]; for (int idx = 0; idx < length; idx++) { _globalNames[idx] = dataReader.ReadString(); } } // EarlyBoundInfo[] earlyBound; length = dataReader.ReadInt32(); if (length != 0) { _earlyBound = new EarlyBoundInfo[length]; for (int idx = 0; idx < length; idx++) { _earlyBound[idx] = new EarlyBoundInfo(dataReader.ReadString(), ebTypes[idx]); } } Debug.Assert(formatVersion != CurrentFormatVersion || dataReader.Read() == -1, "Extra data at the end of the stream"); dataReader.Dispose(); }
/** * Looks up a name code from an (uri,local) pair. */ public int GetNameCode( string uri, string local ) { StringPair p = new StringPair(uri,local); object o; o = nameLiterals[p]; if(o!=null) return (int)o; p.set(uri,WILDCARD); o = nameLiterals[p]; if(o!=null) return (int)o; return defaultNameCode; }
void LoadTransitionGlyph(TextReader sr) { string id; int X, Y, width, height; LoadBounds (sr, out id, out X, out Y, out width, out height); string parentIdFrom = NextLine (sr); string parentIdTo = NextLine (sr); _EntityLinkRel [id] = new StringPair (parentIdFrom, parentIdTo); ITransitionGlyph glyph = _Factory.CreateTransition (id, new Rectangle (X, Y, width, height)); LoadGlyphCommon (sr, glyph); ITransitionGlyph trans = glyph; trans.Name = LoadText (sr, "NAME"); trans.EventSignal = LoadText (sr, "EVENT"); trans.GuardCondition = LoadText (sr, "GUARD"); trans.Action = LoadText (sr, "ACTION"); string transType = LoadText (sr, "TRANSITIONTYPE"); trans.TransitionType = (TransitionType) Enum.Parse (typeof (TransitionType), transType, true); trans.EventSource = LoadText (sr, "EVENTSOURCE"); trans.EventType = LoadText (sr, "EVENTTYPE", ""); string evalOrder = LoadText (sr, "EVALUATIONORDERPRIORITY"); trans.EvaluationOrderPriority = int.Parse (evalOrder); trans.IsInnerTransition = bool.Parse (NextLine (sr)); string timeoutExpression = LoadText (sr, "AFTERTIMEOUT", ""); // this needs to be here because AFTERTIMEOUT being replaced by TIMEOUTEXPRESSION timeoutExpression = ClearZeroTimeOut (timeoutExpression); timeoutExpression = LoadText (sr, "TIMEOUTEXPRESSION", timeoutExpression); timeoutExpression = ClearZeroTimeOut (timeoutExpression); trans.TimeOutExpression = timeoutExpression; BlankLine (sr); // blank line _GlyphLookup.Add (id, glyph); _Glyphs.Add (glyph); }
void LoadPortLinkGlyph(TextReader sr) { string id; int X, Y, width, height; LoadBounds (sr, out id, out X, out Y, out width, out height); string parentIdFrom = NextLine (sr); string parentIdTo = NextLine (sr); _EntityLinkRel [id] = new StringPair (parentIdFrom, parentIdTo); IPortLinkGlyph glyph = _Factory.CreatePortLink (id, new Rectangle (X, Y, width, height)); LoadGlyphCommon (sr, glyph); IPortLinkGlyph link = glyph; link.Name = LoadText (sr, "NAME"); link.FromPortName = LoadText (sr, "FROMPORTNAME", ""); link.ToPortName = LoadText (sr, "TOPORTNAME", ""); link.SendIndex = LoadText (sr, "SENDINDEX", ""); BlankLine (sr); // blank line _GlyphLookup.Add (id, glyph); _Glyphs.Add (glyph); }