Ejemplo n.º 1
0
        public bool hasStatement(org.openrdf.model.Resource r, org.openrdf.model.URI uri, org.openrdf.model.Value v, bool b, params org.openrdf.model.Resource[] rarr)
        {
            SparqlParameterizedString queryString = new SparqlParameterizedString();

            queryString.CommandText = "ASK";
            foreach (Uri u in rarr.ToContexts(this._mapping))
            {
                queryString.CommandText += "\nFROM <" + this._formatter.FormatUri(u) + ">";
            }
            queryString.CommandText += "\nWHERE { ?subject ?predicate ?object}";
            if (r != null)
            {
                queryString.SetVariable("subject", SesameConverter.FromSesameResource(r, this._mapping));
            }
            if (uri != null)
            {
                queryString.SetVariable("predicate", SesameConverter.FromSesameUri(uri, this._mapping));
            }
            if (v != null)
            {
                queryString.SetVariable("object", SesameConverter.FromSesameValue(v, this._mapping));
            }

            return(this.HasTriplesInternal(queryString.ToString()));
        }
Ejemplo n.º 2
0
        public override IEnumerable <Triple> WithSubject(INode subj)
        {
            dotSesame.Resource r = SesameConverter.ToSesameResource(subj, this._mapping);
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(this._g.match(r, null, null, null));

            return(stmtIter.Select(s => SesameConverter.FromSesame(s, this._mapping)));
        }
Ejemplo n.º 3
0
        public org.openrdf.repository.RepositoryResult getStatements(org.openrdf.model.Resource r, org.openrdf.model.URI uri, org.openrdf.model.Value v, bool b, params org.openrdf.model.Resource[] rarr)
        {
            SparqlParameterizedString queryString = new SparqlParameterizedString();
            IEnumerable <Uri>         contexts    = rarr.ToContexts(this._mapping);

            if (contexts.Any())
            {
                queryString.CommandText = "SELECT (?s AS ?subj) (?p AS ?pred) (?o AS ?obj)\n";
                foreach (Uri u in contexts)
                {
                    queryString.CommandText += "FROM <" + this._formatter.FormatUri(u) + ">\n";
                }
                queryString.CommandText += "WHERE { ?s ?p ?o }";
            }
            else
            {
                queryString.CommandText = "SELECT (?s AS ?subj) (?p AS ?pred) (?o AS ?obj) WHERE { ?s ?p ?o }";
            }
            if (r != null)
            {
                queryString.SetVariable("s", SesameConverter.FromSesameResource(r, this._mapping));
            }
            if (uri != null)
            {
                queryString.SetVariable("p", SesameConverter.FromSesameUri(uri, this._mapping));
            }
            if (v != null)
            {
                queryString.SetVariable("o", SesameConverter.FromSesameValue(v, this._mapping));
            }

            return(this.GetStatementsInternal(queryString.ToString(), this._mapping));
        }
Ejemplo n.º 4
0
        public virtual void add(org.openrdf.model.Resource r, org.openrdf.model.URI uri, org.openrdf.model.Value v, params org.openrdf.model.Resource[] rarr)
        {
            IEnumerable <Uri> contexts = rarr.ToContexts(this._mapping);
            Graph             g        = new Graph();

            g.Assert(SesameConverter.FromSesameResource(r, this._mapping), SesameConverter.FromSesameUri(uri, this._mapping), SesameConverter.FromSesameValue(v, this._mapping));
            this.AddInternal(g, contexts);
        }
Ejemplo n.º 5
0
        public override void remove(org.openrdf.model.Resource r, org.openrdf.model.URI uri, org.openrdf.model.Value v, params org.openrdf.model.Resource[] rarr)
        {
            if (this._manager.IsReadOnly)
            {
                throw NotWritableError("remove");
            }

            base.remove(r, uri, v, rarr);
        }
Ejemplo n.º 6
0
 public void exportStatements(org.openrdf.model.Resource r, org.openrdf.model.URI uri, org.openrdf.model.Value v, bool b, org.openrdf.rio.RDFHandler rdfh, params org.openrdf.model.Resource[] rarr)
 {
     dotSesameRepo.RepositoryResult results = this.getStatements(r, uri, v, b, rarr);
     rdfh.startRDF();
     while (results.hasNext())
     {
         rdfh.handleStatement((dotSesame.Statement)results.next());
     }
     rdfh.endRDF();
 }
Ejemplo n.º 7
0
        public bool add(dotSesame.Resource r, dotSesame.URI uri, dotSesame.Value v, params dotSesame.Resource[] rarr)
        {
            Triple t = new Triple(SesameConverter.FromSesameResource(r, this._mapping), SesameConverter.FromSesameUri(uri, this._mapping), SesameConverter.FromSesameValue(v, this._mapping));

            if (this._g.ContainsTriple(t))
            {
                return(false);
            }
            else
            {
                this._g.Assert(t);
                return(true);
            }
        }
