12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System.IO;
- using System.Text;
- using System.Xml;
- namespace AIPractice.Shared.Labels
- {
- /// <summary>
- /// 结论恶性程度
- /// </summary>
- public enum MalignantLevel
- {
- /// <summary>
- /// 正常
- /// </summary>
- Low = 0,
- /// <summary>
- /// 中度
- /// </summary>
- Middle = 1,
- /// <summary>
- /// 恶性
- /// </summary>
- High = 2
- }
- public class ConclusionLabel: ImageLabel
- {
- /// <summary>
- /// Gets the MalignantLevel of this Conclusion.
- /// </summary>
- public MalignantLevel Level { get; set; }
- /// <summary>
- /// Gets or sets if this label is the parts label.
- /// </summary>
- public bool IsParts { get; set; }
- /// <summary>
- /// Gets or sets if this label is unique label of its root.
- /// </summary>
- public bool IsUnique { get; set; }
- public ConclusionLabel(string id, string title, MalignantLevel level) : base(id, title)
- {
- Level = level;
- }
- public static ConclusionLabel FromXml(string xmlContent)
- {
- using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(xmlContent)))
- {
- using (var r = XmlReader.Create(ms))
- {
- r.Read();
- var id = r.GetAttribute("id");
- var title = r.GetAttribute("title");
- var malignantLevelStr = r.GetAttribute("malignantLevel");
- var malignantLevel = MalignantLevel.Low;
- if (int.TryParse(malignantLevelStr, out int m))
- {
- malignantLevel = (MalignantLevel)m;
- }
- var isPartsStr = r.GetAttribute("isParts");
- bool.TryParse(isPartsStr, out var isParts);
- var isUniqueStr = r.GetAttribute("isUnique");
- bool.TryParse(isUniqueStr, out var isUnique);
- return new ConclusionLabel(id, title, malignantLevel)
- {
- IsParts = isParts,
- IsUnique = isUnique
- };
- }
- }
- }
- public override string ToXml()
- {
- return $"<{nameof(ConclusionLabel)} id=\"{Id}\" title=\"{Title}\" malignantLevel=\"{(int)Level}\" isParts=\"{IsParts}\" isUnique=\"{IsUnique}\"/>";
- }
- }
- }
|