static void Main()
        {
            // Path to the folder with models extracted from `stanford-corenlp-3.7.0-models.jar`
            var jarRoot = @"..\..\..\..\paket-files\nlp.stanford.edu\stanford-corenlp-full-2016-10-31\models";

            // Text for processing
            var text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";

            // Annotation pipeline configuration
            var props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, ner,dcoref");
            props.setProperty("ner.useSUTime", "0");

            // We should change current directory, so StanfordCoreNLP could find all the model files automatically
            var curDir = Environment.CurrentDirectory;
            Directory.SetCurrentDirectory(jarRoot);
            var pipeline = new StanfordCoreNLP(props);
            Directory.SetCurrentDirectory(curDir);

            // Annotation
            var annotation = new Annotation(text);
            pipeline.annotate(annotation);

            // Result - Pretty Print
            using (var stream = new ByteArrayOutputStream())
            {
                pipeline.prettyPrint(annotation, new PrintWriter(stream));
                Console.WriteLine(stream.toString());
                stream.close();
            }
        }
Exemple #2
0
        public static byte[] ProcessXslFo(string xslfo, string name)
        {
            var foUserAgent = FopFactory.newFOUserAgent();
            foUserAgent.setCreator("Crispin (Apache FOP 2.1 via IKVM)");
            foUserAgent.setTitle(name);

            var outputStream = new java.io.ByteArrayOutputStream();

            var fop = FopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.__Fields.MIME_PDF, foUserAgent, outputStream);

            var transformerFactory = new com.sun.org.apache.xalan.@internal.xsltc.trax.TransformerFactoryImpl();
            var transformer = transformerFactory.newTransformer();

            var source = new StreamSource(new java.io.StringReader(xslfo));

            var result = new SAXResult(fop.getDefaultHandler());

            transformer.transform(source, result);

            /*
             * Adding the page count requires a second pass. This should be configurable
             * by the report itself.
             * */
            /*
            transformer.setParameter("page-count", fop.getResults().getPageCount().ToString());
            transformer.transform(src, res);
             * */

            outputStream.close();

            return outputStream.toByteArray();
        }
Exemple #3
0
        public static byte[] ProcessXslFo(string xslfo, string name)
        {
            var foUserAgent = FopFactory.newFOUserAgent();

            foUserAgent.setCreator("Crispin (Apache FOP 2.1 via IKVM)");
            foUserAgent.setTitle(name);

            var outputStream = new java.io.ByteArrayOutputStream();

            var fop = FopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.__Fields.MIME_PDF, foUserAgent, outputStream);

            var transformerFactory = new com.sun.org.apache.xalan.@internal.xsltc.trax.TransformerFactoryImpl();
            var transformer        = transformerFactory.newTransformer();

            var source = new StreamSource(new java.io.StringReader(xslfo));

            var result = new SAXResult(fop.getDefaultHandler());

            transformer.transform(source, result);

            /*
             * Adding the page count requires a second pass. This should be configurable
             * by the report itself.
             * */
            /*
             * transformer.setParameter("page-count", fop.getResults().getPageCount().ToString());
             * transformer.transform(src, res);
             * */

            outputStream.close();

            return(outputStream.toByteArray());
        }
