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(); }
/// <summary> /// Converts a dotNetRDF Graph to a Sesame Graph /// </summary> /// <param name="g">dotNetRDF Graph</param> /// <param name="mapping">Blank Node Mapping</param> /// <param name="target">Sesame Graph</param> public static void ToSesame(IGraph g, SesameMapping mapping, dotSesame.Graph target) { foreach (Triple t in g.Triples) { target.add(ToSesameResource(t.Subject, mapping), ToSesameUri(t.Predicate, mapping), ToSesameValue(t.Object, mapping)); } }
/// <summary> /// Converts a Sesame Graph to a dotNetRDF Graph /// </summary> /// <param name="source">Sesame Graph</param> /// <param name="mapping">Blank Node Mapping</param> /// <param name="target">dotNetRDF Graph</param> public static void FromSesame(dotSesame.Graph source, SesameMapping mapping, IGraph target) { Iterator iter = source.iterator(); while (iter.hasNext()) { dotSesame.Statement stmt = (dotSesame.Statement)iter.next(); target.Assert(FromSesame(stmt, mapping)); } }
/// <summary> /// Converts a Sesame Value to a dotNetRDF Node /// </summary> /// <param name="value">Value</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static INode FromSesameValue(dotSesame.Value value, SesameMapping mapping) { if (value is dotSesame.URI) { return(mapping.Graph.CreateUriNode(new Uri(((dotSesame.URI)value).stringValue()))); } else if (value is dotSesame.Literal) { dotSesame.Literal lit = (dotSesame.Literal)value; if (lit.getDatatype() != null) { return(mapping.Graph.CreateLiteralNode(lit.stringValue(), FromSesameUri(lit.getDatatype()))); } else if (lit.getLanguage() != null) { return(mapping.Graph.CreateLiteralNode(lit.stringValue(), lit.getLanguage())); } else { return(mapping.Graph.CreateLiteralNode(lit.stringValue())); } } else if (value is dotSesame.BNode) { dotSesame.BNode bnode = (dotSesame.BNode)value; 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 Value Type to a dotNetRDF INode"); } }
/// <summary> /// Converts a dotNetRDF Node to a Sesame URI /// </summary> /// <param name="n">Node</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static dotSesame.URI ToSesameUri(INode n, SesameMapping mapping) { switch (n.NodeType) { case NodeType.Uri: return(mapping.ValueFactory.createURI(((IUriNode)n).Uri.ToString())); default: throw new RdfException("Only URI Predicates are supported in Sesame"); } }
/// <summary> /// Converts a dotNetRDF Node to a Sesame Value /// </summary> /// <param name="n">Node</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static dotSesame.Value ToSesameValue(INode n, SesameMapping mapping) { switch (n.NodeType) { case NodeType.Uri: return(mapping.ValueFactory.createURI(((IUriNode)n).Uri.ToString())); case NodeType.Literal: ILiteralNode lit = (ILiteralNode)n; if (lit.DataType != null) { return(mapping.ValueFactory.createLiteral(lit.Value, ToSesameUri(lit.DataType, mapping))); } else if (!lit.Language.Equals(String.Empty)) { return(mapping.ValueFactory.createLiteral(lit.Value, lit.Language)); } else { return(mapping.ValueFactory.createLiteral(lit.Value)); } case NodeType.Blank: if (mapping.OutputMapping.ContainsKey(n)) { return(mapping.OutputMapping[n]); } else { dotSesame.BNode bnode = mapping.ValueFactory.createBNode(); lock (mapping) { if (!mapping.OutputMapping.ContainsKey(n)) { mapping.OutputMapping.Add(n, bnode); } else { bnode = mapping.OutputMapping[n]; } if (!mapping.InputMapping.ContainsKey(bnode)) { mapping.InputMapping.Add(bnode, n); } } return(bnode); } default: throw new RdfException("Only URI, Blank Node and Literal Objects are supported by Sesame"); } }
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(); }
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); }
/// <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"); } }
/// <summary> /// Converts a dotNetRDF Node to a Sesame Resource /// </summary> /// <param name="n">Node</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static dotSesame.Resource ToSesameResource(INode n, SesameMapping mapping) { switch (n.NodeType) { case NodeType.Uri: return(mapping.ValueFactory.createURI(((IUriNode)n).Uri.ToString())); case NodeType.Blank: if (mapping.OutputMapping.ContainsKey(n)) { return(mapping.OutputMapping[n]); } else { dotSesame.BNode bnode = mapping.ValueFactory.createBNode(); lock (mapping) { if (!mapping.OutputMapping.ContainsKey(n)) { mapping.OutputMapping.Add(n, bnode); } else { bnode = mapping.OutputMapping[n]; } if (!mapping.InputMapping.ContainsKey(bnode)) { mapping.InputMapping.Add(bnode, n); } } return(bnode); } default: throw new RdfException("Only URI and Blank Node subjects are supported in Sesame"); } }
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"); } }
/// <summary> /// Converts a dotNetRDF Node to a Sesame URI /// </summary> /// <param name="n">Node</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static dotSesame.URI ToSesameUri(INode n, SesameMapping mapping) { switch (n.NodeType) { case NodeType.Uri: return mapping.ValueFactory.createURI(((IUriNode)n).Uri.ToString()); default: throw new RdfException("Only URI Predicates are supported in Sesame"); } }
/// <summary> /// Converts a dotNetRDF Node to a Sesame Value /// </summary> /// <param name="n">Node</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static dotSesame.Value ToSesameValue(INode n, SesameMapping mapping) { switch (n.NodeType) { case NodeType.Uri: return mapping.ValueFactory.createURI(((IUriNode)n).Uri.ToString()); case NodeType.Literal: ILiteralNode lit = (ILiteralNode)n; if (lit.DataType != null) { return mapping.ValueFactory.createLiteral(lit.Value, ToSesameUri(lit.DataType, mapping)); } else if (!lit.Language.Equals(String.Empty)) { return mapping.ValueFactory.createLiteral(lit.Value, lit.Language); } else { return mapping.ValueFactory.createLiteral(lit.Value); } case NodeType.Blank: if (mapping.OutputMapping.ContainsKey(n)) { return mapping.OutputMapping[n]; } else { dotSesame.BNode bnode = mapping.ValueFactory.createBNode(); lock (mapping) { if (!mapping.OutputMapping.ContainsKey(n)) { mapping.OutputMapping.Add(n, bnode); } else { bnode = mapping.OutputMapping[n]; } if (!mapping.InputMapping.ContainsKey(bnode)) mapping.InputMapping.Add(bnode, n); } return bnode; } default: throw new RdfException("Only URI, Blank Node and Literal Objects are supported by Sesame"); } }
public DotNetRdfValueFactory(SesameMapping mapping) { this._mapping = mapping; }
protected override org.openrdf.repository.RepositoryResult GetStatementsInternal(string sparqlQuery, SesameMapping mapping) { try { Object results = this._store.ExecuteQuery(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); } }
public BaseRepositoryConnection(dotSesameRepo.Repository repository, DotNetRdfValueFactory factory) { this._repo = repository; this._mapping = factory.Mapping; this._factory = factory; }
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"); } }
protected abstract dotSesameRepo.RepositoryResult GetStatementsInternal(String sparqlQuery, SesameMapping mapping);
/// <summary> /// Converts a Sesame URI to a dotNetRDF Node /// </summary> /// <param name="uri">URI</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static INode FromSesameUri(dotSesame.URI uri, SesameMapping mapping) { return(mapping.Graph.CreateUriNode(new Uri(uri.stringValue()))); }
/// <summary> /// Converts a Sesame Statement to a dotNetRDF Triple /// </summary> /// <param name="statement">Sesame Statement</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> public static Triple FromSesame(dotSesame.Statement statement, SesameMapping mapping) { return(new Triple(FromSesameResource(statement.getSubject(), mapping), FromSesameUri(statement.getPredicate(), mapping), FromSesameValue(statement.getObject(), mapping))); }
/// <summary> /// Converts a Sesame Graph to a dotNetRDF Graph /// </summary> /// <param name="source">Sesame Graph</param> /// <param name="target">dotNetRDF Graph</param> public static void FromSesame(dotSesame.Graph source, IGraph target) { SesameMapping mapping = new SesameMapping(target, source); FromSesame(source, mapping, target); }
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); } }
/// <summary> /// Converts a URI to a Sesame URI /// </summary> /// <param name="u">URI</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static dotSesame.URI ToSesameUri(Uri u, SesameMapping mapping) { return(mapping.ValueFactory.createURI(u.ToString())); }
/// <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"); } }
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); } }
/// <summary> /// Converts a Sesame Value to a dotNetRDF Node /// </summary> /// <param name="value">Value</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static INode FromSesameValue(dotSesame.Value value, SesameMapping mapping) { if (value is dotSesame.URI) { return mapping.Graph.CreateUriNode(new Uri(((dotSesame.URI)value).stringValue())); } else if (value is dotSesame.Literal) { dotSesame.Literal lit = (dotSesame.Literal)value; if (lit.getDatatype() != null) { return mapping.Graph.CreateLiteralNode(lit.stringValue(), FromSesameUri(lit.getDatatype())); } else if (lit.getLanguage() != null) { return mapping.Graph.CreateLiteralNode(lit.stringValue(), lit.getLanguage()); } else { return mapping.Graph.CreateLiteralNode(lit.stringValue()); } } else if (value is dotSesame.BNode) { dotSesame.BNode bnode = (dotSesame.BNode)value; 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 Value Type to a dotNetRDF INode"); } }
/// <summary> /// Converts a dotNetRDF Graph to a Sesame Graph /// </summary> /// <param name="g">dotNetRDF Graph</param> /// <param name="target">Sesame Graph</param> public static void ToSesame(IGraph g, dotSesame.Graph target) { SesameMapping mapping = new SesameMapping(g, target); ToSesame(g, mapping, target); }
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)); } }
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; } }
public SesameTripleCollection(dotSesame.Graph g, SesameMapping mapping) { this._g = g; this._mapping = mapping; }
/// <summary> /// Converts a dotNetRDF Triple to a Sesame Statement /// </summary> /// <param name="t">Triple</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> public static dotSesame.Statement ToSesame(Triple t, SesameMapping mapping) { return(mapping.ValueFactory.createStatement(ToSesameResource(t.Subject, mapping), ToSesameUri(t.Predicate, mapping), ToSesameValue(t.Object, mapping))); }
public DotNetRdfGraph(IGraph g) { this._g = g; this._mapping = new SesameMapping(this._g, this); this._factory = new DotNetRdfValueFactory(this._mapping); }
/// <summary> /// Converts a dotNetRDF Node to a Sesame Resource /// </summary> /// <param name="n">Node</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static dotSesame.Resource ToSesameResource(INode n, SesameMapping mapping) { switch (n.NodeType) { case NodeType.Uri: return mapping.ValueFactory.createURI(((IUriNode)n).Uri.ToString()); case NodeType.Blank: if (mapping.OutputMapping.ContainsKey(n)) { return mapping.OutputMapping[n]; } else { dotSesame.BNode bnode = mapping.ValueFactory.createBNode(); lock (mapping) { if (!mapping.OutputMapping.ContainsKey(n)) { mapping.OutputMapping.Add(n, bnode); } else { bnode = mapping.OutputMapping[n]; } if (!mapping.InputMapping.ContainsKey(bnode)) mapping.InputMapping.Add(bnode, n); } return bnode; } default: throw new RdfException("Only URI and Blank Node subjects are supported in Sesame"); } }
/// <summary> /// Converts a URI to a Sesame URI /// </summary> /// <param name="u">URI</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static dotSesame.URI ToSesameUri(Uri u, SesameMapping mapping) { return mapping.ValueFactory.createURI(u.ToString()); }
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; }
/// <summary> /// Converts a Sesame Statement to a dotNetRDF Triple /// </summary> /// <param name="statement">Sesame Statement</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> public static Triple FromSesame(dotSesame.Statement statement, SesameMapping mapping) { return new Triple(FromSesameResource(statement.getSubject(), mapping), FromSesameUri(statement.getPredicate(), mapping), FromSesameValue(statement.getObject(), mapping)); }
/// <summary> /// Converts a Sesame URI to a dotNetRDF Node /// </summary> /// <param name="uri">URI</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> internal static INode FromSesameUri(dotSesame.URI uri, SesameMapping mapping) { return mapping.Graph.CreateUriNode(new Uri(uri.stringValue())); }
/// <summary> /// Converts a dotNetRDF Triple to a Sesame Statement /// </summary> /// <param name="t">Triple</param> /// <param name="mapping">Blank Node Mapping</param> /// <returns></returns> public static dotSesame.Statement ToSesame(Triple t, SesameMapping mapping) { return mapping.ValueFactory.createStatement(ToSesameResource(t.Subject, mapping), ToSesameUri(t.Predicate, mapping), ToSesameValue(t.Object, mapping)); }
public SesameGraph(dotSesame.Graph g) { this._g = g; this._mapping = new SesameMapping(this, this._g); this._triples = new SesameTripleCollection(this._g, this._mapping); }