Skip to content

read-from-std-in silently ignores input unless media-type is provided #641

Description

@VladimirAlexiev

(Another issue for #636 )

https://sparql-anything.readthedocs.io/stable/Configuration/#general-purpose-options describes read-from-std-in

  • But it doesn't work: it ignores input and prints only prefixes
sparql-anything -q model-enum.fx < enum.csv
PREFIX fx:   <http://sparql.xyz/facade-x/ns/>
PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xyz:  <http://sparql.xyz/facade-x/data/>

The script is

base <https://example.org/>
prefix fx: <http://sparql.xyz/facade-x/ns/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix xyz: <http://sparql.xyz/facade-x/data/>
construct {
  ?enum_Attribut_IRI_URL a skos:ConceptScheme;
    skos:prefLabel ?Attribut_IRI_enum_lang_de;
    rdfs:label ?Attribut_IRI_enum_lang_de.
  ?enum_Attribut_IRI_Enumeration_DE_URLIFY_URL a skos:Concept;
    skos:inScheme ?enum_Attribut_IRI_URL; skos:topConceptOf ?enum_Attribut_IRI_URL;
    skos:prefLabel ?Enumeration_DE_lang_de, ?Enumeration_FR_lang_fr, ?Enumeration_IT_lang_it.
}
where {
  service <x-sparql-anything:> {
    fx:properties
      fx:read-from-std-in "true" ;
      fx:csv.headers "true" ;
      fx:csv.headers.sanitize "true" ;
      fx:csv.null-string "" .
    optional {?ROW xyz:Attribut_IRI ?Attribut_IRI}
    optional {?ROW xyz:Enumeration_DE ?Enumeration_DE}
    optional {?ROW xyz:Enumeration_FR ?Enumeration_FR}
    optional {?ROW xyz:Enumeration_IT ?Enumeration_IT}
    bind(iri(concat("enum/",?Attribut_IRI)) as ?enum_Attribut_IRI_URL)
    bind(concat(?Attribut_IRI," enum") as ?Attribut_IRI_enum)
    bind(strlang(?Attribut_IRI_enum,"de") as ?Attribut_IRI_enum_lang_de)
    bind(replace(replace(replace(replace(?Enumeration_DE,"[^\\p{L}0-9]+",""),"ä","ae"),"ü","ue"),"ö","oe") as ?Enumeration_DE_URLIFY)
    bind(iri(concat("enum/",?Attribut_IRI,"/",?Enumeration_DE_URLIFY)) as ?enum_Attribut_IRI_Enumeration_DE_URLIFY_URL)
    bind(strlang(?Enumeration_DE,"de") as ?Enumeration_DE_lang_de)
    bind(strlang(?Enumeration_FR,"fr") as ?Enumeration_FR_lang_fr)
    bind(strlang(?Enumeration_IT,"it") as ?Enumeration_IT_lang_it)
  }
}

The same script works if I use fx:location $_location and pass -v location=enum.csv.

The doc has a note below the table that needs to be amended to this:

* It is mandatory to provide either `location, content, command` or `read-from-std-in`

Activity

  1. enridaga commented on Jul 17, 2026

    @enridaga
    Member

    You still need to tell the format as the software is not going to see the file name in this case. Try adding fx:media-type "text/csv".

    Example (untested):

    PREFIX fx:  <http://sparql.xyz/facade-x/ns/>
        PREFIX xyz: <http://sparql.xyz/facade-x/data/>
        SELECT ?name ?age {
            SERVICE <x-sparql-anything:> {
                fx:properties
                    fx:read-from-std-in  "true" ;
                    fx:media-type        "text/csv" ;
                    fx:csv.headers       "true" .
                ?row xyz:name ?name ;
                     xyz:age  ?age .
            }
        }

    used as:

    printf 'name,age\nVincent,45\nJules,50\n' | sparql-anything -q model.fx
  2. VladimirAlexiev commented on Jul 20, 2026

    @VladimirAlexiev
    Author

    @enridaga Thanks! and how silly of me.

    • But maybe it's better for it to throw an exception rather than silently omitting the content?
    • Please fix the doc: the note below the table to this:
    - * It is mandatory to provide either `location, content, command` or `read-from-std-in`
    - * For all except `location` you also need to provide `media-type` so Sparql Anything can interpret the content appropriately
    
  3. changed the title [-]`read-from-std-in` doesn't work[/-] [+]`read-from-std-in` silently ignores input unless `media-type` is provided[/+] on Jul 20, 2026
  4. enridaga commented on Jul 22, 2026

    @enridaga
    Member
    • But maybe it's better for it to throw an exception rather than silently omitting the content?

    Agreed.

    Comment added in doc with d2b971e

  5. enridaga commented on Jul 22, 2026

    @enridaga
    Member

    Regarding STDIN, I think the default triplifier is the text (without additional params, it just puts the content in a literal):

    Without media-type:

    $ echo "a,b,c" | java -jar sparql-anything-cli/target/sparql-anything-1.2.0-RC1.jar fx -q "PREFIX fx: <http://sparql.xyz/facade-x/ns/> select * where { service <x-sparql-anything:> {fx:properties fx:read-from-std-in true. ?s ?p ?o }}"
    s,p,o
    b0,http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://sparql.xyz/facade-x/ns/root
    b0,http://www.w3.org/1999/02/22-rdf-syntax-ns#_1,"a,b,c"

    With media-type:

    $ echo "a,b,c" | java -jar sparql-anything-cli/target/sparql-anything-1.2.0-RC1.jar fx -q "PREFIX fx: <http://sparql.xyz/facade-x/ns/> select * where { service <x-sparql-anything:> {fx:properties fx:read-from-std-in true ; fx:media-type \"text/csv\". ?s ?p ?o }}"
    s,p,o
    b0,http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://sparql.xyz/facade-x/ns/root
    b0,http://www.w3.org/1999/02/22-rdf-syntax-ns#_1,b1
    b1,http://www.w3.org/1999/02/22-rdf-syntax-ns#_1,a
    b1,http://www.w3.org/1999/02/22-rdf-syntax-ns#_2,b
    b1,http://www.w3.org/1999/02/22-rdf-syntax-ns#_3,c
  6. VladimirAlexiev commented on Jul 29, 2026

    @VladimirAlexiev
    Author

    What am I doing wrong here?

    echo '<urn:x> <urn:p> ("fr" "it")' | \
      sparql-anything -q 'construct {?s ?p ?o} where {SERVICE <x-sparql-anything:media-type=text/turtle:read-from-std-in=true> {?s ?p ?o}}'
    [main] ERROR io.github.sparqlanything.engine.PropertyExtractor - Neither location nor content provided
    [main] WARN io.github.sparqlanything.engine.FXGraphMaterialisationStrategy - No triplifier found
    [main] WARN org.apache.jena.sparql.engine.iterator.QueryIteratorCheck - Open iterator [execCxt@2038232668]: QueryIterRoot/0
    
  7. enridaga commented on Jul 29, 2026

    @enridaga
    Member

    What am I doing wrong here?

    echo '<urn:x> <urn:p> ("fr" "it")' | \
      sparql-anything -q 'construct {?s ?p ?o} where {SERVICE <x-sparql-anything:media-type=text/turtle:read-from-std-in=true> {?s ?p ?o}}'
    [main] ERROR io.github.sparqlanything.engine.PropertyExtractor - Neither location nor content provided
    [main] WARN io.github.sparqlanything.engine.FXGraphMaterialisationStrategy - No triplifier found
    [main] WARN org.apache.jena.sparql.engine.iterator.QueryIteratorCheck - Open iterator [execCxt@2038232668]: QueryIterRoot/0
    

    Use a comma to separate properties via url

    x-sparql-anything:media-type=text/turtle,read-from-std-in=true
    

    instead of

    x-sparql-anything:media-type=text/turtle:read-from-std-in=true
    
  8. enridaga commented on Jul 29, 2026

    @enridaga
    Member

    However, when changing to comma it returns an empty result. There must be something else. Changing to location works:

    $ sparql-anything -q 'construct {?s ?p ?o} where {SERVICE <x-sparql-anything:media-type=text/turtle,location=test.ttl> {?s ?p ?o}}'
    <urn:x>  <urn:p>  ( "fr" "it" ) .

    CSV works as expected:

    $   echo 'a,b,c' | \
    >   sparql-anything -q 'construct {?s ?p ?o} where {SERVICE <x-sparql-anything:media-type=text/csv,read-from-std-in=true> {?s ?p ?o}}'
    [ a       <http://sparql.xyz/facade-x/ns/root>;
      <http://www.w3.org/1999/02/22-rdf-syntax-ns#_1>
              [ <http://www.w3.org/1999/02/22-rdf-syntax-ns#_1>
                        "a";
                <http://www.w3.org/1999/02/22-rdf-syntax-ns#_2>
                        "b";
                <http://www.w3.org/1999/02/22-rdf-syntax-ns#_3>
                        "c"
              ]
    ] .
    

    So there seems to be something weird happening when reading turtle from stdin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions