On 02/12/2020 17:33, Jean-Marc Vanel wrote:
I thought I could retrieve the prefix map from TDB 1 with dataset.getDefaultModel().getNsPrefixMap()
PrefixMapping prefixMapping = dataset.getDefaultModel(); PrefixMapping is a subinterface of Model. See https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Model.html
but that was a mistake; really I don't know how to get the prefix map. I started a project called jena-examples, that may grow with help from the community. Here is the Java code that I tried to retrieve the prefix map and use it to print a named graph: https://github.com/jmvanel/jena-examples/blob/main/src/main/java/WriteWithPrefixMap1.java#L22 ( I use my local test database, 13M triples; I can add to code to populate an empty TDB ) ( I just provided SBT files, tell me if you want a pom.xml ) Jean-Marc Vanel <http://semantic-forms.cc:9112/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me> +33 (0)6 89 16 29 52 Le mar. 1 déc. 2020 à 22:36, Andy Seaborne <[email protected]> a écrit :On 01/12/2020 21:15, Jean-Marc Vanel wrote: > This is fine , I can get all the TDB prefix mappings with: > dataset.getDefaultModel().getNsPrefixMap() , > but I don't see how I can add them to a graph resulting from a SPARQL query, You mean CONSTRUCT or DESCRIBE? Add after return or use the execConstruct(model) form to pass in a model with prefixes already set. > in order to write it. I see nothing for this in RDFDataMgr . RDFDataMgr is a convenience library. The lower level interface WriterGraphRIOT takes a PrefixMap. You can get a writer(factory) from the RDFWriterRegistry. > And then, if I can add them while printing a graph, will the big list > of prefixes be added, > or only the prefixes actually used will be printed ? Declared unless you use PrefixMappingUtils.calcInUsePrefixMapping which is not so cheap as to automatically run it each time. Andy > > Jean-Marc Vanel > < http://semantic-forms.cc:9112/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me> +33 > (0)6 89 16 29 52 > > > Le mar. 1 déc. 2020 à 21:34, Andy Seaborne <[email protected]> a écrit : > >> >> >> On 01/12/2020 19:02, Jean-Marc Vanel wrote: >>> Empty maps are obtained by calling getPrefixMapping() , >>> either with a graph from a SPARQL query, or from the Union Graph. >> >> Perfect timing! >> >> JENA-2006 (in-progress as of 2020-12-01 - PR went in today. >> adds Dataset.getPrefixMapping() and DatsetGraph.prefixes() >> >> For a TDB database, all graphs will have the same prefix map, including >> the union graph. >> >> Currently - 3.17.0 - the dataset prefixes (i.e. as used for output) are >> held with the default graph. While the code supports additonal prefix >> sets, they are accssible without going into the implementation. >> >> JENA-2006 changes all that. >> >>> From a SPARQL query, only possible prefix mappings are from the query, >> not >>> the database. >> >> They are on the default graph, if there are any from TriG. >> >>> Same thing with >>> PrefixMappingUtils.calcInUsePrefixMapping(graph) >>> There is a class called DatasetPrefixesTDB , but it seems a low level >>> implementation class. >>> Some code comments imply that a prefixes map is not maintained >>> permanently ... >>> >>> Not yet tested with 3.17.0 . >> >> No change. >> >> Andy >> >>> >>> Jean-Marc Vanel >>> < >> http://semantic-forms.cc:1952/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me >>> >>> +33 (0)6 89 16 29 52 >>> Twitter: @jmvanel , @jmvanel_fr ; chat: irc:// irc.freenode.net#eulergui >>> Chroniques jardin >>> < >> http://semantic-forms.cc:1952/history?uri=http%3A%2F%2Fdbpedia.org%2Fresource%2FChronicle >>> >>> >>
