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  
19  import java.util.Collections;
20  import java.util.HashSet;
21  import java.util.Iterator;
22  import java.util.Set;
23  
24  import org.deri.wsmo4j.logicalexpression.AbstractVisitor;
25  import org.deri.wsmo4j.logicalexpression.ConstantTransformer;
26  import org.omwg.logicalexpression.Atom;
27  import org.omwg.logicalexpression.AttributeConstraintMolecule;
28  import org.omwg.logicalexpression.AttributeInferenceMolecule;
29  import org.omwg.logicalexpression.AttributeValueMolecule;
30  import org.omwg.logicalexpression.CompoundMolecule;
31  import org.omwg.logicalexpression.MembershipMolecule;
32  import org.omwg.logicalexpression.Molecule;
33  import org.omwg.logicalexpression.SubConceptMolecule;
34  import org.omwg.logicalexpression.terms.Term;
35  import org.omwg.ontology.DataValue;
36  
37  
38  /**
39   * The IDCollectHelper collects the concepts, instances and relations from 
40   * axiom definitions into specified Sets.
41   *
42   * <pre>
43   * Created on Sep 9, 2005
44   * Committed by $Author$
45   * $Source$,
46   * </pre>
47   *
48   * @author Holger Lausen (holger.lausen@deri.org)
49   * @author nathalie.steinmetz@deri.org
50   *
51   * @version $Revision$ $Date$
52   */
53  public class IDCollectHelper
54          extends AbstractVisitor {
55  
56      Set <Term> idConcepts = new HashSet <Term> ();
57      
58      Set <Term> explicitConcepts = new HashSet <Term> ();
59  
60      Set <Term> idInstances = new HashSet <Term> ();
61      
62      Set <Term> explicitInstances = new HashSet <Term> ();
63  
64      Set <Term> idRelations = new HashSet <Term> ();
65  
66      Set <Term> explicitRelations = new HashSet <Term> ();
67      
68      Set <Term> idConcreteRelations = new HashSet <Term> ();
69      
70      Set <Term> idAbstractRelations = new HashSet <Term> ();
71      
72      public IDCollectHelper() {
73          super();
74      }
75  
76      /**
77       * The identifiers of atoms must be relations in wsml-core. So the 
78       * identifier is put into the relations Set.
79       * 
80       * @see org.omwg.logicalexpression.Visitor#visitAtom(org.omwg.logicalexpression.Atom)
81       */
82      public void visitAtom(Atom expr) {
83          idRelations.add(expr.getIdentifier());
84      }
85  
86  
87      public void visitAttributeContraintMolecule(AttributeConstraintMolecule expr) {
88          idConcepts.add(expr.getLeftParameter());
89          explicitConcepts.add(expr.getLeftParameter());
90          Term t = expr.getRightParameter();
91          if (!ConstantTransformer.getInstance().isDataType(t.toString())) {
92              idConcepts.add(t);
93              idAbstractRelations.add(expr.getAttribute());
94          }
95          else {
96              idConcreteRelations.add(expr.getAttribute());
97          }
98          idRelations.add(expr.getAttribute());
99      }
100 
101     public void visitAttributeInferenceMolecule(AttributeInferenceMolecule expr) {
102         idConcepts.add(expr.getLeftParameter());
103         Term t = expr.getRightParameter();
104         if (!ConstantTransformer.getInstance().isDataType(t.toString())) {
105             idConcepts.add(t);
106             idAbstractRelations.add(expr.getAttribute());
107         } 
108         else {
109             idConcreteRelations.add(expr.getAttribute());
110         }
111         idRelations.add(expr.getAttribute());
112     }
113 
114     public void visitAttributeValueMolecule(AttributeValueMolecule expr) {
115         idInstances.add(expr.getLeftParameter());
116         Term t = expr.getRightParameter();
117         if (!(t instanceof DataValue)){
118             idInstances.add(t);
119             idAbstractRelations.add(expr.getAttribute());
120         }
121         else {
122             idConcreteRelations.add(expr.getAttribute());
123         }
124         idRelations.add(expr.getAttribute());
125     }
126 
127     public void visitCompoundMolecule(CompoundMolecule expr) {
128         Iterator i = expr.listOperands().iterator();
129         while(i.hasNext()){
130             ((Molecule)i.next()).accept(this);
131         }
132     }
133 
134     public void visitMemberShipMolecule(MembershipMolecule expr) {
135         idConcepts.add(expr.getRightParameter());
136         idInstances.add(expr.getLeftParameter());
137 //        explicitInstances.add(expr.getLeftParameter());
138     }
139 
140     public void visitSubConceptMolecule(SubConceptMolecule expr) {
141         idConcepts.add(expr.getRightParameter());
142         idConcepts.add(expr.getLeftParameter());
143         explicitConcepts.add(expr.getLeftParameter());
144     }
145     
146     /**
147      * @return Set containing the logical expression's concepts
148      */
149     public Set <Term> getConceptIds() {
150         return Collections.unmodifiableSet(idConcepts);
151     }
152 
153     /**
154      * @return Set containing the logical expression's explicitly declared concepts
155      */
156     public Set <Term> getExplicitConcepts() {
157         return explicitConcepts;
158     }
159 
160     /**
161      * @return Set containing the logical expression's instances
162      */
163     public Set <Term> getInstanceIds() {
164         return Collections.unmodifiableSet(idInstances);
165     }
166 
167     /**
168      * @return Set containing the logical expression's explicitly declared instances
169      */
170     public Set <Term> getExplicitInstances() {
171         return explicitInstances;
172     }
173 
174     /**
175      * @return Set containing the logical expression's relations
176      */
177     public Set <Term> getRelationIds() {
178         return Collections.unmodifiableSet(idRelations);
179     }
180 
181     /**
182      * @return Set containing the logical expression's explicitly declared relations
183      */
184     public Set <Term> getExplicitRelations() {
185         return explicitRelations;
186     }
187     
188     /**
189      * @return Set containing the logical expression's relations with abstract range
190      */
191     public Set <Term> getIdAbstractRelations() {
192         return idAbstractRelations;
193     }
194 
195     /**
196      * @return Set containing the logical expression's relations with concrete range
197      */
198     public Set <Term> getIdConcreteRelations() {
199         return idConcreteRelations;
200     }
201 
202 }
203 /*
204  * $Log$
205  * Revision 1.10  2007/04/02 12:13:19  morcen
206  * Generics support added to wsmo-api, wsmo4j and wsmo-test
207  *
208  * Revision 1.9  2005/12/15 16:46:24  nathaliest
209  * check for implicit concepts
210  *
211  * Revision 1.8  2005/10/28 17:21:06  nathaliest
212  * fixed bugs
213  *
214  * Revision 1.7  2005/10/11 15:03:31  nathaliest
215  * organized imports
216  *
217  * Revision 1.6  2005/09/20 13:21:30  holgerlausen
218  * refactored logical expression API to have simple molecules and compound molecules (RFE 1290043)
219  *
220  * Revision 1.5  2005/09/11 22:12:52  nathaliest
221  * fixed problem and added javadoc
222  *
223  * Revision 1.4  2005/09/09 15:51:42  marin_dimitrov
224  * formatting
225  *
226  * Revision 1.3  2005/09/09 14:45:28  nathaliest
227  * implementation of idCollectHelper
228  *
229  * Revision 1.2  2005/09/09 11:58:20  holgerlausen
230  * fixed header logexp no longer extension
231  *
232  * Revision 1.1  2005/09/09 10:37:57  holgerlausen
233  * remplate for nathalie
234  *
235  */