Exemple #4
0
        public void Save(Stream stream)
        {
            //FileOutputStream _javastream = new FileOutputStream(filePath);
            java.io.ByteArrayOutputStream byteStream = new java.io.ByteArrayOutputStream();
            ObjectOutput objOut = new DotnetObjectOutputStream(byteStream);

            this._javaPackage.writeExternal(objOut);
            stream.Write(byteStream.toByteArray(), 0, byteStream.toByteArray().Length);
            byteStream.close();
        }
        private string getAnnotation(string input)
        {
            Annotation annotation = new Annotation(input);
            pipeline.annotate(annotation);

            string result = "";
            using (var stream = new ByteArrayOutputStream())
            {
                pipeline.conllPrint(annotation, new PrintWriter(stream));
                result += stream.toString();
                stream.close();
            }
            return result;
        }
    private void SetDrawable(out Texture2D button, int keyCode)
    {
        OuyaController.ButtonData buttonData;
        buttonData = OuyaController.getButtonData(keyCode);
        if (null == buttonData)
        {
            button = null;
            return;
        }

        if (null == buttonData.buttonDrawable)
        {
            button = null;
            return;
        }

        BitmapDrawable drawable = (BitmapDrawable)buttonData.buttonDrawable;
        if (null == drawable)
        {
            button = null;
            return;
        }

        Bitmap bitmap = drawable.getBitmap();
        if (null == bitmap)
        {
            button = null;
            return;
        }

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        if (stream.size() == 0)
        {
            button = null;
        }
        else
        {
            button = new Texture2D(0, 0);
            button.LoadImage(stream.toByteArray());
        }
        stream.close();
    }
    void AddWidgets(List<OuyaMod> ouyaMods, bool searchByInstalled, bool searchByPublished)
    {
        StringBuilder sb = new StringBuilder();
        foreach (OuyaMod ouyaMod in ouyaMods)
        {
            WidgetOuyaMod widget = new WidgetOuyaMod()
            {
                m_instance = ouyaMod,
                m_category = ouyaMod.getCategory(),
                m_description = ouyaMod.getDescription(),
                m_isDownloading = ouyaMod.isDownloading(),
                m_isFlagged = ouyaMod.isFlagged(),
                m_isInstalled = ouyaMod.isInstalled(),
                m_isPublished = ouyaMod.isPublished(),
                m_metaData = ouyaMod.getMetaData(),
                m_ratingCount = ouyaMod.getRatingCount(),
                m_ratingAverage = ouyaMod.getRatingAverage(),
                m_title = ouyaMod.getTitle(),
                m_userRating = ouyaMod.getUserRating(),
                m_searchByInstalled = searchByInstalled,
                m_searchByPublished = searchByPublished,
            };
            if (sb.Length > 0)
            {
                sb.Remove(0, sb.Length);
            }
            foreach (string filename in ouyaMod.getFilenames())
            {
                sb.Append(filename);
                sb.Append(",");

                using (InputStream inputStream = ouyaMod.openFile(filename))
                {
                    byte[] buffer = new byte[100000];
                    int readAmount = inputStream.read(ref buffer);
                    inputStream.close();

                    byte[] copy = new byte[readAmount];
                    Array.Copy(buffer, copy, readAmount);

                    sb.Append("***");
                    string content = System.Text.UTF8Encoding.UTF8.GetString(copy);
                    sb.Append(content);
                }
            }
            widget.m_filenames = sb.ToString();
            List<OuyaModScreenshot> screenshots = ouyaMod.getScreenshots();
            widget.m_screenshots = new Texture2D[screenshots.Count];
            widget.m_thumbnails = new Texture2D[screenshots.Count];
            for (int index = 0; index < screenshots.Count; ++index)
            {
                using (OuyaModScreenshot ouyaModScreenshot = screenshots[index])
                {
                    if (null != ouyaModScreenshot)
                    {
                        using (Bitmap bitmap = ouyaModScreenshot.getImage())
                        {
                            if (null != bitmap)
                            {
                                using (ByteArrayOutputStream stream = new ByteArrayOutputStream())
                                {
                                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                    if (stream.size() >= 0)
                                    {
                                        Texture2D texture = new Texture2D(0, 0);
                                        texture.LoadImage(stream.toByteArray());
                                        widget.m_screenshots[index] = texture;
                                    }
                                    stream.close();
                                }
                            }
                        }

                        using (Bitmap bitmap = ouyaModScreenshot.getThumbnail())
                        {
                            if (null != bitmap)
                            {
                                using (ByteArrayOutputStream stream = new ByteArrayOutputStream())
                                {
                                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                    if (stream.size() >= 0)
                                    {
                                        Texture2D texture = new Texture2D(0, 0);
                                        texture.LoadImage(stream.toByteArray());
                                        widget.m_thumbnails[index] = texture;
                                    }
                                    stream.close();
                                }
                            }
                        }
                    }
                }
            }
            if (sb.Length > 0)
            {
                sb.Remove(0, sb.Length);
            }
            foreach (string tag in ouyaMod.getTags())
            {
                sb.Append(tag);
                sb.Append(",");
            }
            widget.m_tags = sb.ToString();
            
            m_widgets.Add(widget);

            if (m_widgets.Count == 1)
            {
                m_focusManager.Mappings[m_btnCreate].Down = widget.m_buttonPublish;
                m_focusManager.Mappings[widget.m_buttonPublish] = new FocusManager.ButtonMapping()
                {
                    Up = m_btnCreate,
                    Right = widget.m_buttonDelete,
                };
                m_focusManager.Mappings[widget.m_buttonDelete] = new FocusManager.ButtonMapping()
                {
                    Up = m_btnCreate,
                    Left = widget.m_buttonPublish,
                    Right = widget.m_buttonDownload,
                };
                m_focusManager.Mappings[widget.m_buttonDownload] = new FocusManager.ButtonMapping()
                {
                    Up = m_btnCreate,
                    Left = widget.m_buttonDelete,
                    Right = widget.m_buttonRate,
                };
                m_focusManager.Mappings[widget.m_buttonRate] = new FocusManager.ButtonMapping()
                {
                    Up = m_btnCreate,
                    Left = widget.m_buttonDownload,
                    Right = widget.m_buttonEdit,
                };
                m_focusManager.Mappings[widget.m_buttonEdit] = new FocusManager.ButtonMapping()
                {
                    Up = m_btnCreate,
                    Left = widget.m_buttonRate,
                    Right = widget.m_buttonFlag,
                };
                m_focusManager.Mappings[widget.m_buttonFlag] = new FocusManager.ButtonMapping()
                {
                    Up = m_btnCreate,
                    Left = widget.m_buttonEdit,
                };
            }
            else
            {
                WidgetOuyaMod lastWidget = m_widgets[m_widgets.Count - 2];
                m_focusManager.Mappings[lastWidget.m_buttonPublish].Down = widget.m_buttonPublish;
                m_focusManager.Mappings[lastWidget.m_buttonDelete].Down = widget.m_buttonDelete;
                m_focusManager.Mappings[lastWidget.m_buttonDownload].Down = widget.m_buttonDownload;
                m_focusManager.Mappings[lastWidget.m_buttonRate].Down = widget.m_buttonRate;
                m_focusManager.Mappings[lastWidget.m_buttonEdit].Down = widget.m_buttonEdit;
                m_focusManager.Mappings[lastWidget.m_buttonFlag].Down = widget.m_buttonFlag;
                m_focusManager.Mappings[widget.m_buttonPublish] = new FocusManager.ButtonMapping()
                {
                    Up = lastWidget.m_buttonPublish,
                    Right = widget.m_buttonDelete,
                };
                m_focusManager.Mappings[widget.m_buttonDelete] = new FocusManager.ButtonMapping()
                {
                    Up = lastWidget.m_buttonDelete,
                    Left = widget.m_buttonPublish,
                    Right = widget.m_buttonDownload,
                };
                m_focusManager.Mappings[widget.m_buttonDownload] = new FocusManager.ButtonMapping()
                {
                    Up = lastWidget.m_buttonDownload,
                    Left = widget.m_buttonDelete,
                    Right = widget.m_buttonRate,
                };
                m_focusManager.Mappings[widget.m_buttonRate] = new FocusManager.ButtonMapping()
                {
                    Up = lastWidget.m_buttonRate,
                    Left = widget.m_buttonDownload,
                    Right = widget.m_buttonEdit,
                };
                m_focusManager.Mappings[widget.m_buttonEdit] = new FocusManager.ButtonMapping()
                {
                    Up = lastWidget.m_buttonEdit,
                    Left = widget.m_buttonRate,
                    Right = widget.m_buttonFlag,
                };
                m_focusManager.Mappings[widget.m_buttonFlag] = new FocusManager.ButtonMapping()
                {
                    Up = lastWidget.m_buttonFlag,
                    Left = widget.m_buttonEdit,
                };
            }
        }
    }
