Jena-text starts-wth

2013-11-14 Thread hueyl16
Hi,

I am using the following query to get all concepts that start with the word 
Head. 


PREFIX text: http://jena.apache.org/text# 
PREFIX nci: http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl# 
PREFIX xsd: http://www.w3.org/2001/XMLSchema# 
PREFIX owl: http://www.w3.org/2002/07/owl# 
PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# 
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#

SELECT * 
WHERE { 
?s text:query (nci:Preferred_Name 'Head') . 
?s nci:Preferred_Name ?prefName . 
FILTER ( regex(?prefName, ^Head,  ))  
}


Is there a way of doing that in the text query itself without having to add a 
FILTER? I read that adding an asterisk Head* would work like starts-with, 
but that also matches anywhere in the string. And the regular expression start 
of string symbol ^ does not work either.

Regards,
Wolfgang


Re: Building xsd:dateTime from xsd:gYear + xsd:gMonth + xsd:gDay

2013-11-14 Thread Andy Seaborne

Hi there,

DateTimeStruct is, well, a struct. The fields are public.  You could 
write a builder to target that.  The default constructor could be made 
public.  The statics are specific patterns for the XSD date/time 
datatypes with validation.


DateTimeStruct represents the Date/time Seven-property model of XSD.  It 
can produce the string for xsd:date or xsd:dateTime but not the 
gregorial g* datatypes.


java.util.calendar is OK as a value but, in the details, unusable for 
XSD types.  Why not set DateTimeStruct fields?


javax.xml.datatype.XMLGregorianCalendar could be of use - it has getters 
and setters.


For DateTimeStruct or XMLGregorianCalendar, you can then use

createTypedLiteral(String lex, RDFDatatype dtype)

 Not all mandatory - the
 format can be , -MM, -MM-DD.

You could build the lexical form.

Andy

On 14/11/13 02:02, Martynas Jusevičius wrote:

Hey,

I have datetime components as 3 separate literals, with xsd:gYear,
xsd:gMonth, xsd:gDay respective datatypes. Not all mandatory - the
format can be , -MM, -MM-DD.

Now how do I combine those into a single xsd:dateTime Literal? A
concrete use case would be converting time:inDateTime values into
time:inXSDDateTime values:
http://www.w3.org/TR/owl-time/#calclock

I came up with the code below which seems to work but is not pretty
(and doesn't deal with time). I also looked at DateTimeStruct but
either way there seemed to be some datatype mismatch. I think it would
make more sense for DateTimeStruct to use the builder pattern instead
of static methods.

Is there a better way?

 if 
(resource.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;)))
 {
 Calendar calendar = Calendar.getInstance();
 Resource dateTimeDesc =
resource.getPropertyResourceValue(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;));

 if 
(dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)))
 {
 RDFNode object =
dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)).getObject();
 if (object.isLiteral())
 {
 Literal literal = object.asLiteral();
 calendar.set(Calendar.YEAR,
Integer.parseInt(literal.getLexicalForm()));
 }
 }
 else throw new DateTimeParseException(time:year value is 
missing);

 if 
(dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)))
 {
 RDFNode object =
dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)).getObject();
 if (object.isLiteral())
 {
 Literal literal = object.asLiteral();
 calendar.set(Calendar.MONTH,
Integer.parseInt(literal.getLexicalForm()));
 }
 }

 if 
(dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)))
 {
 RDFNode object =
dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)).getObject();
 if (object.isLiteral())
 {
 Literal literal = object.asLiteral();
 calendar.set(Calendar.DAY_OF_MONTH,
Integer.parseInt(literal.getLexicalForm()));
 }
 }

 calendar.set(Calendar.HOUR, 0);
 calendar.set(Calendar.MINUTE, 0);
 calendar.set(Calendar.SECOND, 0);
 Literal dateTime = 
resource.getModel().createTypedLiteral(calendar);
 
resource.addLiteral(ResourceFactory.createProperty(http://www.w3.org/2006/time#inXSDDateTime;),
dateTime);
 }

Martynas
graphityhq.com





Re: Jena-text starts-wth

2013-11-14 Thread Joshua TAYLOR
On Thu, Nov 14, 2013 at 7:42 AM,  huey...@aol.com wrote:

 I am using the following query to get all concepts that start with the word 
 Head.


 PREFIX text: http://jena.apache.org/text#
 PREFIX nci: http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#
 PREFIX xsd: http://www.w3.org/2001/XMLSchema#
 PREFIX owl: http://www.w3.org/2002/07/owl#
 PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
 PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#

 SELECT *
 WHERE {
 ?s text:query (nci:Preferred_Name 'Head') .
 ?s nci:Preferred_Name ?prefName .
 FILTER ( regex(?prefName, ^Head,  ))
 }


 Is there a way of doing that in the text query itself without having to add a 
 FILTER?

Maybe the Jena Lucene combination can do something without a FILTER,
but I don't know much about that, and can't help you out there.  I
would point out, though, that you can make this FILTER less expensive
by using SPARQL 1.1's STRSTARTS:

filter( strstarts( str(?prefName), Head ))




-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/


Re: Building xsd:dateTime from xsd:gYear + xsd:gMonth + xsd:gDay

2013-11-14 Thread Martynas Jusevičius
I'll try DateTimeStruct again, but that basically means I need my own
copy of the class, since I currently cannot extend it to override the
private constructor?

On Thu, Nov 14, 2013 at 2:15 PM, Andy Seaborne a...@apache.org wrote:
 Hi there,

 DateTimeStruct is, well, a struct. The fields are public.  You could write a
 builder to target that.  The default constructor could be made public.  The
 statics are specific patterns for the XSD date/time datatypes with
 validation.

 DateTimeStruct represents the Date/time Seven-property model of XSD.  It can
 produce the string for xsd:date or xsd:dateTime but not the gregorial g*
 datatypes.

 java.util.calendar is OK as a value but, in the details, unusable for XSD
 types.  Why not set DateTimeStruct fields?

 javax.xml.datatype.XMLGregorianCalendar could be of use - it has getters and
 setters.

 For DateTimeStruct or XMLGregorianCalendar, you can then use

 createTypedLiteral(String lex, RDFDatatype dtype)


 Not all mandatory - the
 format can be , -MM, -MM-DD.

 You could build the lexical form.

 Andy


 On 14/11/13 02:02, Martynas Jusevičius wrote:

 Hey,

 I have datetime components as 3 separate literals, with xsd:gYear,
 xsd:gMonth, xsd:gDay respective datatypes. Not all mandatory - the
 format can be , -MM, -MM-DD.

 Now how do I combine those into a single xsd:dateTime Literal? A
 concrete use case would be converting time:inDateTime values into
 time:inXSDDateTime values:
 http://www.w3.org/TR/owl-time/#calclock

 I came up with the code below which seems to work but is not pretty
 (and doesn't deal with time). I also looked at DateTimeStruct but
 either way there seemed to be some datatype mismatch. I think it would
 make more sense for DateTimeStruct to use the builder pattern instead
 of static methods.

 Is there a better way?

  if
 (resource.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;)))
  {
  Calendar calendar = Calendar.getInstance();
  Resource dateTimeDesc =

 resource.getPropertyResourceValue(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;));

  if
 (dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)))
  {
  RDFNode object =

 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)).getObject();
  if (object.isLiteral())
  {
  Literal literal = object.asLiteral();
  calendar.set(Calendar.YEAR,
 Integer.parseInt(literal.getLexicalForm()));
  }
  }
  else throw new DateTimeParseException(time:year value is
 missing);

  if
 (dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)))
  {
  RDFNode object =

 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)).getObject();
  if (object.isLiteral())
  {
  Literal literal = object.asLiteral();
  calendar.set(Calendar.MONTH,
 Integer.parseInt(literal.getLexicalForm()));
  }
  }

  if
 (dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)))
  {
  RDFNode object =

 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)).getObject();
  if (object.isLiteral())
  {
  Literal literal = object.asLiteral();
  calendar.set(Calendar.DAY_OF_MONTH,
 Integer.parseInt(literal.getLexicalForm()));
  }
  }

  calendar.set(Calendar.HOUR, 0);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
  Literal dateTime =
 resource.getModel().createTypedLiteral(calendar);

 resource.addLiteral(ResourceFactory.createProperty(http://www.w3.org/2006/time#inXSDDateTime;),
 dateTime);
  }

 Martynas
 graphityhq.com




Re: Building xsd:dateTime from xsd:gYear + xsd:gMonth + xsd:gDay

2013-11-14 Thread Martynas Jusevičius
OK I was probably too quick - now I realized the syntax of xsd:gMonth
and xsd:gDay is not so simple...

On Thu, Nov 14, 2013 at 4:05 PM, Martynas Jusevičius
marty...@graphity.org wrote:
 I came up with an approach that concatenates lexical values and
 doesn't need Calendar or DateTimeStruct.

 Not sure however how this aligns with the range of time:inXSDDateTime
 which is xsd:dateTime - can xsd:gYear/xsd:gMonthDay/xsd:date be
 treated as xsd:dateTime values? I guess I'll have to typecast them in
 SPARQL.

 if 
 (resource.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;)))
 {
 Literal dateTime;
 Resource dateTimeDesc =
 resource.getPropertyResourceValue(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;));

 if 
 (!dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)))
 throw new DateTimeParseException(time:year value is 
 missing);
 RDFNode yearObject =
 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)).getObject();
 if (!yearObject.isLiteral())
 throw new DateTimeParseException(time:year value is
 not a Literal);

 if 
 (dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)))
 {
 RDFNode monthObject =
 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)).getObject();
 if (!monthObject.isLiteral())
 throw new DateTimeParseException(time:month value
 is not a Literal);

 if
 (dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)))
 {
 RDFNode dayObject =
 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)).getObject();
 if (!dayObject.isLiteral())
 throw new DateTimeParseException(time:day
 value is not a Literal);

 dateTime =
 resource.getModel().createTypedLiteral(yearObject.asLiteral().getLexicalForm()
 + - +
 monthObject.asLiteral().getLexicalForm() + 
 - +
 dayObject.asLiteral().getLexicalForm(),
 XSDDatatype.XSDdate);
 }
 else
 {
 dateTime =
 resource.getModel().createTypedLiteral(yearObject.asLiteral().getLexicalForm()
 + - +
 monthObject.asLiteral().getLexicalForm(),
 XSDDatatype.XSDgMonthDay);
 }
 }
 else
 dateTime = yearObject.asLiteral();

 
 resource.addLiteral(ResourceFactory.createProperty(http://www.w3.org/2006/time#inXSDDateTime;),
 dateTime);
 }

 On Thu, Nov 14, 2013 at 3:08 PM, Martynas Jusevičius
 marty...@graphity.org wrote:
 I'll try DateTimeStruct again, but that basically means I need my own
 copy of the class, since I currently cannot extend it to override the
 private constructor?

 On Thu, Nov 14, 2013 at 2:15 PM, Andy Seaborne a...@apache.org wrote:
 Hi there,

 DateTimeStruct is, well, a struct. The fields are public.  You could write a
 builder to target that.  The default constructor could be made public.  The
 statics are specific patterns for the XSD date/time datatypes with
 validation.

 DateTimeStruct represents the Date/time Seven-property model of XSD.  It can
 produce the string for xsd:date or xsd:dateTime but not the gregorial g*
 datatypes.

 java.util.calendar is OK as a value but, in the details, unusable for XSD
 types.  Why not set DateTimeStruct fields?

 javax.xml.datatype.XMLGregorianCalendar could be of use - it has getters and
 setters.

 For DateTimeStruct or XMLGregorianCalendar, you can then use

 createTypedLiteral(String lex, RDFDatatype dtype)


 Not all mandatory - the
 format can be , -MM, -MM-DD.

 You could build the lexical form.

 Andy


 On 14/11/13 02:02, Martynas Jusevičius wrote:

 Hey,

 I have datetime components as 3 separate literals, with xsd:gYear,
 xsd:gMonth, xsd:gDay respective datatypes. Not all mandatory - the
 format can be , -MM, -MM-DD.

 Now how do I combine those into a single xsd:dateTime Literal? A
 concrete use case would be converting time:inDateTime values into
 time:inXSDDateTime values:
 http://www.w3.org/TR/owl-time/#calclock

 I came up with the code below which seems to work but is not pretty
 (and doesn't deal with time). I also looked at DateTimeStruct but
 either way there seemed to be some datatype mismatch. I think it would
 make more sense for DateTimeStruct to use the builder pattern instead
 of static methods.

 Is there a better way?

  if
 

Re: Building xsd:dateTime from xsd:gYear + xsd:gMonth + xsd:gDay

2013-11-14 Thread Andy Seaborne

On 14/11/13 16:42, Martynas Jusevičius wrote:

OK I was probably too quick - now I realized the syntax of xsd:gMonth
and xsd:gDay is not so simple...


:-)

