Exemplo n.º 1
0
        public bool ApplyDiff(IDiffResult diffResult)
        {
            // TODO: Make async
            Log.LogTrace("ApplyDiff: {0}", diffResult.ToString());
            var store = GetStore();

            if (!diffResult.Success)
            {
                Log.LogTrace("ApplyDiff: Aborting attempt to apply a failed diff command result");
                return(false);
            }
            var updateGraph = new NonIndexedGraph {
                BaseUri = new Uri("http://example.org/")
            };
            var parser = new NQuadsParser();

            Log.LogTrace("ApplyDiff: Applying deletes");
            parser.Parse(diffResult.FileDiffs.SelectMany(diff => diff.Deleted),
                         triple => store.Retract(triple.Subject, triple.Predicate, triple.Object, triple.GraphUri),
                         updateGraph);
            updateGraph.Clear();
            Log.LogTrace("ApplyDiff: Applying inserts");
            parser.Parse(diffResult.FileDiffs.SelectMany(diff => diff.Inserted),
                         triple => store.Assert(triple.Subject, triple.Predicate, triple.Object, triple.GraphUri),
                         updateGraph);
            Log.LogTrace("ApplyDiff: Flushing changes");
            store.Flush();
            Log.LogTrace("ApplyDiff: Completed");
            return(true);
        }
Exemplo n.º 2
0
        public Triple FromColumns(IEnumerable <TColumn> columns)
        {
            //Determine the Graph we're extracting this from
            TColumn         graphColumn = this.GetColumnWithName(columns, this._graphColumn);
            Uri             graphUri    = this.FromColumn(graphColumn);
            NonIndexedGraph g           = new NonIndexedGraph();

            return(this.FromColumns(g, columns));
        }
Exemplo n.º 3
0
        public static SparqlQueryable Create(string fileOrUri, string namedGraphUri)
        {
            if (System.IO.File.Exists(fileOrUri))
            {
                var graph = new NonIndexedGraph();

                graph.LoadFromFile(fileOrUri);
                return(new SparqlQueryable(graph));
            }
            var endpoint = new SparqlRemoteEndpoint(UriFactory.Create(fileOrUri));

            return(new SparqlQueryable(endpoint, namedGraphUri));
        }
Exemplo n.º 4
0
        static Graph()
        {
            using var schemaFull = new NonIndexedGraph();
            schemaFull.LoadFromEmbeddedResource("GraphEngine.Resources.Schema.ttl, GraphEngine");

            using var schemaClean = new NonIndexedGraph();
            schemaClean.Assert(
                schemaFull
                .GetTriplesWithPredicate(UriFactory.Create(OntologyHelper.PropertyDomain))
                .Where(t => !ExcludedClasses.Contains(t.Object)));

            Reasoner.Initialise(schemaClean);
        }
Exemplo n.º 5
0
        public static Triple ToTriple(this string inputLine)
        {
            if (string.IsNullOrWhiteSpace(inputLine))
            {
                return(null);
            }
            var g = new NonIndexedGraph();

            StringParser.Parse(g, inputLine);
            if (g.Triples == null)
            {
                return(null);
            }
            if (!g.Triples.Any())
            {
                return(null);
            }
            return(g.Triples?.Last());
        }
