public void PersistTriples(string graphIri, HashSet <model.rdf.Triple> triplesToPersist) { _logger.LogTrace("Persisting triples into graph with IRI '{0}'. Triples: {1}", graphIri, triplesToPersist); IGraph model = _rdf4jMapper.TriplesToGraph(triplesToPersist); var tryMore = true; model.BaseUri = new Uri(graphIri); for (var i = 0; i < NUMBER_OF_ATTEMPTS && tryMore; i++) { try { if (_repository.HasGraph(model.BaseUri)) { _stardogGraphConnector.UpdateGraph(model.BaseUri, model.Triples, null); } else { _stardogGraphConnector.SaveGraph(model); } tryMore = false; } catch (Exception ex) { _logger.LogError("Exception was thrown while adding a model to the repository.", ex); } } _logger.LogTrace("Persisted {0} triples into the <{1}> graph.", triplesToPersist.Count, graphIri); }
/// <summary> /// Merges the graphs from IMDb, LastFM and Charts_de into a new database /// </summary> private static void MergeGraphs() { Log("Executing MergeGraphs()"); Log("Connecting to Movie store..."); var movieStore = new StardogConnector(settings.ServerIp, MoviesDbName, settings.Login, settings.Password); movieStore.Timeout = int.MaxValue; #region Tunefind Log("Connecting to Tunefind store..."); var tuneFindStore = new StardogConnector(settings.ServerIp, TuneFindDbName, settings.Login, settings.Password); var tuneFindGraph = new Graph(); tuneFindGraph.BaseUri = new Uri("http://imn.htwk-leipzig.de/pbachman/ontologies/tunefind#"); tuneFindStore.LoadGraph(tuneFindGraph, string.Empty); Log("Uploading Graph..."); movieStore.DeleteGraph("http://imn.htwk-leipzig.de/pbachman/ontologies/tunefind#"); movieStore.SaveGraph(tuneFindGraph); #endregion #region IMDB Log("Connecting to IMDB store..."); var imdbStore = new StardogConnector(settings.ServerIp, ImdbDbName, settings.Login, settings.Password); var imdbGraph = new Graph(); imdbGraph.BaseUri = new Uri("http://imn.htwk-leipzig.de/pbachman/ontologies/imdb#"); imdbStore.LoadGraph(imdbGraph, string.Empty); Log("Uploading Graph..."); movieStore.DeleteGraph("http://imn.htwk-leipzig.de/pbachman/ontologies/imdb#"); movieStore.SaveGraph(imdbGraph); #endregion #region LastFM Log("Connecting to LastFm store..."); var lastFmStore = new StardogConnector(settings.ServerIp, LastFmDbName, settings.Login, settings.Password); var lastFmGraph = new Graph(); lastFmGraph.BaseUri = new Uri("http://imn.htwk-leipzig.de/pbachman/ontologies/lastfm#"); lastFmStore.LoadGraph(lastFmGraph, string.Empty); Log("Uploading Graph..."); movieStore.DeleteGraph("http://imn.htwk-leipzig.de/pbachman/ontologies/lastfm#"); movieStore.SaveGraph(lastFmGraph); #endregion #region Charts_de Log("Connecting to Chart_De store..."); var chartsDeStore = new StardogConnector(settings.ServerIp, ChartsDeDbName, settings.Login, settings.Password); var chartsDeGraph = new Graph(); chartsDeGraph.BaseUri = new Uri("http://imn.htwk-leipzig.de/pbachman/ontologies/charts_de#"); chartsDeStore.LoadGraph(chartsDeGraph, string.Empty); Log("Uploading Graph..."); movieStore.DeleteGraph("http://imn.htwk-leipzig.de/pbachman/ontologies/charts_de#"); movieStore.SaveGraph(chartsDeGraph); #endregion Log("Merging Graphs..."); var movieGraph = SetupMovieGraph(); movieGraph.Merge(tuneFindGraph); movieGraph.Merge(imdbGraph); movieGraph.Merge(lastFmGraph); movieGraph.Merge(chartsDeGraph); Log("Writing Graph..."); var writer = new CompressingTurtleWriter(TurtleSyntax.W3C); writer.Save(movieGraph, @"01_Movies.ttl"); }