org.universAAL.middleware.owl
Class MergedRestriction

Package class diagram package MergedRestriction
java.lang.Object
  extended by org.universAAL.middleware.rdf.Resource
      extended by org.universAAL.middleware.owl.TypeExpression
          extended by org.universAAL.middleware.owl.Intersection
              extended by org.universAAL.middleware.owl.MergedRestriction

public final class MergedRestriction
extends Intersection

Helper class to handle multiple PropertyRestrictions of the same property.

There is often more than one restriction for a specific property, e.g. a minimum cardinality restriction and a maximum cardinality restriction. All these restrictions must be specified separately by an instance of PropertyRestriction. This class helps to manage multiple restrictions for the same property.

NOTE: If you add this class to another Resource with setProperty(String, Object), it will behave like an Intersection of the restrictions contained in this MergedRestriction.

Author:
Carsten Stockloew

Field Summary
static int allValuesFromID
          ID of the AllValuesFromRestriction.
static int exactCardinalityID
          ID of the ExactCardinalityRestriction.
static int hasValueID
          ID of the HasValueRestriction.
static int MAX_UNDEFINED
          The value of maximum cardinality if not defined.
static int maxCardinalityID
          ID of the MaxCardinalityRestriction.
static int MIN_UNDEFINED
          The value of minimum cardinality if not defined.
static int minCardinalityID
          ID of the MinCardinalityRestriction.
static String MY_URI
           
static int someValuesFromID
          ID of the SomeValuesFromRestriction.
 
Fields inherited from class org.universAAL.middleware.owl.Intersection
PROP_OWL_INTERSECTION_OF, types
 
Fields inherited from class org.universAAL.middleware.owl.TypeExpression
EXCEPTION_TTL, OWL_CLASS, OWL_NAMESPACE, PROP_RDFS_SUB_CLASS_OF, RDFS_DATATYPE, TYPE_OWL_THING
 
Fields inherited from class org.universAAL.middleware.rdf.Resource
ANON_URI_PREFIX, blockAddingTypes, isXMLLiteral, ns_delim_index, PROP_RDF_FIRST, PROP_RDF_REST, PROP_RDF_TYPE, PROP_RDFS_COMMENT, PROP_RDFS_LABEL, PROP_SERIALIZATION_FULL, PROP_SERIALIZATION_OPTIONAL, PROP_SERIALIZATION_REDUCED, PROP_SERIALIZATION_UNDEFINED, PROP_uAAL_INVOLVED_HUMAN_USER, props, RDF_EMPTY_LIST, RDF_NAMESPACE, RDFS_NAMESPACE, TYPE_RDF_LIST, TYPE_RDFS_CLASS, uAAL_NAMESPACE_PREFIX, uAAL_SERVICE_NAMESPACE, uAAL_VOCABULARY_NAMESPACE, uri
 
Constructor Summary
MergedRestriction()
          Constructor for deserializers.
MergedRestriction(String onProperty)
          Constructor for an empty set of restrictions.
MergedRestriction(String onProperty, ArrayList restrictions)
          Constructor with a given initial set of restrictions.
 
Method Summary
 MergedRestriction addRestriction(MergedRestriction r)
          Add all restrictions of the given MergedRestriction, performing a sanity check.
 MergedRestriction addRestriction(PropertyRestriction res)
          Add a new Restriction, performing a sanity check.
 boolean addRestrictionCheck(PropertyRestriction res)
          Add a new Restriction, performing a sanity check.
 MergedRestriction appendTo(MergedRestriction root, String[] path)
          Appends this restriction to the given root restriction on the given property path.
 TypeExpression copy()
          Create a copy of this object, i.e. create a new object of this class and copy the necessary properties.
 MergedRestriction copyOnNewProperty(String onProp)
          Create a new MergedRestriction with modified onProperty value.
 MergedRestriction copyWithNewCardinality(int min, int max)
          Create a new MergedRestriction with modified cardinality restrictions.
static MergedRestriction getAllValuesRestriction(String propURI, String typeURI)
           Create a new restriction to state that for all individuals of a certain class the value of the given property is of type typeURI.
static MergedRestriction getAllValuesRestriction(String propURI, TypeExpression expr)
           Create a new restriction to state that for all individuals of a certain class the value of the given property is of type expr.