http://www.w3.org/TR/xmlschema11-2/#dateTime for details.

The range of time:month is a non-negative integer so may be single 
digit.  That'll need normalizing and checking to use xsd: where it must 
be two digits.  Ditto time:day.  And maybe people write years as two digits.


gMonth and gDay have missing parts indicators -- and ---
but I don't see any g* here.

Andy



On Thu, Nov 14, 2013 at 4:05 PM, Martynas Jusevičius
marty...@graphity.org wrote:

I came up with an approach that concatenates lexical values and
doesn't need Calendar or DateTimeStruct.

Not sure however how this aligns with the range of time:inXSDDateTime
which is xsd:dateTime - can xsd:gYear/xsd:gMonthDay/xsd:date be
treated as xsd:dateTime values? I guess I'll have to typecast them in
SPARQL.

 if 
(resource.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;)))
 {
 Literal dateTime;
 Resource dateTimeDesc =
resource.getPropertyResourceValue(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;));

 if 
(!dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)))
 throw new DateTimeParseException(time:year value is missing);
 RDFNode yearObject =
dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)).getObject();
 if (!yearObject.isLiteral())
 throw new DateTimeParseException(time:year value is
not a Literal);

 if 
(dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)))
 {
 RDFNode monthObject =
dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)).getObject();
 if (!monthObject.isLiteral())
 throw new DateTimeParseException(time:month value
is not a Literal);

 if
(dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)))
 {
 RDFNode dayObject =
dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)).getObject();
 if (!dayObject.isLiteral())
 throw new DateTimeParseException(time:day
value is not a Literal);

 dateTime =
resource.getModel().createTypedLiteral(yearObject.asLiteral().getLexicalForm()
+ - +
 monthObject.asLiteral().getLexicalForm() + - 
+
 dayObject.asLiteral().getLexicalForm(),
 XSDDatatype.XSDdate);
 }
 else
 {
 dateTime =
resource.getModel().createTypedLiteral(yearObject.asLiteral().getLexicalForm()
+ - +
 monthObject.asLiteral().getLexicalForm(),
 XSDDatatype.XSDgMonthDay);
 }
 }
 else
 dateTime = yearObject.asLiteral();

 
resource.addLiteral(ResourceFactory.createProperty(http://www.w3.org/2006/time#inXSDDateTime;),
dateTime);
 }

On Thu, Nov 14, 2013 at 3:08 PM, Martynas Jusevičius
marty...@graphity.org wrote:

I'll try DateTimeStruct again, but that basically means I need my own
copy of the class, since I currently cannot extend it to override the
private constructor?

On Thu, Nov 14, 2013 at 2:15 PM, Andy Seaborne a...@apache.org wrote:

Hi there,

DateTimeStruct is, well, a struct. The fields are public.  You could write a
builder to target that.  The default constructor could be made public.  The
statics are specific patterns for the XSD date/time datatypes with
validation.

DateTimeStruct represents the Date/time Seven-property model of XSD.  It can
produce the string for xsd:date or xsd:dateTime but not the gregorial g*
datatypes.

java.util.calendar is OK as a value but, in the details, unusable for XSD
types.  Why not set DateTimeStruct fields?

javax.xml.datatype.XMLGregorianCalendar could be of use - it has getters and
setters.

For DateTimeStruct or XMLGregorianCalendar, you can then use

createTypedLiteral(String lex, RDFDatatype dtype)



Not all mandatory - the
format can be , -MM, -MM-DD.


You could build the lexical form.

 Andy


On 14/11/13 02:02, Martynas Jusevičius wrote:


Hey,

I have datetime components as 3 separate literals, with xsd:gYear,
xsd:gMonth, xsd:gDay respective datatypes. Not all mandatory - the
format can be , -MM, -MM-DD.

Now how do I combine those into a single xsd:dateTime Literal? A
concrete use case would be converting time:inDateTime values into
time:inXSDDateTime values:
http://www.w3.org/TR/owl-time/#calclock

I came up with 

Re: Building xsd:dateTime from xsd:gYear + xsd:gMonth + xsd:gDay

