Ejemplo n.º 1
0
        /// <summary><inheritDoc/></summary>
        /// <exception cref="Javax.Servlet.ServletException"/>
        /// <exception cref="System.IO.IOException"/>
        protected override void DoGet(IHttpServletRequest request, IHttpServletResponse response)
        {
            logger.Info("GET SPIED query from " + request.GetRemoteAddr());
            if (request.GetCharacterEncoding() == null)
            {
                request.SetCharacterEncoding("utf-8");
            }
            response.SetContentType("text/json; charset=UTF-8");
            PrintWriter @out = response.GetWriter();

            try
            {
                string raw       = request.GetParameter("q");
                string seedwords = request.GetParameter("seedwords");
                string model     = request.GetParameter("model");
                if (raw == null || string.Empty.Equals(raw))
                {
                    @out.Print("{\"okay\":false,\"reason\":\"No data provided\"}");
                }
                else
                {
                    Run(@out, raw, seedwords, model);
                }
            }
            catch (Exception t)
            {
                WriteError(t, @out, request.ToString());
            }
            @out.Close();
        }
Ejemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        private void AddResults(IHttpServletRequest request, IHttpServletResponse response)
        {
            string input = request.GetParameter("input");

            if (input == null)
            {
                return;
            }
            input = input.Trim();
            if (input.IsEmpty())
            {
                return;
            }
            PrintWriter @out = response.GetWriter();

            if (input.Length > MaximumQueryLength)
            {
                @out.Print("This query is too long.  If you want to run very long queries, please download and use our <a href=\"http://nlp.stanford.edu/software/CRF-NER.html\">publicly released distribution</a>.");
                return;
            }
            string outputFormat = request.GetParameter("outputFormat");

            if (outputFormat == null || outputFormat.Trim().IsEmpty())
            {
                outputFormat = this.format;
            }
            bool   preserveSpacing;
            string preserveSpacingStr = request.GetParameter("preserveSpacing");

            if (preserveSpacingStr == null || preserveSpacingStr.Trim().IsEmpty())
            {
                preserveSpacing = this.spacing;
            }
            else
            {
                preserveSpacingStr = preserveSpacingStr.Trim();
                preserveSpacing    = bool.ValueOf(preserveSpacingStr);
            }
            string classifier = request.GetParameter("classifier");

            if (classifier == null || classifier.Trim().IsEmpty())
            {
                classifier = this.defaultClassifier;
            }
            response.AddHeader("classifier", classifier);
            response.AddHeader("outputFormat", outputFormat);
            response.AddHeader("preserveSpacing", preserveSpacing.ToString());
            if (outputFormat.Equals("highlighted"))
            {
                OutputHighlighting(@out, ners[classifier], input);
            }
            else
            {
                @out.Print(StringEscapeUtils.EscapeHtml4(ners[classifier].ClassifyToString(input, outputFormat, preserveSpacing)));
            }
        }
Ejemplo n.º 3
0
        /// <summary><inheritDoc/></summary>
        /// <exception cref="Javax.Servlet.ServletException"/>
        /// <exception cref="System.IO.IOException"/>
        protected override void DoGet(IHttpServletRequest request, IHttpServletResponse response)
        {
            if (request.GetCharacterEncoding() == null)
            {
                request.SetCharacterEncoding("utf-8");
            }
            response.SetContentType("text/json; charset=UTF-8");
            PrintWriter @out = response.GetWriter();
            string      raw  = request.GetParameter("q");

            if (raw == null || string.Empty.Equals(raw))
            {
                @out.Println("{ok:false, entailments:[], triples=[], msg=\"\"}");
            }
            else
            {
                DoGet(@out, raw);
            }
            @out.Close();
        }
        /// <exception cref="System.IO.IOException"/>
        private void AddResults(IHttpServletRequest request, IHttpServletResponse response)
        {
            // if we can't handle UTF-8, need to do something like this...
            //String originalQuery = request.getParameter("q");
            //String query = WebappUtil.convertString(originalQuery);
            string query      = request.GetParameter("q");
            string dateString = request.GetParameter("d");
            // TODO: this always returns true...
            bool        dateError      = !pipeline.IsDateOkay(dateString);
            bool        includeOffsets = ParseBoolean(request.GetParameter("includeOffsets"));
            PrintWriter @out           = response.GetWriter();

            if (dateError)
            {
                @out.Println("<br><br>Warning: unparseable date " + StringEscapeUtils.EscapeHtml4(dateString));
            }
            if (!StringUtils.IsNullOrEmpty(query))
            {
                Properties props         = GetTimeAnnotatorProperties(request);
                string     annotatorType = request.GetParameter("annotator");
                if (annotatorType == null)
                {
                    annotatorType = "sutime";
                }
                IAnnotator timeAnnotator = pipeline.GetTimeAnnotator(annotatorType, props);
                if (timeAnnotator != null)
                {
                    Annotation anno = pipeline.Process(query, dateString, timeAnnotator);
                    @out.Println("<h3>Annotated Text</h3> <em>(tagged using " + annotatorType + "</em>)");
                    DisplayAnnotation(@out, query, anno, includeOffsets);
                }
                else
                {
                    @out.Println("<br><br>Error creating annotator for " + StringEscapeUtils.EscapeHtml4(annotatorType));
                }
            }
        }
        /// <exception cref="Javax.Servlet.ServletException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual void AddResults(IHttpServletRequest request, IHttpServletResponse response)
        {
            string input = request.GetParameter("input");

            if (input == null)
            {
                return;
            }
            input = input.Trim();
            if (input.IsEmpty())
            {
                return;
            }
            PrintWriter @out = response.GetWriter();

            if (input.Length > MaximumQueryLength)
            {
                @out.Print("<div>This query is too long.  If you want to run very long queries, please download and use our <a href=\"http://nlp.stanford.edu/software/corenlp.html\">publicly released distribution</a>.</div>");
                return;
            }
            Annotation annotation = new Annotation(input);

            pipeline.Annotate(annotation);
            string outputFormat = request.GetParameter("outputFormat");

            if (outputFormat == null || outputFormat.Trim().IsEmpty())
            {
                outputFormat = this.defaultFormat;
            }
            switch (outputFormat)
            {
            case "xml":
            {
                OutputXml(@out, annotation);
                break;
            }

            case "json":
            {
                OutputJson(@out, annotation);
                break;
            }

            case "conll":
            {
                OutputCoNLL(@out, annotation);
                break;
            }

            case "pretty":
            {
                OutputPretty(@out, annotation);
                break;
            }

            default:
            {
                OutputVisualise(@out, annotation);
                break;
            }
            }
        }