static MergedRestriction getAllValuesRestrictionWithCardinality(String propURI, String typeURI, int min, int max)
           Create a new restriction to state that for all individuals of a certain class the cardinality of the given property is at least min and at most max and the value of the given property is of type typeURI.
static MergedRestriction getAllValuesRestrictionWithCardinality(String propURI, TypeExpression expr, int min, int max)
           Create a new restriction to state that for all individuals of a certain class the cardinality of the given property is at least min and at most max and the value of the given property is of type expr.
static MergedRestriction getCardinalityRestriction(String propURI, int min, int max)
           Create a new restriction to state that for all individuals of a certain class the cardinality of the given property is at least min and at most max.
 Object getConstraint(int id)
          Get the constraint of a specific restriction, e.g. the minimum cardinality for MinCardinalityRestriction.
 Object[] getEnumeratedValues()
          Get the set of instances.
static MergedRestriction getFixedValueRestriction(String propURI, Object value)
           Create a new restriction to state that all individuals of a certain class must have the given value for the given property.
static ArrayList getFromList(List o)
          Get a list of MergedRestrictions from the specified list which may contain restrictions for different properties.
 int getMaxCardinality()
          Get the maximum cardinality, if this object specifies one.
 int getMinCardinality()
          Get the minimum cardinality, if this object specifies one.
 String getOnProperty()
           
static MergedRestriction getPropertyBanningRestriction(String propURI)
           Create a new restriction to state that no individual of a certain class has the given property, i.e. the maximum cardinality of the given property is zero.
 String getPropTypeURI()
          If this MergedRestriction restricts the values of a property to be individuals of a specific class (i.e. an AllValuesFromRestriction of a either a TypeURI or a BoundedValueRestriction), then return the URI of this class.
 PropertyRestriction getRestriction(int id)
          Get a specific PropertyRestriction.
 MergedRestriction getRestrictionOnPath(String[] path)
          Get a MergedRestriction of a property path previously set by appendTo(MergedRestriction, String[])
 List getRestrictions()
          Get all PropertyRestrictions.
 boolean hasMemberIgnoreCardinality(Object o)
          Returns true if the given object is a member of the class represented by this class expression, otherwise false; cardinality restrictions are ignored.
 boolean isWellFormed()
          Returns true, if the state of the resource is valid, otherwise false.
 MergedRestriction merge(MergedRestriction other)
          Create a new MergedRestriction that is a combination of this restriction and the given restriction.
 boolean setProperty(String propURI, Object value)
          Adds a statement with this resource as the subject, the given propURI as the predicate and the given value as the object.
 Iterator types()
          Get an iterator for the added child class expressions.
 
Methods inherited from class org.universAAL.middleware.owl.Intersection
addType, elements, getNamedSuperclasses, getUpperEnumeration, hasMember, isDisjointWith, matches, size
 
Methods inherited from class org.universAAL.middleware.owl.TypeExpression
checkTTL, collectTypesMinimized, getDefaultMatchmakingTTL, hasMember, hasMember, isDisjointWith, isDisjointWith, matches, matches, synchronize
 
Methods inherited from class org.universAAL.middleware.rdf.Resource
addMultiLangProp, addType, asList, asList, asRDFList, changeProperty, copy, deepCopy, equals, generateAnonURI, getDefaultLang, getFilename, getLocalName, getMultiLangProp, getNamespace, getOrConstructLabel, getProperty, getPropertyURIs, getPropSerializationType, getResource, getResourceComment, getResourceLabel, getStaticFieldValue, getType, getTypes, getURI, hashCode, hasProperty, hasQualifiedName, isAnon, isAnon, isBlockingAddingTypes, isClosedCollection, isQualifiedName, literal, numberOfProperties, representsQualifiedURI, serializesAsXMLLiteral, setPropertyPath, setPropertyPath, setPropertyPathFromOffset, setResourceComment, setResourceLabel, toString, toStringRecursive, toStringRecursive, unliteral
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MY_URI

public static final String MY_URI
See Also:
Constant Field Values

MIN_UNDEFINED

public static final int MIN_UNDEFINED
The value of minimum cardinality if not defined.

See Also:
Constant Field Values

MAX_UNDEFINED

public static final int MAX_UNDEFINED
The value of maximum cardinality if not defined.

See Also:
Constant Field Values

allValuesFromID

public static final int allValuesFromID
ID of the AllValuesFromRestriction. Only used in the context of this class.

