1   /*
2    * PropertyImpl.java
3    *
4    * Copyright (c) 2002, The University of Sheffield.
5    *
6    * This file is part of GATE (see http://gate.ac.uk/), and is free
7    * software, licenced under the GNU Library General Public License,
8    * Version 2, June1991.
9    *
10   * A copy of this licence is included in the distribution in the file
11   * licence.html, and is also available at http://gate.ac.uk/gate/licence.html.
12   *
13   * Kalina Bontcheva 11/2003
14   *
15   *
16   *  $Id: PropertyImpl.java,v 1.1 2004/07/23 17:48:08 kalina Exp $
17   */
18  
19   package gate.creole.ontology;
20  
21   import java.util.HashSet;
22  import java.util.Set;
23  
24  public abstract class PropertyImpl implements Property {
25    private String name;
26    private String uri;
27    private OClass domain;
28    private Set samePropertiesSet;
29    private Set superPropertiesSet;
30    private Ontology ontology;
31  
32  
33    public PropertyImpl(String aName, OClass aDomain, Ontology aKB) {
34      this.name = aName;
35      this.domain = aDomain;
36      this.ontology = aKB;
37      samePropertiesSet = new HashSet();
38      superPropertiesSet = new HashSet();
39    }
40  
41    public String getName() {
42      return name;
43    }
44  
45    public String getURI() {
46      return uri;
47    }
48  
49    public void setURI(String theURI) {
50      uri = theURI;
51    }
52  
53    public void setSamePropertyAs(Property theProperty) {
54      this.samePropertiesSet.add(theProperty);
55    }
56  
57    public Set getSamePropertyAs() {
58      if (this.samePropertiesSet.isEmpty() &&
59          ! this.getOntology().getPropertyDefinitions().contains(this)) {
60        Property propDefinition =
61          this.getOntology().getPropertyDefinitionByName(this.name);
62        if (propDefinition == null)
63          return this.samePropertiesSet;
64        else
65          return propDefinition.getSamePropertyAs();
66      }
67      return this.samePropertiesSet;
68    }
69  
70    public void setSubPropertyOf(String propertyName) {
71      this.superPropertiesSet.add(propertyName);
72    }
73  
74    public Set getSubPropertyOf() {
75      if (this.superPropertiesSet.isEmpty() &&
76          ! this.getOntology().getPropertyDefinitions().contains(this)) {
77        Property propDefinition =
78          this.getOntology().getPropertyDefinitionByName(this.name);
79        if (propDefinition == null)
80          return this.superPropertiesSet;
81        else
82          return propDefinition.getSubPropertyOf();
83      }
84      return this.superPropertiesSet;
85    }
86  
87    public OClass getDomain() {
88      return this.domain;
89    }
90  
91    public Ontology getOntology() {
92      return this.ontology;
93    }
94  
95    public String toString() {
96      return this.getName() + "(" + this.domain + ")" + "\n sub-propertyOf "
97              + this.getSubPropertyOf().toString() + "\n samePropertyAs " +
98              this.getSamePropertyAs().toString();
99    }
100 }