Why are you using literals to represent URIs?

 Most people would just use URIs since they are first-class citizens in the RDF 
datamodel. It seems like you are forcing yourself through unnecessary hoops

Rob

On 12/01/2017 10:15, "George News" <george.n...@gmx.net> wrote:

    BTW I think I found a bug:
    
    String b = "http://datypic.com/fraf1";;
    Literal a = (Literal) ResourceFactory.createTypedLiteral(b, 
XSDDatatype.XSDanyURI);
    System.out.println(a.getDatatype());
    System.out.println(a.getValue().getClass());
    
    a = (Literal) ResourceFactory.createTypedLiteral(URI.create(b));
    System.out.println(a.getDatatype());
    System.out.println(a.getValue().getClass());
    
    Output:
    Datatype[http://www.w3.org/2001/XMLSchema#anyURI -> class java.net.URI]
    class java.lang.String
    Datatype[http://www.w3.org/2001/XMLSchema#anyURI -> class java.net.URI]
    class java.net.URI
    
    Shouldn't both getValue() be java.net.URI? I guess this needs to be fixed 
as in both cases the DataType indicastes it's an URI, so when casting the 
String to URI the system complains ;)
    
    Regards,
    Jorge
    
    
    
    
    On 12/01/2017 10:48, George News wrote:
    > 
    > On 12/01/2017 9:58, Chris Dollin wrote:
    >>
    >>
    >> On 12/01/17 08:41, George News wrote:
    >>>
    >>>
    >>> On 11/01/2017 18:17, A. Soroka wrote:
    >>>> And I and Chris Dollin answered your question. Again,
    >>>>
    >>>> 
ResourceFactory.createTypedLiteral("http://hola^^http://www.w3.org/2001/XMSchema#anyURI";,
    >>>> XSDDatatype.XSDanyURI)
    >>>>
    >>>> Don't do a bunch of string processing.
    >>>
    >>> As I said there is no way of getting only "http://hola"; which is the
    >>> value. I don't know what I'm doing wrong but cannot get it.
    >>>
    >>> Example with all possible functions:
    >>> String b = "http://hola^^http://www.w3.org/2001/XMLSchema#anyURI";;
    >>
    >>> Literal a = (Literal) ResourceFactory.createTypedLiteral(b,
    >>> XSDDatatype.XSDanyURI);
    >>
    >> The literal's lexical form had a type in it.
    >>
    >>> System.out.println(a.getDatatype());
    >>> System.out.println(a.getLexicalForm());
    >>
    >> And so when you ask for the lexical form, the type comes out with it.
    > 
    > Fully understand it but if you check the toString() output it
    > concatenates both ;) Which from what you later explain I understand.
    > 
    >>> System.out.println(a.getDatatypeURI());
    >>> System.out.println(a.getString());
    >>> System.out.println(a.getValue());
    >>> System.out.println(a.toString());
    >>>
    >>> Output:
    >>> Datatype[http://www.w3.org/2001/XMLSchema#anyURI -> class java.net.URI]
    >>> http://datypic.com/fraf1^^http://www.w3.org/2001/XMLSchema#anyURI
    >>> http://www.w3.org/2001/XMLSchema#anyURI
    >>> http://datypic.com/fraf1^^http://www.w3.org/2001/XMLSchema#anyURI
    >>> http://datypic.com/fraf1^^http://www.w3.org/2001/XMLSchema#anyURI
    >>> 
http://datypic.com/fraf1^^http://www.w3.org/2001/XMLSchema#anyURI^^http://www.w3.org/2001/XMLSchema#anyURI
    >>>
    >>>
    >>> If I run the same code using a integer:
    >>> a =
    >>> 
ResourceFactory.createTypedLiteral("\"5\"^^http://www.w3.org/2001/XMLSchema#int";,
    >>> XSDDatatype.XSDint);
    >>>
    >>> I get an exception: org.apache.jena.datatypes.DatatypeFormatException.
    >>
    >> Because the xsd:int datatype checks the lexical form of the literal
    >> (and it looks like either xsd:anyURI doesn't, or b's value is in
    >> fact a legal URI).
    >>
    >>> I'm suggesting there should be a function like
    >>> createTypedLiteral(String literal) where
    >>> literal is a well-formatted literal. Then using the parsing from ^^
    >> internally will be
    >>> able to extract the type and somehow obtain the same outcome as the
    >> createTypedLiteral(String, Datatype) function.
    >>>
    >>> I guess that internally there should be such a function.
    >>
    >> Maybe there should be but I don't know if there is one. Code for
    >> parsing Turtle literals is probably embedded in the Turtle
    >> parser rather than being exposed, but it might be available.
    > 
    > That's what I meant ;) I finally explained myself
    > 
    >> WHat bigger problem are you trying ro solve that led you to
    >> try and construct an anyURI literal from a lexicalForm^^typeName string?
    > 
    > I'm getting this data from a Webservice and I wanted to parse it. But I
    > have just realized that maybe it is the webservice the one that should
    > be doing it by properly returning the URI. In the webservice is where
    > the model is managed.
    > 
    >>
    >> Chris
    >>
    > 
    




Reply via email to