Ejemplo n.º 8
0
        public void InteropSesameLoadFromVirtuoso()
        {
            VirtuosoManager virtuoso = new VirtuosoManager("DB", "dba", "dba");

            DotNetRdfGenericRepository repo = new DotNetRdfGenericRepository(virtuoso);

            dotSesameRepo.RepositoryConnection conn = repo.getConnection();

            dotSesame.Resource[] contexts = new dotSesame.Resource[] { repo.getValueFactory().createURI("http://localhost/TurtleImportTest") };

            dotSesameRepo.RepositoryResult result = conn.getStatements(null, null, null, true, contexts);
            while (result.hasNext())
            {
                dotSesame.Statement r = result.next() as dotSesame.Statement;
                Assert.IsTrue(r != null, "Should not be null");
                Console.WriteLine(r.ToString());
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Converts a Sesame Resource to a dotNetRDF Node
 /// </summary>
 /// <param name="resource">Resource</param>
 /// <param name="mapping">Blank Node Mapping</param>
 /// <returns></returns>
 internal static INode FromSesameResource(dotSesame.Resource resource, SesameMapping mapping)
 {
     if (resource is dotSesame.URI)
     {
         return(mapping.Graph.CreateUriNode(new Uri(((dotSesame.URI)resource).stringValue())));
     }
     else if (resource is dotSesame.BNode)
     {
         dotSesame.BNode bnode = (dotSesame.BNode)resource;
         if (mapping.InputMapping.ContainsKey(bnode))
         {
             return(mapping.InputMapping[bnode]);
         }
         else
         {
             INode n = mapping.Graph.CreateBlankNode();
             lock (mapping)
             {
                 if (!mapping.InputMapping.ContainsKey(bnode))
                 {
                     mapping.InputMapping.Add(bnode, n);
                 }
                 else
                 {
                     n = mapping.InputMapping[bnode];
                 }
                 if (!mapping.OutputMapping.ContainsKey(n))
                 {
                     mapping.OutputMapping.Add(n, bnode);
                 }
             }
             return(n);
         }
     }
     else
     {
         throw new RdfException("Unable to convert unexpected Sesame Resource Type to a dotNetRDF INode");
     }
 }
Ejemplo n.º 10
0
        public void parse(org.openrdf.model.Graph g, org.openrdf.model.Resource r)
        {
            Graph         config  = new Graph();
            SesameMapping mapping = new SesameMapping(config, g);

            SesameConverter.FromSesame(g, config);

            this._name = r.stringValue().Substring(r.stringValue().LastIndexOf(":") + 1);

            Object temp = ConfigurationLoader.LoadObject(config, SesameConverter.FromSesameResource(r, mapping));

            if (temp is IInMemoryQueryableStore)
            {
                this._repo = new DotNetRdfInMemoryRepository((IInMemoryQueryableStore)temp);
            }
            else if (temp is IGenericIOManager)
            {
                this._repo = new DotNetRdfGenericRepository((IGenericIOManager)temp);
            }
            else
            {
                throw new dotSesameRepo.config.RepositoryConfigException("Unable to load Configuration for the Repository as the loaded Object was not an IInMemoryQueryableStore or an IGenericIOManager implementation");
            }
        }
Ejemplo n.º 11
0
 public dotSesame.Statement createStatement(dotSesame.Resource r, dotSesame.URI uri, dotSesame.Value v)
 {
     return(this._mapping.ValueFactory.createStatement(r, uri, v));
 }
Ejemplo n.º 12
0
        public java.util.Iterator match(dotSesame.Resource r, dotSesame.URI uri, dotSesame.Value v, params dotSesame.Resource[] rarr)
        {
            INode s = (r != null) ? SesameConverter.FromSesameResource(r, this._mapping) : null;
            INode p = (uri != null) ? SesameConverter.FromSesameUri(uri, this._mapping) : null;
            INode o = (v != null) ? SesameConverter.FromSesameValue(v, this._mapping) : null;
            //Contexts are Ignored for matches on a single Graph

            IEnumerable <Triple> ts;

            if (s != null)
            {
                if (p != null)
                {
                    if (o != null)
                    {
                        //Matching on Subject Predicate and Object
                        Triple t = new Triple(s, p, o);
                        if (this._g.ContainsTriple(t))
                        {
                            ts = t.AsEnumerable();
                        }
                        else
                        {
                            ts = Enumerable.Empty <Triple>();
                        }
                    }
                    else
                    {
                        //Just matching on Subject Predicate
                        ts = this._g.GetTriplesWithSubjectPredicate(s, p);
                    }
                }
                else
                {
                    if (o != null)
                    {
                        //Matching on Subject Object
                        ts = this._g.GetTriplesWithSubjectObject(s, o);
                    }
                    else
                    {
                        //Just Matching on Subject
                        ts = this._g.GetTriplesWithSubject(s);
                    }
                }
            }
            else if (p != null)
            {
                if (o != null)
                {
                    //Matching on Predicate Object
                    ts = this._g.GetTriplesWithPredicateObject(p, o);
                }
                else
                {
                    //Just Matching on Predicate
                    ts = this._g.GetTriplesWithPredicate(p);
                }
            }
            else if (o != null)
            {
                //Matching on Object only
                ts = this._g.GetTriplesWithObject(o);
            }
            else
            {
                //Matching anything
                ts = this._g.Triples;
            }

            return(new DotNetEnumerableWrapper(ts.Select(t => SesameConverter.ToSesame(t, this._mapping))));
        }
Ejemplo n.º 13
0
 public virtual void remove(org.openrdf.model.Resource r, org.openrdf.model.URI uri, org.openrdf.model.Value v, params org.openrdf.model.Resource[] rarr)
 {
     throw new NotImplementedException();
 }