viper.descriptors.attributes
Class Attribute

java.lang.Object
  extended byviper.descriptors.attributes.AbstractAttribute
      extended byviper.descriptors.attributes.Attribute
All Implemented Interfaces:
java.lang.Cloneable, Filterable
Direct Known Subclasses:
Attribute_bvalue, Attribute_circle, Attribute_ellipse, Attribute_lvalue, Attribute_number, Attribute_point, Attribute_polygon, Attribute_svalue

public class Attribute
extends AbstractAttribute
implements java.lang.Cloneable, Filterable

This class is used to hold an attribute for a Descriptor. An Attribute is an aspect of an object that is being monitored in a given video file. For example, Attributes of a text object would be a bounding box, the text, the color, etc.


Nested Class Summary
 
Nested classes inherited from class viper.filters.Filterable
Filterable.Rule
 
Field Summary
protected  boolean composition
          This is true iff this Attribute is composed of several.
protected  double compositionTolerance
           
protected  java.lang.String compositionType
           
protected  boolean errors
           
protected  java.lang.Object value
           
 
Constructor Summary
Attribute()
          Create an empty Attribute. toString will return an empty String until more is known.
Attribute(Attribute old)
          Default copy constructor.
Attribute(boolean dynamic)
          Attributes for OBJECT type should use this constructor, with mobile set to true.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this Attribute.
 int compareTo(java.lang.Object o)
          Useful if arranging the set of Attributes using a linked list, I suppose.
static Attribute compose(FrameSpan thisSpan, Attribute thisAttribute, FrameSpan otherSpan, Attribute otherAttribute)
          This composes two Attributes across a set of frames using the composeValues method.
 Filterable.Rule convertRule(java.lang.String unparsedRule, java.util.List unparsedValues, ErrorWriter err)
          This converts a rule into the proper format for the data type.
 Attribute crop(FrameSpan newSpan, FrameSpan oldSpan)
          Get a copy with only the specified framespan filled in.
 java.lang.String getCompositionType()
          Gets the composition type associated with this descriptor.
 java.util.Map getExtraConfig()
          Gets the extra config information.
 AttributeValue getStaticValue()
          Gets the value of this static attribute
 java.lang.String getType()
          Returns the Attribute type, eg lvalue or bbox.
 AttributeValue getValue(FrameSpan span, int frame)
          Gets the value at a specific frame.
 java.util.Iterator getValues(FrameSpan span)
          Gets an iterator over all values at all frames/times, returning ValueSpanobjects.
 java.lang.String getValueToString()
          Gets the string representation of the value.
 org.w3c.dom.Element getXMLFormat(org.w3c.dom.Document root)
          Returns an XML formatted version of this data.
 org.w3c.dom.Element getXMLFormat(org.w3c.dom.Document root, FrameSpan descriptorSpan)
          Gets the xml representation of this attribute.
 boolean isCompositionType(java.lang.String s)
          This allows attributes to define their own composition types in addition to the default ones.
static boolean isType(java.lang.String str)
          Determines if the specified string is a possible Attribute data type.
 boolean isValidRule(java.lang.String rule)
          Tell if a name is a valid rule or not
protected  org.w3c.dom.Element nullXML(org.w3c.dom.Document root)
           
protected  org.w3c.dom.Element nullXML(org.w3c.dom.Document root, FrameSpan span)
           
 java.util.Map parseExtraConfig(java.lang.String value)
          Reads in the extended information string.
 boolean passes(Filterable.Rule rule)
          Since dyanmic attributes need to evaluate rules multiple times, they have their own evaluation that evaluates the rule on the value returned by getValue for each of the frames.
 boolean possibleValueOf(org.w3c.dom.Element E)
          Tests to see if the given DOM element is data that is valid for this attribute.
 boolean possibleValueOf(java.lang.String S)
          Determines if this Attribute can take the value specified.
 void setCompositionType(java.lang.String s)
          Sets the composition type of the attribute.
protected  void setDefaultValue(org.w3c.dom.Element defaultValue)
           
