Skip to content

Commit

Permalink
All tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinMendelGleason committed Mar 12, 2021
1 parent e7d6e93 commit e28b1f4
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 30 deletions.
5 changes: 3 additions & 2 deletions src/core/api/graph_dump.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@
ask(Desc,
t(doc:scipioJrs, scm:birthday, Date))
),
Date = date(-228,10,10,0,0,0,0,-,-)^^xsd:dateTime,

Date = date_time(-228,10,10,0,0,0.0)^^xsd:dateTime,

graph_dump(System_DB, Auth, Path, "turtle", Output),

re_match('-228-10-10T00:00:00', Output).
re_match('-228-10-10T00:00:00.000Z', Output).

:- end_tests(graph_dump).
51 changes: 47 additions & 4 deletions src/core/query/woql_compile.pl
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,11 @@
; is_boolean(X)
; is_duration(X)
; is_gyear_range(X)
; is_date_range(X)
; is_integer_range(X)
; is_decimal_range(X)
; is_point(X)
; is_coordinate_polygon(X)
))
},
!.
Expand Down Expand Up @@ -4933,8 +4935,8 @@
test_lit(date_time(2020,01,02,03,04,05)^^xsd:dateTime, "\"2020-01-02T03:04:05Z\"^^'http://www.w3.org/2001/XMLSchema#dateTime'").

test(byte_pos) :-
% note that the number saved is not further quoted test_lit(127^^xsd:byte, "127^^'http://www.w3.org/2001/XMLSchema#byte'").

% note that the number saved is not further quoted
test_lit(127^^xsd:byte, "127^^'http://www.w3.org/2001/XMLSchema#byte'").

test(byte_neg) :-
% note that the number saved is not further quoted
Expand Down Expand Up @@ -5013,7 +5015,48 @@
test_lit("this is an english sentence"@en, "\"this is an english sentence\"@en").

test(gyear) :-
test_lit(gyear(2100,0)^^xsd:gYear, W).
test_lit(gyear(2100,0)^^xsd:gYear, "\"2100\"^^'http://www.w3.org/2001/XMLSchema#gYear'").

:- end_tests(store_load_data).
test(gYearMonth) :-
test_lit(gyear_month(2100,3,0)^^xsd:gYearMonth, "\"2100-03\"^^'http://www.w3.org/2001/XMLSchema#gYearMonth'").

test(gMonthDay) :-
test_lit(gmonth_day(05,24,0)^^xsd:gMonthDay, "\"-05-24\"^^'http://www.w3.org/2001/XMLSchema#gMonthDay'").

test(gMonth) :-
test_lit(gmonth(05,0)^^xsd:gMonth, "\"--05\"^^'http://www.w3.org/2001/XMLSchema#gMonth'").

test(gDay) :-
test_lit(gday(24,0)^^xsd:gDay, "\"---24\"^^'http://www.w3.org/2001/XMLSchema#gDay'").

test(time) :-
test_lit(time(12,14,0)^^xsd:time, "\"12:14:00Z\"^^'http://www.w3.org/2001/XMLSchema#time'").

test(date) :-
test_lit(date(1978,6,25,0)^^xsd:date, "\"1978-06-25\"^^'http://www.w3.org/2001/XMLSchema#date'").

test(coordinate) :-
test_lit(point(1.3,34.3)^^xdd:coordinate, "\"[1.3,34.3]\"^^'http://terminusdb.com/schema/xdd#coordinate'").

test(coordinatePolygon) :-
test_lit(coordinate_polygon([[1.3,34.3],[1.3,34.3]])^^xdd:coordinatePolygon, "\"[[1.3,34.3],[1.3,34.3]]\"^^'http://terminusdb.com/schema/xdd#coordinatePolygon'").

test(coordinatePolyline) :-
test_lit(coordinate_polygon([[1.3,34.3],[1.3,34.3]])^^xdd:coordinatePolyline, "\"[[1.3,34.3],[1.3,34.3]]\"^^'http://terminusdb.com/schema/xdd#coordinatePolyline'").

test(integer_range) :-
test_lit(integer_range(1,3)^^xdd:integerRange, "\"[1,3]\"^^'http://terminusdb.com/schema/xdd#integerRange'").

