View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    Copyright (c) 2004, DERI Innsbruck
4    This library is free software; you can redistribute it and/or modify it under
5    the terms of the GNU Lesser General Public License as published by the Free
6    Software Foundation; either version 2.1 of the License, or (at your option)
7    any later version.
8    This library is distributed in the hope that it will be useful, but WITHOUT
9    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11   details.
12   You should have received a copy of the GNU Lesser General Public License along
13   with this library; if not, write to the Free Software Foundation, Inc.,
14   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15   */
16  package org.deri.wsmo4j.validator;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  
21  import org.deri.wsmo4j.io.serializer.wsml.LogExprSerializerWSML;
22  import org.deri.wsmo4j.logicalexpression.AbstractVisitor;
23  import org.omwg.logicalexpression.Atom;
24  import org.omwg.logicalexpression.AttributeConstraintMolecule;
25  import org.omwg.logicalexpression.AttributeInferenceMolecule;
26  import org.omwg.logicalexpression.AttributeValueMolecule;
27  import org.omwg.logicalexpression.CompoundMolecule;
28  import org.omwg.logicalexpression.LogicalExpression;
29  import org.omwg.logicalexpression.MembershipMolecule;
30  import org.omwg.logicalexpression.Molecule;
31  import org.omwg.logicalexpression.SubConceptMolecule;
32  import org.omwg.logicalexpression.terms.BuiltInConstructedTerm;
33  import org.omwg.logicalexpression.terms.ConstructedTerm;
34  import org.omwg.logicalexpression.terms.Term;
35  import org.omwg.ontology.Axiom;
36  import org.wsmo.validator.ValidationError;
37  
38  /**
39   * The FunctionSymbolHelper checks Atoms and Molecules for unallowed
40   * function symbols.
41   *
42   * <pre>
43   * Created on Okt 28, 2005
44   * Committed by $Author: morcen $
45   * $Source$,
46   * </pre>
47   *
48   * @author nathalie.steinmetz@deri.org
49   *
50   * @version $Revision: 1946 $ $Date: 2007-04-02 15:13:28 +0300 (Mon, 02 Apr 2007) $
51   */
52  public class FunctionSymbolHelper extends AbstractVisitor{
53  
54      private Axiom axiom = null;
55      
56      private List <ValidationError> errors = null;
57      
58      private String variant = null;
59      
60      private LogExprSerializerWSML leSerializer = null;
61      
62      
63      protected FunctionSymbolHelper(Axiom axiom, List <ValidationError> errors, String variant, WsmlFullValidator validator) {
64          leSerializer = validator.leSerializer;
65          this.axiom = axiom;
66          this.errors = errors;
67          this.variant = variant;
68      }
69      
70      public void visitAtom(Atom expr) {
71          Iterator it = expr.listParameters().iterator();
72          while (it.hasNext()) {
73              Term t = (Term) it.next();
74              if (t instanceof ConstructedTerm && !(t instanceof BuiltInConstructedTerm)) {
75                  addError(expr, ValidationErrorImpl.AX_ATOMIC_ERR + ": function symbols are not " +
76                          "allowed\n" + leSerializer.serialize(expr));
77              }
78          }
79      }
80      
81      public void visitAttributeContraintMolecule(AttributeConstraintMolecule expr) {
82          checkTerm(expr.getRightParameter(),expr);
83          checkTerm(expr.getLeftParameter(), expr);
84          checkTerm(expr.getAttribute(), expr);
85      }
86  
87      public void visitAttributeInferenceMolecule(AttributeInferenceMolecule expr) {
88          checkTerm(expr.getRightParameter(),expr);
89          checkTerm(expr.getLeftParameter(), expr);
90          checkTerm(expr.getAttribute(), expr);
91      }
92  
93      public void visitAttributeValueMolecule(AttributeValueMolecule expr) {
94          checkTerm(expr.getRightParameter(),expr);
95          checkTerm(expr.getLeftParameter(), expr);
96          checkTerm(expr.getAttribute(), expr);
97      }
98  
99      public void visitCompoundMolecule(CompoundMolecule expr) {
100         Iterator it = expr.listOperands().iterator();
101         while(it.hasNext()){
102             ((Molecule)it.next()).accept(this);
103         }
104     }
105 
106     public void visitMemberShipMolecule(MembershipMolecule expr) {
107         checkTerm(expr.getRightParameter(),expr);
108         checkTerm(expr.getLeftParameter(), expr);
109     }
110 
111     public void visitSubConceptMolecule(SubConceptMolecule expr) {
112         checkTerm(expr.getRightParameter(), expr);
113         checkTerm(expr.getLeftParameter(), expr);
114     }
115     
116     private void checkTerm(Term t, LogicalExpression expr){
117         if (t instanceof ConstructedTerm && !(t instanceof BuiltInConstructedTerm)) {
118             addError(expr, ValidationErrorImpl.AX_ATOMIC_ERR + ": function symbols are not " +
119                     "allowed\n" + leSerializer.serialize(expr));
120         } 
121     }
122    
123     /**
124      * @return List of collected errors
125      */
126     public List getErrors() {
127         return errors;
128     }  
129     
130     
131     private void addError(LogicalExpression logexp, String msg) {
132         errors.add(new LogicalExpressionErrorImpl(axiom, logexp, msg, variant));
133     } 
134 }
135 
136 /*
137  * $Log$
138  * Revision 1.4  2007/04/02 12:13:19  morcen
139  * Generics support added to wsmo-api, wsmo4j and wsmo-test
140  *
141  * Revision 1.3  2005/11/15 16:56:09  nathaliest
142  * changed access at ValidationError
143  *
144  * Revision 1.2  2005/10/31 07:59:10  holgerlausen
145  * corrected function symbol check
146  *
147  * Revision 1.1  2005/10/28 17:19:55  nathaliest
148  * new helper file
149  *
150  *
151  */