protected  void setDefaultValue(java.lang.String defaultValue)
          Some attributes may have a default value.
 void setExtraConfig(java.util.Map list)
          Sets the extra config information.
 void setFrameSpan(FrameSpan newSpan, FrameSpan oldSpan)
          Changes the framespan of the attribute.
 void setName(java.lang.String S)
          Sets the Attribute name.
static void setOutputWidth(int W)
          Sets the width to crop to when printing out attribute overviews.
 void setStaticValue(AttributeValue v)
          Sets the value of this static attribute.
 void setValue(org.w3c.dom.Element el, FrameSpan span)
          Sets the value of the attribute from the given DOM node.
 void setValue(org.w3c.dom.Element el, FrameSpan span, DescVector neighbors)
          Sets the value of the attribute from the given DOM node.
 void setValue(java.lang.String s)
          Sets the attribute to the given string value.
 void setValue(java.lang.String s, ErrorWriter err, FrameSpan span)
          Sets the Attribute to the value indicated by the String over a given FrameSpan.
 void setValue(java.lang.String s, ErrorWriter err, FrameSpan span, DescVector neighbors)
          Sets the value of this attribute, using the given string.
 java.lang.String toString()
          Gets the string representation of static Attribute data or an individual frame of static data.
 
Methods inherited from class viper.descriptors.attributes.AbstractAttribute
getArchetype, getDefault, getExtraConfigInXML, getExtraConfigString, getName, isDynamic, loadAttributeType, named, named, parseAnInt, resetDefault, setArchetype, setArchetype, setArchetype, setDynamic
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

value

protected java.lang.Object value

errors

protected boolean errors

composition

protected boolean composition
This is true iff this Attribute is composed of several.


compositionType

protected java.lang.String compositionType

compositionTolerance

protected double compositionTolerance
Constructor Detail

Attribute

public Attribute()
Create an empty Attribute. toString will return an empty String until more is known.


Attribute

public Attribute(boolean dynamic)
Attributes for OBJECT type should use this constructor, with mobile set to true. Other Descriptor types can use this with mobile set to false.

Parameters:
dynamic - Descriptor that holds this Attribute is of type OBJECT

Attribute

public Attribute(Attribute old)
Default copy constructor.

Parameters:
old - the attribute to copy
Method Detail

setName

public void setName(java.lang.String S)
Description copied from class: AbstractAttribute
Sets the Attribute name.

Overrides:
setName in class AbstractAttribute
Parameters:
S - The new name.

setOutputWidth

public static void setOutputWidth(int W)
Sets the width to crop to when printing out attribute overviews.

Parameters:
W - the number of characters to allow for attribute summaries

setCompositionType

public final void setCompositionType(java.lang.String s)
                              throws ImproperMetricException
Sets the composition type of the attribute. In order to implement new composition types, a subclass must override isCompositionType and the composition functions.

Parameters:
s - the composition type to use - e.g. "none"
Throws:
ImproperMetricException

getCompositionType

public final java.lang.String getCompositionType()
Gets the composition type associated with this descriptor.

Returns:
the composition type

isCompositionType

public boolean isCompositionType(java.lang.String s)
This allows attributes to define their own composition types in addition to the default ones. The compose (Object, Object) methods of the subclasses should call this one first to see if the superclass can handle the composition.

Parameters:
s - the name of composition type to test
Returns:
true if s is "none" or "first".

getType

public java.lang.String getType()
Description copied from class: AbstractAttribute
Returns the Attribute type, eg lvalue or bbox.

Specified by:
getType in class AbstractAttribute
Returns:
"none"

isType

public static final boolean isType(java.lang.String str)
Determines if the specified string is a possible Attribute data type.

Parameters:
str - The string to be tested.
Returns:
true if the string is a proper data type

compareTo

public final int compareTo(java.lang.Object o)
Useful if arranging the set of Attributes using a linked list, I suppose. Does not perform to spec. That is, only the Attributes name is used in the comparison, not the other data fields.

Parameters:
o - the object to compare with this Attribute
Returns:
the value 0 if the argument Attribute's name is equal to this.name; a value less than 0 if this.name is lexicographically less than the argument; and a value greater than 0 if this.name is lexicographically greater than the argument.name
Throws:
java.lang.ClassCastException

