Re: Literal string to appropriate object

2017-01-12 Thread Claude Warren
You might look at how PA4RDF handled the problem.
https://github.com/Claudenw/PA4RDF

in
https://github.com/Claudenw/PA4RDF/blob/master/src/main/java/org/xenei/jena/entities/impl/PredicateInfoImpl.java
the method getHandler() has code that determines what the return type is
for a literal.  The LiteralHandler then performs the task of converting the
RDFNode into the type specified by the literal.

The PA4RDF code has the advantage of knowing what datatype is expected as
the return from the getter method and will use that if the RDFNode is not a
literal, or does not have a datatype. (naked string).

Claude

On Thu, Jan 12, 2017 at 11:09 AM, George News  wrote:

> On 12/01/2017 11:31, Dave Reynolds wrote:
> >
> > On 12/01/17 10:15, George News 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 ;)
> >
> > Up till now we've never included a mapping from xsd:anyURI to
> > java.net.URI in the type mapping table. I seem to recall that was
> > originally because of some doubt as to whether, if there was a mapping,
> > it should use java.net.URI or the IRI machinery built into jena and
> > partly because the rest Jena uses strings so much for URI references.
> >
> > I think you could register such a mapping yourself in your application.
> >
> > Whether that should be added as a default I'm not sure.
>
> I got your point, but the problem is that is confusing when you are
> trying to automate the code. If getValue() returns an String but
> datatype is saying it is an URI then you have a reflection problem.
>
> I just wanted to pointed this out. I'm newbie and not maintainer of the
> code. I accept the internal decisions of people that knows much more
> than I do for sure.
>
> Thanks a lot for the help you all have provided
> Jorge
>



-- 
I like: Like Like - The likeliest place on the web

LinkedIn: http://www.linkedin.com/in/claudewarren


Re: Literal string to appropriate object

2017-01-12 Thread George News
On 12/01/2017 11:31, Dave Reynolds wrote:
> 
> On 12/01/17 10:15, George News 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 ;)
> 
> Up till now we've never included a mapping from xsd:anyURI to
> java.net.URI in the type mapping table. I seem to recall that was
> originally because of some doubt as to whether, if there was a mapping,
> it should use java.net.URI or the IRI machinery built into jena and
> partly because the rest Jena uses strings so much for URI references.
> 
> I think you could register such a mapping yourself in your application.
> 
> Whether that should be added as a default I'm not sure.

I got your point, but the problem is that is confusing when you are
trying to automate the code. If getValue() returns an String but
datatype is saying it is an URI then you have a reflection problem.

I just wanted to pointed this out. I'm newbie and not maintainer of the
code. I accept the internal decisions of people that knows much more
than I do for sure.

Thanks a lot for the help you all have provided
Jorge


Re: Literal string to appropriate object

2017-01-12 Thread George News


On 12/01/2017 11:33, Rob Vesse wrote:
> 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

It's representing an endpoint to access a value in a webservice, i.e.
http://domain.com/customer/value or to modify the status of a particular
element http://domain.com/item/switch/on

Thanks.


> Rob
> 
> On 12/01/2017 10:15, "George News"  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 

Re: Literal string to appropriate object

2017-01-12 Thread Rob Vesse
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"  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
>>
> 







Re: Literal string to appropriate object

2017-01-12 Thread Dave Reynolds


On 12/01/17 10:15, George News 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 ;)


Up till now we've never included a mapping from xsd:anyURI to 
java.net.URI in the type mapping table. I seem to recall that was 
originally because of some doubt as to whether, if there was a mapping, 
it should use java.net.URI or the IRI machinery built into jena and 
partly because the rest Jena uses strings so much for URI references.


I think you could register such a mapping yourself in your application.

Whether that should be added as a default I'm not sure.

Dave


Re: Literal string to appropriate object

2017-01-12 Thread George News
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
>>
> 


Re: Literal string to appropriate object

2017-01-12 Thread George News

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
> 


