org.universAAL.middleware.context
Class ContextEvent

Package class diagram package ContextEvent
java.lang.Object
  extended by org.universAAL.middleware.rdf.Resource
      extended by org.universAAL.middleware.rdf.FinalizedResource
          extended by org.universAAL.middleware.context.ContextEvent
All Implemented Interfaces:
Event, Matchable

public class ContextEvent
extends FinalizedResource
implements Event

Instances of this class can be used to exchange info about the state of context elements using the model of RDF statements. The subject and the predicate of the RDF statement together identify a context element uniquely and the object of the RDF statement specifies its state at a time provided as a timestamp. Other properties can be used to give more info about the validity and provider of the statement, to name a few.

Author:
mtazari - Saied Tazari

Field Summary
static String CONTEXT_EVENT_URI_PREFIX
           
static String LOCAL_NAME_CONFIDENCE
          The confidence of an inferred value or the probability for its correctness as an integer between 0 and 100 to indicate the probability in terms of percentage; e.g., a reasoner trying to find out what a person is doing at a point in time may provide the percentage of reliability / confidence of the reported activity based on its internal evaluation of the used indications in the inference process.
static String LOCAL_NAME_EXPIRATION_TIME
          An optional property of context events is its expiration time which says until when the reported event can still be considered as valid; after that point in time the value should be considered as unknown until a new event reports a new value or confirms the old one.
static String LOCAL_NAME_OBJECT
           
static String LOCAL_NAME_PREDICATE
           
static String LOCAL_NAME_PROVIDER
          The provider of the contextual info.
static String LOCAL_NAME_SUBJECT
           
static String LOCAL_NAME_TIMESTAMP
          A timestamp, as a Long value to be interpreted as the number of milliseconds from 01.01.1970, will be set automatically as soon as a context provider builds an instance of ContextEvent using the ContextEvent(Resource, String) constructor.
static String MY_URI
           
static String PROP_CONTEXT_CONFIDENCE
           
static String PROP_CONTEXT_EXPIRATION_TIME
           
static String PROP_CONTEXT_PROVIDER
           
static String PROP_CONTEXT_TIMESTAMP
           
static String PROP_RDF_OBJECT
           
static String PROP_RDF_PREDICATE
           
static String PROP_RDF_SUBJECT
           
static String uAAL_CONTEXT_NAMESPACE
           
 
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
ContextEvent(Resource subject, String predicate)
          Construct a CHe stub ContextEvent inferring the object from the predicate which URI is present in the properties of the subject
ContextEvent(String uri)
          This constructor is for the exclusive usage by deserializers.
 
Method Summary
static ContextEvent constructSimpleEvent(String subjectURI, String subjectTypeURI, String predicate, Object object)
          Constructs a CHe stub ContextEvent according to the parameters passed
 Integer getConfidence()
          Get the confidence of the event
 Long getExpirationTime()
          Get the expiration time
 int getPropSerializationType(String propURI)
          Answers if the given property has to be considered when serializing this individual in a minimized way, and if not ignore-able, whether its value should be presented in its full form or can be reduced.
 ContextProvider getProvider()
          Get the ContextProvider of the event
 Object getRDFObject()
          Get the object of the event
 String getRDFPredicate()
          Get the predicate of the event
 Resource getRDFSubject()
          Get the subject of the event
 String getSubjectTypeURI()
          Get the type of the subject of the event
 String getSubjectURI()
          Get the URI of the subject of the event
 Long getTimestamp()
          Get the timestamp of the event
 boolean isWellFormed()
          Returns true, if the state of the resource is valid, otherwise false.
 boolean matches(Matchable subset)
           
 boolean setConfidence(Integer confidence)
          Set the confidence
 boolean setExpirationTime(Long expirationTime)
          Set the expiration time
 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.
 boolean setProvider(ContextProvider src)
          Set the Context Provider
 boolean setRDFObject(Object o)
          Set the object
 boolean setRDFPredicate(String propURI)
          Set the predicate
 boolean setRDFSubject(Resource subj)
          Set the subject
 boolean setTimestamp(Long timestamp)
          Set the timestamp
 
Methods inherited from class org.universAAL.middleware.rdf.FinalizedResource
addType, getLocalName, getNamespace, getProperty, getPropertyURIs, getType, getTypes, getURI, hasQualifiedName, isAnon, numberOfProperties
 
