Ejemplo n.º 1
0
        public bool ImportGraph(Uri graphUri)
        {
            INode graph = RDFUtil.CreateUriNode(graphUri);

            this.Assert(graph, RDF.PropertyType, SPIN.ClassLibraryOntology);
            return(true);
        }
Ejemplo n.º 2
0
 // TODO change the name into something sensible
 internal void EnableUpdateControl()
 {
     if (!IsChanged)
     {
         IUriNode sourceDataset = RDFUtil.CreateUriNode(_sourceUri);
         BaseUri = RDFRuntime.NewTempDatasetUri();
         this.Retract(sourceDataset, RDF.PropertyType, SD.ClassDataset);
         this.Assert(RDFUtil.CreateUriNode(BaseUri), RDFRuntime.PropertyUpdatesDataset, sourceDataset);
     }
 }
Ejemplo n.º 3
0
 public bool RemoveGraph(Uri graphUri)
 {
     if (HasGraph(graphUri))
     {
         IUriNode sourceGraph = RDFUtil.CreateUriNode(graphUri);
         this.Retract(sourceGraph, RDF.PropertyType, SD.ClassGraph);
         this.Assert(RDFUtil.CreateUriNode(BaseUri), RDFRuntime.PropertyRemovesGraph, sourceGraph);
         return(true);
     }
     Retract(Triples.Where(t => t.Involves(graphUri)).ToList());
     return(true);
 }
Ejemplo n.º 4
0
        private void OnModificableGraphCleared(object sender, GraphEventArgs e)
        {
            SpinWrappedGraph graph = (SpinWrappedGraph)e.Graph;

            graph.Reset();

            IUriNode sourceGraph = RDFUtil.CreateUriNode(graph.BaseUri);
            IUriNode graphNode   = RDFUtil.CreateUriNode(GetUpdateControlUri(graph.BaseUri));

            this.Retract(graphNode, RDFRuntime.PropertyUpdatesGraph, sourceGraph);
            this.Assert(graphNode, RDFRuntime.PropertyReplacesGraph, sourceGraph);
        }
Ejemplo n.º 5
0
        internal Uri GetTripleAdditionsMonitorUri(Uri graphUri)
        {
            if (_additionGraphs.ContainsKey(graphUri))
            {
                return(_additionGraphs[graphUri]);
            }
            IUriNode monitoredGraph = RDFUtil.CreateUriNode(GetUpdateControlUri(GetModifiableGraph(graphUri).BaseUri));
            Uri      uri            = RDFRuntime.NewTempGraphUri();

            _additionGraphs[graphUri]           = uri;
            _additionGraphs[monitoredGraph.Uri] = uri;
            this.Assert(RDFUtil.CreateUriNode(uri), RDFRuntime.PropertyAddTriplesTo, monitoredGraph);
            return(uri);
        }
Ejemplo n.º 6
0
        internal Uri GetTripleRemovalsMonitorUri(Uri graphUri)
        {
            EnableUpdateControl();
            if (_removalGraphs.ContainsKey(graphUri))
            {
                return(_removalGraphs[graphUri]);
            }
            IUriNode monitoredGraph = RDFUtil.CreateUriNode(GetUpdateControlUri(GetModifiableGraph(graphUri).BaseUri));
            Uri      uri            = RDFRuntime.NewTempGraphUri();

            _removalGraphs[graphUri]           = uri;
            _removalGraphs[monitoredGraph.Uri] = uri;
            this.Assert(RDFUtil.CreateUriNode(uri), RDFRuntime.PropertyDeleteTriplesFrom, monitoredGraph);
            return(uri);
        }
