Beispiel #1
0
 public void CopyFeaturesFrom(DocumentCorpus corpus)
 {
     foreach (KeyValuePair <string, string> item in corpus.mFeatures)
     {
         Features.SetFeatureValue(item.Key, item.Value);
     }
 }
Beispiel #2
0
 public void ReadXml(XmlReader reader)
 {
     Utils.ThrowException(reader == null ? new ArgumentNullException("reader") : null);
     mDocuments.Clear();
     mFeatures.Clear();
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.Element && reader.Name == "Feature" && !reader.IsEmptyElement)
         {
             string featName = "not set";
             string featVal  = "";
             while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Feature"))
             {
                 if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name")
                 {
                     featName = Utils.XmlReadValue(reader, "Name");
                 }
                 else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Value")
                 {
                     featVal = Utils.XmlReadValue(reader, "Value");
                 }
             }
             Features.SetFeatureValue(featName, featVal);
         }
         else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Document" && !reader.IsEmptyElement)
         {
             Document doc = new Document();
             doc.ReadXml(reader);
             AddDocument(doc);
         }
     }
 }
Beispiel #3
0
 public void ReadXml(XmlReader reader)
 {
     Utils.ThrowException(reader == null ? new ArgumentNullException("reader") : null);
     mAnnotations.Clear();
     mFeatures.Clear();
     mText = mName = "";
     while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Document"))
     {
         if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name")
         {
             mName = Utils.XmlReadValue(reader, "Name");
         }
         else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Text")
         {
             mText = Utils.XmlReadValue(reader, "Text");
         }
         else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Annotation" && !reader.IsEmptyElement)
         {
             int    spanStart = 0;
             int    spanEnd   = 0;
             string annotType = "not set";
             int    annotId   = -1;
             ArrayList <Pair <string, string> > features = new ArrayList <Pair <string, string> >();
             while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Annotation"))
             {
                 if (reader.NodeType == XmlNodeType.Element && reader.Name == "SpanStart")
                 {
                     spanStart = Convert.ToInt32(Utils.XmlReadValue(reader, "SpanStart"));
                 }
                 else if (reader.NodeType == XmlNodeType.Element && reader.Name == "SpanEnd")
                 {
                     spanEnd = Convert.ToInt32(Utils.XmlReadValue(reader, "SpanEnd"));
                 }
                 else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Type")
                 {
                     annotType = Utils.XmlReadValue(reader, "Type");
                 }
                 else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Type")
                 {
                     annotType = Utils.XmlReadValue(reader, "Type");
                 }
                 else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Feature" && !reader.IsEmptyElement)
                 {
                     string featName = "not set";
                     string featVal  = "";
                     while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Feature"))
                     {
                         if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name")
                         {
                             featName = Utils.XmlReadValue(reader, "Name");
                         }
                         else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Value")
                         {
                             featVal = Utils.XmlReadValue(reader, "Value");
                         }
                     }
                     features.Add(new Pair <string, string>(featName, featVal));
                 }
             }
             Annotation annot = new Annotation(spanStart, spanEnd, annotType);
             AddAnnotation(annot);
             foreach (Pair <string, string> feature in features)
             {
                 annot.Features.SetFeatureValue(feature.First, feature.Second);
             }
         }
         else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Feature" && !reader.IsEmptyElement)
         {
             string featName = "not set";
             string featVal  = "";
             while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Feature"))
             {
                 if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name")
                 {
                     featName = Utils.XmlReadValue(reader, "Name");
                 }
                 else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Value")
                 {
                     featVal = Utils.XmlReadValue(reader, "Value");
                 }
             }
             Features.SetFeatureValue(featName, featVal);
         }
     }
 }