the file URL comes from the system:

URL url = ReadTest.class.getResource("/MockRoadmap.ttl");
Model model = retval.getNamedModel(url.toString());
model.read(url.toString(), "TURTLE");

I added the the following code

Iterator<String> siter = retval.listNames();
while (siter.hasNext())
{
System.out.println( "Graph: "+siter.next() );
}

and got one result (as expected)
Graph: file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl

So the condition I have is:


   - the java system produces a URL that does not have the three slashes.
   - calling toExternalForm() does not add the slashes
   - converting it to a java URI via url.toURI() does not add the slashes
   - converting it to a java URI and calling toASCIIString() does not add
   the slashes
   - converting it to a java URI and calling normalize() does not add the
   slashes

The graph name is added to the underlying graph without slashes (as
expected).

So given an arbitrary URL that actually resolves to data (e.g. a file or a
real http stream) how can I ensure that a graph name derived from that URL
is fully qualified?

I think the only answer is to verify that he "host" field is populated and
if not add 2 slashes -- but that may not work for http or ftp protocols.

Thoughts?



On Sun, Jul 27, 2014 at 10:10 AM, Andy Seaborne <a...@apache.org> wrote:

> On 27/07/14 09:44, Claude Warren wrote:
>
>> Using apache-jena-libs 2.11.2
>> I have the following code:
>>
>> Dataset retval = TDBFactory.createDataset();
>> retval.begin(ReadWrite.WRITE);
>>   // read <file:/home/claude/git/roadmap/target/test-classes/
>> MockRoadmap.ttl>
>> URL url = ReadTest.class.getResource("/MockRoadmap.ttl");
>> Model model = retval.getNamedModel(url.toString());
>> model.read(url.toString(), "TURTLE");
>>   // <file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl>
>> SelectBuilder sBuilder = RoadmapDataset
>> .setPrefixes(new SelectBuilder())
>> .addPrefix( "xsd", "http://www.w3.org/2001/XMLSchema#";)
>> .addPrefix( "epm", EndpointMonitor.NAMESPACE )
>> //.from("file:/home/claude/git/roadmap/target/test-
>> classes/MockRoadmap.ttl")
>> .addGraph( "?g", new SelectBuilder()
>> .addWhere("?s", "void:sparqlEndpoint", "?e")
>> )
>> ;
>> // print the query
>> System.out.println( sBuilder.build() );
>> QueryExecution qe2 = QueryExecutionFactory.create(
>> QueryFactory.create(sBuilder.build()), retval);
>> ResultSet rs = qe2.execSelect();
>> while (rs.hasNext())
>> {
>> QuerySolution qs = rs.next();
>> System.out.println( "result="+qs );
>> }
>>
>> the query it produces is
>> PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
>> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
>> PREFIX voidext: <http://rdfs.org/ns/void-ext#>
>> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
>> PREFIX owl: <http://www.w3.org/2002/07/owl#>
>> PREFIX void: <http://rdfs.org/ns/void#>
>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>> PREFIX epm: <http://localhost/endpointMonitor#>
>> SELECT *
>> WHERE {
>> GRAPH ?g {
>> ?s void:sparqlEndpoint ?e .
>> }
>> }
>>
>> producing:
>>
>> result=( ?e = <http://localhost/master/sparql> ) ( ?g =
>> <file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl> ) (
>> ?s
>> = <http://localhost/master> )
>> result=( ?e = <http://localhost:8083/slave1/sparql> ) ( ?g =
>> <file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl> ) (
>> ?s
>> = <http://localhost:8083/slave1> )
>> result=( ?e = <http://localhost:8083/slave2/sparql> ) ( ?g =
>> <file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl> ) (
>> ?s
>> = <http://localhost:8083/slave2> )
>>
>> If I modify the query builder to produce
>>
>> PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
>> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
>> PREFIX voidext: <http://rdfs.org/ns/void-ext#>
>> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
>> PREFIX owl: <http://www.w3.org/2002/07/owl#>
>> PREFIX void: <http://rdfs.org/ns/void#>
>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>> PREFIX epm: <http://localhost/endpointMonitor#>
>> SELECT *
>> FROM <file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl>
>>
>
> Virtual dataset with one graph in the default graph
>
>  WHERE {
>> GRAPH ?g {
>>
>
> default graph does not match
>
>
>  ?s void:sparqlEndpoint ?e .
>> }
>> }
>>
>> I get no output
>>
>> if I change FROM to FROM NAMED I get no output
>>
>
> FROM NAMED should work if you have the right IRI.
>
> The SPARQL parser resolves all URIs and <file:/home/...> isn't a absolute
> file: URL.
>
> Try running our query through qparse or use the online validator at
> sparql.org.
>
> It's "file:///home/claude/" in the query and your data has relative IRIs
> in it.  How did you build the data?
>
> Three / -- like http://host/path without the host (host being meaning
> less for file:).
>
>
>
>> if I change the WHERE clause to
>> WHERE {
>> ?s void:sparqlEndpoint ?e .
>> }
>> with  FROM or FROM NAMED or no FROM statement at I get not output.
>>
>> I am looking for something that will produce the results from the first
>> query without looking at all the named graphs.  Is there a way to do that?
>>   I thought that FROM NAMED would limit the named graphs to query but it
>> seems to exclude the one I want.
>> I thought that FROM would make the named graph the default graph but that
>> doesn't seem to work either.
>>
>> Any help would be appreciated.
>>
>
> SELECT *
> FROM <file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl>
> WHERE {
>   ?s void:sparqlEndpoint ?e .
> }
>
> SELECT *
> FROM NAMED <file:/home/claude/git/roadmap/target/test-classes/
> MockRoadmap.ttl>
>
> WHERE {
>    GRAPH ?g {
>   ?s void:sparqlEndpoint ?e .
> } }
>
> which is iterating over one graph
>
> but better:
>
> SELECT *
> WHERE {
> GRAPH <file:///home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl>
> {
>
>   ?s void:sparqlEndpoint ?e .
>  }
> }
>
>         Andy
>
>
>
>
>>
>>
>


-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Reply via email to