In the following DCG, expected a set of parentheses around the last two values, but they are missing in the result; don’t know why?
:- use_module(library(dcg/basics)).
test(Evidence,Rest) :-
Input = "ECO:0000269|PubMed:24603684.",
string_codes(Input,Input_codes),
DCG = evidence_item(Evidence),
phrase(DCG,Input_codes,Rest).
evidence_item((Eco,Source)) -->
evidence_code_ontology(Eco),
evidence_source(Source),
".".
evidence_code_ontology(ECO) -->
"ECO:",
number(ECO_number),
{ ECO = (eco,ECO_number) }.
evidence_source(Source) -->
"|",
"PubMed:",
string_without(".",Source_id_codes),
{
string_codes(Source_id,Source_id_codes),
Source = (pub_med,Source_id)
}.
Result:
?- test(Evidence,Rest).
Evidence = ((eco, 269), pub_med, "24603684"),
Rest = [].
Expected Result:
?- test(Evidence,Rest).
Evidence = ((eco, 269), (pub_med, "24603684")),
Rest = [].
Notice that for the first set of parentheses
(eco, 269)
this code worked,
ECO = (eco,ECO_number)
however for the second missing set of parentheses
pub_med, "24603684"
this code did NOT work
Source = (pub_med,Source_id)
EDIT 1
Here are some test/examples using write_canonical/1 I did in trying to understand this. Also reading ISO/IEC 13211-1
?- write_canonical(((eco, 269), (pub_med, 24603684))).
','(','(eco,269),','(pub_med,24603684))
true.
?- write_canonical(((eco, 269), pub_med, 24603684)).
','(','(eco,269),','(pub_med,24603684))
true.
?- write_canonical((eco, 269)).
','(eco,269)
true.
?- write_canonical((pub_med, 24603684)).
','(pub_med,24603684)
true.
?- write_canonical({pub_med, 24603684}).
{','(pub_med,24603684)}
true.
?- write_canonical(((eco, 269), {pub_med, 24603684})).
','(','(eco,269),{','(pub_med,24603684)})
true.
EDIT 2
Checking print/1
?- print(','(','(eco,269),','(pub_med,24603684))).
(eco,269),pub_med,24603684
true.
First of all, Prolog uses minimal parenthesis, quotes and spacing when writing a term. A term