test(date_range) :-
test_lit(date_range(date(2012,02,03,0),date(2012,02,03,0))^^xdd:dateRange, "\"[2012-02-03,2012-02-03]\"^^'http://terminusdb.com/schema/xdd#dateRange'").

test(gyear_range, [blocked(unimplemented)]) :-
test_lit(gyear_range(gyear(2012,0),gyear(2013,0))^^xdd:gyearRange, "\"[2012,2014]\"^^'http://terminusdb.com/schema/xdd#gyearRange'").

test(duration_year) :-
test_lit(duration(1,10,0,0,0,0,0)^^xsd:duration, "\"P10Y\"^^'http://www.w3.org/2001/XMLSchema#duration'").

test(duration_hour) :-
test_lit(duration(-1,0,0,0,1,0,0)^^xsd:duration, "\"-PT1H\"^^'http://www.w3.org/2001/XMLSchema#duration'").

:- end_tests(store_load_data).
4 changes: 2 additions & 2 deletions src/core/triple/casting.pl
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@
typecast_switch('http://terminusdb.com/schema/xdd#coordinatePolyline', 'http://www.w3.org/2001/XMLSchema#string', Val, _, Cast^^'http://terminusdb.com/schema/xdd#coordinatePolyline') :-
!,
( atom_codes(Val, Codes), phrase(xsd_parser:coordinatePolygon(S),Codes)
-> Cast = coordinate_polyline(S)
-> Cast = coordinate_polygon(S)
; throw(error(casting_error(Val,'http://terminusdb.com/schema/xdd#coordinatePolyline'),_))).
%%% xdd:coordinatePolyline => xsd:string
typecast_switch('http://www.w3.org/2001/XMLSchema#string', 'http://terminusdb.com/schema/xdd#coordinatePolyline', Val, _, S^^'http://www.w3.org/2001/XMLSchema#string') :-
!,
( is_coordinate_polygon(Val),
Val = coordinate_polyline(L)
Val = coordinate_polygon(L)
-> format(string(S), '~w', [L])
; throw(error(casting_error(Val,'http://terminusdb.com/schema/xdd#coordinatePolyline'),_))).
%%% xsd:string => xdd:coordinate
Expand Down
45 changes: 33 additions & 12 deletions src/core/triple/literals.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@
!,
% ToDo, add appropriate time zone! Doesn't work in xsd_time_string!
Date_Time = date_time(Y,M,D,HH,MM,SS),
format(string(String),
'~|~`0t~d~4+-~|~`0t~d~2+-~|~`0t~d~2+T~|~`0t~d~2+:~|~`0t~d~2+:~|~`0t~d~2+Z',
[Y,M,D,HH,MM,SS]).
( integer(SS)
-> format(string(String),
'~|~`0t~d~4+-~|~`0t~d~2+-~|~`0t~d~2+T~|~`0t~d~2+:~|~`0t~d~2+:~|~`0t~d~2+Z',
[Y,M,D,HH,MM,SS])
; S is floor(SS),
MS is floor((SS - S) / 1000),
format(string(String),
'~|~`0t~d~4+-~|~`0t~d~2+-~|~`0t~d~2+T~|~`0t~d~2+:~|~`0t~d~2+:~|~`0t~d~2+.~|~`0t~d~3+Z',
[Y,M,D,HH,MM,S,MS])
).
date_time_string(Date_Time,String) :-
% So expensive! Let's do this faster somehow.
nonvar(String),
Expand All @@ -55,9 +62,16 @@
!,
% ToDo, add appropriate time zone! Doesn't work in xsd_time_string!
Date_Time = date_time(Y,M,D,HH,MM,SS),
format(string(String),
'~|~`0t~d~4+-~|~`0t~d~2+-~|~`0t~d~2+T~|~`0t~d~2+:~|~`0t~d~2+:~|~`0t~d~2+Z',
[Y,M,D,HH,MM,SS]).
( integer(SS)
-> format(string(String),
'~|~`0t~d~4+-~|~`0t~d~2+-~|~`0t~d~2+T~|~`0t~d~2+:~|~`0t~d~2+:~|~`0t~d~2+Z',
[Y,M,D,HH,MM,SS])
; S is floor(SS),
MS is floor((SS - S) / 1000),
format(string(String),
'~|~`0t~d~4+-~|~`0t~d~2+-~|~`0t~d~2+T~|~`0t~d~2+:~|~`0t~d~2+:~|~`0t~d~2+.~|~`0t~d~3+Z',
[Y,M,D,HH,MM,S,MS])
).
date_time_stamp_string(Date_Time,String) :-
% So expensive! Let's do this faster somehow.
nonvar(String),
Expand Down Expand Up @@ -189,9 +203,16 @@
!,
% ToDo, add appropriate time zone! Doesn't work in xsd_time_string!
Time = time(HH,MM,SS),
format(string(String),
'~|~`0t~d~2+:~|~`0t~d~2+:~|~`0t~d~2+Z',
[HH,MM,SS]).
( integer(SS)
-> format(string(String),
'~|~`0t~d~2+:~|~`0t~d~2+:~|~`0t~d~2+Z',
[HH,MM,SS])
; S is floor(SS),
MS is floor((SS - S) / 1000),
format(string(String),
'~|~`0t~d~2+:~|~`0t~d~2+:~|~`0t~d~2+.~|~`0t~d~3+Z',
[HH,MM,S,MS])
).
time_string(Time,String) :-
% So expensive! Let's do this faster somehow.
nonvar(String),
Expand All @@ -216,7 +237,7 @@
( D \= 0
-> format(atom(DP),'~wD',[D])
; DP = ''),
( HH \= 0, MM \= 0, SS \= 0
( \+ (HH =:= 0, MM =:= 0, SS =:= 0)
-> TP = 'T'
; TP = ''),
( HH \= 0
Expand Down Expand Up @@ -293,8 +314,8 @@
( is_number_type(Type)
-> format(string(S), '~q^^~q', [Val,Type])
; typecast(Val^^Type, 'http://www.w3.org/2001/XMLSchema#string',
[], Cast^^_),
format(string(S), '~q^^~q', [Cast,Type])
[], Cast^^_)
-> format(string(S), '~q^^~q', [Cast,Type])
; format(string(S), '~q^^~q', [Val,Type])).
ground_object_storage(O, node(O)).

Expand Down
17 changes: 9 additions & 8 deletions src/core/util/types.pl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
**************************************************************************/
:- reexport(core(util/syntax)).
:- use_module(library(yall)).
:- use_module(library(apply)).
:- use_module(library(apply_macros)).

Expand Down Expand Up @@ -301,14 +302,14 @@
integer(Y),
integer(M), M >= 1, M =< 12,
days_in_month(Y,M,Days), D >= 1, D =< Days,
integer(Offset).
is_offset(Offset).

is_point(point(X,Y)) :-
number(X),
number(Y).

is_coordinate_polygon(coordinate_polygon(L)) :-
maplist([X,Y]>>(number(X),number(Y)),L).
maplist([[X,Y]]>>(number(X),number(Y)),L).

is_date_range(date_range(Date1,Date2)) :-
is_date(Date1),
Expand Down Expand Up @@ -372,12 +373,12 @@

is_duration(duration(Sign,Y,M,D,HH,MM,SS)) :-
member(Sign, [1,-1]),
integer(Y),
integer(M), M >= 1, M =< 12,
days_in_month(Y,M,Days), D >= 1, D =< Days,
integer(HH), HH >= 0, HH =< 24,
integer(MM), MM >= 0, MM =< 60,
number(SS), SS >= 0, HH =< 60.
number(Y),
number(M),
number(D),
number(HH),
number(MM),
number(SS).

is_byte(S) :-
integer(S),
Expand Down
5 changes: 3 additions & 2 deletions src/core/util/xsd_parser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@
twoDigitNatural(H), ":", twoDigitNatural(M), time_offset(Offset).

% Hour, Minute, Second, Offset, Zone, DST
time(H,M,S,Offset) -->
time(H,M,SS,Offset) -->
twoDigitNatural(H), ":", twoDigitNatural(M), ":", twoDigitNatural(S),
".", threeDigitNatural(_), optional_time_offset(Offset).
".", threeDigitNatural(MS), optional_time_offset(Offset),
{ SS is S + MS / 1000}.
time(H,M,S,Offset) -->
twoDigitNatural(H), ":", twoDigitNatural(M), ":", twoDigitNatural(S),
optional_time_offset(Offset) .
Expand Down

0 comments on commit e28b1f4

Please sign in to comment.