You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Martynas Jusevičius <ma...@atomgraph.com> on 2019/08/13 22:46:19 UTC
StreamRDF.base()
Hi,
I'm trying to understand what the purpose/usage of StreamRDF.base() is.
Isn't it supposed to set the base URI that relative URIs in the stream
resolve against?
I've made a simple test:
StreamRDF rdfStream = StreamRDFLib.writer(new BufferedWriter(new
OutputStreamWriter(System.out)));
rdfStream.start();
rdfStream.base("http://localhost/");
rdfStream.triple(new Triple(NodeFactory.createBlankNode(),
NodeFactory.createURI("relative"), NodeFactory.createBlankNode()));
rdfStream.finish();
The output I get:
_:Bf410fc50X2De0baX2D464eX2D996eX2Dbb3207090baa <relative>
_:B4b65b796X2D3561X2D4bf3X2Dbf31X2D1154aac0c816 .
Why is the property URI <relative> and not <http://localhost/relative>?
Doesn't that make the output invalid N-Triples? Or am I writing it wrong?
Martynas
atomgraph.com
Re: StreamRDF.base()
Posted by Andy Seaborne <an...@apache.org>.
On 15/08/2019 13:02, Claude Warren wrote:
> Learn something new every day...
>
> On Wed, Aug 14, 2019 at 5:44 PM Andy Seaborne <an...@apache.org> wrote:
>
>>
>>
>>
>> (and it is technically wrong to have a # in the base)
>>
>>
> so as a base "http://example.com/myfile.txt#" is incorrect but "
> http://example.com/myfile.txt/" is correct?
Legal.
They are completely different URIs. "/" means something in http URIs.
Fragments are within the document named.
Base URIs are like HTTP requests which also do not have a fragement,
Resolving <one> against base URIs:
http://example/dir/
http://example/dir/file
and it's the same outcome.
http://example/dir/one
https://twitter.com/AndySeaborne/status/1156227576257482754
RFC 3986, section 5.2
5.2.3 - "Base.fragment" is not mentioned.
Jena does cope with # in the base - it drops it as per 5.2, 5.2.3
The only assignment is
T.fragment = R.fragment
(R being the relative URI being resolved, T the output)
Relative <#one> gives:
http://example/dir/#one
http://example/dir/file#'one
>
> or technically does the last segment of the base need to be an NCName[1]?
"need" - no.
NCName is an XML-ism.
For RDF/XML it is a good idea - classes and properties can end up as XML
qnames.
> in which case "http://example.com/myfile.txt" but not "
> http://example.com/myfile.txt#" or "http://example.com/myfile.txt/"
>
> How does one create a technically correct base that will convert
> <one>
> to
<one> can't become <http://example.com/myfile.txt#one>
Resolution can't introduce a fragment that isn't in the relative URI to
start with. <#one> works.
> <http://example.com/myfile.txt#one>
> or
> <http://example.com/myfile.txt/one>
>
> ? Or is that just not possible?
>
> Thx,
> Claude
>
>
> [1] https://www.w3.org/TR/xml-names/#NT-NCName
>
Re: StreamRDF.base()
Posted by Claude Warren <cl...@xenei.com>.
Learn something new every day...
On Wed, Aug 14, 2019 at 5:44 PM Andy Seaborne <an...@apache.org> wrote:
>
>
>
> (and it is technically wrong to have a # in the base)
>
>
so as a base "http://example.com/myfile.txt#" is incorrect but "
http://example.com/myfile.txt/" is correct?
or technically does the last segment of the base need to be an NCName[1]?
in which case "http://example.com/myfile.txt" but not "
http://example.com/myfile.txt#" or "http://example.com/myfile.txt/"
How does one create a technically correct base that will convert
<one>
to
<http://example.com/myfile.txt#one>
or
<http://example.com/myfile.txt/one>
? Or is that just not possible?
Thx,
Claude
[1] https://www.w3.org/TR/xml-names/#NT-NCName
--
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren
Re: StreamRDF.base()
Posted by Andy Seaborne <an...@apache.org>.
On 14/08/2019 12:30, Martynas Jusevičius wrote:
> And if I want hash URIs such as <https://localhost/ontology#term> then
> I need to do
>
> IRIResolver.create("https://localhost/ontology").resolve("#term")
IRIResolver resolver = IRIResolver.create("https://localhost/ontology");
...
resolver.resolve("#term");
>
> rather than
>
> IRIResolver.create("https://localhost/ontology#").resolve("term")
>
> which would produce <https://localhost/term> instead, correct?
Yes.
Resolution is not concat.
(and it is technically wrong to have a # in the base)
>
> On Wed, Aug 14, 2019 at 12:32 PM Andy Seaborne <an...@apache.org> wrote:
>>
>> Yes.
>>
>> More efficient is to create a resolver with IRIResolver.create and use
>> that. Includes caching of resolved strings.
>>
>> See the turtle parser.
>>
>> Andy
>>
>> On 14/08/2019 11:28, Martynas Jusevičius wrote:
>>> OK, more or less what I suspected.
>>>
>>> And IRIResolver.resolve(String relStr, String baseStr) can be used by
>>> the parser for said URI resolution?
>>> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/system/IRIResolver.html#resolve-java.lang.String-java.lang.String-
>>>
>>> So far I'm not implementing a proper ReaderRIOT yet, just doing some
>>> conversion to RDF.
>>>
>>> On Wed, Aug 14, 2019 at 12:13 PM Andy Seaborne <an...@apache.org> wrote:
>>>>
>>>> StreamRDF is an interface called by parsers (and other things) based on
>>>> what it sees.
>>>>
>>>> If in, say Turtle, teh pasrer sees a "BASE" then base(...) is called.
>>>>
>>>> StreamRDF (it is an interface) does not do anything - its a stream of
>>>> incoming RDF for the implementation to deal with.
>>>>
>>>> StreamRDFLib.writer writes N-quads. No way to say "BASE".
>>>>
>>>> Triples sent to triple() should be already resolved - a parser
>>>> responsibility.
>>>>
>>>> Andy
>>>>
>>>> On 14/08/2019 09:28, Claude Warren wrote:
>>>>> The StreamRDF just passed the base() argument on to the sink so that the
>>>>> sink would have the base in order to set create the FQ URI from local
>>>>> URIs.
>>>>>
>>>>> StreamRDFLib simply ignores the base() call.
>>>>
>>>> Did you mean StreamRDFBase?
>>>>
>>>> StreamRDFLib is a colelction of fucntiosn and isn't itself does not have
>>>> the StreamRDF interface.
>>>>
>>>>> I assume this is because it
>>>>> is intended to process fully qualified RDF.
>>>>>
>>>>> I think the assumption is that if you are streaming into the graph you
>>>>> would need the base() to resolve any inbound local URIs while if you are
>>>>> streaming out from the graph the URIs are already fully resolved.
>>>>>
>>>>> I didn't write this code so I am not certain but if that is the case
>>>>> perhaps we should note it in the javadocs.
>>>>>
>>>>> I do note that StreamRDF says it is for output, in which case I am not
>>>>> certain why the base() is needed at all.
>>>>>
>>>>> Claude
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Aug 13, 2019 at 11:46 PM Martynas Jusevičius <ma...@atomgraph.com>
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I'm trying to understand what the purpose/usage of StreamRDF.base() is.
>>>>>>
>>>>>> Isn't it supposed to set the base URI that relative URIs in the stream
>>>>>> resolve against?
>>>>>>
>>>>>> I've made a simple test:
>>>>>>
>>>>>> StreamRDF rdfStream = StreamRDFLib.writer(new BufferedWriter(new
>>>>>> OutputStreamWriter(System.out)));
>>>>>> rdfStream.start();
>>>>>> rdfStream.base("http://localhost/");
>>>>>> rdfStream.triple(new Triple(NodeFactory.createBlankNode(),
>>>>>> NodeFactory.createURI("relative"), NodeFactory.createBlankNode()));
>>>>>> rdfStream.finish();
>>>>>>
>>>>>> The output I get:
>>>>>>
>>>>>> _:Bf410fc50X2De0baX2D464eX2D996eX2Dbb3207090baa <relative>
>>>>>> _:B4b65b796X2D3561X2D4bf3X2Dbf31X2D1154aac0c816 .
>>>>>>
>>>>>> Why is the property URI <relative> and not <http://localhost/relative>?
>>>>>> Doesn't that make the output invalid N-Triples? Or am I writing it wrong?
>>>>>>
>>>>>> Martynas
>>>>>> atomgraph.com
>>>>>>
>>>>>
>>>>>
Re: StreamRDF.base()
Posted by Martynas Jusevičius <ma...@atomgraph.com>.
And if I want hash URIs such as <https://localhost/ontology#term> then
I need to do
IRIResolver.create("https://localhost/ontology").resolve("#term")
rather than
IRIResolver.create("https://localhost/ontology#").resolve("term")
which would produce <https://localhost/term> instead, correct?
On Wed, Aug 14, 2019 at 12:32 PM Andy Seaborne <an...@apache.org> wrote:
>
> Yes.
>
> More efficient is to create a resolver with IRIResolver.create and use
> that. Includes caching of resolved strings.
>
> See the turtle parser.
>
> Andy
>
> On 14/08/2019 11:28, Martynas Jusevičius wrote:
> > OK, more or less what I suspected.
> >
> > And IRIResolver.resolve(String relStr, String baseStr) can be used by
> > the parser for said URI resolution?
> > https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/system/IRIResolver.html#resolve-java.lang.String-java.lang.String-
> >
> > So far I'm not implementing a proper ReaderRIOT yet, just doing some
> > conversion to RDF.
> >
> > On Wed, Aug 14, 2019 at 12:13 PM Andy Seaborne <an...@apache.org> wrote:
> >>
> >> StreamRDF is an interface called by parsers (and other things) based on
> >> what it sees.
> >>
> >> If in, say Turtle, teh pasrer sees a "BASE" then base(...) is called.
> >>
> >> StreamRDF (it is an interface) does not do anything - its a stream of
> >> incoming RDF for the implementation to deal with.
> >>
> >> StreamRDFLib.writer writes N-quads. No way to say "BASE".
> >>
> >> Triples sent to triple() should be already resolved - a parser
> >> responsibility.
> >>
> >> Andy
> >>
> >> On 14/08/2019 09:28, Claude Warren wrote:
> >>> The StreamRDF just passed the base() argument on to the sink so that the
> >>> sink would have the base in order to set create the FQ URI from local
> >>> URIs.
> >>>
> >>> StreamRDFLib simply ignores the base() call.
> >>
> >> Did you mean StreamRDFBase?
> >>
> >> StreamRDFLib is a colelction of fucntiosn and isn't itself does not have
> >> the StreamRDF interface.
> >>
> >>> I assume this is because it
> >>> is intended to process fully qualified RDF.
> >>>
> >>> I think the assumption is that if you are streaming into the graph you
> >>> would need the base() to resolve any inbound local URIs while if you are
> >>> streaming out from the graph the URIs are already fully resolved.
> >>>
> >>> I didn't write this code so I am not certain but if that is the case
> >>> perhaps we should note it in the javadocs.
> >>>
> >>> I do note that StreamRDF says it is for output, in which case I am not
> >>> certain why the base() is needed at all.
> >>>
> >>> Claude
> >>>
> >>>
> >>>
> >>> On Tue, Aug 13, 2019 at 11:46 PM Martynas Jusevičius <ma...@atomgraph.com>
> >>> wrote:
> >>>
> >>>> Hi,
> >>>>
> >>>> I'm trying to understand what the purpose/usage of StreamRDF.base() is.
> >>>>
> >>>> Isn't it supposed to set the base URI that relative URIs in the stream
> >>>> resolve against?
> >>>>
> >>>> I've made a simple test:
> >>>>
> >>>> StreamRDF rdfStream = StreamRDFLib.writer(new BufferedWriter(new
> >>>> OutputStreamWriter(System.out)));
> >>>> rdfStream.start();
> >>>> rdfStream.base("http://localhost/");
> >>>> rdfStream.triple(new Triple(NodeFactory.createBlankNode(),
> >>>> NodeFactory.createURI("relative"), NodeFactory.createBlankNode()));
> >>>> rdfStream.finish();
> >>>>
> >>>> The output I get:
> >>>>
> >>>> _:Bf410fc50X2De0baX2D464eX2D996eX2Dbb3207090baa <relative>
> >>>> _:B4b65b796X2D3561X2D4bf3X2Dbf31X2D1154aac0c816 .
> >>>>
> >>>> Why is the property URI <relative> and not <http://localhost/relative>?
> >>>> Doesn't that make the output invalid N-Triples? Or am I writing it wrong?
> >>>>
> >>>> Martynas
> >>>> atomgraph.com
> >>>>
> >>>
> >>>
Re: StreamRDF.base()
Posted by Andy Seaborne <an...@apache.org>.
Yes.
More efficient is to create a resolver with IRIResolver.create and use
that. Includes caching of resolved strings.
See the turtle parser.
Andy
On 14/08/2019 11:28, Martynas Jusevičius wrote:
> OK, more or less what I suspected.
>
> And IRIResolver.resolve(String relStr, String baseStr) can be used by
> the parser for said URI resolution?
> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/system/IRIResolver.html#resolve-java.lang.String-java.lang.String-
>
> So far I'm not implementing a proper ReaderRIOT yet, just doing some
> conversion to RDF.
>
> On Wed, Aug 14, 2019 at 12:13 PM Andy Seaborne <an...@apache.org> wrote:
>>
>> StreamRDF is an interface called by parsers (and other things) based on
>> what it sees.
>>
>> If in, say Turtle, teh pasrer sees a "BASE" then base(...) is called.
>>
>> StreamRDF (it is an interface) does not do anything - its a stream of
>> incoming RDF for the implementation to deal with.
>>
>> StreamRDFLib.writer writes N-quads. No way to say "BASE".
>>
>> Triples sent to triple() should be already resolved - a parser
>> responsibility.
>>
>> Andy
>>
>> On 14/08/2019 09:28, Claude Warren wrote:
>>> The StreamRDF just passed the base() argument on to the sink so that the
>>> sink would have the base in order to set create the FQ URI from local
>>> URIs.
>>>
>>> StreamRDFLib simply ignores the base() call.
>>
>> Did you mean StreamRDFBase?
>>
>> StreamRDFLib is a colelction of fucntiosn and isn't itself does not have
>> the StreamRDF interface.
>>
>>> I assume this is because it
>>> is intended to process fully qualified RDF.
>>>
>>> I think the assumption is that if you are streaming into the graph you
>>> would need the base() to resolve any inbound local URIs while if you are
>>> streaming out from the graph the URIs are already fully resolved.
>>>
>>> I didn't write this code so I am not certain but if that is the case
>>> perhaps we should note it in the javadocs.
>>>
>>> I do note that StreamRDF says it is for output, in which case I am not
>>> certain why the base() is needed at all.
>>>
>>> Claude
>>>
>>>
>>>
>>> On Tue, Aug 13, 2019 at 11:46 PM Martynas Jusevičius <ma...@atomgraph.com>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm trying to understand what the purpose/usage of StreamRDF.base() is.
>>>>
>>>> Isn't it supposed to set the base URI that relative URIs in the stream
>>>> resolve against?
>>>>
>>>> I've made a simple test:
>>>>
>>>> StreamRDF rdfStream = StreamRDFLib.writer(new BufferedWriter(new
>>>> OutputStreamWriter(System.out)));
>>>> rdfStream.start();
>>>> rdfStream.base("http://localhost/");
>>>> rdfStream.triple(new Triple(NodeFactory.createBlankNode(),
>>>> NodeFactory.createURI("relative"), NodeFactory.createBlankNode()));
>>>> rdfStream.finish();
>>>>
>>>> The output I get:
>>>>
>>>> _:Bf410fc50X2De0baX2D464eX2D996eX2Dbb3207090baa <relative>
>>>> _:B4b65b796X2D3561X2D4bf3X2Dbf31X2D1154aac0c816 .
>>>>
>>>> Why is the property URI <relative> and not <http://localhost/relative>?
>>>> Doesn't that make the output invalid N-Triples? Or am I writing it wrong?
>>>>
>>>> Martynas
>>>> atomgraph.com
>>>>
>>>
>>>
Re: StreamRDF.base()
Posted by Martynas Jusevičius <ma...@atomgraph.com>.
OK, more or less what I suspected.
And IRIResolver.resolve(String relStr, String baseStr) can be used by
the parser for said URI resolution?
https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/system/IRIResolver.html#resolve-java.lang.String-java.lang.String-
So far I'm not implementing a proper ReaderRIOT yet, just doing some
conversion to RDF.
On Wed, Aug 14, 2019 at 12:13 PM Andy Seaborne <an...@apache.org> wrote:
>
> StreamRDF is an interface called by parsers (and other things) based on
> what it sees.
>
> If in, say Turtle, teh pasrer sees a "BASE" then base(...) is called.
>
> StreamRDF (it is an interface) does not do anything - its a stream of
> incoming RDF for the implementation to deal with.
>
> StreamRDFLib.writer writes N-quads. No way to say "BASE".
>
> Triples sent to triple() should be already resolved - a parser
> responsibility.
>
> Andy
>
> On 14/08/2019 09:28, Claude Warren wrote:
> > The StreamRDF just passed the base() argument on to the sink so that the
> > sink would have the base in order to set create the FQ URI from local
> > URIs.
> >
> > StreamRDFLib simply ignores the base() call.
>
> Did you mean StreamRDFBase?
>
> StreamRDFLib is a colelction of fucntiosn and isn't itself does not have
> the StreamRDF interface.
>
> > I assume this is because it
> > is intended to process fully qualified RDF.
> >
> > I think the assumption is that if you are streaming into the graph you
> > would need the base() to resolve any inbound local URIs while if you are
> > streaming out from the graph the URIs are already fully resolved.
> >
> > I didn't write this code so I am not certain but if that is the case
> > perhaps we should note it in the javadocs.
> >
> > I do note that StreamRDF says it is for output, in which case I am not
> > certain why the base() is needed at all.
> >
> > Claude
> >
> >
> >
> > On Tue, Aug 13, 2019 at 11:46 PM Martynas Jusevičius <ma...@atomgraph.com>
> > wrote:
> >
> >> Hi,
> >>
> >> I'm trying to understand what the purpose/usage of StreamRDF.base() is.
> >>
> >> Isn't it supposed to set the base URI that relative URIs in the stream
> >> resolve against?
> >>
> >> I've made a simple test:
> >>
> >> StreamRDF rdfStream = StreamRDFLib.writer(new BufferedWriter(new
> >> OutputStreamWriter(System.out)));
> >> rdfStream.start();
> >> rdfStream.base("http://localhost/");
> >> rdfStream.triple(new Triple(NodeFactory.createBlankNode(),
> >> NodeFactory.createURI("relative"), NodeFactory.createBlankNode()));
> >> rdfStream.finish();
> >>
> >> The output I get:
> >>
> >> _:Bf410fc50X2De0baX2D464eX2D996eX2Dbb3207090baa <relative>
> >> _:B4b65b796X2D3561X2D4bf3X2Dbf31X2D1154aac0c816 .
> >>
> >> Why is the property URI <relative> and not <http://localhost/relative>?
> >> Doesn't that make the output invalid N-Triples? Or am I writing it wrong?
> >>
> >> Martynas
> >> atomgraph.com
> >>
> >
> >
Re: StreamRDF.base()
Posted by Andy Seaborne <an...@apache.org>.
StreamRDF is an interface called by parsers (and other things) based on
what it sees.
If in, say Turtle, teh pasrer sees a "BASE" then base(...) is called.
StreamRDF (it is an interface) does not do anything - its a stream of
incoming RDF for the implementation to deal with.
StreamRDFLib.writer writes N-quads. No way to say "BASE".
Triples sent to triple() should be already resolved - a parser
responsibility.
Andy
On 14/08/2019 09:28, Claude Warren wrote:
> The StreamRDF just passed the base() argument on to the sink so that the
> sink would have the base in order to set create the FQ URI from local
> URIs.
>
> StreamRDFLib simply ignores the base() call.
Did you mean StreamRDFBase?
StreamRDFLib is a colelction of fucntiosn and isn't itself does not have
the StreamRDF interface.
> I assume this is because it
> is intended to process fully qualified RDF.
>
> I think the assumption is that if you are streaming into the graph you
> would need the base() to resolve any inbound local URIs while if you are
> streaming out from the graph the URIs are already fully resolved.
>
> I didn't write this code so I am not certain but if that is the case
> perhaps we should note it in the javadocs.
>
> I do note that StreamRDF says it is for output, in which case I am not
> certain why the base() is needed at all.
>
> Claude
>
>
>
> On Tue, Aug 13, 2019 at 11:46 PM Martynas Jusevičius <ma...@atomgraph.com>
> wrote:
>
>> Hi,
>>
>> I'm trying to understand what the purpose/usage of StreamRDF.base() is.
>>
>> Isn't it supposed to set the base URI that relative URIs in the stream
>> resolve against?
>>
>> I've made a simple test:
>>
>> StreamRDF rdfStream = StreamRDFLib.writer(new BufferedWriter(new
>> OutputStreamWriter(System.out)));
>> rdfStream.start();
>> rdfStream.base("http://localhost/");
>> rdfStream.triple(new Triple(NodeFactory.createBlankNode(),
>> NodeFactory.createURI("relative"), NodeFactory.createBlankNode()));
>> rdfStream.finish();
>>
>> The output I get:
>>
>> _:Bf410fc50X2De0baX2D464eX2D996eX2Dbb3207090baa <relative>
>> _:B4b65b796X2D3561X2D4bf3X2Dbf31X2D1154aac0c816 .
>>
>> Why is the property URI <relative> and not <http://localhost/relative>?
>> Doesn't that make the output invalid N-Triples? Or am I writing it wrong?
>>
>> Martynas
>> atomgraph.com
>>
>
>
Re: StreamRDF.base()
Posted by Claude Warren <cl...@xenei.com>.
The StreamRDF just passed the base() argument on to the sink so that the
sink would have the base in order to set create the FQ URI from local
URIs.
StreamRDFLib simply ignores the base() call. I assume this is because it
is intended to process fully qualified RDF.
I think the assumption is that if you are streaming into the graph you
would need the base() to resolve any inbound local URIs while if you are
streaming out from the graph the URIs are already fully resolved.
I didn't write this code so I am not certain but if that is the case
perhaps we should note it in the javadocs.
I do note that StreamRDF says it is for output, in which case I am not
certain why the base() is needed at all.
Claude
On Tue, Aug 13, 2019 at 11:46 PM Martynas Jusevičius <ma...@atomgraph.com>
wrote:
> Hi,
>
> I'm trying to understand what the purpose/usage of StreamRDF.base() is.
>
> Isn't it supposed to set the base URI that relative URIs in the stream
> resolve against?
>
> I've made a simple test:
>
> StreamRDF rdfStream = StreamRDFLib.writer(new BufferedWriter(new
> OutputStreamWriter(System.out)));
> rdfStream.start();
> rdfStream.base("http://localhost/");
> rdfStream.triple(new Triple(NodeFactory.createBlankNode(),
> NodeFactory.createURI("relative"), NodeFactory.createBlankNode()));
> rdfStream.finish();
>
> The output I get:
>
> _:Bf410fc50X2De0baX2D464eX2D996eX2Dbb3207090baa <relative>
> _:B4b65b796X2D3561X2D4bf3X2Dbf31X2D1154aac0c816 .
>
> Why is the property URI <relative> and not <http://localhost/relative>?
> Doesn't that make the output invalid N-Triples? Or am I writing it wrong?
>
> Martynas
> atomgraph.com
>
--
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren