Exemplo n.º 1
0
        public Annotation[] GetAnnotations()
        {
            if (!typeMap.ContainsKey("Annotation"))
            {
                throw new Exception("Not configured for annotations");
            }

            string text = GetText();
            XmlNodeList annotationNodes = this.SelectNodes(".//" + typeMap["Annotation"]);
            List<Annotation> annotations = new List<Annotation>();
            foreach (XmlNode node in annotationNodes)
            {
                Annotation sentence = new Annotation()
                {
                    ID = int.Parse(node.Attributes["annotationID"].Value),
                    StartPosition = (node.Attributes["begin"].Value == string.Empty ? null : new Nullable<int>(int.Parse(node.Attributes["begin"].Value))),
                    EndPosition = (node.Attributes["end"].Value == string.Empty ? null : new Nullable<int>(int.Parse(node.Attributes["end"].Value))),
                    Scope = (UIMA.NET.Annotation.AnnotationScope)byte.Parse(node.Attributes["scope"].Value),
                    EntityLinkID = SafeGetAttribute(node, "linkID", null),
                    Details = (node.Attributes["details"] != null ? node.Attributes["details"].Value : "")
                };
                annotations.Add(sentence);
            }
            return annotations.ToArray<Annotation>();
        }
Exemplo n.º 2
0
        public void DeleteAnnotation(Annotation annotation)
        {
            if (!typeMap.ContainsKey("Annotation"))
            {
                throw new Exception("Not configured for annotations");
            }

            // Does an annotation exist in the document with the ID?
            XmlNodeList annotationNodes = this.SelectNodes(string.Format(".//{0}[@annotationID='{1}'][@linkID='{2}']",
                typeMap["Annotation"],
                annotation.ID,
                annotation.EntityLinkID));
            foreach (XmlNode annotationNode in annotationNodes)
            {
                // Why replace instead of update?  This is just a faster way by reusing existing code.
                FirstChild.RemoveChild(annotationNode);
            }
        }
Exemplo n.º 3
0
        public Annotation UpdateOrAddAnnotation(Annotation annotation)
        {
            if (!typeMap.ContainsKey("Annotation"))
            {
                throw new Exception("Not configured for annotations");
            }

            // Does an annotation exist in the document with the ID?
            XmlNode annotationNode = this.SelectSingleNode(string.Format(".//{0}[@annotationID='{1}'][@linkID='{2}']",
                typeMap["Annotation"],
                annotation.ID,
                annotation.EntityLinkID));
            if (annotationNode == null)
            {
                XmlNodeList list = this.SelectNodes(string.Format(".//{0}", typeMap["Annotation"]));
                annotation.ID = GetMaxID(list, "annotationID");
                annotationNode = annotation.ConvertToNode(typeMap["Annotation"]);
                FirstChild.AppendChild(ImportNode(annotationNode, true));
            }
            else
            {
                // Why replace instead of update?  This is just a faster way by reusing existing code.
                FirstChild.ReplaceChild(
                    ImportNode(annotation.ConvertToNode(typeMap["Annotation"]), true),
                    annotationNode);
            }

            return annotation;
        }