ConclusionLabel.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.IO;
  2. using System.Text;
  3. using System.Xml;
  4. namespace AIPractice.Shared.Labels
  5. {
  6. /// <summary>
  7. /// 结论恶性程度
  8. /// </summary>
  9. public enum MalignantLevel
  10. {
  11. /// <summary>
  12. /// 正常
  13. /// </summary>
  14. Low = 0,
  15. /// <summary>
  16. /// 中度
  17. /// </summary>
  18. Middle = 1,
  19. /// <summary>
  20. /// 恶性
  21. /// </summary>
  22. High = 2
  23. }
  24. public class ConclusionLabel: ImageLabel
  25. {
  26. /// <summary>
  27. /// Gets the MalignantLevel of this Conclusion.
  28. /// </summary>
  29. public MalignantLevel Level { get; set; }
  30. /// <summary>
  31. /// Gets or sets if this label is the parts label.
  32. /// </summary>
  33. public bool IsParts { get; set; }
  34. /// <summary>
  35. /// Gets or sets if this label is unique label of its root.
  36. /// </summary>
  37. public bool IsUnique { get; set; }
  38. public ConclusionLabel(string id, string title, MalignantLevel level) : base(id, title)
  39. {
  40. Level = level;
  41. }
  42. public static ConclusionLabel FromXml(string xmlContent)
  43. {
  44. using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(xmlContent)))
  45. {
  46. using (var r = XmlReader.Create(ms))
  47. {
  48. r.Read();
  49. var id = r.GetAttribute("id");
  50. var title = r.GetAttribute("title");
  51. var malignantLevelStr = r.GetAttribute("malignantLevel");
  52. var malignantLevel = MalignantLevel.Low;
  53. if (int.TryParse(malignantLevelStr, out int m))
  54. {
  55. malignantLevel = (MalignantLevel)m;
  56. }
  57. var isPartsStr = r.GetAttribute("isParts");
  58. bool.TryParse(isPartsStr, out var isParts);
  59. var isUniqueStr = r.GetAttribute("isUnique");
  60. bool.TryParse(isUniqueStr, out var isUnique);
  61. return new ConclusionLabel(id, title, malignantLevel)
  62. {
  63. IsParts = isParts,
  64. IsUnique = isUnique
  65. };
  66. }
  67. }
  68. }
  69. public override string ToXml()
  70. {
  71. return $"<{nameof(ConclusionLabel)} id=\"{Id}\" title=\"{Title}\" malignantLevel=\"{(int)Level}\" isParts=\"{IsParts}\" isUnique=\"{IsUnique}\"/>";
  72. }
  73. }
  74. }