// POST: api/Document
        public async Task <HttpResponseMessage> Post()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root     = HttpContext.Current.Server.MapPath("~/App_Data");
            var    provider = new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                // This illustrates how to get the file names.
                foreach (MultipartFileData file in provider.FileData)
                {
                    Document      doc = new Document();
                    string        textExtractionResult = new TextExtractor().Extract(file.LocalFileName).Text;
                    List <string> shingles             = _minHashes.GetShingles(textExtractionResult);
                    doc.ID        = documents.Count + 1;
                    doc.Name      = file.Headers.ContentDisposition.FileName.Replace("\"", "");
                    doc.MinHashes = _minHashes.GetMinHash(shingles);
                    documents.Add(doc);
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (System.Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
Beispiel #2
0
        public void GetShinglesTest()
        {
            MinHash       minHash  = new MinHash(10);
            string        input    = "Hello world I am a string";
            List <string> result   = minHash.GetShingles(input);
            List <string> expected = new List <string>()
            {
                "hello world i", "world i am", "i am a", "am a string", "a string", "string"
            };

            Assert.AreEqual(string.Join(" ", expected), string.Join(" ", result));
        }