Re: Literal string to appropriate object

2017-01-12 Thread Lorenz B.
Exactly, first argument is the value, second one declares the datatype -
here XSDDatatype.XSDanyURI, see the Javadoc [1]

[1]
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/ResourceFactory.html#createTypedLiteral-java.lang.String-org.apache.jena.datatypes.RDFDatatype-

> 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)
>
> That should be:
>
> ResourceFactory.createTypedLiteral("http://hola;, XSDDatatype.XSDanyURI)
>
> Dave
>
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center



Re: Literal string to appropriate object

2017-01-12 Thread Dave Reynolds

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)


That should be:

ResourceFactory.createTypedLiteral("http://hola;, XSDDatatype.XSDanyURI)

Dave


Re: Literal string to appropriate object

2017-01-12 Thread Chris Dollin



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)


Re: Literal string to appropriate object

2017-01-12 Thread George News


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);
System.out.println(a.getDatatype());
System.out.println(a.getLexicalForm());
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.

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.

Thanks a lot for your help and understanding.

See you
Jorge






> 
> ---
> A. Soroka
> The University of Virginia Library
> 
>> On Jan 11, 2017, at 12:11 PM, George News  wrote:
>>
>>
>>
>> On 11/01/2017 17:18, A. Soroka wrote:
>>> You do know the type: http://www.w3.org/2001/XMSchema#anyURI
>>>
>>> It is clearly written in your example.
>>
>> I know. What I wanted is to know if there is a utility in Jena that
>> parses the string, like the example function I posted.
>>
>> Thanks for your help.
>>
>>> ---
>>> A. Soroka
>>> The University of Virginia Library
>>>
 On Jan 11, 2017, at 10:25 AM, George News  wrote:

 On 11/01/2017 15:59, A. Soroka wrote:
> Perhaps parse it as a Jena Literal (e.g. using 
> ResourceFactory.createTypedLiteral() ), then use Literal.getString() to 
> get the value you seek.

 then I need to know the type. The issue is that I wanted to know if
 there is any Jena function that directly parses the literal in the
 Turtle (or any other) form and get the object type.

> ---
> A. Soroka
> The University of Virginia Library
>
>> On Jan 11, 2017, at 9:55 AM, George News  wrote:
>>
>> Hi,
>>
>> I have this literal:
>> http://hola^^http://www.w3.org/2001/XMSchema#anyURI
>>
>> And I want to create a URI from it. Is there any way to do so?
>>
>> I have tried
>> URI z = (URI) XSDDatatype.XSDanyURI.parseValidated(literalString);
>>
>> but I get:
>> java.lang.ClassCastException: java.lang.String cannot be cast to
>> java.net.URI
>>
>> I don't know if I should take the shortcut, that is, remove everything
>> after ^^ using substring, and then URI.create(shortenedLiteralString).
>>
>> Any help is welcome.
>> Jorge
>
>
>>>
>>>
> 
> 


Re: Literal string to appropriate object

2017-01-11 Thread A. Soroka
You do know the type: http://www.w3.org/2001/XMSchema#anyURI

It is clearly written in your example.

---
A. Soroka
The University of Virginia Library

> On Jan 11, 2017, at 10:25 AM, George News  wrote:
> 
> On 11/01/2017 15:59, A. Soroka wrote:
>> Perhaps parse it as a Jena Literal (e.g. using 
>> ResourceFactory.createTypedLiteral() ), then use Literal.getString() to get 
>> the value you seek.
> 
> then I need to know the type. The issue is that I wanted to know if
> there is any Jena function that directly parses the literal in the
> Turtle (or any other) form and get the object type.
> 
>> ---
>> A. Soroka
>> The University of Virginia Library
>> 
>>> On Jan 11, 2017, at 9:55 AM, George News  wrote:
>>> 
>>> Hi,
>>> 
>>> I have this literal:
>>> http://hola^^http://www.w3.org/2001/XMSchema#anyURI
>>> 
>>> And I want to create a URI from it. Is there any way to do so?
>>> 
>>> I have tried
>>> URI z = (URI) XSDDatatype.XSDanyURI.parseValidated(literalString);
>>> 
>>> but I get:
>>> java.lang.ClassCastException: java.lang.String cannot be cast to
>>> java.net.URI
>>> 
>>> I don't know if I should take the shortcut, that is, remove everything
>>> after ^^ using substring, and then URI.create(shortenedLiteralString).
>>> 
>>> Any help is welcome.
>>> Jorge
>> 
>> 



