public List <IentityBase> updatedEntityList() { List <IentityBase> entList = new List <IentityBase>(); for (int i = 0; i < entitiesDGV.Rows.Count; i++) { if (entitiesDGV.Rows[i].Cells[1].Value != null) { var value = entitiesDGV.Rows[i].Cells[1].Value.ToString(); var type = entitiesDGV.Rows[i].Cells[2].Value.ToString(); var syn = entitiesDGV.Rows[i].Cells[3].Value.ToString(); if (syn.Contains("#")) { var entS = new multyEntity(); entS.entityValue = value; entS.entityType = type; entS.parts = concat(syn.Split(';').Where(me => me.Count() > 0 && me.Split('#').Count() > 1)); entS.singleValue = syn.Split(';').Where(me => me.Count() > 0 && me.Split('#').Count() == 1).FirstOrDefault(); } else { var entS = new entity(); entS.entityValue = value; entS.entityType = type; entS.entitySynonimus = syn; entList.Add(entS); } } } return(entList); }
public List <IentityBase> findMatchingEntities(string text) { text = text.Trim(); var res = new List <IentityBase>(); if (entities == null) { entities = DBctrl1.getEntitys().ToList(); } if (multyEntities == null) { multyEntities = DBctrl1.getMultyEntitys().ToList(); } var words = getWordsObjectFromParserServer(text); var ent = findMathedEntities(words); var resEntityPart = new List <IentityBase>(); IEnumerable <IentityBase> multyMatch = new List <IentityBase>(); if (text.Split(' ').Count() > 1) { multyMatch = findMultyMatch(multyEntities, ent, 0, resEntityPart).Distinct(); if (multyMatch.Any()) { if (ent.Count() > 0 && ent[0].Where(e => multyMatch.Where(me => ((multyEntity)me).parts.Contains(e.entityValue)).Any()).Any()) { res.AddRange(multyMatch); } else { foreach (var w in words) { DBctrl.addNewEntity(w.Lemma, w.getTypeString()); } } } else if (words.TrueForAll(x => x.isA(WordType.properNameWord))) { var newEnt = new entity(); newEnt.entityType = "personWord"; var name = ""; if (words.Count > 1) { name = words[0].Text.Remove(0, words[0].Prefixes.Where(x => x != "ה").Count()); for (int i = 1; i < words.Count(); i++) { name += words[i].Text; } } else { name = words[0].Text; } newEnt.entityValue = name; newEnt.entitySynonimus = ";" + name + ";"; res.Add(newEnt); } else { var multyEntityVal = text.Remove(0, words[0].Prefixes.Where(x => x != "ה").Count()); var parts = ";"; foreach (var w in words) { parts += w.Lemma + "#"; var newEnt = new entity(); newEnt.entityValue = w.Text.Remove(0, w.Prefixes.Count()); newEnt.entitySynonimus = ";" + w.Lemma + ";"; newEnt.entityType = w.getTypeString(); res.Add(newEnt); } parts = parts.TrimEnd('#') + ";"; var mulEntity = new multyEntity(); mulEntity.entityType = "nounWord"; mulEntity.parts = parts; mulEntity.entityValue = multyEntityVal; res.Add(mulEntity); } } foreach (var e in ent) { res.AddRange(e); } if (res.Count() == 0) { foreach (var w in words) { var newEnt = new entity(); newEnt.entityValue = w.Text.Remove(0, w.Prefixes.Count()); newEnt.entitySynonimus = ";" + w.Lemma + ";"; newEnt.entityType = w.getTypeString(); res.Add(newEnt); } } return(res.Distinct().ToList()); }
//after adding question toi the DB, automaticlly add all entity in the question to the DB //and then tag them by hand internal void updateEntities() { var db = DBctrl1.updateDBmanual(); var list = new List <IMultyEntity>(); foreach (var e in db.entity) { if (e.entityValue.Split(' ').Count() > 1) { var val = e.entityValue.Trim().Replace(' ', '#'); var newmulty = new multyEntity(); newmulty.entityValue = e.entityValue; newmulty.parts = ";" + val + ";"; newmulty.entityType = e.entityType; list.Add(newmulty); foreach (var w in e.entityValue.Split(' ')) { if (db.entity.Where(x => x.entitySynonimus.Contains(";" + w + ";")).Count() == 0) { var ent = new entity(); ent.entityValue = w; ent.entityType = e.entityType; var word = getWordsObjectFromParserServer(w).Single(); if (word.Lemma != w) { ent.entitySynonimus = (";" + w + ";" + word.Lemma + ";"); } else { ent.entitySynonimus = (";" + w + ";"); } db.entity.Add(ent); } } } foreach (var s in e.entitySynonimus.Split(';')) { if (s != "") { if (s.Split(' ').Count() > 1) { var val = e.entityValue.Trim().Replace(' ', '#'); var newmulty = new multyEntity(); newmulty.entityValue = s; newmulty.parts = ";" + val + ";"; newmulty.singleValue = e.entityValue; newmulty.entityType = e.entityType; list.Add(newmulty); foreach (var w in e.entityValue.Split(' ')) { if (db.entity.Where(x => x.entitySynonimus.Contains(";" + w + ";")).Count() == 0) { var ent = new entity(); ent.entityValue = w; ent.entityType = e.entityType; var word = getWordsObjectFromParserServer(w).Single(); if (word.Lemma != w) { ent.entitySynonimus = (";" + w + ";" + word.Lemma + ";"); } else { ent.entitySynonimus = (";" + w + ";"); } db.entity.Add(ent); } } } } } } foreach (var m in list) { var curr = db.multyEntity.Where(x => x.entityValue == m.entityValue); if (curr.Count() != 0) { var c = curr.Single(); c.parts = (c.parts + m.parts).Replace(";;", ";"); } else { db.multyEntity.Add(m as multyEntity); } } db.SaveChanges(); }