clone

public java.lang.Object clone()
Returns a clone of this Attribute.

Specified by:
clone in class AbstractAttribute
Returns:
a reference to a new Attribute with all the values of the original

compose

public static Attribute compose(FrameSpan thisSpan,
                                Attribute thisAttribute,
                                FrameSpan otherSpan,
                                Attribute otherAttribute)
                         throws UncomposableException
This composes two Attributes across a set of frames using the composeValues method. Depending on how it is implemented, this function might not be comutative.

Parameters:
thisSpan - the span of attribute A
thisAttribute - the value of attribute A
otherSpan - the span of attribute B
otherAttribute - the value of attribute B
Returns:
the composed attribute, if the two attributes may be composed
Throws:
UncomposableException

possibleValueOf

public boolean possibleValueOf(java.lang.String S)
Determines if this Attribute can take the value specified. Relations are not yet supported.

Parameters:
S - the string to be tested
Returns:
whether or not the string is valid

possibleValueOf

public boolean possibleValueOf(org.w3c.dom.Element E)
Tests to see if the given DOM element is data that is valid for this attribute.

Parameters:
E - the data DOM element to test
Returns:
if the element represents a unit of data for this type of attribute

nullXML

protected final org.w3c.dom.Element nullXML(org.w3c.dom.Document root)

nullXML

protected final org.w3c.dom.Element nullXML(org.w3c.dom.Document root,
                                            FrameSpan span)

getXMLFormat

public org.w3c.dom.Element getXMLFormat(org.w3c.dom.Document root)
Description copied from class: AbstractAttribute
Returns an XML formatted version of this data.

Specified by:
getXMLFormat in class AbstractAttribute
Parameters:
root - where to print the data.
Returns:
an xml element representing the attribute or attribute schema

getXMLFormat

public org.w3c.dom.Element getXMLFormat(org.w3c.dom.Document root,
                                        FrameSpan descriptorSpan)
Gets the xml representation of this attribute. Dynamic attributes require the descriptor's span information.

Parameters:
root - the xml root
descriptorSpan - the descriptor's span
Returns:
an element representing this attribute

toString

public java.lang.String toString()
Gets the string representation of static Attribute data or an individual frame of static data.

Returns:
a string in proper format of the data value

setValue

public void setValue(java.lang.String s)
              throws BadDataException
Sets the attribute to the given string value. Use this for static attributes. For dynamic, call another setValue.

Parameters:
s - the attribute value
Throws:
BadDataException

getValue

public AttributeValue getValue(FrameSpan span,
                               int frame)
Gets the value at a specific frame. This is a reference to the internal value, so treat it carefully. Also, not that is may become severed if someone calls the setValue method while you aren't paying attention.

Parameters:
span - The attributes span. Ignored if this is a static attr.
frame - The frame number's data to return. Ignored for static data. Will throw an AIOOBX if the frame isn't inside the span.
Returns:
the value at the specified frame number

getValues

public java.util.Iterator getValues(FrameSpan span)
Gets an iterator over all values at all frames/times, returning ValueSpanobjects.

Parameters:
span - the attributes span
Returns:
Iterator<ValueSpan>

setStaticValue

public void setStaticValue(AttributeValue v)
                    throws BadDataException
Sets the value of this static attribute.

Parameters:
v - the new value
Throws:
BadDataException - if this is a dynamic attribute, or if the data isn't the right type

getStaticValue

public AttributeValue getStaticValue()
Gets the value of this static attribute

Returns:
the value

setFrameSpan

public void setFrameSpan(FrameSpan newSpan,
                         FrameSpan oldSpan)
Changes the framespan of the attribute. Since attributes currently don't have a link to their framespan, requires both the old and new framespans. This only has any affect if the attribute is dynamic, in which case it sets things outside the new framespan to null.

Parameters:
newSpan - the new span
oldSpan - the old span
Throws:
java.lang.IndexOutOfBoundsException - when oldSpan is of inappropriate length

crop

public Attribute crop(FrameSpan newSpan,
                      FrameSpan oldSpan)
Get a copy with only the specified framespan filled in.