Ejemplo n.º 7
0
 private void OnModificableGraphChange(object sender, GraphEventArgs e)
 {
     if (e.TripleEvent != null)
     {
         Uri      graphUri  = e.TripleEvent.GraphUri;
         IUriNode graphNode = RDFUtil.CreateUriNode(GetUpdateControlUri(graphUri));
         if (e.TripleEvent.WasAsserted)
         {
             this.Assert(RDFUtil.CreateUriNode(GetTripleAdditionsMonitorUri(graphUri)), RDFRuntime.PropertyAddTriplesTo, graphNode);
         }
         else
         {
             this.Assert(RDFUtil.CreateUriNode(GetTripleRemovalsMonitorUri(graphUri)), RDFRuntime.PropertyDeleteTriplesFrom, graphNode);
         }
     }
 }
Ejemplo n.º 8
0
        private IGraph GetModifiableGraph(Uri graphUri, INode modificationMode)
        {
            if (_modificableGraphs.ContainsKey(graphUri))
            {
                return(_modificableGraphs[graphUri]);
            }
            if (ContainsTriple(new Triple(RDFUtil.CreateUriNode(graphUri), RDF.PropertyType, RDFRuntime.ClassReadOnlyGraph)))
            {
                throw new SpinException("The graph " + graphUri.ToString() + " is marked as Readonly for the current dataset");
            }

            IUriNode sourceGraph        = RDFUtil.CreateUriNode(graphUri);
            IUriNode updateControlGraph = RDFUtil.CreateUriNode(GetUpdateControlUri(graphUri, true));

            this.Retract(RDFUtil.CreateUriNode(BaseUri), RDFRuntime.PropertyRemovesGraph, sourceGraph);
            this.Assert(sourceGraph, RDF.PropertyType, SD.ClassGraph);
            this.Assert(updateControlGraph, RDF.PropertyType, RDFRuntime.ClassUpdateControlGraph);

            if (!RDFUtil.sameTerm(sourceGraph, updateControlGraph))
            {
                this.Assert(updateControlGraph, modificationMode, sourceGraph);
                this.Assert(updateControlGraph, RDFRuntime.PropertyUpdatesGraph, updateControlGraph);
            }
            else
            {
                this.Assert(updateControlGraph, RDFRuntime.PropertyUpdatesGraph, sourceGraph);
            }

            SpinWrappedGraph graph = (SpinWrappedGraph)this[graphUri];

            graph.BaseUri  = graphUri;
            graph.Readonly = false;
            graph.Changed += OnModificableGraphChange;
            graph.Cleared += OnModificableGraphCleared;
            _modificableGraphs[graphUri] = graph;
            return(graph);
        }
Ejemplo n.º 9
0
        internal static IGraph CreateUpdateControlledDataset(this SpinWrappedDataset queryModel)
        {
            IGraph             dataset = queryModel._configuration;
            IUpdateableStorage storage = queryModel.UnderlyingStorage;

            if (!dataset.ContainsTriple(new Triple(RDFUtil.CreateUriNode(dataset.BaseUri), RDF.PropertyType, SD.ClassDataset)) && !dataset.ContainsTriple(new Triple(RDFUtil.CreateUriNode(dataset.BaseUri), RDF.PropertyType, RDFRuntime.ClassUpdateControlledDataset)))
            {
                throw new Exception("Invalid dataset to operate on : " + dataset.BaseUri.ToString());
            }

            // TODO ?See whether we should nest "transactions" or not? Currently not
            if (dataset.ContainsTriple(new Triple(RDFUtil.CreateUriNode(dataset.BaseUri), RDF.PropertyType, RDFRuntime.ClassUpdateControlledDataset)))
            {
                return(dataset);
            }

            // creates the work Dataset
            SpinDatasetDescription workingset = new SpinDatasetDescription();

            workingset.BaseUri = UriFactory.Create(RDFRuntime.DATASET_NS_URI + Guid.NewGuid().ToString());
            workingset.Assert(dataset.Triples);

            INode datasetNode    = RDFUtil.CreateUriNode(dataset.BaseUri);
            INode workingsetNode = RDFUtil.CreateUriNode(workingset.BaseUri);

            // adds workingset metadata
            workingset.Retract(dataset.GetTriplesWithSubject(datasetNode));
            workingset.Assert(workingsetNode, RDFRuntime.PropertyUpdatesGraph, workingsetNode);
            workingset.Assert(workingsetNode, RDF.PropertyType, RDFRuntime.ClassUpdateControlledDataset);
            workingset.Assert(workingsetNode, RDFRuntime.PropertyUpdatesDataset, datasetNode);
            workingset.Assert(workingsetNode, DCTerms.PropertyCreated, DateTime.Now.ToLiteral(RDFUtil.nodeFactory));

            queryModel._configuration = workingset;
            queryModel.Initialise();
            return(workingset);
        }
