internal SmartsAtomAtomMapFilter(IAtomContainer query, IAtomContainer target) { IMultiDictionary <int, int> reactInvMap = null; IMultiDictionary <int, int> prodInvMap = null; this.target = target; // transform query maps in to matchable data-structure int numAtoms = query.Atoms.Count; for (int idx = 0; idx < numAtoms; idx++) { IAtom atom = query.Atoms[idx]; int mapidx = Mapidx(atom); if (mapidx == 0) { continue; } switch (Role(atom)) { case ReactionRole.Reactant: if (reactInvMap == null) { reactInvMap = new MultiDictionary <int, int>(); } reactInvMap.Add(mapidx, idx); break; case ReactionRole.Product: if (prodInvMap == null) { prodInvMap = new MultiDictionary <int, int>(); } prodInvMap.Add(mapidx, idx); break; } } if (reactInvMap != null && prodInvMap != null) { foreach (var e in reactInvMap) { int[] reacMaps = e.Value.ToArray(); int[] prodMaps = prodInvMap[e.Key].ToArray(); if (prodMaps.Length == 0) { continue; // unpaired } mapped.Add(new MappedPairs(reacMaps, prodMaps)); } } }
public JmdicReader(ILogWriter log, string path, IMultiDictionary dictionary) { _log = log; Stopwatch sw = new Stopwatch(); sw.Start(); _log.Debug($"Loading {path}"); _dictionary = dictionary; _document = new XmlDocument(); _document.Load(path); _log.Debug($"Indexing {path}"); CreateDictionary(); sw.Stop(); _log.Debug($"done in {sw.ElapsedMilliseconds}ms"); }
private static void PrintDictionary(IMultiDictionary <int, string> dictionary) { Console.WriteLine($"Dictionary Contains {dictionary.Count} values:"); Console.WriteLine($"Keys:"); foreach (var item in dictionary.Keys) { Console.Write($"{item} "); } Console.WriteLine(); Console.WriteLine($"Values:"); foreach (var item in dictionary.Values) { Console.Write($"{item} "); } Console.WriteLine("\n"); }
public JmdicFastReader( ILogWriter log, IResourceLocator resourceLocator, IMultiDictionary dictionary) { _log = log; _path = Path.Combine(resourceLocator.ResourcesPath, "data", "dic", "JMdict_e"); _dictionary = dictionary; Stopwatch sw = new Stopwatch(); sw.Start(); _log.Debug($"Indexing {_path}"); ReadDictionary(); sw.Stop(); _log.Debug($"done in {sw.ElapsedMilliseconds}ms"); }
IEnumerable <T> DependencyTree <T, U>(IMultiDictionary <T, U> rel, T startItem) { HashSet <T> visited = new HashSet <T>(); Stack <T> pendingItems = new Stack <T>(); pendingItems.Push(startItem); while (pendingItems.Count > 0) { T currentItem = pendingItems.Pop(); if (rel.ContainsKey(currentItem)) { foreach (T depend in rel[currentItem].Cast <T>()) { if (!visited.Contains(depend)) { visited.Add(depend); pendingItems.Push(depend); yield return(depend); } } } } }
public MultiDictionaryGraph() { items = new TMultiDictionary(); edges = new TCollection(); }