You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Holger Knublauch <ya...@knublauch.com> on 2011/05/06 07:33:52 UTC

Why does IRI(?x) not accept xsd:string literals?

Andy,

we are puzzled why the IRI built-in of SPARQL only accepts untyped literals, but not xsd:strings? I find this unnecessarily restrictive.

Thanks
Holger


(From NodeFunctions in ARQ 2.8.7):
    
    public static Node iri(Node nv, String baseIRI)
    {
        if ( nv.isURI() )
            return nv ;
        
        if ( nv.isBlank() )
        {
            // Skolemization of blank nodes to IRIs : Don't ask, just don't ask.
            String x = nv.getBlankNodeLabel() ;
            return Node.createURI("_:"+x) ;
        }
        
        if ( nv.isLiteral() && 
             nv.getLiteralDatatype() == null && 
             nv.getLiteralLanguage().equals("") )
        {
            // Plain literal
            IRI iri = null ;
            String iriStr = nv.getLiteralLexicalForm() ;
            
            // Level of checking?
            if ( baseIRI != null )
            {
                IRI base = iriFactory.create(baseIRI);
                iri = base.create(iriStr);
            }
            else
                iri = iriFactory.create(iriStr);
            
            if ( ! iri.isAbsolute() )
                throw new ExprEvalException("Relative IRI string: "+iriStr) ;
            if ( warningsForIRIs && iri.hasViolation(false) )
            {
                String msg = "unknown violation from IRI library" ; 
                Iterator<Violation> iter = iri.violations(false) ;
                if ( iter.hasNext() )
                {
                    Violation viol = iter.next() ;
                    msg = viol.getShortMessage() ;
                }
                Log.warn(NodeFunctions.class, "Bad IRI: "+msg+": "+iri) ;
            }
            return Node.createURI(iri.toString()) ;
        }
        throw new ExprEvalException("Can't make an IRI from "+nv) ;
    }


Re: Why does IRI(?x) not accept xsd:string literals?

Posted by Andy Seaborne <an...@epimorphics.com>.

On 06/05/11 06:33, Holger Knublauch wrote:
> Andy,
>
> we are puzzled why the IRI built-in of SPARQL only accepts untyped literals, but not xsd:strings? I find this unnecessarily restrictive.

I have no idea other than it's what the spec says ... which begs the 
question why the spec says that especially as I wrote it.

Do you want to send a SPARQL comment about that?

(And I've changed it anyway as it's a legal extension - as is the 
handling blank nodes here but "shh" about that one!)

> Thanks
> Holger

BTW You may be interested in the RDF WG proposal that:

"""
Recommend that data publishers use plain literals instead of xs:string 
typed literals and tell systems to silently convert xs:string literals 
to plain literals without language tag.
"""

The exact form, implications and fallout on deployed code and data, of 
this are on-going (to say the least).  It's not given it will make it 
through to any spec changes.

Comments from data publishers and data consumers would be very helpful.

	Andy