Bob,

Yes.  I mistakenly tested passing stdin as the --query argument.  The
--data argument apparently keys the input type from the suffix of the
filename.  That makes it a bit more of a pain to deal with.

#!/bin/sh
# Write some sample data.
cat << DATADOC > /tmp/data.n3
@prefix : <http://inf.ed.ac.uk/ont#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

:stu foaf:knows :bea ;
     foaf:name "Stuart" .
:bea foaf:knows :amy ;
     foaf:name "Beatrice" .
:amy foaf:name "Amy" .
:dan foaf:knows :mik ;
     foaf:name "Dan" .
:mik foaf:knows :dan ;
     foaf:name "Mik" .
DATADOC

# Write a query
cat << QUERYDOC > /tmp/query.rq
SELECT ?s ?p ?o
WHERE { ?s ?p ?o . }
QUERYDOC

# Fails to load data.
# cat /tmp/data.n3 | arq --query=/tmp/query.rq --data=/dev/stdin

# ARQ keys off file suffix to pick up format.  Use a named pipe to supply a
filename suffix to --data
mkfifo /tmp/datapipe.n3; \
  cat /tmp/data.n3 > /tmp/datapipe.n3 & \
  arq --query=/tmp/query.rq --data=/tmp/datapipe.n3; \
  rm /tmp/datapipe.n3

Might be worth writing a shell function to wrap the call to arq if this
gets done on the fly often.

Colin A. Gross


On Sat, Feb 27, 2021 at 4:00 PM Bob DuCharme <[email protected]> wrote:

> That looked promising to me, but with Jena 3.3 under Ubuntu it gave me
> "Failed to load data".
>
> Wouldn't there need to be some way to indicate which serialization the
> data was using?
>
> Thanks,
>
> Bob
>
>
> On 2/27/21 2:47 PM, Colin Gross wrote:
> > Bob,
> >
> > Have you tried passing /dev/stdin as the argument for --data?  E.g:
> > arq --query=example.rq --data=/dev/stdin
> > That should wait on stdin until it hits EOF (ctrl+d).
> >
> > This should let you piping from a file or wherever E.g.
> > cat people.n3 | arq --query=example.rq --data=/dev/stdin
> >
> > If you need to pipe from multiple sources, such as if you need to have
> > multiple --data args, you could make a series of fifo pipes that data
> > was fed into by other processes.
> >
> >
> > Regards,
> > Colin A. Gross
> >
> >
> > On Sat, Feb 27, 2021 at 9:41 AM Bob DuCharme <[email protected]> wrote:
> >
> >> This is just an idea. I like how jena's riot utility accepts data from
> >> stdin as long as you provide a --syntax parameter to tell it what
> >> serialization the stdin triples are. When I was at TopQuadrant I liked
> >> SPARQLMotion, their proprietary system for pipelining RDF through
> >> various steps to create an automated workflow. I wrote about doing
> >> something similar with Python in "Pipelining SPARQL queries in memory
> >> with the rdflib Python library" at
> >> http://www.bobdc.com/blog/pipelining-sparql-queries-in-m/ .
> >> <http://www.bobdc.com/blog/pipelining-sparql-queries-in-m/>
> >>
> >> I was thinking that if arq could accept triples via stdin like riot can,
> >> I could use curl to pull triples from an endpoint, pipe it to arq
> >> running a CONSTRUCT query that does some cleanup transformations, and
> >> then pipe the output of that to arq to run a SELECT query that pulls
> >> what I ultimately want, all on one command from the command line. (I see
> >> that arq already has a --syntax switch that is about the query itself,
> >> so it would need a different switch to specify the serialization of
> >> input data if it's coming from stdin.)
> >> <http://www.bobdc.com/blog/pipelining-sparql-queries-in-m/>
> >>
> >> Of course, I could do all this now from a shell script in which some
> >> lines save output to temporary files and later lines read those, but
> >> supporting stdin would add some flexibility. riot's ability to do this
> >> is inspiring!
> >>
> >> Thanks,
> >>
> >> Bob
> >>
> >>
> >>
>

Reply via email to