예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BratDocument"/> class.
        /// </summary>
        /// <param name="config">The annotation configuration.</param>
        /// <param name="id">The document identifier.</param>
        /// <param name="text">The document text.</param>
        /// <param name="annotations">The annotations.</param>
        public BratDocument(AnnotationConfiguration config, string id, string text, IEnumerable<BratAnnotation> annotations) {

            Config = config;
            Id = id;
            Text = text;

            var list = new Dictionary<string, BratAnnotation>();
            foreach (var annotation in annotations) {
                list.Add(annotation.Id, annotation);
            }
            annotationMap = new ReadOnlyDictionary<string, BratAnnotation>(list);
        }
예제 #2
0
        public BratDocument(AnnotationConfiguration config, string id, string text, IEnumerable <BratAnnotation> annotations)
        {
            Config = config;
            Id     = id;
            Text   = text;

            var list = new Dictionary <string, BratAnnotation>();

            foreach (var annotation in annotations)
            {
                list.Add(annotation.Id, annotation);
            }
            annotationMap = new ReadOnlyDictionary <string, BratAnnotation>(list);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BratAnnotationStream"/> class.
        /// </summary>
        /// <param name="config">The annotation configuration.</param>
        /// <param name="id">The stream identifier.</param>
        /// <param name="inputStream">The input stream.</param>
        public BratAnnotationStream(AnnotationConfiguration config, string id, Stream inputStream)
        {
            this.config = config;
            this.id     = id;

            if (inputStream.CanSeek)
            {
                input = inputStream;
                start = inputStream.Position;
            }
            else
            {
                start = -1;
            }

            reader = new StreamReader(inputStream, Encoding.UTF8);
        }
예제 #4
0
        /// <summary>
        /// Parses the specified brat document using two streams for the document and annotations.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="documentStream">The document stream.</param>
        /// <param name="annotationStream">The annotation stream.</param>
        /// <returns>The parsed <see cref="BratDocument"/> object.</returns>
        public static BratDocument Parse(AnnotationConfiguration config, string id, Stream documentStream, Stream annotationStream)
        {
            string document;

            using (var reader = new StreamReader(documentStream, Encoding.UTF8)) {
                document = reader.ReadToEnd();
            }

            var annotations = new List <BratAnnotation>();

            using (var reader = new BratAnnotationStream(config, id, annotationStream)) {
                BratAnnotation ann;
                while ((ann = reader.Read()) != null)
                {
                    annotations.Add(ann);
                }
            }

            return(new BratDocument(config, id, document, annotations));
        }
예제 #5
0
        /// <summary>
        /// Parses the specified brat document using two streams for the document and annotations.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="documentStream">The document stream.</param>
        /// <param name="annotationStream">The annotation stream.</param>
        /// <returns>The parsed <see cref="BratDocument"/> object.</returns>
        public static BratDocument Parse(AnnotationConfiguration config, string id, Stream documentStream, Stream annotationStream) {
            string document;
            using (var reader = new StreamReader(documentStream, Encoding.UTF8)) {
                document = reader.ReadToEnd();
            }
            
            var annotations = new List<BratAnnotation>();
            using (var reader = new BratAnnotationStream(config, id, annotationStream)) {
                BratAnnotation ann;
                while ((ann = reader.Read()) != null) {
                    annotations.Add(ann);
                }
            }

            return new BratDocument(config, id, document, annotations);
        }