public virtual void InterruptAndJoinPool(IExecutorService exec, TimeSpan waitTime) { OnJoinPool(exec, true); exec.ShutdownNow(); Assert.IsTrue(exec.AwaitTermination(waitTime)); }
public virtual void JoinPool(IExecutorService exec, TimeSpan waitTime) { OnJoinPool(exec, false); exec.Shutdown(); Assert.IsTrue(exec.AwaitTermination(waitTime)); }
/// <summary>An entry method for annotating standard in with OpenIE extractions.</summary> /// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public static void Main(string[] args) { // Parse the arguments Properties props = StringUtils.ArgsToProperties(args, new _Dictionary_667()); ArgumentParser.FillOptions(new Type[] { typeof(Edu.Stanford.Nlp.Naturalli.OpenIE), typeof(ArgumentParser) }, props); AtomicInteger exceptionCount = new AtomicInteger(0); IExecutorService exec = Executors.NewFixedThreadPool(ArgumentParser.threads); // Parse the files to process string[] filesToProcess; if (Filelist != null) { filesToProcess = IOUtils.LinesFromFile(Filelist.GetPath()).Stream().Map(null).Map(null).Map(null).ToArray(null); } else { if (!string.Empty.Equals(props.GetProperty(string.Empty, string.Empty))) { filesToProcess = props.GetProperty(string.Empty, string.Empty).Split("\\s+"); } else { filesToProcess = new string[0]; } } // Tweak the arguments if (string.Empty.Equals(props.GetProperty("annotators", string.Empty))) { if (!Sharpen.Runtime.EqualsIgnoreCase("false", props.GetProperty("resolve_coref", props.GetProperty("openie.resolve_coref", "false")))) { props.SetProperty("coref.md.type", "dep"); // so we don't need the `parse` annotator props.SetProperty("coref.mode", "statistical"); // explicitly ask for scoref props.SetProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,ner,mention,coref,natlog,openie"); } else { props.SetProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie"); } } if (string.Empty.Equals(props.GetProperty("depparse.extradependencies", string.Empty))) { props.SetProperty("depparse.extradependencies", "ref_only_uncollapsed"); } if (string.Empty.Equals(props.GetProperty("parse.extradependencies", string.Empty))) { props.SetProperty("parse.extradependencies", "ref_only_uncollapsed"); } if (string.Empty.Equals(props.GetProperty("tokenize.class", string.Empty))) { props.SetProperty("tokenize.class", "PTBTokenizer"); } if (string.Empty.Equals(props.GetProperty("tokenize.language", string.Empty))) { props.SetProperty("tokenize.language", "en"); } // Tweak properties for console mode. // In particular, in this mode we can assume every line of standard in is a new sentence. if (filesToProcess.Length == 0 && string.Empty.Equals(props.GetProperty("ssplit.isOneSentence", string.Empty))) { props.SetProperty("ssplit.isOneSentence", "true"); } // Some error checks on the arguments if (!props.GetProperty("annotators").ToLower().Contains("openie")) { log.Error("If you specify custom annotators, you must at least include 'openie'"); System.Environment.Exit(1); } // Copy properties that are missing the 'openie' prefix new HashSet <object>(props.Keys).Stream().Filter(null).ForEach(null); // Create the pipeline StanfordCoreNLP pipeline = new StanfordCoreNLP(props); // Run OpenIE if (filesToProcess.Length == 0) { // Running from stdin; one document per line. log.Info("Processing from stdin. Enter one sentence per line."); Scanner scanner = new Scanner(Runtime.@in); string line; try { line = scanner.NextLine(); } catch (NoSuchElementException) { log.Info("No lines found on standard in"); return; } while (line != null) { ProcessDocument(pipeline, "stdin", line); try { line = scanner.NextLine(); } catch (NoSuchElementException) { return; } } } else { // Running from file parameters. // Make sure we can read all the files in the queue. // This will prevent a nasty surprise 10 hours into a running job... foreach (string file in filesToProcess) { if (!new File(file).Exists() || !new File(file).CanRead()) { log.Error("Cannot read file (or file does not exist: '" + file + '\''); } } // Actually process the files. foreach (string file_1 in filesToProcess) { log.Info("Processing file: " + file_1); if (ArgumentParser.threads > 1) { // Multi-threaded: submit a job to run string fileToSubmit = file_1; exec.Submit(null); } else { // Single-threaded: just run the job ProcessDocument(pipeline, file_1, IOUtils.SlurpFile(new File(file_1))); } } } // Exit exec.Shutdown(); log.Info("All files have been queued; awaiting termination..."); exec.AwaitTermination(long.MaxValue, TimeUnit.Seconds); log.Info("DONE processing files. " + exceptionCount.Get() + " exceptions encountered."); System.Environment.Exit(exceptionCount.Get()); }
public virtual bool AwaitTermination(TimeSpan duration) { return(_executorService.AwaitTermination(duration)); }
public void Dispose() { _threadPool.Shutdown(); _threadPool.AwaitTermination(new TimeSpan(0, 0, 10)); }