// TODO: when this method throws an exception (for whatever reason)
        // a waiting client might hang.  There should be some graceful
        // handling of that.
        /// <exception cref="System.IO.IOException"/>
        public virtual void HandleDependencies(string arg, OutputStream outStream, string commandArgs)
        {
            Tree tree = Parse(arg, false);

            if (tree == null)
            {
                return;
            }
            // TODO: this might throw an exception if the parser doesn't support dependencies.  Handle that cleaner?
            GrammaticalStructure          gs   = parser.GetTLPParams().GetGrammaticalStructure(tree, parser.TreebankLanguagePack().PunctuationWordRejectFilter(), parser.GetTLPParams().TypedDependencyHeadFinder());
            ICollection <TypedDependency> deps = null;

            switch (commandArgs.ToUpper())
            {
            case "COLLAPSED_TREE":
            {
                deps = gs.TypedDependenciesCollapsedTree();
                break;
            }

            default:
            {
                throw new NotSupportedException("Dependencies type not implemented: " + commandArgs);
            }
            }
            OutputStreamWriter osw = new OutputStreamWriter(outStream, "utf-8");

            foreach (TypedDependency dep in deps)
            {
                osw.Write(dep.ToString());
                osw.Write("\n");
            }
            osw.Flush();
        }
        // TODO: these booleans would be more readable as enums similar to Mode.
        // Then the arguments would make more sense
        public static SemanticGraph MakeFromTree(GrammaticalStructure gs, SemanticGraphFactory.Mode mode, GrammaticalStructure.Extras includeExtras, IPredicate <TypedDependency> filter)
        {
            ICollection <TypedDependency> deps;

            switch (mode)
            {
            case SemanticGraphFactory.Mode.Enhanced:
            {
                deps = gs.TypedDependenciesEnhanced();
                break;
            }

            case SemanticGraphFactory.Mode.EnhancedPlusPlus:
            {
                deps = gs.TypedDependenciesEnhancedPlusPlus();
                break;
            }

            case SemanticGraphFactory.Mode.CollapsedTree:
            {
                deps = gs.TypedDependenciesCollapsedTree();
                break;
            }

            case SemanticGraphFactory.Mode.Collapsed:
            {
                deps = gs.TypedDependenciesCollapsed(includeExtras);
                break;
            }

            case SemanticGraphFactory.Mode.Ccprocessed:
            {
                deps = gs.TypedDependenciesCCprocessed(includeExtras);
                break;
            }

            case SemanticGraphFactory.Mode.Basic:
            {
                deps = gs.TypedDependencies(includeExtras);
                break;
            }

            default:
            {
                throw new ArgumentException("Unknown mode " + mode);
            }
            }
            if (filter != null)
            {
                IList <TypedDependency> depsFiltered = Generics.NewArrayList();
                foreach (TypedDependency td in deps)
                {
                    if (filter.Test(td))
                    {
                        depsFiltered.Add(td);
                    }
                }
                deps = depsFiltered;
            }
            // there used to be an if clause that filtered out the case of empty
            // dependencies. However, I could not understand (or replicate) the error
            // it alluded to, and it led to empty dependency graphs for very short fragments,
            // which meant they were ignored by the RTE system. Changed. (pado)
            // See also the SemanticGraph constructor.
            //log.info(deps.toString());
            return(new SemanticGraph(deps));
        }