2013-11-14 Thread Martynas Jusevičius
Andy, now I'm confused. Where are you looking? I checked the RDF/XML
version of Time ontology and it says:

  owl:DatatypeProperty rdf:ID=year
rdfs:domain rdf:resource=#DateTimeDescription /
rdfs:range  rdf:resource=xsd;gYear /
  /owl:DatatypeProperty

  owl:DatatypeProperty rdf:ID=month
rdfs:domain rdf:resource=#DateTimeDescription /
rdfs:range  rdf:resource=xsd;gMonth /
  /owl:DatatypeProperty

  owl:DatatypeProperty rdf:ID=day
rdfs:domain rdf:resource=#DateTimeDescription /
rdfs:range  rdf:resource=xsd;gDay /
  /owl:DatatypeProperty

On Thu, Nov 14, 2013 at 7:10 PM, Andy Seaborne a...@apache.org wrote:
 On 14/11/13 16:42, Martynas Jusevičius wrote:

 OK I was probably too quick - now I realized the syntax of xsd:gMonth
 and xsd:gDay is not so simple...


 :-)

 http://www.w3.org/TR/xmlschema11-2/#dateTime for details.

 The range of time:month is a non-negative integer so may be single digit.
 That'll need normalizing and checking to use xsd: where it must be two
 digits.  Ditto time:day.  And maybe people write years as two digits.

 gMonth and gDay have missing parts indicators -- and ---
 but I don't see any g* here.

 Andy



 On Thu, Nov 14, 2013 at 4:05 PM, Martynas Jusevičius
 marty...@graphity.org wrote:

 I came up with an approach that concatenates lexical values and
 doesn't need Calendar or DateTimeStruct.

 Not sure however how this aligns with the range of time:inXSDDateTime
 which is xsd:dateTime - can xsd:gYear/xsd:gMonthDay/xsd:date be
 treated as xsd:dateTime values? I guess I'll have to typecast them in
 SPARQL.

  if
 (resource.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;)))
  {
  Literal dateTime;
  Resource dateTimeDesc =

 resource.getPropertyResourceValue(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;));

  if
 (!dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)))
  throw new DateTimeParseException(time:year value is
 missing);
  RDFNode yearObject =

 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)).getObject();
  if (!yearObject.isLiteral())
  throw new DateTimeParseException(time:year value is
 not a Literal);

  if
 (dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)))
  {
  RDFNode monthObject =

 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)).getObject();
  if (!monthObject.isLiteral())
  throw new DateTimeParseException(time:month value
 is not a Literal);

  if

 (dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)))
  {
  RDFNode dayObject =

 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)).getObject();
  if (!dayObject.isLiteral())
  throw new DateTimeParseException(time:day
 value is not a Literal);

  dateTime =

 resource.getModel().createTypedLiteral(yearObject.asLiteral().getLexicalForm()
 + - +
  monthObject.asLiteral().getLexicalForm()
 + - +
  dayObject.asLiteral().getLexicalForm(),
  XSDDatatype.XSDdate);
  }
  else
  {
  dateTime =

 resource.getModel().createTypedLiteral(yearObject.asLiteral().getLexicalForm()
 + - +

 monthObject.asLiteral().getLexicalForm(),
  XSDDatatype.XSDgMonthDay);
  }
  }
  else
  dateTime = yearObject.asLiteral();


 resource.addLiteral(ResourceFactory.createProperty(http://www.w3.org/2006/time#inXSDDateTime;),
 dateTime);
  }

 On Thu, Nov 14, 2013 at 3:08 PM, Martynas Jusevičius
 marty...@graphity.org wrote:

 I'll try DateTimeStruct again, but that basically means I need my own
 copy of the class, since I currently cannot extend it to override the
 private constructor?

 On Thu, Nov 14, 2013 at 2:15 PM, Andy Seaborne a...@apache.org wrote:

 Hi there,

 DateTimeStruct is, well, a struct. The fields are public.  You could
 write a
 builder to target that.  The default constructor could be made public.
 The
 statics are specific patterns for the XSD date/time datatypes with
 validation.

 DateTimeStruct represents the Date/time Seven-property model of XSD.
 It can
 produce the string for xsd:date or xsd:dateTime but not the gregorial
 g*
 datatypes.

 java.util.calendar is OK as a value but, in the details, unusable for
 XSD
 types.  Why not set DateTimeStruct fields?

 javax.xml.datatype.XMLGregorianCalendar could be of use - it has
 getters and
 

