Esempio n. 1
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));
        }
Esempio n. 2
0
        public void evaluate(org.openrdf.query.TupleQueryResultHandler tqrh)
        {
            SparqlResultSet rset = this.EvaluateQuery();

            java.util.ArrayList vars = new java.util.ArrayList();
            foreach (String var in rset.Variables)
            {
                vars.add(var);
            }

            tqrh.startQueryResult(vars);
            SesameMapping mapping = new SesameMapping(new Graph(), new dotSesame.impl.GraphImpl());

            foreach (SparqlResult r in rset)
            {
                dotSesameQuery.impl.MapBindingSet binding = new org.openrdf.query.impl.MapBindingSet();
                foreach (String var in r.Variables)
                {
                    binding.addBinding(var, SesameConverter.ToSesameValue(r[var], mapping));
                }
                tqrh.handleSolution(binding);
            }

            tqrh.endQueryResult();
        }
Esempio n. 3
0
 internal static IEnumerable <Triple> ToTriples(this info.aduna.iteration.Iteration iter, SesameMapping mapping)
 {
     while (iter.hasNext())
     {
         yield return(SesameConverter.FromSesame((dotSesame.Statement)iter.next(), mapping));
     }
 }
Esempio n. 4
0
 public bool add(object obj)
 {
     if (obj is dotSesame.Statement)
     {
         dotSesame.Statement stmt = (dotSesame.Statement)obj;
         Triple t = SesameConverter.FromSesame(stmt, this._mapping);
         if (this._g.ContainsTriple(t))
         {
             return(false);
         }
         else
         {
             this._g.Assert(t);
             return(true);
         }
     }
     else if (obj is Triple)
     {
         Triple t = (Triple)obj;
         if (this._g.ContainsTriple(t))
         {
             return(false);
         }
         else
         {
             this._g.Assert(t);
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
Esempio n. 5
0
        public override IEnumerable <Triple> WithObject(INode obj)
        {
            dotSesame.Value v = SesameConverter.ToSesameValue(obj, this._mapping);
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(this._g.match(null, null, v, null));

            return(stmtIter.Select(s => SesameConverter.FromSesame(s, this._mapping)));
        }
Esempio n. 6
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()));
        }
