Example #1
0
        private static void CreateImage()
        {
            var client = new HttpClient();

            var request = JsonConvert.SerializeObject(new CreateImageCommand()
            {
                Uri         = ImorEnum.GetUri("TestImage6"),
                Description = "Test 6",
                Content     = "https://wallpaperbrowse.com/media/images/3848765-wallpaper-images-download.jpg",
                Tags        = new List <string>()
                {
                    "DogTag",
                    "PetTag",
                    "TestTag"
                }
            });

            var httpRequest = new HttpRequestMessage(HttpMethod.Post, "http://localhost:52676/api/images/create");

            httpRequest.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));

            httpRequest.Content = new StringContent(request, Encoding.UTF8, "application/json");

            var result = client.SendAsync(httpRequest).Result;

            Console.WriteLine(request);

            Console.WriteLine(result.StatusCode);

            Console.WriteLine(result.Content.ReadAsStringAsync().Result);
        }
Example #2
0
        public void InsertImage(ImorImage image)

        {
            var node = graph.CreateUriNode(new Uri(image.Uri));

            var typeNode = graph.GetUriNode(new Uri(ImorEnum.RdfType));

            var imageNode = graph.GetUriNode(new Uri(ImorEnum.Image));

            var t = new Triple(node, typeNode, imageNode);

            if (!string.IsNullOrEmpty(image.Description))
            {
                var descriptionNode = graph.GetUriNode(new Uri(ImorEnum.Description));

                var descriptionTriple = new Triple(node, descriptionNode, graph.CreateLiteralNode(image.Description));

                graph.Assert(descriptionTriple);
            }

            if (!string.IsNullOrEmpty(image.Content))
            {
                var contentNode = graph.GetUriNode(new Uri(ImorEnum.Content));

                var contenTriple = new Triple(node, contentNode, graph.CreateLiteralNode(image.Content));

                graph.Assert(contenTriple);
            }

            if (image.Tags.Any())
            {
                foreach (var tag in image.Tags)
                {
                    var tagNode = graph.GetUriNode(new Uri(ImorEnum.GetUri(tag.Uri)));

                    if (tagNode != null)
                    {
                        var hasNode = graph.GetUriNode(new Uri(ImorEnum.HasA));

                        var tagTriple = new Triple(node, hasNode, tagNode);

                        graph.Assert(tagTriple);
                    }
                }
            }

            graph.Assert(t);

            var sw = new StringWriter(new StringBuilder(DatabaseInitializer.ontology));

            graph.SaveToStream(sw, new CompressingTurtleWriter());
        }
        public ImorTag GetTagByUri(string uri)
        {
            var imorUri = new Uri(ImorEnum.GetUri(uri));

            var tagNode = graph.GetUriNode(imorUri);

            if (tagNode == null)
            {
                return(null);
            }

            var properties = graph.GetTriplesWithSubject(tagNode);

            var tag = this.MapImorTag(imorUri.ToString(), properties);

            return(tag);
        }
Example #4
0
        private void InsertImage()
        {
            var repository = new ImagesRepository();

            repository.InsertImage(new ImorImage()
            {
                Uri         = ImorEnum.GetUri("TestImage3"),
                Description = "Test image 3",
                Content     = "https://imagesvc.timeincapp.com/v3/mm/image?url=https%3A%2F%2Ffortunedotcom.files.wordpress.com%2F2017%2F01%2Fgettyimages-632438922.jpg&w=800&q=85",
                Tags        = new List <ImorTag>
                {
                    new ImorTag
                    {
                        Uri         = "http://www.semanticweb.org/ImagesOntology#CatsTag",
                        Description = "This is a cat tag",
                        Label       = "Cats"
                    }
                }
            });
        }
        public void Post([FromBody] CreateImageCommand request)
        {
            var repository = new ImagesRepository();

            var tagRepository = new TagsRepository();

            var tags = new List <ImorTag>();

            foreach (var tagLabel in request.Tags)
            {
                var existingTag = tagRepository.GetTagByUri(tagLabel);

                if (existingTag != null)
                {
                    tags.Add(existingTag);
                }
                else
                {
                    var tag = new ImorTag()
                    {
                        Uri         = ImorEnum.GetUri(tagLabel),
                        Label       = tagLabel,
                        Description = "This is a label for " + tagLabel
                    };

                    tagRepository.InsertImorTag(tag);

                    tags.Add(tag);
                }
            }

            repository.InsertImage(new ImorImage
            {
                Uri         = request.Uri,
                Description = request.Description,
                Content     = request.Content,
                Tags        = tags
            });
        }