private void _StartWorker(DocumentOutput doc) { ModuleWorker worker = new ModuleWorker(this.EntityManager, doc); /*cream un thread nou*/ Thread thread = new Thread(new ThreadStart(worker.Run)); thread.Start(); }
/// <summary> /// Create a new DocumentOutput object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="documentId">Initial value of the DocumentId property.</param> /// <param name="type">Initial value of the Type property.</param> /// <param name="document">Initial value of the Document property.</param> /// <param name="status">Initial value of the Status property.</param> public static DocumentOutput CreateDocumentOutput(global::System.Int32 id, global::System.Int32 documentId, global::System.String type, global::System.String document, global::System.Int32 status) { DocumentOutput documentOutput = new DocumentOutput(); documentOutput.Id = id; documentOutput.DocumentId = documentId; documentOutput.Type = type; documentOutput.Document = document; documentOutput.Status = status; return(documentOutput); }
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ public DocumentOutput AddDocumentOutput(int documentId, string type, int status, string text) { if (this._dbContainer == null) { throw new EntityManagerException("Nu suntem conectati la baza de date!"); } /*verificam daca exista un document cu id-ul respectiv*/ List <Document> rezDoc = (from d in this._dbContainer.Documents where d.Id == documentId select d).ToList(); if (rezDoc.Count != 1) { throw new EntityManagerException("Nu exista un document cu id-ul specificat."); } /*verificam daca mai sunt alte fisiere pentru acelasi document id cu tipul specificat*/ List <DocumentOutput> rezOut = (from d in this._dbContainer.DocumentOutputs where d.DocumentId == documentId && d.Type == type select d).ToList(); /*daca mai exista alt fisier cu acelasi tip, il modificam pe acela*/ if (rezOut.Count > 0) { rezOut[0].Document = text; rezOut[0].Status = status; return(rezOut[0]); } DocumentOutput ret = new DocumentOutput() { DocumentId = documentId, Document = text, Status = status, Type = type }; /*adaugam fisierul in baza noastra de daze*/ this._dbContainer.DocumentOutputs.AddObject(ret); this._dbContainer.SaveChanges(); return(ret); }
/// <summary> /// Valideaza un document. Daca statusul sau este gol, atunci /// se porneste parsarea si apelarea celorlalte moduule. /// </summary> /// <param name="doc">Documentul ce trebuie validat</param> /// <returns>Fisierul XML daca exista. Null daca documentul inca nu a fost creat.</returns> public String ValidateDocumentOutput(DocumentOutput doc) { if (this.EntityManager == null) return null; switch (doc.Status) { /*daca fisierul a fost creat, il intoarcems*/ case DocumentManager.StatusOK: return doc.Document; /*daca documentul e in curs de parsare, nu facem nimic*/ case DocumentManager.StatusParsing: return null; /*daca documentul este gol, pornim workerul ce se ocupa de apelarea modulelor*/ case DocumentManager.StatusEmpty: this._StartWorker(doc); return null; default: return null; } }
/// <summary> /// Create a new DocumentOutput object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="documentId">Initial value of the DocumentId property.</param> /// <param name="type">Initial value of the Type property.</param> /// <param name="document">Initial value of the Document property.</param> /// <param name="status">Initial value of the Status property.</param> public static DocumentOutput CreateDocumentOutput(global::System.Int32 id, global::System.Int32 documentId, global::System.String type, global::System.String document, global::System.Int32 status) { DocumentOutput documentOutput = new DocumentOutput(); documentOutput.Id = id; documentOutput.DocumentId = documentId; documentOutput.Type = type; documentOutput.Document = document; documentOutput.Status = status; return documentOutput; }
/// <summary> /// Deprecated Method for adding a new object to the DocumentOutputs EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToDocumentOutputs(DocumentOutput documentOutput) { base.AddObject("DocumentOutputs", documentOutput); }
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ public DocumentOutput AddDocumentOutput(int documentId, string type, int status, string text) { if (this._dbContainer == null) throw new EntityManagerException("Nu suntem conectati la baza de date!"); /*verificam daca exista un document cu id-ul respectiv*/ List<Document> rezDoc = (from d in this._dbContainer.Documents where d.Id == documentId select d).ToList(); if(rezDoc.Count != 1) throw new EntityManagerException("Nu exista un document cu id-ul specificat."); /*verificam daca mai sunt alte fisiere pentru acelasi document id cu tipul specificat*/ List<DocumentOutput> rezOut = (from d in this._dbContainer.DocumentOutputs where d.DocumentId == documentId && d.Type == type select d).ToList(); /*daca mai exista alt fisier cu acelasi tip, il modificam pe acela*/ if (rezOut.Count > 0) { rezOut[0].Document = text; rezOut[0].Status = status; return rezOut[0]; } DocumentOutput ret = new DocumentOutput() { DocumentId = documentId, Document = text, Status = status, Type = type }; /*adaugam fisierul in baza noastra de daze*/ this._dbContainer.DocumentOutputs.AddObject(ret); this._dbContainer.SaveChanges(); return ret; }
private DocumentOutput _CombineSummary(DocumentOutput info, DocumentOutput summ) { XmlDocument root = new XmlDocument(); XmlDocument infoDoc = new XmlDocument(); infoDoc.LoadXml(info.Document); var summary = root.CreateElement("summary"); root.AppendChild(summary); /*numele romanului*/ var name = root.CreateElement("name"); summary.AppendChild(name); var nameText = root.CreateTextNode("Document title"); name.AppendChild(nameText); var extraction = root.CreateElement("extraction"); summary.AppendChild(extraction); /*tipul romanului*/ var type = root.CreateElement("type"); extraction.AppendChild(type); foreach (XmlElement genre in infoDoc.GetElementsByTagName("genre")) { /*luam doar primul*/ type.AppendChild(root.CreateTextNode(genre.GetAttribute("name"))); break; } /*personajele*/ var characters = root.CreateElement("characters"); extraction.AppendChild(characters); foreach (XmlElement ch in infoDoc.GetElementsByTagName("character")) { String cname = Regex.Replace(ch.InnerText, @"[^A-Za-z0-9 ]+", "").Trim(); var che = root.CreateElement("character"); characters.AppendChild(che); che.SetAttribute("name", cname); if (ch.HasAttribute("main")) che.SetAttribute("type", "main"); if (ch.HasAttribute("secondary")) che.SetAttribute("type", "secondary"); } /*locatiile*/ var locations = root.CreateElement("locations"); extraction.AppendChild(locations); foreach (XmlElement loc in infoDoc.GetElementsByTagName("location")) { String cloc = Regex.Replace(loc.InnerText, @"[^A-Za-z0-9 ]+", ""); var loce = root.CreateElement("location"); locations.AppendChild(loce); loce.SetAttribute("name", cloc); } /*relatiile*/ var relations = root.CreateElement("relations"); extraction.AppendChild(relations); foreach (XmlElement rel in infoDoc.GetElementsByTagName("relationship")) { String ent1 = Regex.Replace(rel.GetAttribute("entity1"), @"[^A-Za-z0-9 ]+", "").Trim(); String ent2 = Regex.Replace(rel.GetAttribute("entity2"), @"[^A-Za-z0-9 ]+", "").Trim(); String link = Regex.Replace(rel.GetAttribute("link"), @"[^A-Za-z0-9 ]+", ""); var rele = root.CreateElement("relation"); relations.AppendChild(rele); rele.SetAttribute("character1", ent1); rele.SetAttribute("character2", ent2); rele.SetAttribute("verb", link); } /*rezumatul*/ var summarisation = root.CreateElement("summarisation"); summary.AppendChild(summarisation); var summary2 = root.CreateElement("summary"); summary.AppendChild(summary2); summary2.InnerText = summ.Document; MemoryStream ms = new MemoryStream(); root.Save(ms); return this._em.AddDocumentOutput(this._doc.DocumentId, "summary", DocumentManager.StatusOK, Encoding.UTF8.GetString(ms.ToArray())) ; }
public ModuleWorker(IDocumentEntityManager em, DocumentOutput doc) { this._em = em; this._doc = doc; }
private DocumentOutput _CombineTimeline(DocumentOutput summ, DocumentOutput sit, DocumentOutput time) { XmlDocument root = new XmlDocument(); XmlDocument sitDoc = new XmlDocument(); sitDoc.LoadXml(sit.Document); XmlDocument timeDoc = new XmlDocument(); timeDoc.LoadXml(time.Document); XmlDocument summDoc = new XmlDocument(); summDoc.LoadXml(summ.Document); var situations = root.CreateElement("situations"); root.AppendChild(situations); /*infromatiile extrase anterior*/ foreach (XmlElement elem in summDoc.GetElementsByTagName("extraction")) { situations.AppendChild(elem); } foreach (XmlElement esit in sitDoc.GetElementsByTagName("situation")) { } MemoryStream ms = new MemoryStream(); root.Save(ms); return this._em.AddDocumentOutput(this._doc.DocumentId, "summary", DocumentManager.StatusOK, Encoding.UTF8.GetString(ms.ToArray())); }