Esempio n. 7
0
        public override IEnumerable <Triple> WithPredicate(INode pred)
        {
            dotSesame.URI u = SesameConverter.ToSesameUri(pred, this._mapping);
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(this._g.match(null, u, null, null));

            return(stmtIter.Select(s => SesameConverter.FromSesame(s, this._mapping)));
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public virtual void add(org.openrdf.model.Statement s, params org.openrdf.model.Resource[] rarr)
        {
            IEnumerable <Uri> contexts = rarr.ToContexts(this._mapping);
            Graph             g        = new Graph();

            g.Assert(SesameConverter.FromSesame(s, this._mapping));
            this.AddInternal(g, contexts);
        }
Esempio n. 10
0
        public org.openrdf.query.BindingSet getBindings()
        {
            dotSesameQuery.impl.MapBindingSet s = new org.openrdf.query.impl.MapBindingSet();

            foreach (KeyValuePair <String, INode> kvp in this._queryString.Variables)
            {
                s.addBinding(kvp.Key, SesameConverter.ToSesameValue(kvp.Value, this._mapping));
            }

            return(s);
        }
Esempio n. 11
0
 public bool contains(object obj)
 {
     if (obj is dotSesame.Statement)
     {
         Triple t = SesameConverter.FromSesame((dotSesame.Statement)obj, this._mapping);
         return(this._g.ContainsTriple(t));
     }
     else
     {
         return(false);
     }
 }
Esempio n. 12
0
        public bool equals(object obj)
        {
            if (obj is dotSesame.Graph)
            {
                Graph h = new Graph();
                SesameConverter.FromSesame((dotSesame.Graph)obj, h);

                return(this._g.Equals(h));
            }
            else
            {
                return(this._g.Equals(obj));
            }
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
0
        public bool addAll(java.util.Collection c)
        {
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <dotSesame.Statement>(c.iterator());
            bool added = false;

            foreach (dotSesame.Statement stmt in stmtIter)
            {
                Triple t = SesameConverter.FromSesame(stmt, this._mapping);
                if (!this._g.ContainsTriple(t))
                {
                    this._g.Assert(t);
                    added = added || true;
                }
            }
            return(added);
        }
Esempio n. 15
0
        public void evaluate(org.openrdf.rio.RDFHandler rdfh)
        {
            IGraph        g       = this.EvaluateQuery();
            SesameMapping mapping = new SesameMapping(g, new dotSesame.impl.GraphImpl());


            rdfh.startRDF();
            foreach (String prefix in g.NamespaceMap.Prefixes)
            {
                rdfh.handleNamespace(prefix, g.NamespaceMap.GetNamespaceUri(prefix).ToString());
            }
            foreach (Triple t in g.Triples)
            {
                rdfh.handleStatement(SesameConverter.ToSesame(t, mapping));
            }
            rdfh.endRDF();
        }
Esempio n. 16
0
        public bool containsAll(java.util.Collection c)
        {
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(c.iterator());
            bool contains = true;

            foreach (dotSesame.Statement stmt in stmtIter)
            {
                Triple t = SesameConverter.FromSesame(stmt, this._mapping);
                if (!this._g.ContainsTriple(t))
                {
                    contains = false;
                    break;
                }
            }

            return(contains);
        }
Esempio n. 17
0
        public bool removeAll(java.util.Collection c)
        {
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(c.iterator());
            bool removed = false;

            foreach (dotSesame.Statement stmt in stmtIter)
            {
                Triple t = SesameConverter.FromSesame(stmt, this._mapping);
                if (this._g.ContainsTriple(t))
                {
                    this._g.Retract(t);
                    removed = removed || true;
                }
            }

            return(removed);
        }
Esempio n. 18
0
        public org.openrdf.query.GraphQueryResult evaluate()
        {
            IGraph        g       = this.EvaluateQuery();
            SesameMapping mapping = new SesameMapping(g, new dotSesame.impl.GraphImpl());
            IEnumerable <dotSesame.Statement> stmts = from t in g.Triples
                                                      select SesameConverter.ToSesame(t, mapping);

            DotNetEnumerableWrapper wrapper = new DotNetEnumerableWrapper(stmts);

            java.util.HashMap map = new java.util.HashMap();
            foreach (String prefix in g.NamespaceMap.Prefixes)
            {
                map.put(prefix, g.NamespaceMap.GetNamespaceUri(prefix).ToString());
            }
            dotSesameQuery.impl.GraphQueryResultImpl results = new org.openrdf.query.impl.GraphQueryResultImpl(map, wrapper);
            return(results);
        }
Esempio n. 19
0
 public bool remove(object obj)
 {
     if (obj is dotSesame.Statement)
     {
         Triple t = SesameConverter.FromSesame((dotSesame.Statement)obj, this._mapping);
         if (this._g.ContainsTriple(t))
         {
             this._g.Retract(t);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Esempio n. 20
0
        public bool retainAll(java.util.Collection c)
        {
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(c.iterator());
            HashSet <Triple> retained = new HashSet <Triple>();
            bool             changed  = false;

            foreach (dotSesame.Statement stmt in stmtIter)
            {
                retained.Add(SesameConverter.FromSesame(stmt, this._mapping));
            }
            foreach (Triple t in this._g.Triples.ToList())
            {
                if (!retained.Contains(t))
                {
                    changed = true;
                    this._g.Retract(t);
                }
            }
            return(changed);
        }
Esempio n. 21
0
        public object[] toArray(object[] objarr)
        {
            if (objarr.Length < this._g.Triples.Count)
            {
                objarr = new object[this._g.Triples.Count];
            }

            int i = 0;

            foreach (Triple t in this._g.Triples)
            {
                objarr[i] = SesameConverter.ToSesame(t, this._mapping);
                i++;
            }
            if (i < objarr.Length)
            {
                objarr[i] = null;
            }
            return(objarr);
        }
Esempio n. 22
0
 internal static IEnumerable <Uri> ToContexts(this dotSesame.Resource[] contexts, SesameMapping mapping)
 {
     if (contexts == null)
     {
         return(Enumerable.Empty <Uri>());
     }
     else if (contexts.Length == 0)
     {
         return(Enumerable.Empty <Uri>());
     }
     else
     {
         List <Uri> results = new List <Uri>();
         foreach (dotSesame.Resource r in contexts)
         {
             if (r != null && r is dotSesame.URI)
             {
                 results.Add(((IUriNode)SesameConverter.FromSesameResource(r, mapping)).Uri);
             }
         }
         return(results);
     }
 }
Esempio n. 23
0
        public override org.openrdf.repository.RepositoryResult getContextIDs()
        {
            try
            {
                Object results = this._store.ExecuteQuery("SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o }}");
                if (results is SparqlResultSet)
                {
                    IEnumerable <dotSesame.Resource> resIter = from result in (SparqlResultSet)results
                                                               where result.HasValue("g") && result["g"] != null
                                                               select SesameConverter.ToSesameResource(result["g"], this._mapping);

                    return(new org.openrdf.repository.RepositoryResult(new DotNetAdunaIterationWrapper(resIter)));
                }
                else
                {
                    throw new dotSesameRepo.RepositoryException("Unable to return the Context IDs from this repository as the repository returned an unexpected result");
                }
            }
            catch (Exception ex)
            {
                throw new dotSesameRepo.RepositoryException("Unable to return the Context IDs from this repository due to the following error: " + ex.Message);
            }
        }
Esempio n. 24
0
        public override org.openrdf.repository.RepositoryResult getContextIDs()
        {
            if (this._manager.ListGraphsSupported)
            {
                IEnumerable <dotSesame.Resource> resIter = from u in this._manager.ListGraphs()
                                                           select(dotSesame.Resource) this._mapping.ValueFactory.createURI(u.ToString());

                return(new org.openrdf.repository.RepositoryResult(new DotNetAdunaIterationWrapper(resIter)));
            }
            else if (this._manager is IQueryableGenericIOManager)
            {
                try
                {
                    Object results = ((IQueryableGenericIOManager)this._manager).Query("SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o }}");
                    if (results is SparqlResultSet)
                    {
                        IEnumerable <dotSesame.Resource> resIter = from result in (SparqlResultSet)results
                                                                   where result.HasValue("g") && result["g"] != null
                                                                   select SesameConverter.ToSesameResource(result["g"], this._mapping);

                        return(new org.openrdf.repository.RepositoryResult(new DotNetAdunaIterationWrapper(resIter)));
                    }
                    else
                    {
                        throw new dotSesameRepo.RepositoryException("Unable to return the Context IDs from this repository as the repository returned an unexpected result");
                    }
                }
                catch (Exception ex)
                {
                    throw new dotSesameRepo.RepositoryException("Unable to return the Context IDs from this repository due to the following error: " + ex.Message);
                }
            }
            else
            {
                throw new dotSesameRepo.RepositoryException("This dotNetRDF Generic Repository does not support returning the Context IDs");
            }
        }
Esempio n. 25
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");
            }
        }
Esempio n. 26
0
 public void setBinding(string str, org.openrdf.model.Value v)
 {
     this._queryString.SetVariable(str, SesameConverter.FromSesameValue(v, this._mapping));
 }
Esempio n. 27
0
 public override bool Contains(Triple t)
 {
     return(this._g.contains(SesameConverter.ToSesame(t, this._mapping)));
 }
Esempio n. 28
0
        public override IEnumerator <Triple> GetEnumerator()
        {
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(this._g.iterator());

            return(stmtIter.Select(s => SesameConverter.FromSesame(s, this._mapping)).GetEnumerator());
        }
Esempio n. 29
0
 protected override void Delete(Triple t)
 {
     this._g.remove(SesameConverter.ToSesame(t, this._mapping));
 }
Esempio n. 30
0
        protected override org.openrdf.repository.RepositoryResult GetStatementsInternal(string sparqlQuery, SesameMapping mapping)
        {
            if (this._manager is IQueryableGenericIOManager)
            {
                try
                {
                    Object results = ((IQueryableGenericIOManager)this._manager).Query(sparqlQuery);
                    if (results is SparqlResultSet)
                    {
                        IEnumerable <dotSesame.Statement> stmts = from result in (SparqlResultSet)results
                                                                  select this._factory.createStatement(SesameConverter.ToSesameResource(result["subj"], mapping), SesameConverter.ToSesameUri(result["pred"], mapping), SesameConverter.ToSesameValue(result["obj"], mapping));

                        return(new dotSesameRepo.RepositoryResult(new DotNetAdunaIterationWrapper(stmts)));
                    }
                    else
                    {
                        throw new dotSesameRepo.RepositoryException("Unable to return Statements from this repository as the repository returned an unexpected result");
                    }
                }
                catch (Exception ex)
                {
                    throw new dotSesameRepo.RepositoryException("Unable to return Statements from this repository due to the following error: " + ex.Message);
                }
            }
            else
            {
                throw new dotSesameRepo.RepositoryException("This dotNetRDF Generic Repository does not support returning specific Statements");
            }
        }