Ejemplo n.º 10
0
        internal static SpinDatasetDescription Load(IUpdateableStorage storage, Uri datasetUri = null, IEnumerable <Uri> graphsUri = null)
        {
            SpinDatasetDescription dataset;

            if (datasetUri == null)
            {
                SparqlResultSet datasetDiscovery = (SparqlResultSet)storage.Query("SELECT ?dataset WHERE {?dataset a <" + SD.ClassDataset.Uri.ToString() + ">}");
                int             datasetCount     = datasetDiscovery.Results.Count;
                if (datasetCount > 1)
                {
                    throw new Exception("More than one dataset has been found in the current storage provider. Please specify which to use through the datasetUri parameter.");
                }
                else if (datasetCount == 1)
                {
                    datasetUri = ((IUriNode)datasetDiscovery.Results.FirstOrDefault().Value("dataset")).Uri;
                }
                else
                {
                    datasetUri = UriFactory.Create(RDFRuntime.DATASET_NS_URI + Guid.NewGuid().ToString());
                }
            }
            dataset = new SpinDatasetDescription(datasetUri);
            storage.LoadGraph(dataset, datasetUri);
            dataset.BaseUri = datasetUri;
            Triple isUpdateControlledDataset = dataset.GetTriplesWithPredicate(RDFRuntime.PropertyUpdatesDataset).FirstOrDefault();

            if (isUpdateControlledDataset != null)
            {
                dataset._sourceUri = ((IUriNode)isUpdateControlledDataset.Object).Uri;
            }
            else
            {
                dataset.Assert(RDFUtil.CreateUriNode(datasetUri), RDF.PropertyType, SD.ClassDataset);
            }
            return(dataset);
        }
Ejemplo n.º 11
0
 internal static IResource CreateUpdateControlledGraph(this SpinWrappedDataset queryModel, Uri graphUri, INode mode = null)
 {
     return(queryModel.CreateUpdateControlledGraph(Resource.Get(RDFUtil.CreateUriNode(graphUri), queryModel.spinProcessor), mode));
 }
Ejemplo n.º 12
0
 internal bool IsGraphUpdated(Uri sourceGraph)
 {
     return(GetTriplesWithPredicateObject(RDFRuntime.PropertyUpdatesGraph, RDFUtil.CreateUriNode(sourceGraph)).Any());
 }
Ejemplo n.º 13
0
        internal Uri GetUpdateControlUri(Uri graphUri, bool create = true)
        {
            Uri uri = GetTriplesWithPredicateObject(RDFRuntime.PropertyReplacesGraph, RDFUtil.CreateUriNode(graphUri))
                      .Union(GetTriplesWithPredicateObject(RDFRuntime.PropertyUpdatesGraph, RDFUtil.CreateUriNode(graphUri)))
                      .Select(t => ((IUriNode)t.Subject).Uri)
                      .FirstOrDefault();

            if (uri == null && create)
            {
                uri = RDFRuntime.NewUpdateControlGraphUri();
            }
            return(uri);
        }
Ejemplo n.º 14
0
 public bool HasGraph(Uri graphUri)
 {
     return(ContainsTriple(new Triple(RDFUtil.CreateUriNode(graphUri), RDF.PropertyType, SD.ClassGraph)));
 }