Re: Literal string to appropriate object

2017-01-11 Thread Chris Dollin



On 11/01/17 15:42, George News wrote:


Literal a = (Literal)
ResourceFactory.createTypedLiteral("http://hola^^http://www.w3.org/2001/XMSchema#anyURI;,
XSDDatatype.XSDanyURI);
System.out.println(a.getDatatype());
System.out.println(a.getLexicalForm());
System.out.println(a.getDatatypeURI());
System.out.println(a.getString());

Output:
Datatype[http://www.w3.org/2001/XMLSchema#anyURI -> class java.net.URI]
http://hola^^http://www.w3.org/2001/XMSchema#anyURI
http://www.w3.org/2001/XMLSchema#anyURI
http://hola^^http://www.w3.org/2001/XMSchema#anyURI


None of them returns "http://hola; which is the actual URI.


ResourceFactory.createTypedLiteral doesn't do what you think it does.

You've given it a String and so it creates a typed literal of type
xsd:string since that's the xsd datatype Jena takes as being "the"
datatype for strings.

So all of the ^^http gubbins is just part of the string value
you passed in and, naturally, that's what you get out when
you use getLexicalForm.

Don't do that.

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)


Re: Literal string to appropriate object

2017-01-11 Thread George News
At the end I decide to take a shortcut that also might help explain what
I want:

|private URI rdfLiteralToUri(String literal) { int xsdIndex =
literal.lastIndexOf("^^"); if (xsdIndex == -1) { throw new
IllegalArgumentException("Not valid literal format"); } String uriStr =
literal.substring(0, xsdIndex); String type = literal.substring(xsdIndex
+ 2, literal.length()); if
(!XSDDatatype.XSDanyURI.getURI().equals(type)) { throw new
IllegalArgumentException("Not valid literal type"); } return
URI.create(uriStr); } |

On 11/01/2017 16:42, George News wrote:

