public frmNamedEntities(SemanticDatabase db, NamedEntity selected) { InitializeComponent(); int selIndex = db.NamedEntities.Values.ToList().IndexOf(selected); NamedEntities = db.NamedEntities.SerializeClone(); RefreshNamedEntityList(NamedEntities.Values.ToList()); lvNamedEntities.Items[selIndex].Selected = true; lvNamedEntities.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); }
public static Document Open(string filename, SemanticDatabase DB) { if (!File.Exists(filename)) { return(null); } var xdoc = XDocument.Load(filename); if (xdoc != null) { var doc = new Document(); foreach (var sentenceEl in xdoc.Root.Elements("Sentence")) { var sent = new Sentence(); var namedEntityMarkers = new List <Tuple <int, int, int> >(); sent.Text = sentenceEl.Attribute("Text").Value; sent.ID = sentenceEl.Attribute("ID").Value; if (sentenceEl.Element("Words") != null) { foreach (var wordEl in sentenceEl.Element("Words").Elements("Word")) { var word = new Word(); word.Index = int.Parse(wordEl.Attribute("Index").Value); word.Original = GetValue(wordEl.Attribute("Original")); word.Morph1 = GetValue(wordEl.Attribute("Morph1")); word.Morph2 = GetValue(wordEl.Attribute("Morph2")); word.Lemma = GetValue(wordEl.Attribute("Lemma")); if (wordEl.Attribute("Parent") != null) { if (!int.TryParse(GetValue(wordEl.Attribute("Parent")), out word.ParentIndex)) { word.ParentIndex = -1; } } else { if (!int.TryParse(GetValue(wordEl.Attribute("Constituent")), out word.ParentIndex)) { word.ParentIndex = -1; } else { word.IsConstituent = true; } } sent.Words.Add(word); } sent.Words = sent.Words.OrderBy(o => o.Index).ToList(); } if (sentenceEl.Element("NamedEntities") != null) { foreach (var entity in sentenceEl.Element("NamedEntities").Elements("NamedEntity")) { var ID = int.Parse(entity.Attribute("ID").Value); var wordIndex = int.Parse(entity.Attribute("WordIndex").Value); sent.WordToNamedEntityMap.Add(sent.Words[wordIndex], DB.NamedEntities[ID]); } } if (sentenceEl.Element("Markers") != null) { foreach (var entity in sentenceEl.Element("Markers").Elements("NamedEntityMarker")) { var ID = int.Parse(entity.Attribute("ID").Value); var x = int.Parse(entity.Attribute("X").Value); var y = int.Parse(entity.Attribute("Y").Value); namedEntityMarkers.Add(Tuple.Create(ID, x, y)); } } doc.Sentences.Add(sent); foreach (var tuple in namedEntityMarkers) { sent.NamedEntityMarkers.Add(new NamedEntityMarker { Location = new Point(tuple.Item2, tuple.Item3), NamedEntity = DB.NamedEntities[tuple.Item1] }); } } return(doc); } return(null); }