Проект о переводе полунатурального языка в таблицы SQL.Код:
label(S) --> label_h(C), {atom_codes(A, C), string_to_atom(S, A)}, !.
label_h([C|D]) --> letter(C), letters_or_digits(D), !.
letters_or_digits([C|D]) --> letter_or_digit(C), letters_or_digits(D), !.
letters_or_digits([C]) --> letter_or_digit(C), !.
letters_or_digits([]) --> "", !.
letter(C) --> [C], {"a"=<C, C=<"z"}, !.
letter(C) --> [C], {"A"=<C, C=<"Z"}, !.
letter_or_digit(C) --> [C], {"a"=<C, C=<"z"}, !.
letter_or_digit(C) --> [C], {"A"=<C, C=<"Z"}, !.
letter_or_digit(C) --> [C], {"0"=<C, C=<"9"}, !.
table("student").
sbvr2sql --> label(Name), " is an integer.", {assert(fields(Name, "INT"))}.
sbvr2sql --> label(Name), " is a string.", {assert(fields(Name, "VARCHAR(64)"))}.
sbvr2sql(Table, Property) --> label(Table), " has ", label(Property), ".".
Вот как это работает нормально:
?- sbvr2sql("age is an integer.", []).
true
?- sbvr2sql("firstName is a string.", []).
true.
?- sbvr2sql(T, P, "student has firstName.", []).
T = "student",
P = "firstName".
?- fields(F, T).
F = "age",
T = [73, 78, 84] n
F = "firstName",
T = [86, 65, 82, 67, 72, 65, 82, 40, 54|...].
?- sbvr2sql(T, P, "student has firstName.", []), fields(P, _).
T = "student",
P = "firstName".
Но здесь это не работает:
?- table(T).
T = [115, 116, 117, 100, 101, 110, 116]. % "student"
?- sbvr2sql(T, P, "student has firstName.", []), table(T).
false.
Очевидно, это непризнать table("student")
как истину.Он распознает «студента» как метку, как показано выше.Что дает?