// Add category and childrens in a graph to the database public async Task <Boolean> AddCategory(Graph g, Category broader) { IUriNode dcatDataset = g.CreateUriNode("skos:Concept"); String[] datasetUri = findSubjectUri(g, dcatDataset).Split(","); // From the dataset uri make a dictionary with the attributes Dictionary <string, string> attributes = getAttributesFromSubject(g, datasetUri[0]); String[] prefLabels = attributes.GetValueOrDefault("prefLabel", "").Split(","); Category category = new Category { Name = prefLabels[0], Broader = broader }; await _categoryRepository.AddAsync(category); await _unitOfWork.CompleteAsync(); String[] narrowerUrls = attributes.GetValueOrDefault("narrower", "").Split(","); foreach (String url in narrowerUrls) { if (!String.IsNullOrEmpty(url)) { await AddCategory(NetworkHandling.LoadFromUriXml(url), category); } } return(true); }
// Add concept scheme in a graph to the database public async Task <Boolean> AddConceptScheme(Graph g) { IUriNode dcatDataset = g.CreateUriNode("skos:ConceptScheme"); String[] datasetUri = findSubjectUri(g, dcatDataset).Split(","); // From the dataset uri make a dictionary with the attributes Dictionary <string, string> attributes = getAttributesFromSubject(g, datasetUri[0]); String[] topConceptUrls = attributes.GetValueOrDefault("hasTopConcept", "").Split(","); foreach (String topConceptUrl in topConceptUrls) { await AddCategory(NetworkHandling.LoadFromUriXml(topConceptUrl), null); } return(true); }
// TODO: De fra data.norge.no har flere format på en distribution?? Skal vi støtte det? :o // RART: Finner ikke kategori kobling i rdfene // Import dataset from link containing rdf schema. public async Task <DatasetResponse> import(String url, int categoryId) { Graph g; try { // Guess the url is actually an url. if (url.Contains("/")) { // If it is in fellesdatakatalog API we need to request with headers to get on rdf format if (url.Contains("fellesdatakatalog.digdir.no")) { g = NetworkHandling.LoadFromUriWithHeadersTurtle(url); } // If the url is directly to the page on data.norge.no fetch with the id else if (url.Contains("data.norge.no")) { g = NetworkHandling.LoadFromUriWithHeadersTurtle("https://fellesdatakatalog.digdir.no/api/datasets/" + url.Substring(url.LastIndexOf("/") + 1)); } // Otherwise hope the url is directly to a rdf file location on XML format else { g = NetworkHandling.LoadFromUriXml(url); } } // Guess it is not an url, and instead ID to some dataset in data.norge.no else { g = NetworkHandling.LoadFromUriWithHeadersTurtle("https://fellesdatakatalog.digdir.no/api/datasets/" + url); } } catch (Exception ex) { return(new DatasetResponse($"Invalid import url. {ex.Message}")); } // Try to parse the dataset and save it in the database DatasetResponse dataset = await _graphService.AddDataset(g, categoryId); return(dataset); }
// Import categories public async Task <Boolean> importCategories(String url) { Graph g = NetworkHandling.LoadFromUriXml(url); return(await _graphService.AddCategory(g, null)); }