Exemplo n.º 6
0
        public void ParseDiff(IDiffResult diffResult, QuinceDiff quinceDiff)
        {
            // TODO: Make async
            Log.LogTrace("ParseDiff: {0}", diffResult.ToString());
            if (!diffResult.Success)
            {
                Log.LogTrace("ParseDiff: Aborting attempt to apply a failed diff command result");
                return;
            }
            var diffGraph = new NonIndexedGraph {
                BaseUri = new Uri("http://example.org/")
            };
            var parser = new NQuadsParser();

            Log.LogTrace("ParseDiff: Parsing deletes");
            parser.Parse(diffResult.FileDiffs.Where(fd => fd.FilePath.StartsWith("_s")).SelectMany(diff => diff.Deleted),
                         quinceDiff.Deleted,
                         diffGraph);
            diffGraph.Clear();
            Log.LogTrace("ParseDiff: Parsing inserts");
            parser.Parse(diffResult.FileDiffs.Where(fd => fd.FilePath.StartsWith("_s")).SelectMany(diff => diff.Inserted),
                         quinceDiff.Inserted,
                         diffGraph);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Processes a DROP command
        /// </summary>
        /// <param name="cmd">Drop Command</param>
        public void ProcessDropCommand(DropCommand cmd)
        {
            if (this._manager is IUpdateableGenericIOManager)
            {
                ((IUpdateableGenericIOManager)this._manager).Update(cmd.ToString());
            }
            else
            {
                try
                {
                    Graph g;
                    switch (cmd.Mode)
                    {
                        case ClearMode.Graph:
                        case ClearMode.Default:
                            if (this._manager.DeleteSupported)
                            {
                                //If available use DeleteGraph()
                                this._manager.DeleteGraph(cmd.TargetUri);
                            }
                            else if ((cmd.TargetUri == null && (this._manager.IOBehaviour & IOBehaviour.OverwriteDefault) != 0) || (cmd.TargetUri != null && (this._manager.IOBehaviour & IOBehaviour.OverwriteNamed) != 0))
                            {
                                //Can approximate by saving an empty Graph over the existing Graph
                                g = new Graph();
                                g.BaseUri = cmd.TargetUri;
                                this._manager.SaveGraph(g);
                            }
                            else if (this._manager.UpdateSupported && (this._manager.IOBehaviour & IOBehaviour.CanUpdateDeleteTriples) != 0)
                            {
                                //Can approximate by loading the Graph and then deleting all Triples from it
                                g = new NonIndexedGraph();
                                this._manager.LoadGraph(g, cmd.TargetUri);
                                this._manager.UpdateGraph(cmd.TargetUri, null, g.Triples);
                            }
                            else
                            {
                                throw new SparqlUpdateException("Unable to evaluate a DROP command as the underlying store does not provide appropriate IO Behaviour to approximate this command");
                            }
                            break;

                        case ClearMode.All:
                        case ClearMode.Named:
                            if (this._manager.ListGraphsSupported)
                            {
                                List<Uri> graphs = this._manager.ListGraphs().ToList();
                                foreach (Uri u in graphs)
                                {
                                    if (this._manager.DeleteSupported)
                                    {
                                        //If available use DeleteGraph()
                                        this._manager.DeleteGraph(u);
                                    }
                                    else if ((u == null && (this._manager.IOBehaviour & IOBehaviour.OverwriteDefault) != 0) || (u != null && (this._manager.IOBehaviour & IOBehaviour.OverwriteNamed) != 0))
                                    {
                                        //Can approximate by saving an empty Graph over the existing Graph
                                        g = new Graph();
                                        g.BaseUri = u;
                                        this._manager.SaveGraph(g);
                                    }
                                    else if (this._manager.UpdateSupported && (this._manager.IOBehaviour & IOBehaviour.CanUpdateDeleteTriples) != 0)
                                    {
                                        //Can approximate by loading the Graph and then deleting all Triples from it
                                        g = new NonIndexedGraph();
                                        this._manager.LoadGraph(g, u);
                                        this._manager.UpdateGraph(u, null, g.Triples);
                                    }
                                    else
                                    {
                                        throw new SparqlUpdateException("Unable to evaluate a DROP command as the underlying store does not provide appropriate IO Behaviour to approximate this command");
                                    }
                                }
                            }
                            else
                            {
                                throw new NotSupportedException("The Generic Update processor does not support this form of the DROP command");
                            }
                            break;
                    }
                }
                catch
                {
                    if (!cmd.Silent) throw;
                }
            }
        }
Exemplo n.º 8
0
 private void Graph_TripleAsserted(object sender, TripleEventArgs args)
 {
     using var g = new NonIndexedGraph();
     g.Assert(args.Triple);
     Reasoner.Apply(g, this);
 }
Exemplo n.º 9
0
 private void mnuStructureView_Click(object sender, RoutedEventArgs e)
 {
     if (this._editor.DocumentManager.ActiveDocument == null) return;
     ISyntaxValidator validator = this._editor.DocumentManager.ActiveDocument.SyntaxValidator;
     if (validator != null)
     {
         ISyntaxValidationResults results = validator.Validate(this._editor.DocumentManager.ActiveDocument.Text);
         if (results.IsValid)
         {
             if (!this._editor.DocumentManager.ActiveDocument.Syntax.Equals("None"))
             {
                 try
                 {
                     SyntaxDefinition def = SyntaxManager.GetDefinition(this._editor.DocumentManager.ActiveDocument.Syntax);
                     if (def.DefaultParser != null)
                     {
                         NonIndexedGraph g = new NonIndexedGraph();
                         def.DefaultParser.Load(g, new StringReader(this._editor.DocumentManager.ActiveDocument.Text));
                         TriplesWindow window = new TriplesWindow(g);
                         window.ShowDialog();
                     }
                     //else if (def.Validator is RdfDatasetSyntaxValidator)
                     //{
                     //    TripleStore store = new TripleStore();
                     //    StringParser.ParseDataset(store, textEditor.Text);
                     //}
                     else if (def.Validator is SparqlResultsValidator)
                     {
                         SparqlResultSet sparqlResults = new SparqlResultSet();
                         StringParser.ParseResultSet(sparqlResults, this._editor.DocumentManager.ActiveDocument.Text);
                         if (sparqlResults.ResultsType == SparqlResultsType.VariableBindings)
                         {
                             ResultSetWindow window = new ResultSetWindow(sparqlResults);
                             window.ShowDialog();
                         }
                         else
                         {
                             MessageBox.Show("Cannot open Structured View since this form of SPARQL Results is not structured");
                         }
                     }
                     else
                     {
                         MessageBox.Show("Cannot open Structured View since this is not a syntax for which Structure view is available");
                     }
                 }
                 catch
                 {
                     MessageBox.Show("Unable to open Structured View as could not parse the Syntax successfully for structured display");
                 }
             }
             else
             {
                 MessageBox.Show("Cannot open Structured View since this is not a syntax for which Structure view is available");
             }
         }
         else
         {
             MessageBox.Show("Cannot open Structured View as the Syntax is not valid");
         }
     }
     else
     {
         MessageBox.Show("Cannot open Structured View as you have not selected a Syntax");
     }
 }