示例#1
0
 private static void WriteXml(Offsets offsets, XmlWriter writer)
 {
     WriteXmlOffsetPair(writer, offsets.Sentence, SENTENCE_TAG);
     WriteXmlOffsetPair(writer, offsets.Objects, OBJECT_TAG);
     WriteXmlOffsetPair(writer, offsets.PositiveTonality, POSITIVETONALITY_TAG);
     WriteXmlOffsetPair(writer, offsets.NegativeTonality, NEGATIVETONALITY_TAG);
     WriteXmlOffsetPair(writer, offsets.NeutralTonality, NEUTRALTONALITY_TAG);
     WriteXmlOffsetPair(writer, offsets.Anaphoria, ANAPHORIA_TAG);
 }
示例#2
0
        private static void ReadXml(Offsets offsets, XmlReader reader)
        {
            var xd = XDocument.Parse(reader.ReadOuterXml());

            offsets.Sentence         = ReadXmlOffsetPair(xd, SENTENCE_TAG, true);
            offsets.Objects          = ReadXmlOffsetPairs(xd, OBJECT_TAG);
            offsets.PositiveTonality = ReadXmlOffsetPairTonalitys(xd, POSITIVETONALITY_TAG);
            offsets.NegativeTonality = ReadXmlOffsetPairTonalitys(xd, NEGATIVETONALITY_TAG);
            offsets.NeutralTonality  = ReadXmlOffsetPairs(xd, NEUTRALTONALITY_TAG);
            offsets.Anaphoria        = ReadXmlOffsetPairAnaphorias(xd, ANAPHORIA_TAG);
        }
示例#3
0
        public static string ToTextString(Offsets offsets)
        {
            var sb = new StringBuilder();

            WriteOffsetPair(sb, offsets.Sentence); sb.Append(FIELD_SEPARATOR);
            WriteOffsetPair(sb, offsets.Objects); sb.Append(FIELD_SEPARATOR);
            WriteOffsetPair(sb, offsets.PositiveTonality); sb.Append(FIELD_SEPARATOR);
            WriteOffsetPair(sb, offsets.NegativeTonality); sb.Append(FIELD_SEPARATOR);
            WriteOffsetPair(sb, offsets.NeutralTonality); sb.Append(FIELD_SEPARATOR);
            WriteOffsetPair(sb, offsets.Anaphoria); sb.Append(FIELD_SEPARATOR);

            return(sb.ToString());
        }
示例#4
0
        internal static Offsets FromXmlString(string offsetsXml)
        {
            var ofs = new Offsets();

            using (var sr = new StringReader(offsetsXml))
                using (var xr = new XmlTextReader(sr))
                {
                    xr.Read();

                    ReadXml(ofs, xr);
                }

            return(ofs);
        }
示例#5
0
        public static string ToXmlString(Offsets offsets)
        {
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
                using (var xw = new XmlTextWriter(sw)
                {
                    Formatting = Formatting.None
                })
                {
                    xw.WriteStartElement(ROOT_TAG);
                    WriteXml(offsets, xw);
                    xw.WriteEndElement();
                }
            return(sb.ToString());
        }
示例#6
0
        internal static Offsets FromTextString(string offsetsText)
        {
            var ofs = new Offsets();

            var fields = offsetsText.Split(new[] { FIELD_SEPARATOR }, StringSplitOptions.None);

            if (fields.Length < FIELD_COUNT)
            {
                throw (new ArgumentException("offsetsText.Split( new[] { FIELD_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries ) < " + FIELD_COUNT));
            }

            ofs.Sentence         = ReadOffsetPair(fields[0], true);
            ofs.Objects          = ReadOffsetPairs(fields[1]);
            ofs.PositiveTonality = ReadOffsetPairTonalitys(fields[2]);
            ofs.NegativeTonality = ReadOffsetPairTonalitys(fields[3]);
            ofs.NeutralTonality  = ReadOffsetPairs(fields[4]);
            ofs.Anaphoria        = ReadOffsetPairAnaphorias(fields[5]);

            return(ofs);
        }