Assembly Namespace Mappings

Dec 24, 2013 at 2:21 AM
Edited Dec 24, 2013 at 2:22 AM
I'm having issues with the Assembly Namespace Mappings.

I have this attribute in my Core/Entity assembly:
[assembly: NamespaceDeclaration("id", "http://www.brightstardb.com/.well-known/genid/")]

Then when I do this query, I get this exception:

SELECT DISTINCT * WHERE { id:fa3d9836-a73c-4600-9888-d10066ef48c6 ?property ?Value }

VDS.RDF.RdfException
{"The Namespace URI for the given Prefix 'id' is not known by the in-scope NamespaceMapper. Did you forget to define a namespace for this prefix?"}

at VDS.RDF.NamespaceMapper.GetNamespaceUri(String prefix)
at VDS.RDF.Tools.ResolveQName(String qname, INamespaceMapper nsmap, Uri baseUri, Boolean allowDefaultPrefixFallback)
at VDS.RDF.Tools.ResolveQName(String qname, INamespaceMapper nsmap, Uri baseUri)
at VDS.RDF.Parsing.SparqlQueryParser.ResolveQName(SparqlQueryParserContext context, String qname)
at VDS.RDF.Parsing.SparqlQueryParser.TryCreatePatternItem(SparqlQueryParserContext context, IToken t)
at VDS.RDF.Parsing.SparqlQueryParser.TryParsePredicateObjectList(SparqlQueryParserContext context, GraphPattern p, Int32 expectedCount)
at VDS.RDF.Parsing.SparqlQueryParser.TryParseTriplePatterns(SparqlQueryParserContext context, GraphPattern p)
at VDS.RDF.Parsing.SparqlQueryParser.TryParseGraphPattern(SparqlQueryParserContext context, Boolean requireOpeningLeftBracket)
at VDS.RDF.Parsing.SparqlQueryParser.TryParseGraphPattern(SparqlQueryParserContext context)
at VDS.RDF.Parsing.SparqlQueryParser.TryParseGraphPatterns(SparqlQueryParserContext context)
at VDS.RDF.Parsing.SparqlQueryParser.ParseInternal(SparqlQueryParserContext context)
at VDS.RDF.Parsing.SparqlQueryParser.ParseInternal(TextReader input)
at VDS.RDF.Parsing.SparqlQueryParser.ParseFromString(String queryString)
at BrightstarDB.Server.ServerCore.ParseSparql(String exp) in c:\dev\nuzzgraph\BrightstarDB\src\core\BrightstarDB\Server\ServerCore.cs:line 464
at BrightstarDB.Server.ServerCore.Query(String storeName, String queryExpression, IEnumerable1 defaultGraphUris, Nullable1 ifNotModifiedSince, SparqlResultsFormat sparqlResultFormat, RdfFormat graphFormat, Stream responseStream) in c:\dev\nuzzgraph\BrightstarDB\src\core\BrightstarDB\Server\ServerCore.cs:line 180
at BrightstarDB.Client.EmbeddedDataObjectStore.ExecuteSparql(String sparqlExpression) in c:\dev\nuzzgraph\BrightstarDB\src\core\BrightstarDB\Client\EmbeddedDataObjectStore.cs:line 57
at BrightstarDB.Client.EmbeddedDataObjectStore.BindDataObjectsWithSparql(String sparqlExpression) in c:\dev\nuzzgraph\BrightstarDB\src\core\BrightstarDB\Client\EmbeddedDataObjectStore.cs:line 51
at BrightstarDB.EntityFramework.BrightstarEntityContext.<ExecuteQuery>d__91.MoveNext() in c:\dev\nuzzgraph\BrightstarDB\src\core\BrightstarDB\EntityFramework\BrightstarEntityContext.cs:line 271
at System.Linq.Enumerable.WhereSelectEnumerableIterator
2.MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at NuzzGraph.Core.Entities.Node._GetRelatedNodes() in c:\dev\nuzzgraph\nuzzgraph\NuzzGraph.Core\Entities\Node.cs:line 49
at NuzzGraph.Viewer.UserControls.NodeDisplay..ctor() in c:\dev\nuzzgraph\nuzzgraph\NuzzGraph.Viewer\UserControls\NodeDisplay.xaml.cs:line 82


If anyone could let me know if I'm doing this wrong, or provide an alternate way to specify namespaces. For now I could just add the PREFIX clause to each of my queries as I believe that's what happens internally anyway.
Coordinator
Dec 27, 2013 at 12:31 PM
The namespace declarations in the assembly attribute only apply to the Entity Framework. In your SPARQL queries you still need to add namespace declarations yourself, so add the following to the start of your query

"PREFIX id: http://www.brightstardb.com/.well-known/genid/ "

It might be nice to have a utility method to pull out the namespace declarations in your assembly attributes and format them for SPARQL queries so that you don't have to do this manually, but right now you will have to code this by hand (or just hardcode the prefix declaraions for your SPARQL queries).