> On 11/01/2017 16:25, Chris Dollin wrote:
>> On 11/01/17 14:55, George News wrote:
>>> Hi,
>>>
>>> I have this literal:
>>> http://hola^^http://www.w3.org/2001/XMSchema#anyURI
>> What do you mean by "have"? A String value, a Literal
>> value, or what?
> I want to get http://hola as a String or as a URI. Better as a URI, but
> only if it is conforming with the type linked.
>
>
>>> And I want to create a URI from it. Is there any way to do so?
>> And do you want an actual URI object or just its spelling?
>>
>> Because you can get the spelling of the URI using getLexicalForm.
> Literal a = (Literal)
> ResourceFactory.createTypedLiteral("http://hola^^http://www.w3.org/2001/XMSchema#anyURI;,
> XSDDatatype.XSDanyURI);
> System.out.println(a.getDatatype());
> System.out.println(a.getLexicalForm());
> System.out.println(a.getDatatypeURI());
> System.out.println(a.getString());
>
> Output:
> Datatype[http://www.w3.org/2001/XMLSchema#anyURI -> class java.net.URI]
> http://hola^^http://www.w3.org/2001/XMSchema#anyURI
> http://www.w3.org/2001/XMLSchema#anyURI
> http://hola^^http://www.w3.org/2001/XMSchema#anyURI
>
>
> None of them returns "http://hola; which is the actual URI.
>
>> Chris
>>
​


Re: Literal string to appropriate object

2017-01-11 Thread George News

On 11/01/2017 16:25, Chris Dollin wrote:
> 
> 
> On 11/01/17 14:55, George News wrote:
>> Hi,
>>
>> I have this literal:
>> http://hola^^http://www.w3.org/2001/XMSchema#anyURI
> 
> What do you mean by "have"? A String value, a Literal
> value, or what?

I want to get http://hola as a String or as a URI. Better as a URI, but
only if it is conforming with the type linked.


>> And I want to create a URI from it. Is there any way to do so?
> 
> And do you want an actual URI object or just its spelling?
> 
> Because you can get the spelling of the URI using getLexicalForm.

Literal a = (Literal)
ResourceFactory.createTypedLiteral("http://hola^^http://www.w3.org/2001/XMSchema#anyURI;,
XSDDatatype.XSDanyURI);
System.out.println(a.getDatatype());
System.out.println(a.getLexicalForm());
System.out.println(a.getDatatypeURI());
System.out.println(a.getString());

Output:
Datatype[http://www.w3.org/2001/XMLSchema#anyURI -> class java.net.URI]
http://hola^^http://www.w3.org/2001/XMSchema#anyURI
http://www.w3.org/2001/XMLSchema#anyURI
http://hola^^http://www.w3.org/2001/XMSchema#anyURI


None of them returns "http://hola; which is the actual URI.

> Chris
> 


Re: Literal string to appropriate object

2017-01-11 Thread Chris Dollin



On 11/01/17 14:55, George News wrote:

Hi,

I have this literal:
http://hola^^http://www.w3.org/2001/XMSchema#anyURI


What do you mean by "have"? A String value, a Literal
value, or what?


And I want to create a URI from it. Is there any way to do so?


And do you want an actual URI object or just its spelling?

Because you can get the spelling of the URI using getLexicalForm.

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)


Re: Literal string to appropriate object

2017-01-11 Thread George News
On 11/01/2017 15:59, A. Soroka wrote:
> Perhaps parse it as a Jena Literal (e.g. using 
> ResourceFactory.createTypedLiteral() ), then use Literal.getString() to get 
> the value you seek.

then I need to know the type. The issue is that I wanted to know if
there is any Jena function that directly parses the literal in the
Turtle (or any other) form and get the object type.

> ---
> A. Soroka
> The University of Virginia Library
> 
>> On Jan 11, 2017, at 9:55 AM, George News  wrote:
>>
>> Hi,
>>
>> I have this literal:
>> http://hola^^http://www.w3.org/2001/XMSchema#anyURI
>>
>> And I want to create a URI from it. Is there any way to do so?
>>
>> I have tried
>> URI z = (URI) XSDDatatype.XSDanyURI.parseValidated(literalString);
>>
>> but I get:
>> java.lang.ClassCastException: java.lang.String cannot be cast to
>> java.net.URI
>>
>> I don't know if I should take the shortcut, that is, remove everything
>> after ^^ using substring, and then URI.create(shortenedLiteralString).
>>
>> Any help is welcome.
>> Jorge
> 
> 


Re: Literal string to appropriate object

2017-01-11 Thread A. Soroka
Perhaps parse it as a Jena Literal (e.g. using 
ResourceFactory.createTypedLiteral() ), then use Literal.getString() to get the 
value you seek.

---
A. Soroka
The University of Virginia Library

> On Jan 11, 2017, at 9:55 AM, George News  wrote:
> 
> Hi,
> 
> I have this literal:
> http://hola^^http://www.w3.org/2001/XMSchema#anyURI
> 
> And I want to create a URI from it. Is there any way to do so?
> 
> I have tried
> URI z = (URI) XSDDatatype.XSDanyURI.parseValidated(literalString);
> 
> but I get:
> java.lang.ClassCastException: java.lang.String cannot be cast to
> java.net.URI
> 
> I don't know if I should take the shortcut, that is, remove everything
> after ^^ using substring, and then URI.create(shortenedLiteralString).
> 
> Any help is welcome.
> Jorge