Parameters:
newSpan - the new span to crop to
oldSpan - the old span
Returns:
the cropped attribute
Throws:
java.lang.IndexOutOfBoundsException

setValue

public void setValue(java.lang.String s,
                     ErrorWriter err,
                     FrameSpan span)
Sets the Attribute to the value indicated by the String over a given FrameSpan.

Parameters:
s - the string containing the new value for the Attribute
err - where to write errors and warnings
span - the numbers of the beginning and end frame; needed for dynamic attributes

setValue

public void setValue(java.lang.String s,
                     ErrorWriter err,
                     FrameSpan span,
                     DescVector neighbors)
Sets the value of this attribute, using the given string.

Parameters:
s - the value
err - where to write any errors in the value's format
span - the span
neighbors - the enclosing desc vector
See Also:
setValue(String, ErrorWriter, FrameSpan)

setValue

public void setValue(org.w3c.dom.Element el,
                     FrameSpan span,
                     DescVector neighbors)
              throws BadDataException
Sets the value of the attribute from the given DOM node.

Parameters:
el - the attribute dom node to parse
span - the descriptor's frame span
neighbors - the descriptor list
Throws:
BadDataException

setValue

public void setValue(org.w3c.dom.Element el,
                     FrameSpan span)
              throws BadDataException
Sets the value of the attribute from the given DOM node.

Parameters:
el - the attribute dom node to parse
span - the descriptor's frame span
Throws:
BadDataException

isValidRule

public boolean isValidRule(java.lang.String rule)
Description copied from interface: Filterable
Tell if a name is a valid rule or not

Specified by:
isValidRule in interface Filterable
Parameters:
rule - the name of the rule
Returns:
true when it is "==" or "!="

convertRule

public Filterable.Rule convertRule(java.lang.String unparsedRule,
                                   java.util.List unparsedValues,
                                   ErrorWriter err)
                            throws BadDataException
This converts a rule into the proper format for the data type. Each subclass of this class must implement this function if they want to be able to use the rule-based filtering system.

Specified by:
convertRule in interface Filterable
Parameters:
unparsedRule - the rule to convert
unparsedValues - the values
err - the error stream
Returns:
the rule for this attribute
Throws:
BadDataException - if there is an error in the rule or values

passes

public final boolean passes(Filterable.Rule rule)
Since dyanmic attributes need to evaluate rules multiple times, they have their own evaluation that evaluates the rule on the value returned by getValue for each of the frames.

Specified by:
passes in interface Filterable
Parameters:
rule - the rule to test against
Returns:
true if at least one frame's attribute passes the rule.

getValueToString

public java.lang.String getValueToString()
Gets the string representation of the value.

Returns:
the value of the attribute, encoded as a string

setExtraConfig

public void setExtraConfig(java.util.Map list)
                    throws MethodNotSupportedException,
                           BadDataException
Sets the extra config information. It is a map from the first string to the remaining strings.

Parameters:
list - the map
Throws:
MethodNotSupportedException - if the attribute does not entail extended information
BadDataException

getExtraConfig

public java.util.Map getExtraConfig()
Gets the extra config information.

Returns:
an empty map, or a map from extended information names to strings

parseExtraConfig

public java.util.Map parseExtraConfig(java.lang.String value)
                               throws BadDataException
Reads in the extended information string.

Parameters:
value - the extedned information.
Returns:
the extended information map
Throws:
BadDataException

setDefaultValue

protected void setDefaultValue(java.lang.String defaultValue)
                        throws BadDataException
Description copied from class: AbstractAttribute
Some attributes may have a default value. If the type is set, this will check the string using Attributes.isGoodValue(viper.descriptors.attributes.Attribute, java.lang.String).

Specified by:
setDefaultValue in class AbstractAttribute
Parameters:
defaultValue - What to set as the default.
Throws:
BadDataException - if Attributes.isGoodValue returns false.

setDefaultValue

protected void setDefaultValue(org.w3c.dom.Element defaultValue)
                        throws BadDataException,
                               MethodNotSupportedException
Specified by:
setDefaultValue in class AbstractAttribute
Throws:
BadDataException
MethodNotSupportedException