public static PatternsForEachToken GetPatternsInstance(Properties props, ConstantsAndVariables.PatternForEachTokenWay storePatsForEachToken) { storeWay = storePatsForEachToken; PatternsForEachToken p = null; switch (storePatsForEachToken) { case ConstantsAndVariables.PatternForEachTokenWay.Memory: { p = new PatternsForEachTokenInMemory(props); break; } case ConstantsAndVariables.PatternForEachTokenWay.Db: { p = new PatternsForEachTokenDB(props); break; } case ConstantsAndVariables.PatternForEachTokenWay.Lucene: { try { Type c = Sharpen.Runtime.GetType("edu.stanford.nlp.patterns.surface.PatternsForEachTokenLucene"); p = (PatternsForEachToken)c.GetDeclaredConstructor(typeof(Properties)).NewInstance(props); break; } catch (TypeLoadException) { throw new Exception("Lucene option is not distributed (license clash). Email us if you really want it."); } catch (ReflectiveOperationException e) { throw new Exception(e); } break; } } return(p); }
/// <summary>creates all patterns and saves them in the correct PatternsForEachToken* class appropriately</summary> /// <param name="sents"/> /// <param name="props"/> /// <param name="storePatsForEachTokenWay"/> public virtual void GetAllPatterns(IDictionary <string, DataInstance> sents, Properties props, ConstantsAndVariables.PatternForEachTokenWay storePatsForEachTokenWay) { // this.patternsForEachToken = new HashMap<String, Map<Integer, Triple<Set<Integer>, Set<Integer>, Set<Integer>>>>(); // this.patternsForEachToken = new HashMap<String, Map<Integer, Set<Integer>>>(); DateTime startDate = new DateTime(); IList <string> keyset = new List <string>(sents.Keys); int num; if (constVars.numThreads == 1) { num = keyset.Count; } else { num = keyset.Count / (constVars.numThreads); } IExecutorService executor = Executors.NewFixedThreadPool(constVars.numThreads); Redwood.Log(ConstantsAndVariables.extremedebug, "Computing all patterns. keyset size is " + keyset.Count + ". Assigning " + num + " values to each thread"); IList <IFuture <bool> > list = new List <IFuture <bool> >(); for (int i = 0; i < constVars.numThreads; i++) { int from = i * num; int to = -1; if (i == constVars.numThreads - 1) { to = keyset.Count; } else { to = Math.Min(keyset.Count, (i + 1) * num); } // // Redwood.log(ConstantsAndVariables.extremedebug, "assigning from " + i * num // + " till " + Math.min(keyset.size(), (i + 1) * num)); IList <string> ids = keyset.SubList(from, to); ICallable <bool> task = new CreatePatterns.CreatePatternsThread(this, sents, ids, props, storePatsForEachTokenWay); IFuture <bool> submit = executor.Submit(task); list.Add(submit); } // Now retrieve the result foreach (IFuture <bool> future in list) { try { future.Get(); } catch (Exception e) { //patternsForEachToken.putAll(future.get()); executor.ShutdownNow(); throw new Exception(e); } } executor.Shutdown(); DateTime endDate = new DateTime(); string timeTaken = GetPatternsFromDataMultiClass.ElapsedTime(startDate, endDate); Redwood.Log(Redwood.Dbg, "Done computing all patterns [" + timeTaken + "]"); }
public CreatePatternsThread(CreatePatterns <E> _enclosing, IDictionary <string, DataInstance> sents, IList <string> sentIds, Properties props, ConstantsAndVariables.PatternForEachTokenWay storePatsForEachToken) { this._enclosing = _enclosing; //return patternsForEachToken; // /** // * Returns null if using DB backed!! // * @return // */ // public Map<String, Map<Integer, Set<Integer>>> getPatternsForEachToken() { // return patternsForEachToken; // } //String label; // Class otherClass; //this.label = label; // this.otherClass = otherClass; this.sents = sents; this.sentIds = sentIds; this.patsForEach = PatternsForEachToken.GetPatternsInstance(props, storePatsForEachToken); }