Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 176   Methods: 13
NCLOC: 116   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ItemCollectHelper.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3    Copyright (c) 2005, University of Innsbruck, Austria
 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.logicalexpression.util;
 17   
 18    import java.util.Collections;
 19    import java.util.HashMap;
 20    import java.util.HashSet;
 21    import java.util.Iterator;
 22    import java.util.Map;
 23    import java.util.Set;
 24   
 25    import org.deri.wsmo4j.logicalexpression.AbstractVisitor;
 26    import org.deri.wsmo4j.logicalexpression.ConstantTransformer;
 27    import org.omwg.logicalexpression.Atom;
 28    import org.omwg.logicalexpression.AttributeConstraintMolecule;
 29    import org.omwg.logicalexpression.AttributeInferenceMolecule;
 30    import org.omwg.logicalexpression.AttributeValueMolecule;
 31    import org.omwg.logicalexpression.CompoundMolecule;
 32    import org.omwg.logicalexpression.MembershipMolecule;
 33    import org.omwg.logicalexpression.Molecule;
 34    import org.omwg.logicalexpression.SubConceptMolecule;
 35    import org.omwg.logicalexpression.terms.Term;
 36    import org.omwg.ontology.DataValue;
 37    import org.omwg.ontology.Variable;
 38   
 39    /**
 40    * Helper class for retrieving the concepts, instances and
 41    * attributes from logical expressions.
 42    *
 43    * @author Nathalie Steinmetz, DERI Innsbruck
 44    *
 45    */
 46    public class ItemCollectHelper extends AbstractVisitor {
 47   
 48    private Set <Term> conceptIds = new HashSet <Term>();
 49   
 50    // key is a concept id, value is an attribute id
 51    private Map <Term, Term> attributeIds = new HashMap <Term, Term> ();
 52   
 53    private Set <Term> instanceIds = new HashSet <Term> ();
 54   
 55    private Set <Term> relationIds = new HashSet <Term> ();
 56   
 57  0 public ItemCollectHelper() {
 58  0 super();
 59    }
 60   
 61  0 public void visitAtom(Atom expr) {
 62  0 Iterator it = expr.listParameters().iterator();
 63  0 while (it.hasNext()) {
 64  0 Term t = (Term) it.next();
 65  0 if (isValid(t)) {
 66  0 instanceIds.add(t);
 67    }
 68    }
 69  0 relationIds.add(expr.getIdentifier());
 70    }
 71   
 72  0 public void visitCompoundMolecule(CompoundMolecule expr) {
 73  0 Iterator i = expr.listOperands().iterator();
 74  0 while(i.hasNext()){
 75  0 ((Molecule)i.next()).accept(this);
 76    }
 77   
 78    }
 79   
 80  0 public void visitSubConceptMolecule(SubConceptMolecule expr) {
 81  0 Term left = expr.getLeftParameter();
 82  0 Term right = expr.getRightParameter();
 83  0 if (isValid(left)) {
 84  0 conceptIds.add(left);
 85    }
 86  0 if (isValid(right)) {
 87  0 conceptIds.add(right);
 88    }
 89    }
 90   
 91  0 public void visitMemberShipMolecule(MembershipMolecule expr) {
 92  0 Term left = expr.getLeftParameter();
 93  0 Term right = expr.getRightParameter();
 94  0 if (isValid(left)) {
 95  0 instanceIds.add(left);
 96    }
 97  0 if (isValid(right)) {
 98  0 conceptIds.add(right);
 99    }
 100    }
 101   
 102  0 public void visitAttributeValueMolecule(AttributeValueMolecule expr) {
 103  0 Term left = expr.getLeftParameter();
 104  0 Term right = expr.getRightParameter();
 105  0 if (isValid(left)) {
 106  0 instanceIds.add(left);
 107    }
 108  0 if (isValid(right)) {
 109  0 instanceIds.add(right);
 110    }
 111    }
 112   
 113  0 public void visitAttributeContraintMolecule(AttributeConstraintMolecule expr) {
 114  0 Term left = expr.getLeftParameter();
 115  0 Term right = expr.getRightParameter();
 116  0 Term attribute = expr.getAttribute();
 117  0 if (isValid(left)) {
 118  0 conceptIds.add(left);
 119    }
 120  0 attributeIds.put(expr.getLeftParameter(), attribute);
 121  0 if (isValid(right)) {
 122  0 conceptIds.add(right);
 123    }
 124    }
 125   
 126  0 public void visitAttributeInferenceMolecule(AttributeInferenceMolecule expr) {
 127  0 Term left = expr.getLeftParameter();
 128  0 Term right = expr.getRightParameter();
 129  0 Term attribute = expr.getAttribute();
 130  0 if (isValid(left)) {
 131  0 conceptIds.add(left);
 132    }
 133  0 attributeIds.put(expr.getLeftParameter(), attribute);
 134  0 if (isValid(right)) {
 135  0 conceptIds.add(right);
 136    }
 137    }
 138   
 139    /**
 140    * @return Set containing the identifier of the logical expression's concepts
 141    */
 142  0 public Set <Term> getConceptIds() {
 143  0 return Collections.unmodifiableSet(conceptIds);
 144    }
 145   
 146    /**
 147    * @return Set containing the identifier of the logical expression's instances
 148    */
 149  0 public Set <Term> getInstanceIds() {
 150  0 return Collections.unmodifiableSet(instanceIds);
 151    }
 152   
 153    /**
 154    * @return Set containing the identifier of the logical expression's attributes
 155    */
 156  0 public Map <Term, Term> getAttributeIds() {
 157  0 return Collections.unmodifiableMap(attributeIds);
 158    }
 159   
 160    /**
 161    * @return Set containing the identifier of the logical expression's relations
 162    */
 163  0 public Set <Term> getRelationIds() {
 164  0 return Collections.unmodifiableSet(relationIds);
 165    }
 166   
 167    /*
 168    * A term must only be a constructed term, an identifier or a numbered anonymous id
 169    */
 170  0 private boolean isValid(Term term) {
 171  0 return (!ConstantTransformer.getInstance().isDataType(term.toString())
 172    && !(term instanceof DataValue)
 173    && !(term instanceof Variable));
 174    }
 175   
 176    }