Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 222   Methods: 4
NCLOC: 116   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CreateOntologyExample.java - 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3   
 4    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
 5   
 6    This library is free software; you can redistribute it and/or modify it under
 7    the terms of the GNU Lesser General Public License as published by the Free
 8    Software Foundation; either version 2.1 of the License, or (at your option)
 9    any later version.
 10    This library is distributed in the hope that it will be useful, but WITHOUT
 11    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 12    FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 13    details.
 14    You should have received a copy of the GNU Lesser General Public License along
 15    with this library; if not, write to the Free Software Foundation, Inc.,
 16    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 17    */
 18   
 19    package com.ontotext.wsmo4j.examples;
 20   
 21    import java.io.IOException;
 22    import java.io.PrintWriter;
 23    import java.util.HashMap;
 24   
 25    import org.omwg.ontology.Attribute;
 26    import org.omwg.ontology.Concept;
 27    import org.omwg.ontology.Instance;
 28    import org.omwg.ontology.Ontology;
 29    import org.omwg.ontology.Parameter;
 30    import org.omwg.ontology.Relation;
 31    import org.omwg.ontology.RelationInstance;
 32    import org.omwg.ontology.WsmlDataType;
 33    import org.wsmo.common.Namespace;
 34    import org.wsmo.common.TopEntity;
 35    import org.wsmo.common.exception.InvalidModelException;
 36    import org.wsmo.factory.DataFactory;
 37    import org.wsmo.factory.Factory;
 38    import org.wsmo.factory.WsmoFactory;
 39    import org.wsmo.wsml.Serializer;
 40   
 41    /**
 42    * <p>
 43    * Title:
 44    * </p>
 45    * <p>
 46    * Description:
 47    * </p>
 48    * <p>
 49    * Copyright: Copyright (c) 2004-2005
 50    * </p>
 51    * <p>
 52    * Company: Ontotext Lab., Sirma AI
 53    * </p>
 54    *
 55    * @author not attributable
 56    * @version 1.0
 57    */
 58   
 59    public class CreateOntologyExample {
 60   
 61    private WsmoFactory factory;
 62   
 63    private DataFactory dataFactory;
 64   
 65  0 public static Ontology showExample() throws InvalidModelException {
 66  0 CreateOntologyExample example = new CreateOntologyExample();
 67  0 example.createFactory();
 68  0 return example.createSimpleOntology();
 69    }
 70   
 71  0 private void createFactory() {
 72    // use default implementation for factory
 73  0 factory = Factory.createWsmoFactory(null);
 74  0 dataFactory = Factory.createDataFactory(null);
 75    }
 76   
 77  0 private Ontology createSimpleOntology() throws InvalidModelException {
 78    // TODO: TO BE UPDATED!
 79  0 Ontology ontology = factory.createOntology(factory.createIRI("http://www.example.org/ontologies/example"));
 80  0 Namespace nsDefault = factory.createNamespace("default", factory
 81    .createIRI("http://www.example.org/ontologies/example"));
 82  0 Namespace nsDC = factory.createNamespace("dc", factory.createIRI("http://purl.org/dc/elements/1.1"));
 83   
 84    // add NFP values
 85  0 ontology.addNFPValue(factory.createIRI(nsDefault, "title"), dataFactory.createWsmlString("WSML example ontology"));
 86  0 ontology.addNFPValue(factory.createIRI(nsDefault, "date"), dataFactory.createWsmlDate(2005, 9, 15, 12, 30));
 87  0 ontology.addNFPValue(factory.createIRI(nsDC, "rights"), factory.createIRI("http://www.deri.org/privacy.html"));
 88   
 89    // create a concept human
 90  0 Concept human = factory.createConcept(factory.createIRI(nsDefault, "Human"));
 91   
 92    // create attribute of concept hasName of type wsmlString
 93  0 Attribute attributeName = human.createAttribute(factory.createIRI(nsDefault, "hasName"));
 94  0 attributeName.addType(dataFactory.createWsmlDataType(WsmlDataType.WSML_STRING));
 95   
 96    // create attribute of concept hasAge of type wsmlInteger
 97  0 Attribute attributeAge = human.createAttribute(factory.createIRI(nsDefault, "hasAge"));
 98  0 attributeAge.addType(dataFactory.createWsmlDataType(WsmlDataType.WSML_INTEGER));
 99   
 100    // create attribute of concept hasChild of type Human inverseOf(hasParent)
 101  0 Attribute attributeChild = human.createAttribute(factory.createIRI(nsDefault, "hasChild"));
 102  0 attributeChild.addType(human);
 103  0 attributeChild.setInverseOf(factory.createIRI(nsDefault, "hasParent"));
 104   
 105    // create attribute of concept hasParent of type Human inverseOf(hasChild)
 106  0 Attribute attributeParent = human.createAttribute(factory.createIRI(nsDefault, "hasParent"));
 107  0 attributeParent.addType(human);
 108  0 attributeParent.setInverseOf(factory.createIRI(nsDefault, "hasChild"));
 109   
 110    // create atrribute of concept isMarriedTo of type Human symmetric
 111  0 Attribute attributeMarriedTo = human.createAttribute(factory.createIRI(nsDefault, "isMarriedTo"));
 112  0 attributeMarriedTo.addType(human);
 113  0 attributeMarriedTo.setSymmetric(true);
 114  0 attributeMarriedTo.setMinCardinality(0);
 115  0 attributeMarriedTo.setMaxCardinality(1);
 116   
 117    // create a concept man and woman
 118  0 Concept man = factory.createConcept(factory.createIRI(nsDefault, "Man"));
 119  0 man.addSuperConcept(human);
 120  0 Concept woman = factory.createConcept(factory.createIRI(nsDefault, "Woman"));
 121  0 woman.addSuperConcept(human);
 122   
 123    // create a concept Country
 124  0 Concept country = factory.createConcept(factory.createIRI(nsDefault, "Country"));
 125  0 Attribute attributeCountrName = country.createAttribute(factory.createIRI(nsDefault, "hasCountryName"));
 126  0 attributeCountrName.addType(dataFactory.createWsmlDataType(WsmlDataType.WSML_STRING));
 127   
 128    // create relation CitizenOf with parameters Human and Country
 129  0 Relation citizenOf = factory.createRelation(factory.createIRI(nsDefault, "CitizenOf"));
 130  0 Parameter parameterHuman = citizenOf.createParameter((byte) 0);
 131  0 parameterHuman.addType(human);
 132  0 Parameter parameterCountry = citizenOf.createParameter((byte) 1);
 133  0 parameterCountry.addType(country);
 134   
 135    // create Man with name Joe age 28, wife Mary and son Paul
 136  0 Instance joe = factory.createInstance(factory.createIRI(nsDefault, "Joe"), man);
 137  0 joe.addAttributeValue(attributeName.getIdentifier(), dataFactory.createWsmlString("Joe"));
 138  0 joe.addAttributeValue(attributeAge.getIdentifier(), dataFactory.createWsmlInteger("28"));
 139  0 joe.addAttributeValue(attributeChild.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Paul")));
 140  0 joe.addAttributeValue(attributeMarriedTo.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Mary")));
 141   
 142    // create Woman with name Joe age 27, husband Joe and son Paul
 143  0 Instance mary = factory.createInstance(factory.createIRI(nsDefault, "Mary"), woman);
 144  0 mary.addAttributeValue(attributeName.getIdentifier(), dataFactory.createWsmlString("Mary"));
 145  0 mary.addAttributeValue(attributeAge.getIdentifier(), dataFactory.createWsmlInteger("27"));
 146  0 mary.addAttributeValue(attributeChild.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Paul")));
 147  0 mary.addAttributeValue(attributeMarriedTo.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Joe")));
 148   
 149    // create Man with name Paul age 4 and parent Mary and Joe
 150  0 Instance paul = factory.createInstance(factory.createIRI(nsDefault, "Paul"), man);
 151  0 paul.addAttributeValue(attributeName.getIdentifier(), dataFactory.createWsmlString("John"));
 152  0 paul.addAttributeValue(attributeAge.getIdentifier(), dataFactory.createWsmlInteger("4"));
 153  0 paul.addAttributeValue(attributeParent.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Joe")));
 154  0 paul.addAttributeValue(attributeParent.getIdentifier(), factory.getInstance(factory.createIRI(nsDefault, "Mary")));
 155   
 156    // create countries UK, France
 157  0 Instance uk = factory.createInstance(factory.createIRI(nsDefault, "UK"), country);
 158  0 uk.addAttributeValue(attributeCountrName.getIdentifier(), dataFactory.createWsmlString("UK"));
 159  0 Instance france = factory.createInstance(factory.createIRI(nsDefault, "France"), country);
 160  0 france.addAttributeValue(attributeCountrName.getIdentifier(), dataFactory.createWsmlString("France"));
 161   
 162    // Joe would be from UK
 163  0 RelationInstance relInstanceJoe = factory.createRelationInstance(citizenOf);
 164  0 relInstanceJoe.setParameterValue((byte) 0, paul);
 165  0 relInstanceJoe.setParameterValue((byte) 1, uk);
 166   
 167    // Mary from France
 168  0 RelationInstance relInstanceMary = factory.createRelationInstance(citizenOf);
 169  0 relInstanceMary.setParameterValue((byte) 0, mary);
 170  0 relInstanceMary.setParameterValue((byte) 1, france);
 171   
 172    // Paul from UK
 173  0 RelationInstance relInstancePaul = factory.createRelationInstance(citizenOf);
 174  0 relInstancePaul.setParameterValue((byte) 0, joe);
 175  0 relInstancePaul.setParameterValue((byte) 1, uk);
 176   
 177    // add all ontology elements to the ontology
 178  0 ontology.addConcept(human);
 179  0 ontology.addConcept(man);
 180  0 ontology.addConcept(woman);
 181  0 ontology.addConcept(country);
 182  0 ontology.addRelation(citizenOf);
 183  0 ontology.addInstance(joe);
 184  0 ontology.addInstance(mary);
 185  0 ontology.addInstance(paul);
 186  0 ontology.addInstance(uk);
 187  0 ontology.addInstance(france);
 188  0 ontology.addRelationInstance(relInstanceJoe);
 189  0 ontology.addRelationInstance(relInstanceMary);
 190  0 ontology.addRelationInstance(relInstancePaul);
 191   
 192  0 return ontology;
 193    }
 194   
 195  0 public static void main(String[] args) throws InvalidModelException, IOException {
 196  0 Ontology ontology = CreateOntologyExample.showExample();
 197   
 198  0 Serializer serializer = Factory.createSerializer(new HashMap<String, Object>(0));
 199  0 serializer.serialize(new TopEntity[] {ontology}, new PrintWriter(System.out));
 200    }
 201    }
 202   
 203   
 204   
 205    /*
 206    * $Log$
 207    * Revision 1.6 2007/06/06 07:27:54 lcekov
 208    * Add main method to the example
 209    *
 210    * Revision 1.5 2007/06/06 07:15:52 lcekov
 211    * example had compilation errors
 212    *
 213    * Revision 1.4 2007/06/06 06:59:40 lcekov
 214    * This is commit with errors in one of the examples. It should trigger automatic build of wsmo4j project
 215    * Revision 1.3 2006/02/10 14:41:38
 216    * vassil_momtchev examples updated
 217    *
 218    * Revision 1.2 2005/09/23 12:20:42 holgerlausen *** empty log message ***
 219    *
 220    * Revision 1.1 2005/09/19 10:20:22 vassil_momtchev inherite OntologyExample
 221    *
 222    */