Exemple #8
0
 public void Save(Stream stream)
 {
     //FileOutputStream _javastream = new FileOutputStream(filePath);
     java.io.ByteArrayOutputStream byteStream = new java.io.ByteArrayOutputStream();
     ObjectOutput objOut = new DotnetObjectOutputStream(byteStream);
     this._javaPackage.writeExternal(objOut);
     stream.Write(byteStream.toByteArray(), 0, byteStream.toByteArray().Length);
     byteStream.close();
 }
Exemple #9
0
        /// <summary>
        /// Runs text processing using StanfordCoreNLP procject.
        /// </summary>
        /// <param name="text">Text to process</param>
        public void RunCoreNLP(String text)
        {
            // needs to be before Annotation(text)
            // otherwise it throws error
            StanfordCoreNLP pipeLine = Pipeline;
            Annotation annotation = new Annotation(text);
            pipeLine.annotate(annotation);

            if (_redirectOutputToFile)
            {
                FileStream filestream = new FileStream(_redirectOutputToFileFileName, FileMode.OpenOrCreate, FileAccess.Write);
                var streamwriter = new StreamWriter(filestream);
                streamwriter.AutoFlush = true;
                Console.SetOut(streamwriter);
                Console.SetError(streamwriter);
            }

            if (_verbose)
            {
                // Result - Pretty Print
                using (ByteArrayOutputStream stream = new ByteArrayOutputStream())
                {
                    pipeLine.prettyPrint(annotation, new PrintWriter(stream));
                    Console.WriteLine(stream.toString());
                    stream.close();
                }
            }

            _notes = Parse(annotation);
            PrintNotes(_notes);
        }