public int?GetOwner(int fileId) { OCRDatabaseEntities db = new OCRDatabaseEntities(); int?owner = db.Documents.Where(a => a.Id == fileId).FirstOrDefault().Owner; return(owner); }
public IHttpActionResult UpdateDocumentType(int fileId) { HttpContent requestContent = Request.Content; System.Diagnostics.Debug.WriteLine(requestContent); string jsonContent = requestContent.ReadAsStringAsync().Result; //System.Diagnostics.Debug.WriteLine(jsonContent.GetType()); //string text = JsonConvert.DeserializeObject<String>(jsonContent); dynamic jsonText = JsonConvert.DeserializeObject(jsonContent); string type = JsonConvert.SerializeObject(jsonText.type); int val = Int32.Parse(type); /* * string text = ""; * for(int i = 0; i < 40; i++) * { * text += jsonText.text[i].Text; * text += jsonText.text[i].Coords; * } */ //System.Diagnostics.Debug.WriteLine(type); //string text = jsonText.text; OCRDatabaseEntities db = new OCRDatabaseEntities(); Document doc = db.Documents.Find(fileId); if (doc == null) { return(NotFound()); } doc.DocumentType = type; System.Diagnostics.Debug.WriteLine("Type: " + type); db.SaveChanges(); string dataFilePath = System.Web.HttpContext.Current.Server.MapPath("~/Data/data_train.csv"); string processedText = TextPreprocessorService.parseJSONText(db.Documents.Find(fileId).DocumentText); //System.Diagnostics.Debug.WriteLine("Nakon JSON parse-a:" + processedText); processedText = TextPreprocessorService.ProcessText(ref processedText); FileIO.CSVWrite(processedText, val, dataFilePath); fileService.UnlockDocument(fileId); return(Ok()); // //Document doc = db.Documents.Find(fileId); //if (doc.DocumentText == null) //{ // OCRService ocr = new OCRService(); // if (!ocr.RecognizeText(fileId)) // { // //Debug.WriteLine("cao1"); // return NotFound(); // } //} ////Debug.WriteLine("cao"); //return Ok(doc.DocumentText); }
public int?getCurrentUser() { OCRDatabaseEntities db = new OCRDatabaseEntities(); int?user = db.Users.Where(a => a.Username == System.Web.HttpContext.Current.User.Identity.Name).FirstOrDefault().Id; return(user); }
public IHttpActionResult FileOCR(int fileId) { OCRDatabaseEntities db = new OCRDatabaseEntities(); System.Diagnostics.Debug.WriteLine("Init TEXT:" + db.Documents.Find(fileId).DocumentText); string text = DocFileService.GetFileText(fileId); //db.Documents.Find(fileId).DocumentText; if (text == null) { System.Diagnostics.Debug.WriteLine("usao u prvi if"); if ((text = OcrService.RecognizeText(fileId)).Length == 0) { //System.Diagnostics.Debug.WriteLine("usao u drugi if"); //Debug.WriteLine("cao1"); return(NotFound()); } //text = db.Documents.Find(fileId).DocumentText; } //Debug.WriteLine("cao"); //System.Diagnostics.Debug.WriteLine("TEXT:" +doc.DocumentText); //Document doc = db.Documents.Find(fileId); //System.Diagnostics.Debug.WriteLine("Controller TEXT:" + doc.DocumentText); return(Ok(text)); }
public List <Document> GetFilesByOwner(int?owner) { OCRDatabaseEntities db = new OCRDatabaseEntities(); List <Document> docs = db.Documents.Where(d => d.Owner == owner).ToList(); return(docs); }
public List <Document> GetAllVirutalFolders() { OCRDatabaseEntities db = new OCRDatabaseEntities(); List <Document> virtualFolders = db.Documents.ToList(); return(virtualFolders); }
public string GetFileText(int fileId) { OCRDatabaseEntities db = new OCRDatabaseEntities(); string text = db.Documents.Find(fileId).DocumentText; return(text); }
public List <Document> GetAllFilesFromFolder(string folder) { OCRDatabaseEntities db = new OCRDatabaseEntities(); List <Document> files = db.Documents.Where(a => a.Virtual_Path == folder).ToList(); return(files); }
public IHttpActionResult DeleteFolder(string folder) { //string[] path = folderAndName.Split('/'); OCRDatabaseEntities db = new OCRDatabaseEntities(); List <Document> files = db.Documents.Where(a => a.Virtual_Path == folder).ToList(); if (files.Count == 0) { //Debug.WriteLine("cao1"); return(NotFound()); } //Debug.WriteLine("cao"); foreach (Document doc in files) { db.Documents.Remove(doc); string file = doc.Path; if ((System.IO.File.Exists(file))) { System.IO.File.Delete(file); } } db.SaveChanges(); return(Ok()); }
public ActionResult Register(Register r, string ReturnUrl = "") { using (OCRDatabaseEntities db = new OCRDatabaseEntities()) { if (ModelState.IsValid) { db.Users.Add(new User { Username = r.Username, Firstname = r.FirstName, Lastname = r.LastName, Email = r.Email, Password = r.Password }); db.SaveChanges(); FormsAuthentication.SetAuthCookie(r.Username, r.RememberMe); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("UploadDocument", "Document")); } } } ModelState.Remove("Password"); return(View()); }
public JsonResult IsUserExists2(string email) { //check if any of the UserName matches the UserName specified in the Parameter using the ANY extension method. OCRDatabaseEntities db = new OCRDatabaseEntities(); return(Json(!db.Users.Any(x => x.Email == email), JsonRequestBehavior.AllowGet)); }
public ActionResult Login(Login l, string ReturnUrl = "") { using (OCRDatabaseEntities db = new OCRDatabaseEntities()) { var user = db.Users.Where(a => a.Username.Equals(l.Username) && a.Password.Equals(l.Password)).FirstOrDefault(); if (user != null) { FormsAuthentication.SetAuthCookie(user.Username, l.RememberMe); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { Session["Username"] = l.Username; return(RedirectToAction("UploadDocument", "Document")); } } else { ModelState.AddModelError("Log", "Invalid Username or Password."); } } ModelState.Remove("Password"); return(View()); }
public Document FindDocumentById(long id) { OCRDatabaseEntities db = new OCRDatabaseEntities(); var document = db.Documents.Where(a => a.Id == id).FirstOrDefault(); return(document); }
public User FindUserById(long id) { using (OCRDatabaseEntities db = new OCRDatabaseEntities()) { var user = db.Users.Where(a => a.Id == id).FirstOrDefault(); return(user); } }
public bool ChangeText(int id, string text) { OCRDatabaseEntities db = new OCRDatabaseEntities(); Document doc = db.Documents.Find(id); doc.DocumentText = text; db.SaveChanges(); return(true); }
public IHttpActionResult UpdateFile(int fileId) { HttpContent requestContent = Request.Content; System.Diagnostics.Debug.WriteLine(requestContent); string jsonContent = requestContent.ReadAsStringAsync().Result; //System.Diagnostics.Debug.WriteLine(jsonContent.GetType()); //string text = JsonConvert.DeserializeObject<String>(jsonContent); dynamic jsonText = JsonConvert.DeserializeObject(jsonContent); string text = JsonConvert.SerializeObject(jsonText.text); /* * string text = ""; * for(int i = 0; i < 40; i++) * { * text += jsonText.text[i].Text; * text += jsonText.text[i].Coords; * } */ System.Diagnostics.Debug.WriteLine(text); //string text = jsonText.text; OCRDatabaseEntities db = new OCRDatabaseEntities(); //Document doc = DocFileService.getFileById(fileId); Document doc = db.Documents.Find(fileId); if (doc == null) { return(NotFound()); } System.Diagnostics.Debug.WriteLine("Tekst na pocetku:" + doc.DocumentText + " , id = " + doc.Id + ", request id: " + fileId); doc.DocumentText = text; //db.SaveChanges(); db.SaveChanges(); System.Diagnostics.Debug.WriteLine("Tekst na pocetku:" + doc.DocumentText); DocFileService.UnlockDocument(fileId); return(Ok()); // //Document doc = db.Documents.Find(fileId); //if (doc.DocumentText == null) //{ // OCRService ocr = new OCRService(); // if (!ocr.RecognizeText(fileId)) // { // //Debug.WriteLine("cao1"); // return NotFound(); // } //} ////Debug.WriteLine("cao"); //return Ok(doc.DocumentText); }
public void RemoveDocuments(Document file) { OCRDatabaseEntities db = new OCRDatabaseEntities(); db.Documents.Remove(file); string fileName = file.Path; if ((System.IO.File.Exists(fileName))) { System.IO.File.Delete(fileName); } db.SaveChanges(); }
public void UpdateDocument(string text, long id) { OCRDatabaseEntities db = new OCRDatabaseEntities(); try { Document doc = db.Documents.Find(id); doc.DocumentText = text; db.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.StackTrace); } }
public void SaveDocument(Document doc) { using (OCRDatabaseEntities db = new OCRDatabaseEntities()) { db.Documents.Add(new Document { Name = doc.Name, Path = doc.Path, DocumentText = doc.DocumentText, DocumentType = doc.DocumentType, DocumentLock = doc.DocumentLock, Owner = doc.Owner, Uploader = doc.Uploader, Language = doc.Language, Virtual_Path = doc.Virtual_Path }); db.SaveChanges(); } }
public IHttpActionResult IsLocked(int fileId) { OCRDatabaseEntities db = new OCRDatabaseEntities(); var owner = DocFileService.GetOwner(fileId); DBService dbService = new DBService(); if (owner != null) { string ownerName = DbService.FindUserById((int)owner).Username; if (System.Web.HttpContext.Current.User.Identity.Name == ownerName) { return(Ok(true)); } return(Ok(false)); } return(Ok(-1)); }
public IHttpActionResult UnlockAll() { OCRDatabaseEntities db = new OCRDatabaseEntities(); //get { return dbService; } set { dbService = value; } int?user = AppUserService.getCurrentUser(); System.Diagnostics.Debug.WriteLine(user + " USER ID "); //FileService fs = new FileService(); var docs = DocFileService.GetFilesByOwner(user); foreach (var doc in docs) { DocFileService.UnlockDocument(doc.Id); } db.SaveChanges(); return(Ok(1991)); }
public IHttpActionResult DeleteFile(string folder, int fileid) { //string[] path = folderAndName.Split('/'); OCRDatabaseEntities db = new OCRDatabaseEntities(); Document file = db.Documents.Where(a => a.Virtual_Path == folder && a.Id == fileid).FirstOrDefault(); if (file == null) { //Debug.WriteLine("cao1"); return(NotFound()); } //Debug.WriteLine("cao"); //foreach (Document doc in files) // db.Documents.Remove(doc); db.Documents.Remove(file); if ((System.IO.File.Exists(file.Path))) { System.IO.File.Delete(file.Path); } db.SaveChanges(); return(Ok()); }
public ActionResult UploadDocument(UploadModel files) { HttpPostedFileBase[] postedFile = files.PostedFiles; string virtualPath = files.VirtualPath; if (virtualPath == null) { virtualPath = "default"; } var user = System.Web.HttpContext.Current.User.Identity.Name; virtualPath = virtualPath.Trim().Replace(' ', '-'); string path = Server.MapPath("~/Uploads/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } OCRDatabaseEntities db = new OCRDatabaseEntities(); List <string> extensions = new List <string>(new string[] { ".jpg", ".jpeg", ".png", ".gif", ".JPG", ".PNG", ".JPEG", ".GIF" }); if (postedFile != null) { foreach (HttpPostedFileBase file in postedFile) { if (file != null) { //FileService.saveFile(ServerPathName); string extension = Path.GetExtension(file.FileName); var InputFileName = Path.GetFileName(file.FileName); if (extensions.Contains(extension)) { var ServerPathName = path + virtualPath + "_" + InputFileName; InputFileName = virtualPath + "_" + InputFileName; var list = db.Documents.Select(item => item.Path == ServerPathName).ToList(); int count = list.Count; file.SaveAs(ServerPathName); string messageText; var uploader = db.Users.Where(a => a.Username == System.Web.HttpContext.Current.User.Identity.Name).FirstOrDefault().Id; System.Diagnostics.Debug.WriteLine(uploader); Document doc = new Document() { Name = InputFileName, Path = ServerPathName, DocumentText = null, DocumentType = "0", DocumentLock = false, Owner = null, Uploader = uploader, Language = "en", Virtual_Path = virtualPath }; if (count > 0) { var duplicateDocs = db.Documents.Where(c => c.Path == ServerPathName); foreach (var dupDoc in duplicateDocs) { //db.Documents.Remove(dupDoc); db.Documents.Remove(dupDoc); } } db.Documents.Add(doc); db.SaveChanges(); System.Diagnostics.Debug.WriteLine(db.Documents.ToList()[0]); //file.SaveAs(path); //assigning file uploaded status to ViewBag for showing message to user. ViewBag.Message += string.Format("<span style='color: green;'><b>{0}</b> uploaded.<br /><span>", InputFileName); TempData["ourmessage"] += string.Format("<span style='color: green;'><b>{0}</b> uploaded.<br /></span>", InputFileName); } else { ViewBag.Message += string.Format("<span style='color: red;'><font color=\"red\"><b>{0}</b> cannot be uploaded. Wrong file format.<br /></font></span>", InputFileName); TempData["ourmessage"] += string.Format("<span style='color: red;'><font color=\"red\"><b>{0}</b> cannot be uploaded. Wrong file format.<br /></font></span>", InputFileName); } } } } return(RedirectToAction("UploadDocument")); }
public FileService() { _db = new OCRDatabaseEntities(); }
public string classify(int id) { OCRDatabaseEntities db = new OCRDatabaseEntities(); Document doc = db.Documents.Find(id); string text = doc.DocumentText; if ((text == null)) { text = RecognizeDocText(id); text = TextPreprocessorService.parseJSONText(text); text = TextPreprocessorService.ProcessText(ref text); if (text == null) { return(null); } } Dictionary <int, double> dict = PredictByText(text); System.Diagnostics.Debug.WriteLine("ByText"); System.Diagnostics.Debug.WriteLine(dict[1].ToString()); System.Diagnostics.Debug.WriteLine(dict[2].ToString()); System.Diagnostics.Debug.WriteLine(dict[3].ToString()); int predictionNumOFWords = PredictByNumOfWords(); System.Diagnostics.Debug.WriteLine(predictionNumOFWords); if (predictionNumOFWords == 2) { dict[2] += 0.2; } System.Diagnostics.Debug.WriteLine("ByNumOfWords"); System.Diagnostics.Debug.WriteLine(dict[1].ToString()); System.Diagnostics.Debug.WriteLine(dict[2].ToString()); System.Diagnostics.Debug.WriteLine(dict[3].ToString()); System.Diagnostics.Debug.WriteLine(OCRService.FaceFlag); int faceFlag = OCRService.FaceFlag; System.Diagnostics.Debug.WriteLine("FaceFlag"); System.Diagnostics.Debug.WriteLine(faceFlag); if (faceFlag == 1) { dict[1] += 0.75; } System.Diagnostics.Debug.WriteLine("ByFace"); System.Diagnostics.Debug.WriteLine(dict[1].ToString()); System.Diagnostics.Debug.WriteLine(dict[2].ToString()); System.Diagnostics.Debug.WriteLine(dict[3].ToString()); double maxPerc = dict.Values.Max(); if (maxPerc <= 0.1) { return("0"); } string retVal = dict.FirstOrDefault(x => x.Value == maxPerc).Key.ToString(); string type = "-" + retVal; doc.DocumentType = type; System.Diagnostics.Debug.WriteLine(doc.DocumentType); db.SaveChanges(); return(type); }