See Also:
Constant Field Values

someValuesFromID

public static final int someValuesFromID
ID of the SomeValuesFromRestriction. Only used in the context of this class.

See Also:
Constant Field Values

hasValueID

public static final int hasValueID
ID of the HasValueRestriction. Only used in the context of this class.

See Also:
Constant Field Values

minCardinalityID

public static final int minCardinalityID
ID of the MinCardinalityRestriction. Only used in the context of this class.

See Also:
Constant Field Values

maxCardinalityID

public static final int maxCardinalityID
ID of the MaxCardinalityRestriction. Only used in the context of this class.

See Also:
Constant Field Values

exactCardinalityID

public static final int exactCardinalityID
ID of the ExactCardinalityRestriction. Only used in the context of this class.

See Also:
Constant Field Values
Constructor Detail

MergedRestriction

public MergedRestriction()
Constructor for deserializers.


MergedRestriction

public MergedRestriction(String onProperty)
Constructor for an empty set of restrictions. Restrictions can be added by calling addRestriction(PropertyRestriction) or addRestriction(MergedRestriction).

Parameters:
onProperty - The property for which this restriction is defined.

MergedRestriction

public MergedRestriction(String onProperty,
                         ArrayList restrictions)
Constructor with a given initial set of restrictions.

Parameters:
onProperty - The property for which this restriction is defined.
restrictions - The initial set of restrictions. The array must contain only instances of PropertyRestriction.
Method Detail

getPropertyBanningRestriction

public static final MergedRestriction getPropertyBanningRestriction(String propURI)

Create a new restriction to state that no individual of a certain class has the given property, i.e. the maximum cardinality of the given property is zero.

The new MergedRestriction contains

Parameters:
propURI - The property for which this restriction is defined.
Returns:
the restriction, or null if the parameters are invalid.

getFixedValueRestriction

public static final MergedRestriction getFixedValueRestriction(String propURI,
                                                               Object value)

Create a new restriction to state that all individuals of a certain class must have the given value for the given property.

The new MergedRestriction contains

Parameters:
propURI - The property for which this restriction is defined.
value - The value that the given property must have. If this value is a String that contains a valid URI, then the value must be a Resource with this URI.
Returns:
the restriction, or null if the parameters are invalid.

getCardinalityRestriction

public static final MergedRestriction getCardinalityRestriction(String propURI,
                                                                int min,
                                                                int max)

Create a new restriction to state that for all individuals of a certain class the cardinality of the given property is at least min and at most max.

The new MergedRestriction contains

Parameters:
propURI - The property for which this restriction is defined.
min - The minimum cardinality, or 0 if undefined.
max - The maximum cardinality, or -1 if undefined.
Returns:
the restriction, or null if the parameters are invalid.

getAllValuesRestrictionWithCardinality

public static final MergedRestriction getAllValuesRestrictionWithCardinality(String propURI,
                                                                             String typeURI,
                                                                             int min,
                                                                             int max)

Create a new restriction to state that for all individuals of a certain class the cardinality of the given property is at least min and at most max and the value of the given property is of type typeURI.

The new MergedRestriction contains

Parameters:
propURI - The property for which this restriction is defined.
min - The minimum cardinality, or 0 if undefined.
max - The maximum cardinality, or -1 if undefined.
typeURI - URI of the type of values for this property.
Returns:
the restriction, or null if the parameters are invalid.

getAllValuesRestrictionWithCardinality

public static final MergedRestriction getAllValuesRestrictionWithCardinality(String propURI,
                                                                             TypeExpression expr,
                                                                             int min,
                                                                             int max)

Create a new restriction to state that for all individuals of a certain class the cardinality of the given property is at least min and at most max and the value of the given property is of type expr.

The new MergedRestriction contains

Parameters:
propURI - The property for which this restriction is defined.
min - The minimum cardinality, or 0 if undefined.
max - The maximum cardinality, or -1 if undefined.
expr - The type of values for this property.
Returns:
the restriction, or null if the parameters are invalid.

getAllValuesRestriction

public static final MergedRestriction getAllValuesRestriction(String propURI,
                                                              String typeURI)

Create a new restriction to state that for all individuals of a certain class the value of the given property is of type typeURI.

The new MergedRestriction contains