Methods inherited from class org.universAAL.middleware.rdf.Resource
addMultiLangProp, asList, asList, asRDFList, changeProperty, copy, deepCopy, equals, generateAnonURI, getDefaultLang, getFilename, getMultiLangProp, getOrConstructLabel, getResource, getResourceComment, getResourceLabel, getStaticFieldValue, hashCode, hasProperty, isAnon, isBlockingAddingTypes, isClosedCollection, isQualifiedName, literal, 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

uAAL_CONTEXT_NAMESPACE

public static final String uAAL_CONTEXT_NAMESPACE
See Also:
Constant Field Values

MY_URI

public static final String MY_URI
See Also:
Constant Field Values

CONTEXT_EVENT_URI_PREFIX

public static final String CONTEXT_EVENT_URI_PREFIX
See Also:
Constant Field Values

LOCAL_NAME_SUBJECT

public static final String LOCAL_NAME_SUBJECT
See Also:
Constant Field Values

PROP_RDF_SUBJECT

public static final String PROP_RDF_SUBJECT
See Also:
Constant Field Values

LOCAL_NAME_PREDICATE

public static final String LOCAL_NAME_PREDICATE
See Also:
Constant Field Values

PROP_RDF_PREDICATE

public static final String PROP_RDF_PREDICATE
See Also:
Constant Field Values

LOCAL_NAME_OBJECT

public static final String LOCAL_NAME_OBJECT
See Also:
Constant Field Values

PROP_RDF_OBJECT

public static final String PROP_RDF_OBJECT
See Also:
Constant Field Values

LOCAL_NAME_CONFIDENCE

public static final String LOCAL_NAME_CONFIDENCE
The confidence of an inferred value or the probability for its correctness as an integer between 0 and 100 to indicate the probability in terms of percentage; e.g., a reasoner trying to find out what a person is doing at a point in time may provide the percentage of reliability / confidence of the reported activity based on its internal evaluation of the used indications in the inference process. Any number not in range (< 0 || > 100) should be interpreted as 'null'. Confidence is an optional property.

See Also:
Constant Field Values

PROP_CONTEXT_CONFIDENCE

public static final String PROP_CONTEXT_CONFIDENCE
See Also:
Constant Field Values

LOCAL_NAME_PROVIDER

public static final String LOCAL_NAME_PROVIDER
The provider of the contextual info. The middleware is supposed to fill this field with the info provided by a corresponding ContextPublisher at its registration time.

See Also:
Constant Field Values

PROP_CONTEXT_PROVIDER

public static final String PROP_CONTEXT_PROVIDER
See Also:
Constant Field Values

LOCAL_NAME_EXPIRATION_TIME

public static final String LOCAL_NAME_EXPIRATION_TIME
An optional property of context events is its expiration time which says until when the reported event can still be considered as valid; after that point in time the value should be considered as unknown until a new event reports a new value or confirms the old one.

When not set, values reported will remain valid until they are overridden by a more up-to-date event.

See Also:
Constant Field Values

PROP_CONTEXT_EXPIRATION_TIME

public static final String PROP_CONTEXT_EXPIRATION_TIME
See Also:
Constant Field Values

LOCAL_NAME_TIMESTAMP

public static final String LOCAL_NAME_TIMESTAMP
A timestamp, as a Long value to be interpreted as the number of milliseconds from 01.01.1970, will be set automatically as soon as a context provider builds an instance of ContextEvent using the ContextEvent(Resource, String) constructor. However, when the middleware constructs a context event in the course of deserializing a context event using the constructors inherited from Resource, then it can set the timestamp 'manually'.

See Also:
Constant Field Values

PROP_CONTEXT_TIMESTAMP

public static final String PROP_CONTEXT_TIMESTAMP
See Also:
Constant Field Values
Constructor Detail

ContextEvent

public ContextEvent(String uri)
This constructor is for the exclusive usage by deserializers.


ContextEvent

public ContextEvent(Resource subject,
                    String predicate)
Construct a CHe stub ContextEvent inferring the object from the predicate which URI is present in the properties of the subject

Parameters:
subject - The Resource representing the subject of the event. Must include the property specified in the second parameter, and must have a certain value
predicate - The property of the subject that will be used as object in the event
Method Detail

