internal override void AddImages(ComplexOntologyResource pResource) { base.AddImages(pResource); List <ImageAction> listAcciones = new List <ImageAction>(); listAcciones.Add(new ImageAction(234, ImageTransformationType.Crop, 100)); listAcciones.Add(new ImageAction(318, ImageTransformationType.ResizeToWidth, 100)); try { pResource.AttachImage(this.Schema_image, listAcciones, "schema:image", true, "jpg"); } catch (Exception ex) { pResource.AttachImage("https://image.freepik.com/vector-gratis/tira-pelicula-icono-herramientas-cinematografia_24640-18839.jpg", listAcciones, "schema:image", true, "jpg"); } }
private static void SubirRutas(Dictionary <string, Entity> entityList) { List <Entity> rutas = entityList.Values.Where(ent => ent.Properties.Values.Any(prop => prop.Predicate.Equals($"{Constants.Ontologies.Rdf}type") && prop.Objects.Exists(obj => obj.Value.Equals($"{Constants.Ontologies.Route}Route")))).ToList(); ResourceApi resourceAPI = new ResourceApi(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config", "config.xml")); foreach (Entity ruta in rutas) { ComplexOntologyResource resource = CreateComplexOntologyResourceRoute(entityList, ruta, resourceAPI); try { resourceAPI.LoadComplexSemanticResource(resource); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
public virtual ComplexOntologyResource ToGnossApiResource(ResourceApi resourceAPI, List <string> listaDeCategorias, Guid idrecurso, Guid idarticulo) { ComplexOntologyResource resource = new ComplexOntologyResource(); Ontology ontology = null; GetProperties(); if (idrecurso.Equals(Guid.Empty) && idarticulo.Equals(Guid.Empty)) { ontology = new Ontology(resourceAPI.GraphsUrl, resourceAPI.OntologyUrl, "http://schema.org/Person", "http://schema.org/Person", prefList, propList, entList); } else { ontology = new Ontology(resourceAPI.GraphsUrl, resourceAPI.OntologyUrl, "http://schema.org/Person", "http://schema.org/Person", prefList, propList, entList, idrecurso, idarticulo); } resource.Id = GNOSSID; resource.Ontology = ontology; resource.TextCategories = listaDeCategorias; AddResourceTitle(resource); AddResourceDescription(resource); AddImages(resource); AddFiles(resource); return(resource); }
public void CargarPeliculas(List <Movie> peliculas, Dictionary <string, string> guidDictionary) { mResourceApi.ChangeOntoly("pelicula"); List <string> guidsExistentes = new List <string>(); try { SparqlObject resultados = mResourceApi.VirtuosoQuery("Select distinct ?o ?id ", "Where { ?o <http://schema.org/name> ?id }", "pelicula"); foreach (var resultado in resultados.results.bindings) { guidsExistentes.Add(resultado["o"].value); } } catch (Exception e) { mResourceApi.Log.Error($"Error al hacer la consulta a Virtuoso: {e.Message} -> {e.StackTrace}"); } foreach (Movie pelicula in peliculas) { if (!guidsExistentes.Contains("http://try.gnoss.com/items/" + guidDictionary[pelicula.Schema_name])) { try { ComplexOntologyResource complexResource = pelicula.ToGnossApiResource(mResourceApi, null, new Guid(guidDictionary[pelicula.Schema_name].Split('_')[1]), new Guid(guidDictionary[pelicula.Schema_name].Split('_')[2])); mResourceApi.LoadComplexSemanticResource(complexResource); } catch (Exception e) { mResourceApi.Log.Error(pelicula.Schema_name); } } } }
public static ComplexOntologyResource CreateComplexOntologyResourceRoute(Dictionary <string, Entity> entityList, Entity route, ResourceApi resourceAPI) { ComplexOntologyResource recurso = new ComplexOntologyResource(); // Prefijos de ontología List <string> prefijosOntologia = new List <string>() { Constants.Prefixes.Rdf, Constants.Prefixes.Rdfs, Constants.Prefixes.Owl, Constants.Prefixes.Xsd, Constants.Prefixes.Eroute, Constants.Prefixes.Route, Constants.Prefixes.Wgs84_pos, Constants.Prefixes.Eharmonise }; // Propiedades List <OntologyProperty> listPropiedades = new List <OntologyProperty>(); if (route.Properties.ContainsKey(Constants.RouteProperties.Name)) { recurso.Title = route.Properties[Constants.RouteProperties.Name].Objects[0].Value; foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Name].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.NameWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Description)) { recurso.Description = route.Properties[Constants.RouteProperties.Description].Objects[0].Value; foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Description].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.DescriptionWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Ads)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Ads].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.AdsWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Color)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Color].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.ColorWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Date)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Date].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.DateWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.GpsRoute)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.GpsRoute].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.GpsRouteWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.HeadOf)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.HeadOf].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.HeadOfWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Hunts)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Hunts].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.HuntsWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Pdf)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Pdf].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.PdfWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Points)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Points].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.PointsWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Publication)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Publication].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.PublicationWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.RouteFeature)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.RouteFeature].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.RouteFeatureWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.RouteId)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.RouteId].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.RouteIdWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.RouteNaturalValue)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.RouteNaturalValue].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.RouteNaturalValueWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.RouteNumber)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.RouteNumber].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.RouteNumberWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Source)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Source].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.SourceWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.TouristInformation)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.TouristInformation].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.TouristInformationWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Trail)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Trail].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.TrailWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Region)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Region].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.RegionWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Duration)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Duration].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.DurationWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Length)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Length].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.LengthWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Signaling)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Signaling].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.SignalingWithNamespace, obj.Value, obj.Language)); } } if (route.Properties.ContainsKey(Constants.RouteProperties.Url)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Url].Objects) { listPropiedades.Add(new StringOntologyProperty(Constants.RouteProperties.UrlWithNamespace, obj.Value, obj.Language)); } } List <OntologyEntity> relatedEntitiesList = new List <OntologyEntity>(); if (route.Properties.ContainsKey(Constants.RouteProperties.Location)) { foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Location].Objects) { Entity location = entityList[obj.Value]; List <OntologyProperty> listPropiedadesEntidad = new List <OntologyProperty>(); if (location.Properties.ContainsKey(Constants.RouteProperties.Lat)) { listPropiedadesEntidad.Add(new StringOntologyProperty(Constants.RouteProperties.LatWithNamespace, location.Properties[Constants.RouteProperties.Lat].Objects[0].Value)); } if (location.Properties.ContainsKey(Constants.RouteProperties.Long)) { listPropiedadesEntidad.Add(new StringOntologyProperty(Constants.RouteProperties.LongWithNamespace, location.Properties[Constants.RouteProperties.Long].Objects[0].Value)); } OntologyEntity entLocation = new OntologyEntity(Constants.Ontologies.Eharmonise + "Location", Constants.Ontologies.Eharmonise + "Location", Constants.RouteProperties.LocationWithNamespace, listPropiedadesEntidad); relatedEntitiesList.Add(entLocation); } } List <ImageToAttach> imagesToAttach = new List <ImageToAttach>(); if (route.Properties.ContainsKey(Constants.RouteProperties.Images)) { bool mainImage = true; byte[] imageBytes = null; foreach (ObjectWithLanguage obj in route.Properties[Constants.RouteProperties.Images].Objects) { Entity image = entityList[obj.Value]; List <OntologyProperty> listPropiedadesEntidad = new List <OntologyProperty>(); if (image.Properties.ContainsKey(Constants.RouteProperties.Image)) { string relativeImageUrl = image.Properties[Constants.RouteProperties.Image].Objects[0].Value; imageBytes = DownloadRouteImage(relativeImageUrl); } if (image.Properties.ContainsKey(Constants.RouteProperties.Title)) { listPropiedadesEntidad.Add(new StringOntologyProperty(Constants.RouteProperties.TitleWithNamespace, image.Properties[Constants.RouteProperties.Title].Objects[0].Value)); } OntologyEntity entImage = new OntologyEntity(Constants.Ontologies.Eharmonise + "Image", Constants.Ontologies.Eharmonise + "Image", Constants.RouteProperties.ImagesWithNamespace, listPropiedadesEntidad); List <ImageAction> listAcciones = new List <ImageAction>(); listAcciones.Add(new ImageAction(234, Gnoss.ApiWrapper.Helpers.ImageTransformationType.Crop, 100)); listAcciones.Add(new ImageAction(660, Gnoss.ApiWrapper.Helpers.ImageTransformationType.ResizeToHeight, 100)); imagesToAttach.Add(new ImageToAttach() { ImageBytes = imageBytes, ActionList = listAcciones, Predicate = Constants.RouteProperties.ImageWithNamespace, Extension = "jpg", IsMainImage = mainImage, Entity = entImage }); relatedEntitiesList.Add(entImage); mainImage = false; } } Ontology ont = new Ontology(resourceAPI.GraphsUrl, resourceAPI.OntologyUrl, "http://www.obertadecatalunya/route#Route", "http://www.obertadecatalunya/route#Route", prefijosOntologia, listPropiedades, relatedEntitiesList); recurso.Ontology = ont; recurso.CreationDate = DateTime.Now; recurso.Visibility = ResourceVisibility.open; foreach (ImageToAttach image in imagesToAttach) { recurso.AttachImage(image.ImageBytes, image.ActionList, image.Predicate, image.IsMainImage, image.Extension, image.Entity); } return(recurso); }
internal virtual void AddFiles(ComplexOntologyResource pResource) { }
internal override void AddImages(ComplexOntologyResource pResource) { base.AddImages(pResource); }
internal void AddResourceDescription(ComplexOntologyResource resource) { resource.Description = this.Schema_description; }
internal void AddResourceTitle(ComplexOntologyResource resource) { resource.Title = this.Schema_name; }