예제 #1
0
        public void InsertImorTag(ImorTag tag)
        {
            var node = graph.CreateUriNode(new Uri(tag.Uri));

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

            var tagNode = graph.GetUriNode(new Uri(ImorEnum.Tag));

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

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

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

                graph.Assert(descriptionTriple);
            }

            if (!string.IsNullOrEmpty(tag.Label))
            {
                var label = graph.GetUriNode(new Uri(ImorEnum.TagLabel));

                var contenTriple = new Triple(node, label, graph.CreateLiteralNode(tag.Label));

                graph.Assert(contenTriple);
            }

            graph.Assert(t);

            graph.SaveToFile(DatabaseInitializer.ontology);
        }
        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
            });
        }
예제 #3
0
        private ImorTag MapImorTag(string uri, IEnumerable <Triple> tagProperties)
        {
            var tag = new ImorTag()
            {
                Uri = uri
            };

            foreach (var property in tagProperties)
            {
                if (property.Predicate.ToString() == ImorEnum.TagLabel)
                {
                    tag.Label = property.Object.AsValuedNode().AsString();
                }

                if (property.Predicate.ToString() == ImorEnum.Description)
                {
                    tag.Description = property.Object.AsValuedNode().AsString();
                }
            }

            return(tag);
        }
예제 #4
0
        public IEnumerable <ImorTag> GetTagsForImage(string imageUri)
        {
            var tags = new List <ImorTag>();

            var imageNode = graph.GetUriNode(new Uri(imageUri));

            var hasA = graph.GetUriNode(new Uri(ImorEnum.HasA));

            var triplesForNode = graph.GetTriplesWithSubjectPredicate(imageNode, hasA);

            foreach (var triple in triplesForNode)
            {
                var tag = new ImorTag
                {
                    Uri = triple.Object.ToString()
                };

                var tagProperties = graph.GetTriplesWithSubject(triple.Object);

                foreach (var property in tagProperties)
                {
                    if (property.Predicate.ToString() == ImorEnum.TagLabel)
                    {
                        tag.Label = property.Object.AsValuedNode().AsString();
                    }

                    if (property.Predicate.ToString() == ImorEnum.Description)
                    {
                        tag.Description = property.Object.AsValuedNode().AsString();
                    }
                }

                tags.Add(tag);
            }

            return(tags);
        }