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.

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.

WHat bigger problem are you trying ro solve that led you to
try and construct an anyURI literal from a lexicalForm^^typeName string?


Chris

--
"He could not weigh up which was worse and so tried not to think about either."
                                                /The Spellgrinder's Apprentice/

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)

Reply via email to