Parameters:
propURI - The property for which this restriction is defined.
typeURI - The type of values of the property.
Returns:
the restriction, or null if the parameters are invalid.

getAllValuesRestriction

public static final MergedRestriction getAllValuesRestriction(String propURI,
                                                              TypeExpression expr)

Create a new restriction to state that for all individuals of a certain class the value of the given property is of type expr.

The new MergedRestriction contains

Parameters:
propURI - The property for which this restriction is defined.
expr - The type of values of the property.
Returns:
the restriction, or null if the parameters are invalid.

getFromList

public static ArrayList getFromList(List o)
Get a list of MergedRestrictions from the specified list which may contain restrictions for different properties. For each property, there exists exactly one MergedRestriction in the returned list.

Parameters:
o - The list of PropertyRestrictions. Elements of this list that are not instances of PropertyRestriction are ignored. Restrictions can be defined for different properties.
Returns:
The list of MergedRestriction.

getMinCardinality

public int getMinCardinality()
Get the minimum cardinality, if this object specifies one. The minimum cardinality can be specified be either a MinCardinalityRestriction or an ExactCardinalityRestriction.

Returns:
the minimum cardinality, or 0 if no minimum cardinality is specified.

getMaxCardinality

public int getMaxCardinality()
Get the maximum cardinality, if this object specifies one. The maximum cardinality can be specified be either a MaxCardinalityRestriction or an ExactCardinalityRestriction.

Returns:
the maximum cardinality, or -1 if no maximum cardinality is specified.

getConstraint

public Object getConstraint(int id)
Get the constraint of a specific restriction, e.g. the minimum cardinality for MinCardinalityRestriction. This method calls PropertyRestriction.getConstraint(); the return value depends on the individual restriction.

Parameters:
id - ID of the restriction.
Returns:
The constraint of the restriction.

getRestrictions

public List getRestrictions()
Get all PropertyRestrictions. The list is backed by the MergedRestriction, so changes to the MergedRestriction are reflected in the list.

Returns:
an unmodifiable list of restrictions.

getRestriction

public PropertyRestriction getRestriction(int id)
Get a specific PropertyRestriction.

Parameters:
id - ID of the property restriction.
Returns:
the property restriction.

addRestriction

public MergedRestriction addRestriction(PropertyRestriction res)
Add a new Restriction, performing a sanity check. It is not guaranteed that the given restriction will really be added, e.g. when this MergedRestriction already has a MinCardinalityRestriction and a MaxCardinalityRestriction with the same value is added, then the MinCardinalityRestriction is removed and an ExactCardinalityRestriction is added instead.

Parameters:
res - The Restriction to add.
Returns:
this restriction. This object is returned to allow for multiple calls of this method.
Throws:
IllegalArgumentException - If the given restriction is defined for a different property than this merged restriction.

addRestrictionCheck

public boolean addRestrictionCheck(PropertyRestriction res)
Add a new Restriction, performing a sanity check. It is not guaranteed that the given restriction will really be added, e.g. when this MergedRestriction already has a MinCardinalityRestriction and a MaxCardinalityRestriction with the same value is added, then the MinCardinalityRestriction is removed and an ExactCardinalityRestriction is added instead.

Parameters:
res - The Restriction to add.
Returns:
true, if the restriction could be added, i.e. the underlying list of restrictions has changed.
Throws:
IllegalArgumentException - If the given restriction is defined for a different property than this merged restriction.

addRestriction

public MergedRestriction addRestriction(MergedRestriction r)
Add all restrictions of the given MergedRestriction, performing a sanity check. It is not guaranteed that the given restriction will really be added, e.g. when this MergedRestriction already has a MinCardinalityRestriction and a MaxCardinalityRestriction with the same value is added, then the MinCardinalityRestriction is removed and an ExactCardinalityRestriction is added instead.

Parameters:
r - The restriction to add.
Returns:
this restriction. This object is returned to allow for multiple calls of this method.

copy

public TypeExpression copy()
Description copied from class: TypeExpression
Create a copy of this object, i.e. create a new object of this class and copy the necessary properties.

Overrides:
copy in class Intersection
Returns:
The newly created copy.
See Also:
TypeExpression.copy()

copyWithNewCardinality

public MergedRestriction copyWithNewCardinality(int min,
                                                int max)
Create a new MergedRestriction with modified cardinality restrictions.