constructSimpleEvent

public static ContextEvent constructSimpleEvent(String subjectURI,
                                                String subjectTypeURI,
                                                String predicate,
                                                Object object)
Constructs a CHe stub ContextEvent according to the parameters passed

Parameters:
subjectURI - URI of the subject. Must not be null.
subjectTypeURI - URI of the subject type. Must not be null.
predicate - URI of the predicate. Must not be null.
object - The object of the event. Must not be null.
Returns:
the ContextEvent.

getConfidence

public Integer getConfidence()
Get the confidence of the event

Returns:
The confidence represented as a percentage (0 to 100)

getExpirationTime

public Long getExpirationTime()
Get the expiration time

Returns:
The amount of milliseconds after reception from which the information in the event is no longer valid

getPropSerializationType

public int getPropSerializationType(String propURI)
Description copied from class: Resource
Answers if the given property has to be considered when serializing this individual in a minimized way, and if not ignore-able, whether its value should be presented in its full form or can be reduced. The return value must be one of Resource.PROP_SERIALIZATION_OPTIONAL, Resource.PROP_SERIALIZATION_REDUCED, or Resource.PROP_SERIALIZATION_FULL. It can be assumed that the given property is one of those returned by Resource.getPropertyURIs().
Decision criterion should be if the value of this property is absolutely necessary when this resource is being sent to a remote node. If the subclass rates it as unlikely that the receiver side would need this info, the answer should be PROP_SERIALIZATION_OPTIONAL in favor of lower communication traffic and higher performance even at risk of a possible additional query on the receiver side for fetching this info. With the same rationale, if a property should be included in the process of serialization, it is preferable to include it in a reduced form; in this case the return value should be PROP_SERIALIZATION_REDUCED, otherwise PROP_SERIALIZATION_FULL can be returned. Subclasses should normally overwrite this method as this default implementation returns always PROP_SERIALIZATION_FULL.

Overrides:
getPropSerializationType in class Resource

getRDFObject

public Object getRDFObject()
Get the object of the event

Returns:
The object of the event (a Resource)

getRDFPredicate

public String getRDFPredicate()
Get the predicate of the event

Returns:
The URI of the predicate of the event

getProvider

public ContextProvider getProvider()
Get the ContextProvider of the event

Returns:
The ContextProvider representing the provider that originated the event

getRDFSubject

public Resource getRDFSubject()
Get the subject of the event

Returns:
The Resource that is the subject to the event

getSubjectTypeURI

public String getSubjectTypeURI()
Get the type of the subject of the event

Returns:
The URI of the type of the subject to the event

getSubjectURI

public String getSubjectURI()
Get the URI of the subject of the event

Returns:
The URI of the individual that is the subject to the event

getTimestamp

public Long getTimestamp()
Get the timestamp of the event

Returns:
The timestamp, in UNIX format, associated to the event

isWellFormed

public boolean isWellFormed()
Description copied from class: Resource
Returns true, if the state of the resource is valid, otherwise false.

Subclasses should overwrite this methods as the default implementation returns always true.

Overrides:
isWellFormed in class Resource

setConfidence

public boolean setConfidence(Integer confidence)
Set the confidence

Parameters:
confidence - The confidence in percentage (0 to 100)

setExpirationTime

public boolean setExpirationTime(Long expirationTime)
Set the expiration time

Parameters:
expirationTime - The amount of millisecond after which the event is not valid afer reception

setRDFObject

public boolean setRDFObject(Object o)
Set the object

Parameters:
o -

setRDFPredicate

public boolean setRDFPredicate(String propURI)
Set the predicate

Parameters:
propURI - The URI of the predicate

setProvider

public boolean setProvider(ContextProvider src)
Set the Context Provider

Parameters:
src -

setRDFSubject

public boolean setRDFSubject(Resource subj)
Set the subject

Parameters:
subj -

setTimestamp

public boolean setTimestamp(Long timestamp)
Set the timestamp

Parameters:
timestamp - The timestamp in UNIX format

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 Resource
Returns:
true if the property changed as a result of the call

matches

public boolean matches(Matchable subset)
Specified by:
matches in interface Matchable
Returns:
true if the other Matchable matches, false if not
See Also:
Currently, this method always returns false.


Copyright © 2014 universAAL Consortium. All Rights Reserved.