diff --git a/swipl/client.pl b/swipl/client.pl index 57ed2b3..002f63c 100644 --- a/swipl/client.pl +++ b/swipl/client.pl @@ -69,13 +69,13 @@ % build_DB_URI(+Server, +User, +DB, -DB_URI) build_DB_URI(Server, User, DB, DB_URI) :- (ends_with(Server, '/') - -> atomic_list_concat([Server, 'db/', User, '/', DB], DB_URI) - ; atomic_list_concat([Server, '/db/', User, '/', DB], DB_URI)). + -> atomic_list_concat([Server, 'api/db/', User, '/', DB], DB_URI) + ; atomic_list_concat([Server, '/api/db/', User, '/', DB], DB_URI)). % build_DB_URI2(+Server, +DB, +EndPoint, -DB_URI) build_DB_URI2(Server, DB, EndPoint, DB_URI) :- - atomic_list_concat([DB, '/', EndPoint], Path), + atomic_list_concat([DB, '/api/', EndPoint], Path), build_DB_URI(Server, Path, DB_URI). @@ -97,8 +97,8 @@ non_null('User', User), non_null('Database', DB), (ends_with(Server, '/') - -> atomic_list_concat([Server, 'woql/', User, '/', DB, '/local/branch/master'], Query_url) - ; atomic_list_concat([Server, '/woql/', User, '/', DB, '/local/branch/master'], Query_url)). + -> atomic_list_concat([Server, 'api/woql/', User, '/', DB, '/local/branch/main'], Query_url) + ; atomic_list_concat([Server, '/api/woql/', User, '/', DB, '/local/branch/main'], Query_url)). % build_graph_URL(+Server, +User, +DB, +GType, +GId, -Graph_URI) @@ -109,8 +109,8 @@ non_null('Graph type', GType), non_null('Graph ID', GId), (ends_with(Server, '/') - -> atomic_list_concat([Server, 'graph/', User, '/', DB, '/local/branch/master/schema/main'], Graph_URI) - ; atomic_list_concat([Server, '/graph/', User, '/', DB, '/local/branch/master/schema/main'], Graph_URI)). + -> atomic_list_concat([Server, 'api/graph/', User, '/', DB, '/local/branch/main/schema/main'], Graph_URI) + ; atomic_list_concat([Server, '/api/graph/', User, '/', DB, '/local/branch/main/schema/main'], Graph_URI)). @@ -209,7 +209,8 @@ (var(Result) -> true ; logging:fatal('\'connect\' requires an unbound argument..')), - dispatch(Cli, Cli.url, 'connect', {}, Result, ''), + atomic_list_concat([Cli.url, '/api'], URL), + dispatch(Cli, URL, 'connect', {}, Result, ''), extract_context(Result, C), A = Cli.ac, D = Cli.db, X = Cli.url, Y = Cli.user, Z = Cli.key. diff --git a/swipl/swoql.pl b/swipl/swoql.pl index f0ab195..40f1166 100644 --- a/swipl/swoql.pl +++ b/swipl/swoql.pl @@ -55,13 +55,13 @@ 'Class': 'owl:Class', 'DatatypeProperty': 'owl:DatatypeProperty', 'ObjectProperty': 'owl:ObjectProperty', - 'Entity': 'tcs:Entity', - 'Document': 'tcs:Document', - 'Relationship': 'tcs:Relationship', - 'temporality': 'tcs:temporality', - 'geotemporality': 'tcs:geotemporality', - 'geography': 'tcs:geography', - 'abstract': 'tcs:abstract', + 'Entity': 'system:Entity', + 'Document': 'system:Document', + 'Relationship': 'system:Relationship', + 'temporality': 'system:temporality', + 'geotemporality': 'system:geotemporality', + 'geography': 'system:geography', + 'abstract': 'system:abstract', 'comment': 'rdfs:comment', 'range': 'rdfs:range', 'domain': 'rdfs:domain', @@ -103,8 +103,8 @@ (begins_with_pattern_colon(S, rdfs); begins_with_pattern_colon(S, rdf); begins_with_pattern_colon(S, owl); - begins_with_pattern_colon(S, tcs); - begins_with_pattern_colon(S, terminus); + begins_with_pattern_colon(S, api); + begins_with_pattern_colon(S, system); begins_with_pattern_colon(S, xsd); begins_with_pattern_colon(S, xdd)). @@ -867,7 +867,7 @@ start_scope(doc, DocName, DictIn, Dict1), jsonise_scm(DocName, JDocName), do_ask(and([add_quad(JDocName, 'rdf:type', 'owl:Class', 'schema/main'), - add_quad(JDocName, 'rdfs:subClassOf', 'terminus:Document', 'schema/main')]), + add_quad(JDocName, 'rdfs:subClassOf', 'system:Document', 'schema/main')]), _, Dict1, Dict2), do_ask(Qualifier, _, Dict2, DictOut). @@ -1516,17 +1516,17 @@ -> true ; logging:fatal('\'result_success\' requires a bound argument..')), result_to_dict(Result, Dict), - (is_dict(Dict) - -> (get_dict('terminus:status', Dict, Terminus_Result) - -> (Terminus_Result == "terminus:success" %NB: have to use string quotes here, not '' - -> true - ; logging:info('\'terminus:status\' = \'~w\' in result ~w passed to \'result_success\'', [Terminus_Result, Result]), - false) - ; (get_dict('terminus:agent_key_hash', Dict, _) - -> true % Call was actually a 'connect', and the result looks valid - ; (get_dict('bindings', Dict, _) - -> logging:info('\'bindings\' received in result passed to \'result_success\': ~w', [Result]) - ; logging:info('Missing response in result passed to \'result_success\': ~w', [Result]), - false))) - ; logging:info('\'result_success\' has a non-dict result: ~w', [Result]), - false). + ( is_dict(Dict) + -> ( get_dict('api:status', Dict, Terminus_Result) + -> ( Terminus_Result == "api:success" %NB: have to use string quotes here, not '' + -> true + ; logging:info('\'api:status\' = \'~w\' in result ~w passed to \'result_success\'', [Terminus_Result, Result]), + false) + ; ( get_dict('@type', Dict, "system:User") + -> true % Call was actually a 'connect', and the result looks valid + ; ( get_dict('bindings', Dict, _) + -> logging:info('\'bindings\' received in result passed to \'result_success\': ~w', [Result]) + ; logging:info('Missing response in result passed to \'result_success\': ~w', [Result]), + false))) + ; logging:info('\'result_success\' has a non-dict result: ~w', [Result]), + false). diff --git a/swipl/test1.pl b/swipl/test1.pl index dad5d06..74c0639 100644 --- a/swipl/test1.pl +++ b/swipl/test1.pl @@ -10,41 +10,31 @@ key('root'). data_url('https://raw.githubusercontent.com/Chrisjhorn/terminusDB/master/python/jupyter-tutorials/tutorial2/people.csv'). - -check_terminus_error(Name, Key, Dict, Error, Offset) :- - get_dict(Key, Dict, ErrMsg), - string_length(Error, Len), - string_length(ErrMsg, Len1), - ((Len1 >= Len, Len > 0) - -> sub_string(ErrMsg, Offset, Len, _, XXX), - atom_string(Error,E), atom_string(XXX,X), - (E == X - -> format('- ~w got expected exception -------------------------------------------------~n', Name), - true - ; false) - ; false) -; false. - -terminus_message(Name, Dict, ErrType, ErrMsg) :- - ErrType == 'tm' - -> check_terminus_error(Name, 'terminus:message', Dict, ErrMsg, 0) - ; false. - -witness_message(Name, Arg, ErrType, ErrMsg) :- - ErrType == 'vi' - -> (is_dict(Arg) - -> (get_dict('terminus:witnesses', Arg, List) - -> [Dict2|_] = List, - is_dict(Dict2), - check_terminus_error(Name, 'vio:literal', Dict2, ErrMsg, 1) - ; false) - ; [Dict2|_] = Arg, - is_dict(Dict2), - (get_dict('vio:message', Dict2, Dict3) - -> check_terminus_error(Name, '@value', Dict3, ErrMsg, 0) - ; false)) - ; false. - +escape_pcre(String, Escaped) :- + re_replace('[-[\\]{}()*+?.,\\\\^$|#\\s]'/g, '\\\\0', String, Escaped). + +check_terminus_error_(Key, Dict, Pattern) :- + get_dict(Key, Dict, ErrMsg), + re_match(Pattern, ErrMsg). + +check_terminus_error(Name, Key, Dict, Error, 0) :- + atomic_list_concat(['^',Error,'.*'], Pattern), + check_terminus_error_(Key, Dict, Pattern), + format('- ~w got expected exception -------------------------------------------------~n', Name). + +error_message(Name, Dict, tm, ErrMsg) :- + check_terminus_error(Name, 'api:message', Dict, ErrMsg, 0). +error_message(Name, Arg, vi, ErrMsg) :- + ( is_dict(Arg) + -> get_dict('system:witnesses', Arg, List), + [Dict2|_] = List, + is_dict(Dict2), + check_terminus_error(Name, 'vio:literal', Dict2, ErrMsg, 1) + ; [Dict2|_] = Arg, + is_dict(Dict2), + get_dict('vio:message', Dict2, Dict3), + check_terminus_error(Name, '@value', Dict3, ErrMsg, 0) + ). test(Name, Client, Query, Inserts, ErrType, Error, Result) :- format('- ~w starting --------------------------------------------------------~n', Name), @@ -52,17 +42,15 @@ swoql:ask(Client, Query, Result), - (swoql:result_success(Result) - -> (swoql:result_check_statistic('inserts', Inserts, Result) - -> true - ; logging:fatal('~w failed: expected ~w inserts~n', [Name, Inserts])) - ; (swoql:result_to_dict(Result, Dict), - (terminus_message(Name, Dict, ErrType, Error) - -> true - ; (witness_message(Name, Dict, ErrType, Error) - -> true - ; format('witness_message failed...~n'), - logging:fatal('~w failed...~w', [Name, Result]))))), + ( swoql:result_success(Result) + -> ( swoql:result_check_statistic('inserts', Inserts, Result) + -> true + ; logging:fatal('~w failed: expected ~w inserts~n', [Name, Inserts])) + ; ( swoql:result_to_dict(Result, Dict), + ( error_message(Name, Dict, ErrType, Error) + -> true + ; format('witness_message failed...~n'), + logging:fatal('~w failed...~w', [Name, Result])))), format('- ~w Done ------------------------------------------------------------~n~n', Name), logging:info('- ~w Done ------------------------------------------------------~n~n', [Name]). @@ -144,10 +132,10 @@ test('Test-Q1', Client, quad('AAA', 'BBB', 'CCC', 'DDD'), 'vi', 'Unable to compile AST query'), - test('Test-AQ1', Client, add_quad('AAA', 'BBB', 'CCC', 'DDD'), 'vi', 'Unable to compile AST query'), - test('Test-AQ2', Client, add_quad('scm:PersonType', 'BBB', 'CCC', 'DDD'), 'vi', 'Unable to compile AST query'), - test('Test-AQ3', Client, add_quad('scm:PersonType', 'rdf:type', 'CCC', 'DDD'), 'vi', 'Unable to compile AST query'), - test('Test-AQ4', Client, add_quad('scm:PersonType', 'rdf:type', 'owl:Class', 'DDD'), 'vi', 'Unable to compile AST query'), + test('Test-AQ1', Client, add_quad('AAA', 'BBB', 'CCC', 'DDD'), 'tm', 'Badly formed ast after compilation with term'), + test('Test-AQ2', Client, add_quad('scm:PersonType', 'BBB', 'CCC', 'DDD'), 'tm', 'Badly formed ast after compilation with term'), + test('Test-AQ3', Client, add_quad('scm:PersonType', 'rdf:type', 'CCC', 'DDD'), 'tm', 'Badly formed ast after compilation with term'), + test('Test-AQ4', Client, add_quad('scm:PersonType', 'rdf:type', 'owl:Class', 'DDD'), 'tm', 'Badly formed ast after compilation with term'), test('Test-AQ5', Client, add_quad('scm:PersonType', 'rdf:type', 'owl:Class', 'schema/main'), 1), test('Test-And1', Client, and([triple('AAA', 'BBB', 'CCC')])), @@ -282,8 +270,8 @@ test('Test-Concat1', Client, concat('Journey from v:Start_ID to v:End_ID at v:Start_Time', 'v:Journey_Label')), - test('Test-TypeCast1', Client, cast('v:Duration', v('Duration_Cast')^^integer), 'tm', 'Error: \'Variable unbound in typcast to'), % server spelling mistake! - test('Test-TypeCast2', Client, cast(v('Duration'), v('Duration_Cast')^^'xsd:integer'), 'tm', 'Error: \'Variable unbound in typcast to'), + test('Test-TypeCast1', Client, cast('v:Duration', v('Duration_Cast')^^integer), 'tm', 'Error: \'Variable unbound in typecast'), % server spelling mistake! + test('Test-TypeCast2', Client, cast(v('Duration'), v('Duration_Cast')^^'xsd:integer'), 'tm', 'Error: \'Variable unbound in typecast to'), test('Test-Opt1', Client, opt(triple('AAA', 'BBB', 'CCC'))),