public GenericWebServiceAnnotator(Properties props)
 {
     // annotator endpoint
     annotatorEndpoint = props.GetProperty("generic.endpoint");
     annotatorRequires = ParseClasses(props.GetProperty("generic.requires", string.Empty));
     annotatorProvides = ParseClasses(props.GetProperty("generic.provides", string.Empty));
     startCommand      = Optional.OfNullable(props.GetProperty("generic.start")).Map(null);
     stopCommand       = Optional.OfNullable(props.GetProperty("generic.stop")).Map(null);
     serializer        = new ProtobufAnnotationSerializer();
 }
        /// <exception cref="System.IO.IOException"/>
        private IList <CoreLabel> ReadProtoBufAnnotation(byte[] sent)
        {
            ProtobufAnnotationSerializer p    = new ProtobufAnnotationSerializer();
            IList <CoreLabel>            toks = new List <CoreLabel>();
            ByteArrayInputStream         @is  = new ByteArrayInputStream(sent);

            CoreNLPProtos.Token d;
            do
            {
                d = CoreNLPProtos.Token.ParseDelimitedFrom(@is);
                if (d != null)
                {
                    toks.Add(p.FromProto(d));
                }
            }while (d != null);
            return(toks);
        }
Beispiel #3
0
        public static Annotation ReadSerializedProtobufFile(File fileIn)
        {
            Annotation annotation;

            try
            {
                ProtobufAnnotationSerializer pas = new ProtobufAnnotationSerializer();
                InputStream @is = new BufferedInputStream(new FileInputStream(fileIn));
                Pair <Annotation, InputStream> pair = pas.Read(@is);
                pair.second.Close();
                annotation = pair.first;
                IOUtils.CloseIgnoringExceptions(@is);
                return(annotation);
            }
            catch (Exception e)
            {
                throw new Exception(e);
            }
        }
 public static void ProcessCoreNLPIfDoesNotExist(File processedFile, Properties coreNLPProps, string text)
 {
     if (!processedFile.Exists())
     {
         try
         {
             StanfordCoreNLP coreNLP             = new StanfordCoreNLP(coreNLPProps);
             Annotation      processedAnnotation = coreNLP.Process(text);
             //this document holds the split for paragraphs.
             ProtobufAnnotationSerializer pas = new ProtobufAnnotationSerializer(true);
             OutputStream fos = new BufferedOutputStream(new FileOutputStream(processedFile.GetAbsolutePath()));
             pas.Write(processedAnnotation, fos);
         }
         catch (IOException e)
         {
             Sharpen.Runtime.PrintStackTrace(e);
         }
     }
 }