Parameters:
min - The new value for MinCardinalityRestriction.
max - The new value for MaxCardinalityRestriction.
Returns:
The new MergedRestriction.

copyOnNewProperty

public MergedRestriction copyOnNewProperty(String onProp)
Create a new MergedRestriction with modified onProperty value.

Parameters:
onProp - The new URI of the property this restriction is defined for.
Returns:
the new MergedRestriction which contains all simple restrictions of this class, but is defined for a different property.

isWellFormed

public boolean isWellFormed()
Description copied from class: TypeExpression
Returns true, if the state of the resource is valid, otherwise false. Redefined in this class as abstract to force subclasses to override it.

Overrides:
isWellFormed in class Intersection
See Also:
TypeExpression.isWellFormed()

setProperty

public boolean setProperty(String propURI,
                           Object value)
Description copied from class: Resource
Adds a statement with this resource as the subject, the given propURI as the predicate and the given value as the object. Subclasses must override this in order to decide if the statement to be added fits the general class constraints. If not, the call of this method should be ignored. For each property only one single call may be made to this method, unless subsequent calls to this method for setting the value of the same property are treated as an update for an update-able property. Multi-valued properties must be set using an instance of List. The differentiation, if a such list should be treated as an rdf:List, can be made with the help of Resource.isClosedCollection(String). The default implementation here accepts all property-value pairs blindly except for rdf:type which is handled if the value is a type URI, a Resource or a java.util.List of them.

Note: The setting of the property rdf:type is being handled by this class via the final methods Resource.addType(String, boolean), Resource.getType(), and Resource.getTypes(). Although these methods give the view of handling type URIs as strings, but in reality the types are stored as direct instances of this class. So, the subclasses should ignore calls for setting rdf:type; if not, then the subclass must pay attention that the value should be a List of direct instances of this class so that (1) the Resource.toString() method returns just the URI and (2) the serializers get no problems with the value. Also, settings via subclasses may be overwritten by this class if a subsequent call to Resource.addType(String, boolean) is made.

Overrides:
setProperty in class Intersection
Returns:
true if the property changed as a result of the call
See Also:
Resource.setProperty(String, Object)

types

public Iterator types()
Get an iterator for the added child class expressions.

Overrides:
types in class Intersection

getPropTypeURI

public String getPropTypeURI()
If this MergedRestriction restricts the values of a property to be individuals of a specific class (i.e. an AllValuesFromRestriction of a either a TypeURI or a BoundedValueRestriction), then return the URI of this class.

Returns:
The URI of the class the property must be an individual of.

getOnProperty

public String getOnProperty()

appendTo

public MergedRestriction appendTo(MergedRestriction root,
                                  String[] path)
Appends this restriction to the given root restriction on the given property path.

Parameters:
root - The root restriction for the first element of the property path. Can be null.
path - The property path.
Returns:
null if the parameters are invalid because of either
  • path is null
  • path is empty
  • the onProperty of this object is not set
  • the onProperty does not match the last element of the path
  • the onProperty of root does not match the first element of the path
a MergedRestriction()that is either
  • this if root is null and the length of path is one
  • a modified root (or a new MergedRestriction() if root is null) otherwise

getRestrictionOnPath

public MergedRestriction getRestrictionOnPath(String[] path)
Get a MergedRestriction of a property path previously set by appendTo(MergedRestriction, String[])

Parameters:
path - The property path.
Returns:
The MergedRestriction that is defined for the last element of the property path

getEnumeratedValues

public Object[] getEnumeratedValues()
Get the set of instances.

Returns:
an array of all known instances.

merge

public MergedRestriction merge(MergedRestriction other)
Create a new MergedRestriction that is a combination of this restriction and the given restriction. If some parts are defined in both restrictions, then the parts from other will be preferred.

Parameters:
other - The restriction to merge with
Returns:

null if this restriction is not fully defined (has no onProperty).

this if the onProperty of this object does not match the onProperty of the given object.

A new MergedRestriction that combines all PropertyRestrictions of this object and the given object.


hasMemberIgnoreCardinality

public boolean hasMemberIgnoreCardinality(Object o)
Returns true if the given object is a member of the class represented by this class expression, otherwise false; cardinality restrictions are ignored.

Parameters:
o - The object to test for membership.
Returns:
true, if the given object is a member of this class expression.


Copyright © 2014 universAAL Consortium. All Rights Reserved.