On streaming mechanism, I find it rather bold that when the DTD generator sees PQR, it assumes (P|Q|R)* right away and forgets about PQR (as it needs to conserve memory), then hoping in future to find RQP, PRQ, RPQ, QPR & QRP. In the instance under discussion, the DTD generator finds RQP and happily lives with the decision of (P|Q|R)* ever after. Can't say it is right or wrong as it is a means of helping the user identify potential pattern, which might just be the right pattern after all. Still, I find it rather bold... You're overlooking the question of how users design
schemas. If you find two or three instances containing the same elements in
different orderings, then there's a very good chance that the user intention was
to allow the elements to appear in any order. We're not just trying to detect
the pattern in the sense of a regular expression, we're trying to detect the
user design pattern.
If there are six child elements, with 720 possible
orderings, and you find that 187 of those orderings are actually used in a
particular document, then a schema that allows precisely those 187 orderings and
no others would be the last thing the user wants from the tool. It's all an
exercise in extrapolation.
What the Saxon DTDGenerator does is to gradually refine its
pattern. For example, given a sequence of instances
PQR, PQQR, PR, PRR, QRP, QPRS
its sequence of best guesses will be
PQR, PQ+R, PQ*R, PQ*R+, (P|Q|R)*,
(P|Q|R|S)*
Now, you could argue that (P|Q|R)*S is a "better" pattern,
but I would say that it's excessively bold to assume that because the only
appearance of S in your sample is at the end, that every appearance will be at
the end.
Michael Kay
|