Re: Building xsd:dateTime from xsd:gYear + xsd:gMonth + xsd:gDay

2013-11-14 Thread Martynas Jusevičius
BTW, there seems to be a related question on StackOverflow:
http://answers.semanticweb.com/questions/610/ordering-by-time-in-sparql-query

I might just give up building an xsd:dateTime and use separate
year/month/day components.

On Thu, Nov 14, 2013 at 7:26 PM, Martynas Jusevičius
marty...@graphity.org wrote:
 Andy, now I'm confused. Where are you looking? I checked the RDF/XML
 version of Time ontology and it says:

   owl:DatatypeProperty rdf:ID=year
 rdfs:domain rdf:resource=#DateTimeDescription /
 rdfs:range  rdf:resource=xsd;gYear /
   /owl:DatatypeProperty

   owl:DatatypeProperty rdf:ID=month
 rdfs:domain rdf:resource=#DateTimeDescription /
 rdfs:range  rdf:resource=xsd;gMonth /
   /owl:DatatypeProperty

   owl:DatatypeProperty rdf:ID=day
 rdfs:domain rdf:resource=#DateTimeDescription /
 rdfs:range  rdf:resource=xsd;gDay /
   /owl:DatatypeProperty

 On Thu, Nov 14, 2013 at 7:10 PM, Andy Seaborne a...@apache.org wrote:
 On 14/11/13 16:42, Martynas Jusevičius wrote:

 OK I was probably too quick - now I realized the syntax of xsd:gMonth
 and xsd:gDay is not so simple...


 :-)

 http://www.w3.org/TR/xmlschema11-2/#dateTime for details.

 The range of time:month is a non-negative integer so may be single digit.
 That'll need normalizing and checking to use xsd: where it must be two
 digits.  Ditto time:day.  And maybe people write years as two digits.

 gMonth and gDay have missing parts indicators -- and ---
 but I don't see any g* here.

 Andy



 On Thu, Nov 14, 2013 at 4:05 PM, Martynas Jusevičius
 marty...@graphity.org wrote:

 I came up with an approach that concatenates lexical values and
 doesn't need Calendar or DateTimeStruct.

 Not sure however how this aligns with the range of time:inXSDDateTime
 which is xsd:dateTime - can xsd:gYear/xsd:gMonthDay/xsd:date be
 treated as xsd:dateTime values? I guess I'll have to typecast them in
 SPARQL.

  if
 (resource.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;)))
  {
  Literal dateTime;
  Resource dateTimeDesc =

 resource.getPropertyResourceValue(ResourceFactory.createProperty(http://www.w3.org/2006/time#inDateTime;));

  if
 (!dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)))
  throw new DateTimeParseException(time:year value is
 missing);
  RDFNode yearObject =

 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#year;)).getObject();
  if (!yearObject.isLiteral())
  throw new DateTimeParseException(time:year value is
 not a Literal);

  if
 (dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)))
  {
  RDFNode monthObject =

 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#month;)).getObject();
  if (!monthObject.isLiteral())
  throw new DateTimeParseException(time:month value
 is not a Literal);

  if

 (dateTimeDesc.hasProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)))
  {
  RDFNode dayObject =

 dateTimeDesc.getProperty(ResourceFactory.createProperty(http://www.w3.org/2006/time#day;)).getObject();
  if (!dayObject.isLiteral())
  throw new DateTimeParseException(time:day
 value is not a Literal);

  dateTime =

 resource.getModel().createTypedLiteral(yearObject.asLiteral().getLexicalForm()
 + - +
  monthObject.asLiteral().getLexicalForm()
 + - +
  dayObject.asLiteral().getLexicalForm(),
  XSDDatatype.XSDdate);
  }
  else
  {
  dateTime =

 resource.getModel().createTypedLiteral(yearObject.asLiteral().getLexicalForm()
 + - +

 monthObject.asLiteral().getLexicalForm(),
  XSDDatatype.XSDgMonthDay);
  }
  }
  else
  dateTime = yearObject.asLiteral();


 resource.addLiteral(ResourceFactory.createProperty(http://www.w3.org/2006/time#inXSDDateTime;),
 dateTime);
  }

 On Thu, Nov 14, 2013 at 3:08 PM, Martynas Jusevičius
 marty...@graphity.org wrote:

 I'll try DateTimeStruct again, but that basically means I need my own
 copy of the class, since I currently cannot extend it to override the
 private constructor?

 On Thu, Nov 14, 2013 at 2:15 PM, Andy Seaborne a...@apache.org wrote:

 Hi there,

 DateTimeStruct is, well, a struct. The fields are public.  You could
 write a
 builder to target that.  The default constructor could be made public.
 The
 statics are specific patterns for the XSD date/time datatypes with
 validation.

 DateTimeStruct represents the Date/time 

Re: Building xsd:dateTime from xsd:gYear + xsd:gMonth + xsd:gDay

2013-11-14 Thread Andy Seaborne

On 14/11/13 18:29, Martynas Jusevičius wrote:

BTW, there seems to be a related question on StackOverflow:
http://answers.semanticweb.com/questions/610/ordering-by-time-in-sparql-query

I might just give up building an xsd:dateTime and use separate
year/month/day components.

On Thu, Nov 14, 2013 at 7:26 PM, Martynas Jusevičius
marty...@graphity.org wrote:

Andy, now I'm confused. Where are you looking?


My mistake - I just grepped for month and didn't look carefully enough.

gMonth and friends are OK to parse, albeit a syntax that people don't 
engage with.  But my experience all date/times formats suffer from bad 
data if not machine generated, whether xsd, RFC or whatever.



I checked the RDF/XML
version of Time ontology and it says:

   owl:DatatypeProperty rdf:ID=year
 rdfs:domain rdf:resource=#DateTimeDescription /
 rdfs:range  rdf:resource=xsd;gYear /
   /owl:DatatypeProperty

   owl:DatatypeProperty rdf:ID=month
 rdfs:domain rdf:resource=#DateTimeDescription /
 rdfs:range  rdf:resource=xsd;gMonth /
   /owl:DatatypeProperty

   owl:DatatypeProperty rdf:ID=day
 rdfs:domain rdf:resource=#DateTimeDescription /
 rdfs:range  rdf:resource=xsd;gDay /
   /owl:DatatypeProperty





Re: Jena-text starts-wth

2013-11-14 Thread Andy Seaborne
See the links to the syntax of Lucene query strings -- if that works for 
you, you can use it.


Even so, if you need to both use text:query and a FILTER, then it's 
probably faster because there are less triples to consider.


Andy

PS It helps to start a new thread, not reply to an existing one, when 
the topic is different.


On 14/11/13 15:40, huey...@aol.com wrote:

Hi Andy,

I tried Head* but it does not work like starts-with.

Head* matches DICOM Header Tag, which just Head does not. So that behaves 
as expected.

But it still does not solve my starts-with problem since DICOM Header Tag was returned as part 
of the results in the first place. I only want matches like Head Carcinoma, Head Injury etc.

I checked out the two links you sent before posting this question. The tutorial 
mentions starts-with using the asterisk, but it matches any word in the text 
that starts-with the search string which is not what I am looking for.

How do I tell the text query that it should only look for matches at the start of the 
string? (like ^ in regex or strstarts).

-Wolfgang

-Original Message-

From: Andy Seaborne a...@apache.org
To: users users@jena.apache.org
Sent: Thu, Nov 14, 2013 3:44 pm
Subject: Re: Jena-text starts-wth


On 14/11/13 14:04, Joshua TAYLOR wrote:

On Thu, Nov 14, 2013 at 7:42 AM,  huey...@aol.com wrote:


I am using the following query to get all concepts that start with the word

Head.



PREFIX text: http://jena.apache.org/text#
PREFIX nci: http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
PREFIX owl: http://www.w3.org/2002/07/owl#
PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#

SELECT *
WHERE {
?s text:query (nci:Preferred_Name 'Head') .
?s nci:Preferred_Name ?prefName .
FILTER ( regex(?prefName, ^Head,  ))
}


Is there a way of doing that in the text query itself without having to add a

FILTER?


Maybe the Jena Lucene combination can do something without a FILTER,
but I don't know much about that, and can't help you out there.  I
would point out, though, that you can make this FILTER less expensive
by using SPARQL 1.1's STRSTARTS:

  filter( strstarts( str(?prefName), Head ))






You can use the full Lucene query syntax:

 ?s text:query (nci:Preferred_Name 'Head*') .

http://www.lucenetutorial.com/lucene-query-syntax.html
http://lucene.apache.org/core/4_3_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html

on the default field.

Andy










Re: Building xsd:dateTime from xsd:gYear + xsd:gMonth + xsd:gDay

2013-11-14 Thread Martynas Jusevičius
OK. One more question - most of the examples I was looking at (like
the one from StackOverflow) use simple integer values like
11^^xsd:gMonth, and not the --11^^xsd:gMonth syntax. But strictly
speaking, these are illegal values?

On Thu, Nov 14, 2013 at 9:11 PM, Andy Seaborne a...@apache.org wrote:
 On 14/11/13 18:29, Martynas Jusevičius wrote:

 BTW, there seems to be a related question on StackOverflow:

 http://answers.semanticweb.com/questions/610/ordering-by-time-in-sparql-query

 I might just give up building an xsd:dateTime and use separate
 year/month/day components.

 On Thu, Nov 14, 2013 at 7:26 PM, Martynas Jusevičius
 marty...@graphity.org wrote:

 Andy, now I'm confused. Where are you looking?


 My mistake - I just grepped for month and didn't look carefully enough.

 gMonth and friends are OK to parse, albeit a syntax that people don't engage
 with.  But my experience all date/times formats suffer from bad data if not
 machine generated, whether xsd, RFC or whatever.


 I checked the RDF/XML
 version of Time ontology and it says:

owl:DatatypeProperty rdf:ID=year
  rdfs:domain rdf:resource=#DateTimeDescription /
  rdfs:range  rdf:resource=xsd;gYear /
/owl:DatatypeProperty

owl:DatatypeProperty rdf:ID=month
  rdfs:domain rdf:resource=#DateTimeDescription /
  rdfs:range  rdf:resource=xsd;gMonth /
/owl:DatatypeProperty

owl:DatatypeProperty rdf:ID=day
  rdfs:domain rdf:resource=#DateTimeDescription /
  rdfs:range  rdf:resource=xsd;gDay /
/owl:DatatypeProperty




Re: Building xsd:dateTime from xsd:gYear + xsd:gMonth + xsd:gDay

2013-11-14 Thread Andy Seaborne

On 14/11/13 20:28, Martynas Jusevičius wrote:

OK. One more question - most of the examples I was looking at (like
the one from StackOverflow) use simple integer values like
11^^xsd:gMonth, and not the --11^^xsd:gMonth syntax. But strictly
speaking, these are illegal values?


Yes - strictly illegal.

Andy



On Thu, Nov 14, 2013 at 9:11 PM, Andy Seaborne a...@apache.org wrote:

On 14/11/13 18:29, Martynas Jusevičius wrote:


BTW, there seems to be a related question on StackOverflow:

http://answers.semanticweb.com/questions/610/ordering-by-time-in-sparql-query

I might just give up building an xsd:dateTime and use separate
year/month/day components.

On Thu, Nov 14, 2013 at 7:26 PM, Martynas Jusevičius
marty...@graphity.org wrote:


Andy, now I'm confused. Where are you looking?



My mistake - I just grepped for month and didn't look carefully enough.

gMonth and friends are OK to parse, albeit a syntax that people don't engage
with.  But my experience all date/times formats suffer from bad data if not
machine generated, whether xsd, RFC or whatever.



I checked the RDF/XML
version of Time ontology and it says:

owl:DatatypeProperty rdf:ID=year
  rdfs:domain rdf:resource=#DateTimeDescription /
  rdfs:range  rdf:resource=xsd;gYear /
/owl:DatatypeProperty

owl:DatatypeProperty rdf:ID=month
  rdfs:domain rdf:resource=#DateTimeDescription /
  rdfs:range  rdf:resource=xsd;gMonth /
/owl:DatatypeProperty

owl:DatatypeProperty rdf:ID=day
  rdfs:domain rdf:resource=#DateTimeDescription /
  rdfs:range  rdf:resource=xsd;gDay /
/owl:DatatypeProperty







convert Node to Expr

2013-11-14 Thread Tim Harsch
Is there a way to convert from com.hp.hpl.jena.graph.Node
to

com.hp.hpl.jena.sparql.expr.Expr
?

Thanks,
Tim