flora-commits Mailing List for Flora-2
Brought to you by:
kifer
You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(59) |
Jun
(43) |
Jul
(4) |
Aug
(4) |
Sep
(102) |
Oct
(20) |
Nov
(47) |
Dec
(32) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(24) |
Feb
(34) |
Mar
(72) |
Apr
(36) |
May
(10) |
Jun
(46) |
Jul
(36) |
Aug
(24) |
Sep
(37) |
Oct
(27) |
Nov
(43) |
Dec
(40) |
| 2004 |
Jan
(35) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(30) |
Aug
(83) |
Sep
(68) |
Oct
(38) |
Nov
(3) |
Dec
(7) |
| 2005 |
Jan
(9) |
Feb
(31) |
Mar
(46) |
Apr
(73) |
May
(21) |
Jun
(1) |
Jul
(32) |
Aug
(33) |
Sep
(3) |
Oct
(28) |
Nov
(4) |
Dec
(23) |
| 2006 |
Jan
(22) |
Feb
(2) |
Mar
(12) |
Apr
(23) |
May
(73) |
Jun
(14) |
Jul
|
Aug
(20) |
Sep
(14) |
Oct
(5) |
Nov
|
Dec
(14) |
| 2007 |
Jan
(54) |
Feb
(81) |
Mar
(286) |
Apr
(313) |
May
(154) |
Jun
(85) |
Jul
(8) |
Aug
(11) |
Sep
(12) |
Oct
(14) |
Nov
(6) |
Dec
(6) |
| 2008 |
Jan
|
Feb
|
Mar
(1) |
Apr
(12) |
May
(4) |
Jun
|
Jul
(13) |
Aug
(22) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(46) |
Jun
(43) |
Jul
(46) |
Aug
(9) |
Sep
(13) |
Oct
(31) |
Nov
(42) |
Dec
(18) |
| 2014 |
Jan
(7) |
Feb
(7) |
Mar
(11) |
Apr
(13) |
May
(16) |
Jun
(6) |
Jul
(17) |
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
|
| 2015 |
Jan
|
Feb
(17) |
Mar
(4) |
Apr
(3) |
May
(2) |
Jun
(3) |
Jul
(2) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
1
(5) |
2
|
3
|
4
|
5
|
6
|
7
|
|
8
|
9
|
10
|
11
|
12
|
13
|
14
|
|
15
|
16
|
17
|
18
|
19
|
20
|
21
|
|
22
|
23
|
24
|
25
|
26
|
27
|
28
|
|
29
|
30
|
31
|
|
|
|
|
|
From: Hui W. <hw...@us...> - 2006-10-01 15:39:55
|
Update of /cvsroot/flora/flora2/lib In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv4314/lib Modified Files: flrtypeconstraint.flr Log Message: Small code improvement. Index: flrtypeconstraint.flr =================================================================== RCS file: /cvsroot/flora/flora2/lib/flrtypeconstraint.flr,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- flrtypeconstraint.flr 1 Oct 2006 13:35:16 -0000 1.4 +++ flrtypeconstraint.flr 1 Oct 2006 15:39:45 -0000 1.5 @@ -29,17 +29,9 @@ /* @> is used to compare ?Count and ?High since ?High may be '*', which stands for infinity */ -?Object[%CheckCardinality(?Method,'=>')] :- - caller{?Module}, - ?Object[?Method {?Low:?High} => ?]@?Module, - ?Count = count{?V | ?Object[?Method->?V]@?Module}, - (?Count < ?Low ; ?Count @> ?High). - -?Object[%CheckCardinality(?Method,'*=>')] :- - caller{?Module}, - ?Object[?Method {?Low:?High} *=> ?]@?Module, - ?Count = count{?V | ?Object[?Method*->?V]@?Module}, - (?Count < ?Low ; ?Count @> ?High). +?Object[%CheckCardinality(?Method,?Type)] :- + caller{?Module}, + ?Object[%CheckCardinality(?Module,?Method,?Type)]. ?Object[%CheckCardinality(?Module,?Method,'=>')] :- ?Object[?Method {?Low:?High} => ?]@?Module, @@ -51,6 +43,12 @@ ?Count = count{?V | ?Object[?Method*->?V]@?Module}, (?Count < ?Low ; ?Count @> ?High). +?_Object[%CheckCardinality(?_Module,?_Method,?Type)] :- + nonvar(?Type), + notMethodConstraintType(?Type), + flora_abort('%CheckCardinality(?Module,?Method,?Type) or %CheckCardinality(?Method,?Type) syntax error: ?Type can only be bound to => or *=>.')@prolog(flrutils). + + /***************************************************************************** ?Object[%CheckCardinality(?Method,-LowBound,-HighBound,?MethodType)] ?Object[%CheckCardinality(?Module,?Method,-LowBound,-HighBound,?MethodType)] @@ -63,82 +61,63 @@ bound. Otherwise bound to 'ok' ******************************************************************************/ -?Object[%CheckCardinality(?Method,?LowBound,?HighBound,'=>')] :- - if ?HighBound == ?LowBound then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low and ?High must be different')@prolog(flrutils), - if (nonvar(?LowBound), ?LowBound \== NOT_VIOLATED) then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low must be unbound')@prolog(flrutils), - if (nonvar(?HighBound), ?HighBound \== NOT_VIOLATED) then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?High must be unbound')@prolog(flrutils), + +?Object[%CheckCardinality(?Method,?LowBound,?HighBound,?Type)] :- caller{?Module}, + ?Object[%CheckCardinality(?Module,?Method,?LowBound,?HighBound,?Type)]. + +?Object[%CheckCardinality(?Module,?Method,?LowBound,?HighBound,'=>')] :- + checkBounds(?LowBound,?HighBound), ?Object[?Method {?Low:?High} => ?]@?Module, ?Count = count{?V | ?Object[?Method->?V]@?Module}, (?Count < ?Low ; ?Count @> ?High), - if ?Count < ?Low then - ?LowBound = ?Low // The lower bound is violated. Bind ?LowBound - // to the violated lower bound. - // Else, bind ?LowBound to 'ok'. - else ?LowBound = NOT_VIOLATED, - if ?Count @> ?High then - ?HighBound = ?High // The higher bound is violated. Bind ?HighBound - // to the violated higher bound. - // Else, bind ?HighBound to 'ok'. - else ?HighBound = NOT_VIOLATED. + boundViolated(?Count,?Low,?High,?LowBound,?HighBound). -?Object[%CheckCardinality(?Method,?LowBound,?HighBound,'*=>')] :- - if ?HighBound == ?LowBound then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low and ?High must be different')@prolog(flrutils), - if (nonvar(?LowBound), ?LowBound \== NOT_VIOLATED) then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low must be unbound')@prolog(flrutils), - if (nonvar(?HighBound), ?HighBound \== NOT_VIOLATED) then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?High must be unbound')@prolog(flrutils), - caller{?Module}, +?Object[%CheckCardinality(?Module,?Method,?LowBound,?HighBound,'*=>')] :- + checkBounds(?LowBound,?HighBound), ?Object[?Method {?Low:?High} *=> ?]@?Module, ?Count = count{?V | ?Object[?Method*->?V]@?Module}, (?Count < ?Low ; ?Count @> ?High), - if ?Count < ?Low then - ?LowBound = ?Low // The lower bound is violated. Bind ?LowBound - // to the violated bound. Else, bind ?LowBound to 'ok'. - else ?LowBound = NOT_VIOLATED, - if ?Count @> ?High then - ?HighBound = ?High // The higher bound is violated. Bind ?HighBound - // to the violated bound. Else, bind ?HighBound to 'ok'. - else ?HighBound = NOT_VIOLATED. + boundViolated(?Count,?Low,?High,?LowBound,?HighBound). -?Object[%CheckCardinality(?Module,?Method,?LowBound,?HighBound,'=>')] :- - if ?HighBound == ?LowBound then - flora_abort('Instantiation error in %CheckCardinality(?Module,?Method,?Low,?High,?Type): ?Low and ?High must be different')@prolog(flrutils), - if (nonvar(?LowBound), ?LowBound \== NOT_VIOLATED) then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low must be unbound')@prolog(flrutils), - if (nonvar(?HighBound), ?HighBound \== NOT_VIOLATED) then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?High must be unbound')@prolog(flrutils), - ?Object[?Method {?Low:?High} => ?]@?Module, - ?Count = count{?V | ?Object[?Method->?V]@?Module}, - (?Count < ?Low ; ?Count @> ?High), - if ?Count < ?Low then - ?LowBound = ?Low // The lower bound is violated, bind ?LowBound to the violated lower bound. - //else, bind ?LowBound to 'ok'. - else ?LowBound = NOT_VIOLATED, - if ?Count @> ?High then - ?HighBound = ?High // The higher bound is violated, bind ?HighBound to the violated higher bound. - // else, bind ?HighBound to 'ok'. - else ?HighBound = NOT_VIOLATED. +?_Object[%CheckCardinality(?_Module,?_Method,?_LowBound,?_HighBound,?Type)] :- + nonvar(?Type), + notMethodConstraintType(?Type), + flora_abort('%CheckCardinality(?Module,?Method,?LowBound,?HighBound,?Type)) or %CheckCardinality(?Method,?Low,?High,?Type) syntax error: ?Type can only be bound to => or *=>.')@prolog(flrutils). -?Object[%CheckCardinality(?Module,?Method,?LowBound,?HighBound,'*=>')] :- + +/**************************************************************************** + and *=> can have method cardinality constraints on them. +****************************************************************************/ +notMethodConstraintType(?Type) :- + ?Type \== '=>', + ?Type \== '*=>'. + +/***************************************************************************** +checkBounds(-LowBound,-HighBound) + +Verify that ?LowBound and ?HighBound should be unbound variables, and should not be equal. +*****************************************************************************/ +checkBounds(?LowBound,?HighBound) :- if ?HighBound == ?LowBound then - flora_abort('Instantiation error in %CheckCardinality(?Module,?Method,?Low,?High,?Type): ?Low and ?High must be different')@prolog(flrutils), + flora_abort('Instantiation error in %CheckCardinality(?Module,?Method,?Low,?High,?Type) or %CheckCardinality(?Method,?Low,?High,?Type): ?Low and ?High must be different')@prolog(flrutils), if (nonvar(?LowBound), ?LowBound \== NOT_VIOLATED) then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low must be unbound')@prolog(flrutils), + flora_abort('Instantiation error in %CheckCardinality(?Module,?Method,?Low,?High,?Type) or %CheckCardinality(?Method,?Low,?High,?Type): ?Low must be unbound')@prolog(flrutils), if (nonvar(?HighBound), ?HighBound \== NOT_VIOLATED) then - flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?High must be unbound')@prolog(flrutils), - ?Object[?Method {?Low:?High} *=> ?]@?Module, - ?Count = count{?V | ?Object[?Method*->?V]@?Module}, - (?Count < ?Low ; ?Count @> ?High), + flora_abort('Instantiation error in %CheckCardinality(?Module,?Method,?Low,?High,?Type) or %CheckCardinality(?Method,?Low,?High,?Type): ?High must be unbound')@prolog(flrutils). + + +/***************************************************************************** +boundViolated(+Count,+Low,+High,-LowBound,-HighBound) + +?Count is the actual cardinality, ?Low and ?High are the bounds, ?LowBound and ?HighBound signal the violated bounds. +*****************************************************************************/ +boundViolated(?Count,?Low,?High,?LowBound,?HighBound) :- if ?Count < ?Low then ?LowBound = ?Low // The lower bound is violated, bind ?LowBound to the violated lower bound. //else, bind ?LowBound to 'ok'. else ?LowBound = NOT_VIOLATED, if ?Count @> ?High then ?HighBound = ?High // The higher bound is violated, bind ?HighBound to the violated higher bound. - // else, bind ?HighBound to 'ok'. + // else, bind ?HighBound to 'ok'. else ?HighBound = NOT_VIOLATED. |
|
From: Michael K. <ki...@us...> - 2006-10-01 13:35:26
|
Update of /cvsroot/flora/flora2/docs In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv20974/docs Modified Files: flora2.tex Log Message: small improvements. added Hui's descriptions of cardinality constraints, signatures, etc. Index: flora2.tex =================================================================== RCS file: /cvsroot/flora/flora2/docs/flora2.tex,v retrieving revision 1.155 retrieving revision 1.156 diff -u -d -r1.155 -r1.156 --- flora2.tex 25 May 2006 02:49:48 -0000 1.155 +++ flora2.tex 1 Oct 2006 13:35:16 -0000 1.156 @@ -151,9 +151,9 @@ \title{ \FLORA: User's Manual \\ - {\Large Version 0.94} + {\Large Version 0.95} \vspace{-2mm}\\ - {\large (Narumigata)} + {\large (Androcymbium)} } \author{ @@ -161,6 +161,8 @@ \hspace{1cm} Michael Kifer$^2$ \hspace{1cm} + Hui Wan$^2$ + \hspace{1cm} Chang Zhao$^2$ } \\\\ @@ -1974,8 +1976,8 @@ \index{method!boolean} -% -As a syntactic sugar, \FLORA introduces boolean methods, which can be +%% +As a syntactic sugar, \FLORA provides boolean methods, which can be considered as value-returning methods that return some fixed value, e.g., {\tt void}. For example, the following facts: \begin{verbatim} @@ -2013,6 +2015,22 @@ it follows that John is also a vegetarian, i.e., \verb|John[is_vegetarian]|. +\subsection{Boolean Signatures} + +Boolean methods can have signatures like value-returning methods. +For noninheritable Boolean methods, signatures are specified as follows: +%% +\begin{verbatim} + Class[=>Meth] +\end{verbatim} +%% +For inheritable Boolean methods, signatures are declared similarly: +%% +\begin{verbatim} + C[*=>Meth] +\end{verbatim} +%% + \section{Anonymous and Generated Oids}\label{sec-anon-gen-oids} @@ -4724,7 +4742,7 @@ will succeed. -\subsection{Choosing the Inheritance Semantics}\label{sec-inheritance-directive} +\subsection{Choosing an Inheritance Semantics}\label{sec-inheritance-directive} As mentioned earlier, the {\tt setsemantics} directive accepts two options: {\tt inheritance(none)} and {\tt inheritance(flogic)}. The default is {\tt @@ -4799,6 +4817,119 @@ +\section{Cardinality Constraints}\label{sec-card-in-signatures} + +The earlier versions of F-logic made a distinction between functional and +set-valued attributes and methods. The former were allowed to have only one +value for any particular object and the latter could have any. In \FLORA, +this dichotomy was replaced with the much more general mechanism of +cardinality constraints. These constraints can be specified in signature +expressions, which we have earlier used only to define types of attributes +and methods. The extended syntax is as follows: +%% +\begin{verbatim} + Cl[Meth{LowerBound:UpperBound}=>Cl2] + Cl[Meth{LowerBound:UpperBound}*=>Cl2] +\end{verbatim} +%% +The first signature applies to object {\tt Cl} and to its noninheritable +method {\tt Meth}. The second expression applies to the inheritable +method {\tt Meth} of {\tt Cl}, of the subclasses of {\tt Cl}, +and to \emph{non}inheritable method {\tt Meth} of the objects that belong +to class {\tt Cl}. (Recall that inheritable methods are inherited as +inheritable methods to subclasses, but they become non-inheritable once +they are inherited to class members.) + +The lower and upper bounds in cardinality constraints can be non-negative +integers, variables, or the symbol {\tt *}. Variables can occur in +signatures in rule bodies when one wants to query the bounds of the +cardinality constraints and {\tt *} means infinity. + +For example, +%% +\begin{verbatim} + c1[m{2:?X}=>c2] :- ?X=3. +\end{verbatim} +%% +means that the method {\tt m} of class {\tt c1} must have at least 2 at +most 3 values. Similarly, +%% +\begin{verbatim} + c1[m{2:*}=>c2]. +\end{verbatim} +%% +means that {\tt m} has at least 2 values; there is no upper bound. + +We can query the specified cardinality constraints by putting variables in +the appropriate places. For instance, consider the following knowledge base +loaded into module {\tt foo}: +%% +\begin{verbatim} + C[m{3:*}*=>B]. + C[m{?x:1}=>B] :- ?x=0. + + v:C. + C2::C. + v2:C2. + + C[m->{1,2}]. + v[m->2]. + C2[m*->{1,2,3}]. +\end{verbatim} +%% +The query +%% +\begin{verbatim} + ?- ?C[?M{?L:?H}=>?]@foo. +\end{verbatim} +%% +will yield three solutions: +%% +\begin{verbatim} + ?C = C + ?M = m + ?L = 0 + ?H = 1 + + ?C = v + ?M = m + ?L = 3 + ?H = * + + ?C = v2 + ?M = m + ?L = 3 + ?H = * +\end{verbatim} +%% +Note that the objects {\tt v} and {\tt v2} are in the answer to the query +because they inherited the cardinality constraint for non-inheritable +version of {\tt m} from the first clause, {\tt C[m{3:*}*=>B]}. + +On the other hand, the query +%% +\begin{verbatim} + ?- ?C[?M{?L:?H}*=>?]@foo. +\end{verbatim} +%% +has two solutions: +%% +\begin{verbatim} +?C = C +?M = m +?L = 3 +?H = * + +?C = C2 +?M = m +?L = 3 +?H = * +\end{verbatim} +%% +Class {\tt C} is in the result because the constraint is specified +explicitly and {\tt C2} is in the result because it inherited the +constraint from {\tt C}. + \section{\FLORA and Tabling}\label{sec-tabling-flora} @@ -5120,6 +5251,23 @@ return any values. The only difference is that procedural methods are \emph{not} tabled, while boolean methods are. +\subsubsection{Procedural Signatures} + +Procedural methods can have signatures like other kinds of methods. +For noninheritable Boolean methods, signatures are specified as follows: +%% +\begin{verbatim} + Class[=>%Meth] +\end{verbatim} +%% +\FLORA does not support inheritable procedural methods at present, but the +syntax permits signatures for such methods (which are just ignored): +%% +\begin{verbatim} + C[*=>%Meth] +\end{verbatim} +%% + \subsection{Operational Semantics of \FLORA}\label{sec-flora-procedural} Although \FLORA is a declarative language, it provides primitives, such as @@ -6979,6 +7127,105 @@ catch\{...\}} primitive are also specified as Prolog terms. he primitive takes care of the Prolog-to-HiLog conversion automatically. +\section{Data Types}\label{sec-data-types} + +An extensive data type support is being planned for \FLORA in the future. +At present, apart from the built-in \emph{integer}, \emph{real}, and +\emph{string} data types, the only other supported data type is URI +(universal resource identifier). + +\subsection{URI Data Type}\label{sec-uri} + +URIs can come in the usual full form or in an abbreviated form +known as \emph{sQName} (serialized qualified name) or \emph{curi} +form (compact URI). + +A \emph{full URI} is a sequence of characters enclosed between \_ and the +double quotes. For instance, {\tt \_"http://w3.org/"}. The string inside +the double quotes is supposed to be a syntactically valid URI. + +An \emph{sQName} or a \emph{compact form} of a URI (curi) consists of a +prefix and a local-name as follows: \emph{PREFIXNAME\#LOCALNAME}. Here +\emph{PREFIXNAME} is an alphanumeric identifier that must be defined as a +shortcut for a URI elsewhere (see below). \emph{LOCALNAME} can be a string, +an alphanumeric identifier, or a quoted atom. (If \emph{LOCALNAME} contains +non-alphanumeric symbols, it must be enclosed in double quotes as in {\tt + "ab\%20"}.) An sQName is treated as a macro that expands into a full URI +by concatenating the expansion of \emph{PREFIXNAME} +with LOCALNAME. + +The prefix of an sQName must be defined as follows: +%% +\begin{verbatim} + :- prefix PREFIXNAME = PREFIXURI. +\end{verbatim} +%% +Here {\tt PREFIXURI} can be an alphanumeric identifier, a +quoted atom, or a string. Prefixes can also be defined on +command line at run time: +%% +\begin{verbatim} + ?- prefix PREFIXNAME = PREFIXURI. +\end{verbatim} +%% +Such a prefix becomes defined only after the command is executed. +If a prefix is used before it is defined, an error will result. +For example, +%% +\begin{verbatim} + :- prefix w3c = "http://www.w3c.org/", AAAWEB = "http://www.AAA.com/". +\end{verbatim} +%% +Defines two prefixes, which can be used in subsequent commands like this: +%% +\begin{verbatim} + ?- ?X = w3c#a. +\end{verbatim} +%% +This will bind {\tt ?X} to {\tt \_"http://www.w3c.org/a"}. +Likewise, +%% +\begin{verbatim} + ?- ?Y = AAAWEB#"ab%20" +\end{verbatim} +%% +binds {\tt ?Y} to {\tt \_"http://www.AAA.com/ab\%20"}. + +Note that prefix definitions are local to the module where they are +defined. If we execute +%% +\begin{verbatim} + ?- (prefix W3="foow3/", W4="w4/")@foo. +\end{verbatim} +%% +and then load the following file into module {\tt main} +%% +\begin{verbatim} + :- prefix W3 = "mainW3/". + C[a->_"foow3/a"]. + D[a->_"mainW3/a"]. + r(?X):-?X[a->(W3#a)@foo]. + s(?X):-?X[a->W3#a]. +\end{verbatim} +%% +then the different occurrences of {\tt W3} will have different expansions. +Thus, the answer to +%% +\begin{verbatim} + ?- r(?X). +\end{verbatim} +%% +will be {\tt C} and the answer to +%% +\begin{verbatim} + ?- s(?X). +\end{verbatim} +%% +will be {\tt D}. Note that a reference to {\tt W3\#c} in another module, +might result in an error, if {\tt W3} is not defined as a prefix in that +module. + + \section{Debugging User Programs}\label{sec-debugging} \index{debugging} @@ -7265,47 +7512,166 @@ This assumption may not hold when one asks queries as general as {\tt type\_error}. -\subsection{Checking the Cardinality of Methods}\label{sec-cardinality} +\subsection{Checking Cardinality of Methods}\label{sec-cardinality} \index{cardinality constraint} %% \FLORA does not automatically enforce the cardinality constraint specified -in method signatures. However, \FLORA creates {\tt .con} files, which -include the constraints that can be used to verify the cardinality -restrictions. +in method signatures. However, the {\tt type} system module in \FLORA +provides methods for checking cardinality +constraints for methods that have such constraints declared in their +signatures. In practice as well as in theory things are more complicated however. -First, it is theoretically not possible to write a query that will flag a -violation of the functional property iff it exists \emph{and} will -terminate and return a negative result if no violation exists. +First, it is theoretically impossible to have a query that will flag a +violation of a cardinality constrain if and only if one exists \emph{and} +will terminate. -In practice, the constraints in the {\tt .con} files may trigger run-time +In practice, the constraint checking methods +in the {\tt type} system library may trigger run-time errors if there are rules that use non-logical features or certain builtins -in their bodies. Therefore, in practice, the user should invoke the -queries in the {\tt .con} file only for particular methods and only when it -makes purely logical sense. +in their bodies. Therefore, in practice, the user should use the +constraint-checking methods only for purely logical methods. Cardinality +constraints declared for methods that are defined with the help of +non-logical features should be used for documentation only. The above problems aside, it is easy to verify that a particular -satisfies a cardinality constraint. For instance, we can -define the following: +satisfies a cardinality constraint. +For instance, if method {\tt foo} is declared as %% \begin{verbatim} - ?Meth[maxCardinality->?Max] :- - ?Max = max{?Count| ?Count=count{?Val| ?_X[?Meth->?Val]}}. - ?Meth[minCardinality->?Min] :- - ?Min = min{?Count| ?Count=count{?Val| ?_X[?Meth->?Val]}}. + someclass[foo {2:3}*=> sometype]. \end{verbatim} %% -To verify that certain method, say {\tt foo}, has maximum cardinality -5 and minimum cardinality of 2 we can ask the following query: +Then to verify that the cardinality constraint is not violated, +one can ask the following query: %% \begin{verbatim} - flora2 ?- foo[maxCardinality->?Max, minCardinality->?Min], ?Max < 6, ?Min > 1. + flora2 ?- ?Obj[%CheckCardinality(foo, =>)]@flora(type). \end{verbatim} %% -This kind of constraints are automatically generated by the compiler and -placed in an appropriate {\tt .con} file. The user can invoke those -constraints to check for violations when necessary. +If there are violations of this constraint then {\tt ?Obj} will get bound +to the objects for which the violation was detected. For instance, consider +the following situation: +%% +\begin{verbatim} + cl[foo {2:3}*=> int]. + c::cl. + + o1:c. + o2:c. + o3:c. + + o1[foo->{1,2,3,4}]. + o3[foo->{3,4}]. + + c[foo *-> 2]. + cl[foo *-> {3,4,5}]. +\end{verbatim} +%% +Then the query +%% +\begin{verbatim} + ?O[%CheckCardinality(foo,=>)]@flora(type). +\end{verbatim} +%% +will return {\tt ?O = o1} and {\tt ?O = o2} because {\tt o1} has a +non-inheritable method {\tt foo} with 4 values while only 2 or 3 are +allowed according to the signature. The object {\tt o2} is returned because +{\tt foo} has no values for that object, and {\tt o3} is not returned +because this object does not violate the constraint. Similarly, the query +%% +\begin{verbatim} + ?O[%CheckCardinality(foo,*=>)]@flora(type). +\end{verbatim} +%% +will return {\tt ?O = c} because the inheritable version of method {\tt + foo} has only 1 value for that class, while at least two are required by +the signature. The class {\tt cl} is not returned because it does not +violate the constraint. + +Other versions of the method {\tt \%CheckCardinality} are as follows. +The method type argument can be either {\tt =>} or {\tt *=>}. The {\tt =>} +version checks non-inheritable methods. Such a method would normally be +declared as a class property for a particular class or it would be +inherited by an object from its superclass. The {\tt *=>} version checks +inheritable methods. Such a method would be either declared as inheritable +in a class-object or it would be inherited by a subclass of that class. +%% +\begin{itemize} +\item + {\tt + ?Object[\%CheckCardinality(?MethodName,?MethodType)]@flora(type)} + \\ + Checks cardinality constraints for {\tt ?MethodName} of type {\tt + ?MethodType} in the current module. +\item + {\tt + ?Object[\%CheckCardinality(?Module,?MethodName,?MethodType)]@flora(type)}\\ + Checks cardinality constraints for {\tt ?MethodName} of type {\tt + ?MethodType} in module {\tt ?Module}. +\item {\tt + ?Object[\%CheckCardinality(?Module,?Method,?LowBound,?HighBound,?MethodType)]@flora(type)}\\ + Like the previous query, but has two more arguments {\tt ?LowBound} and + {\tt ?HighBound}, which must normally be unbound variables. They are used to + indicate which bounds are violated. If the lower bound is violated, then + {\tt ?LowBound} will be bound to the violated lower bound; otherwise, it + is bound to {\tt ok}. If the higher bound is violated, then {\tt + ?HighBound} will be bound to the violated higher bound; otherwise it is + bound to {\tt ok}. Either one of {\tt ?LowBound} or {\tt ?HighBound} (but + not both) can be also initially bound to {\tt ok}. If, for example, + {\tt ?LowBound} is bound to {\tt ok} when the method is called then the + query succeeds only for those cases where only the high bound is + violated. + + If {\tt ?Module} is unbound then it will be bound to the module(s) in which + the cardinality constraint is violated. + + For instance, for the above program the query + %% +\begin{verbatim} + ?- ?O[%CheckCardinality(?Mod,foo,?Low,?High,*=>)]@flora(type). +\end{verbatim} + %% + will bind {\tt ?O} to {\tt c}, {\tt ?Mod} to {\tt main}, {\tt ?Low} to 2, + and {\tt ?High} to {\tt ok}. Indeed, only the lower bound of the + cardinality constrain c[foo {2:3}*=> {\tt int]} (which was inherited from + {\tt cl}) is violated by the class {\tt c}. + + If {\tt ?MethodType} is unbound then it will be bound to the method types + for which the constraint was violated. For instance, + %% +\begin{verbatim} + ?- ?O[%CheckCardinality(foo,?Low,?High,?MethodType)]@flora(type). +\end{verbatim} + %% + will return the following results: + %% +\begin{verbatim} + ?O = c + ?Low = 2 + ?High = ok + ?MethodType = *=> + + ?O = o1 + ?Low = ok + ?High = 3 + ?MethodType = => + + ?O = o2 + ?Low = 2 + ?High = ok + ?MethodType = => +\end{verbatim} + %% + +\item {\tt + ?Object[\%CheckCardinality(?Method,?LowBound,?HighBound,?MethodType)]@flora(type)}\\ + This is similar to the previous method except that the constraint is + checked in the current module. + +\end{itemize} +%% @@ -7646,54 +8012,6 @@ \emph{system modules}. We describe the functionality of these modules below. -\subsection{Pretty Printing} - -This library provides methods for pretty printing the information about an -object or about all objects in a given class. This information can be saved -in a file or printed on the screen. This library is preloaded in the -system module {\tt pp} and is accessible using the {\tt @flora(pp)} -syntax. - -To pretty print information about an object, the following calls can be -used. The first argument is the user module whose object is to be pretty -printed. (Recall that the same object can have completely different sets of -properties in different user modules, so the pretty printing methods need to -know which set of properties to use.) -%% -\begin{itemize} -\item {\tt ?Class[\%pp\_class]} --- pretty print all objects in class {\tt - ?Class} in the current module. Send the result to standard output. -\item {\tt ?Class[\%pp\_class(?Module)]} --- same, but the information is - printed on objects in module {\tt ?Module}. -\item {\tt ?Class[\%pp\_class(?Module,?Outfile)]} --- same, but - put the result in {\tt ?Outfile}. -\item {\tt ?Obj[\%pp\_self]} --- pretty print the state of the object {\tt ?Obj} - in the current module. Send the result to standard output. -\item {\tt ?Obj[\%pp\_self(?Module)]} --- same, but use the object {\tt ?Obj} - in module {\tt ?Module}. -\item {\tt ?Obj[\%pp\_self(?Module,?Outfile)]} --- same, but send the result - to file {\tt ?Outfile}. -\item {\tt ?Class[\%pp\_isa]} --- pretty print the part of the isa - hierarchy beneath {\tt ?Class} in the current module. Send the result to - standard output. -\item {\tt ?Class[\%pp\_isa(?Module)]} --- same, but use the isa hierarchy in - module {\tt ?Module}. -\item {\tt ?Class[\%pp\_isa(?Module,?Outfile)]} --- same, but send the result - to file {\tt ?Outfile}. -\end{itemize} -%% -The following example illustrates the use of this library: -%% -\begin{quote} - {\tt - flora2 ?- John[\%pp\_self(\thismodule)]@flora(pp). - } -\end{quote} -%% -When this method is called, the token \thismodule is replaced with the name -of the module in which the call occurs, so it known that it has to pretty -print the object {\tt John} in that module. - \subsection{Input and Output} This library simplifies access to the most common Prolog I/O facilities. @@ -7875,6 +8193,62 @@ \end{itemize} %% +\subsection{Cardinality Constraint Checking}\label{sec-type-sysmod} + +This system module of \FLORA provides methods for testing cardinality +constraints of the methods defined in the \FLORA knowledge base. +The module defines the transactional methods {\tt \%CheckCardinality} with +two, three, four, and five arguments. This method and its use is described +in Section~\ref{sec-cardinality}. + +\subsection{Pretty Printing} + +This library provides methods for pretty printing the information about an +object or about all objects in a given class. This information can be saved +in a file or printed on the screen. This library is preloaded in the +system module {\tt pp} and is accessible using the {\tt @flora(pp)} +syntax. + +To pretty print information about an object, the following calls can be +used. The first argument is the user module whose object is to be pretty +printed. (Recall that the same object can have completely different sets of +properties in different user modules, so the pretty printing methods need to +know which set of properties to use.) +%% +\begin{itemize} +\item {\tt ?Class[\%pp\_class]} --- pretty print all objects in class {\tt + ?Class} in the current module. Send the result to standard output. +\item {\tt ?Class[\%pp\_class(?Module)]} --- same, but the information is + printed on objects in module {\tt ?Module}. +\item {\tt ?Class[\%pp\_class(?Module,?Outfile)]} --- same, but + put the result in {\tt ?Outfile}. +\item {\tt ?Obj[\%pp\_self]} --- pretty print the state of the object {\tt ?Obj} + in the current module. Send the result to standard output. +\item {\tt ?Obj[\%pp\_self(?Module)]} --- same, but use the object {\tt ?Obj} + in module {\tt ?Module}. +\item {\tt ?Obj[\%pp\_self(?Module,?Outfile)]} --- same, but send the result + to file {\tt ?Outfile}. +\item {\tt ?Class[\%pp\_isa]} --- pretty print the part of the isa + hierarchy beneath {\tt ?Class} in the current module. Send the result to + standard output. +\item {\tt ?Class[\%pp\_isa(?Module)]} --- same, but use the isa hierarchy in + module {\tt ?Module}. +\item {\tt ?Class[\%pp\_isa(?Module,?Outfile)]} --- same, but send the result + to file {\tt ?Outfile}. +\end{itemize} +%% +The following example illustrates the use of this library: +%% +\begin{quote} + {\tt + flora2 ?- John[\%pp\_self(\thismodule)]@flora(pp). + } +\end{quote} +%% +When this method is called, the token \thismodule is replaced with the name +of the module in which the call occurs, so it known that it has to pretty +print the object {\tt John} in that module. + \section{Notes on the Programming Style and Common Pitfalls} @@ -8259,25 +8633,6 @@ \end{enumerate} %% -\section{Authors} -Much of \FLORA was designed and implemented by Guizhen Yang. Some architectural -ideas, such as the use of trailer files to implement the F-logic semantics, -were inspired by the \FLIP compiler developed by Bertram Lud\"aescher. - -Michael Kifer helped design \FLORA, implemented the debugger, and many -other features. - -Chang Zhao made a great many crucial enhancements to the system, such as -run-time undefinedness checks, the checker for dependency among tabled -predicates and updates, tabling of HiLog predicates, and dynamic insertion -and deletion of program rules. - -Vishal Chowdhary added encapsulation to the \FLORA module system and -implemented persistence modules. - -Hui Wan implemented {\tt flAdd} and {\tt flCompileAdd} and the -corresponding infrastructure. - \appendix |
|
From: Michael K. <ki...@us...> - 2006-10-01 13:35:24
|
Update of /cvsroot/flora/flora2 In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv20974 Modified Files: version.flh Log Message: small improvements. added Hui's descriptions of cardinality constraints, signatures, etc. Index: version.flh =================================================================== RCS file: /cvsroot/flora/flora2/version.flh,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- version.flh 22 Aug 2006 16:32:31 -0000 1.20 +++ version.flh 1 Oct 2006 13:35:17 -0000 1.21 @@ -1,2 +1,2 @@ -#define FLORA_VERSION '0.95devel (Androcymbium) of August 2006' +#define FLORA_VERSION '0.95devel (Androcymbium) of October 2006' |
|
From: Michael K. <ki...@us...> - 2006-10-01 13:35:24
|
Update of /cvsroot/flora/flora2/lib In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv20974/lib Modified Files: flrtypeconstraint.flr Log Message: small improvements. added Hui's descriptions of cardinality constraints, signatures, etc. Index: flrtypeconstraint.flr =================================================================== RCS file: /cvsroot/flora/flora2/lib/flrtypeconstraint.flr,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- flrtypeconstraint.flr 28 Sep 2006 22:09:04 -0000 1.3 +++ flrtypeconstraint.flr 1 Oct 2006 13:35:16 -0000 1.4 @@ -23,7 +23,11 @@ ** */ -/* @> is used to compare ?Count and ?High since ?High is probably '*' which stands for infinity */ + +#include "flora_terms.flh" + +/* @> is used to compare ?Count and ?High since ?High may be '*', + which stands for infinity */ ?Object[%CheckCardinality(?Method,'=>')] :- caller{?Module}, @@ -47,89 +51,94 @@ ?Count = count{?V | ?Object[?Method*->?V]@?Module}, (?Count < ?Low ; ?Count @> ?High). -/************************************************************************************************************************* +/***************************************************************************** ?Object[%CheckCardinality(?Method,-LowBound,-HighBound,?MethodType)] ?Object[%CheckCardinality(?Module,?Method,-LowBound,-HighBound,?MethodType)] - ?LowBound and ?HighBound should be unbound variables in the input, they are used to signal which bound is violated. - If the lower bound is violated, then ?LowBound will be bound to the (violated) lower bound, otherwise bound to 'not_violated' - If the higher bound is violated, then ?HighBound will be bound to the (violated) higher bound, otherwise bound to 'not_violated' + ?LowBound and ?HighBound should be unbound variables or one of them is 'ok'. + They are used to signal which bound is violated. + If the lower bound is violated, then ?LowBound will be bound to the violated + bound. Otherwise bound to 'ok' + If the upper bound is violated, then ?HighBound will be bound to the violated + bound. Otherwise bound to 'ok' - ***********************************************************************************************************************/ +******************************************************************************/ ?Object[%CheckCardinality(?Method,?LowBound,?HighBound,'=>')] :- if ?HighBound == ?LowBound then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?Low, ?High should be different with each other!')@flora(sys), - if not(var(?LowBound)) then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?Low should be unbound!')@flora(sys), - if not(var(?HighBound)) then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?High should be unbound!')@flora(sys), + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low and ?High must be different')@prolog(flrutils), + if (nonvar(?LowBound), ?LowBound \== NOT_VIOLATED) then + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low must be unbound')@prolog(flrutils), + if (nonvar(?HighBound), ?HighBound \== NOT_VIOLATED) then + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?High must be unbound')@prolog(flrutils), caller{?Module}, ?Object[?Method {?Low:?High} => ?]@?Module, ?Count = count{?V | ?Object[?Method->?V]@?Module}, (?Count < ?Low ; ?Count @> ?High), if ?Count < ?Low then - ?LowBound = ?Low // The lower bound is violated, bind ?LowBound to the violated lower bound. - //else, bind ?LowBound to 'not_violated'. - else ?LowBound = 'not_violated', + ?LowBound = ?Low // The lower bound is violated. Bind ?LowBound + // to the violated lower bound. + // Else, bind ?LowBound to 'ok'. + else ?LowBound = NOT_VIOLATED, if ?Count @> ?High then - ?HighBound = ?High // The higher bound is violated, bind ?HighBound to the violated higher bound. - // else, bind ?HighBound to 'not_violated'. - else ?HighBound = 'not_violated'. + ?HighBound = ?High // The higher bound is violated. Bind ?HighBound + // to the violated higher bound. + // Else, bind ?HighBound to 'ok'. + else ?HighBound = NOT_VIOLATED. ?Object[%CheckCardinality(?Method,?LowBound,?HighBound,'*=>')] :- if ?HighBound == ?LowBound then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?Low, ?High should be different with each other!')@flora(sys), - if not(var(?LowBound)) then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?Low should be unbound!')@flora(sys), - if not(var(?HighBound)) then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?High should be unbound!')@flora(sys), + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low and ?High must be different')@prolog(flrutils), + if (nonvar(?LowBound), ?LowBound \== NOT_VIOLATED) then + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low must be unbound')@prolog(flrutils), + if (nonvar(?HighBound), ?HighBound \== NOT_VIOLATED) then + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?High must be unbound')@prolog(flrutils), caller{?Module}, ?Object[?Method {?Low:?High} *=> ?]@?Module, ?Count = count{?V | ?Object[?Method*->?V]@?Module}, (?Count < ?Low ; ?Count @> ?High), if ?Count < ?Low then - ?LowBound = ?Low // The lower bound is violated, bind ?LowBound to the violated lower bound. - //else, bind ?LowBound to 'not_violated'. - else ?LowBound = 'not_violated', + ?LowBound = ?Low // The lower bound is violated. Bind ?LowBound + // to the violated bound. Else, bind ?LowBound to 'ok'. + else ?LowBound = NOT_VIOLATED, if ?Count @> ?High then - ?HighBound = ?High // The higher bound is violated, bind ?HighBound to the violated higher bound. - // else, bind ?HighBound to 'not_violated'. - else ?HighBound = 'not_violated'. + ?HighBound = ?High // The higher bound is violated. Bind ?HighBound + // to the violated bound. Else, bind ?HighBound to 'ok'. + else ?HighBound = NOT_VIOLATED. ?Object[%CheckCardinality(?Module,?Method,?LowBound,?HighBound,'=>')] :- if ?HighBound == ?LowBound then - %abort('Using %CheckCardinality(?Module,?Method,?Low,?High,?Type): ?Low, ?High should be different with each other!')@flora(sys), - if not(var(?LowBound)) then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?Low should be unbound!')@flora(sys), - if not(var(?HighBound)) then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?High should be unbound!')@flora(sys), + flora_abort('Instantiation error in %CheckCardinality(?Module,?Method,?Low,?High,?Type): ?Low and ?High must be different')@prolog(flrutils), + if (nonvar(?LowBound), ?LowBound \== NOT_VIOLATED) then + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low must be unbound')@prolog(flrutils), + if (nonvar(?HighBound), ?HighBound \== NOT_VIOLATED) then + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?High must be unbound')@prolog(flrutils), ?Object[?Method {?Low:?High} => ?]@?Module, ?Count = count{?V | ?Object[?Method->?V]@?Module}, (?Count < ?Low ; ?Count @> ?High), if ?Count < ?Low then ?LowBound = ?Low // The lower bound is violated, bind ?LowBound to the violated lower bound. - //else, bind ?LowBound to 'not_violated'. - else ?LowBound = 'not_violated', + //else, bind ?LowBound to 'ok'. + else ?LowBound = NOT_VIOLATED, if ?Count @> ?High then ?HighBound = ?High // The higher bound is violated, bind ?HighBound to the violated higher bound. - // else, bind ?HighBound to 'not_violated'. - else ?HighBound = 'not_violated'. + // else, bind ?HighBound to 'ok'. + else ?HighBound = NOT_VIOLATED. ?Object[%CheckCardinality(?Module,?Method,?LowBound,?HighBound,'*=>')] :- if ?HighBound == ?LowBound then - %abort('Using %CheckCardinality(?Module,?Method,?Low,?High,?Type): ?Low, ?High should be different with each other!')@flora(sys), - if not(var(?LowBound)) then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?Low should be unbound!')@flora(sys), - if not(var(?HighBound)) then - %abort('Using %CheckCardinality(?Method,?Low,?High,?Type): ?High should be unbound!')@flora(sys), + flora_abort('Instantiation error in %CheckCardinality(?Module,?Method,?Low,?High,?Type): ?Low and ?High must be different')@prolog(flrutils), + if (nonvar(?LowBound), ?LowBound \== NOT_VIOLATED) then + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?Low must be unbound')@prolog(flrutils), + if (nonvar(?HighBound), ?HighBound \== NOT_VIOLATED) then + flora_abort('Instantiation error in %CheckCardinality(?Method,?Low,?High,?Type): ?High must be unbound')@prolog(flrutils), ?Object[?Method {?Low:?High} *=> ?]@?Module, ?Count = count{?V | ?Object[?Method*->?V]@?Module}, (?Count < ?Low ; ?Count @> ?High), if ?Count < ?Low then ?LowBound = ?Low // The lower bound is violated, bind ?LowBound to the violated lower bound. - //else, bind ?LowBound to 'not_violated'. - else ?LowBound = 'not_violated', + //else, bind ?LowBound to 'ok'. + else ?LowBound = NOT_VIOLATED, if ?Count @> ?High then ?HighBound = ?High // The higher bound is violated, bind ?HighBound to the violated higher bound. - // else, bind ?HighBound to 'not_violated'. - else ?HighBound = 'not_violated'. + // else, bind ?HighBound to 'ok'. + else ?HighBound = NOT_VIOLATED. |
|
From: Michael K. <ki...@us...> - 2006-10-01 13:35:24
|
Update of /cvsroot/flora/flora2/flrincludes In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv20974/flrincludes Modified Files: flora_terms.flh Log Message: small improvements. added Hui's descriptions of cardinality constraints, signatures, etc. Index: flora_terms.flh =================================================================== RCS file: /cvsroot/flora/flora2/flrincludes/flora_terms.flh,v retrieving revision 1.66 retrieving revision 1.67 diff -u -d -r1.66 -r1.67 --- flora_terms.flh 17 May 2006 06:52:28 -0000 1.66 +++ flora_terms.flh 1 Oct 2006 13:35:16 -0000 1.67 @@ -967,3 +967,9 @@ #define FL_TERM FLORA_SYMBOL('term') #define FL_INVALIDMODULE FLORA_SYMBOL('invalid_module') #define FL_URI '_uri' + + +/**************************************************************************** + constraint checking +****************************************************************************/ +#define NOT_VIOLATED ok |