Semantic MediaWiki and related extensions
Public Member Functions | Public Attributes | Protected Attributes | Static Protected Attributes | List of all members
SMW\SemanticData Class Reference

Public Member Functions

 __construct (DIWikiPage $subject, $noDuplicates=true)
 
 __sleep ()
 
 getSubject ()
 
 getProperties ()
 
 hasProperty (DIProperty $property)
 
 getPropertyValues (DIProperty $property)
 
 getOption ($key)
 
 setOption ($key, $value)
 
 getErrors ()
 
 addError ($error)
 
 getHash ()
 
 getSubSemanticData ()
 
 clearSubSemanticData ()
 
 hasVisibleProperties ()
 
 hasVisibleSpecialProperties ()
 
 addPropertyObjectValue (DIProperty $property, SMWDataItem $dataItem)
 
 addPropertyValue ($propertyName, SMWDataItem $dataItem)
 
 addDataValue (SMWDataValue $dataValue)
 
 addSubobject (Subobject $subobject)
 
 removePropertyObjectValue (DIProperty $property, SMWDataItem $dataItem)
 
 removeProperty (DIProperty $property)
 
 clear ()
 
 isEmpty ()
 
 importDataFrom (SemanticData $semanticData)
 
 removeDataFrom (SemanticData $semanticData)
 
 hasSubSemanticData ($subobjectName=null)
 
 findSubSemanticData ($subobjectName)
 
 addSubSemanticData (SemanticData $semanticData)
 
 removeSubSemanticData (SemanticData $semanticData)
 

Public Attributes

const OPT_LAST_MODIFIED = 'opt.last.modified'
 
 $stubObject
 
 $subContainerDepthCounter = 0
 

Protected Attributes

 $mPropVals = array()
 
 $mProperties = array()
 
 $mHasVisibleProps = false
 
 $mHasVisibleSpecs = false
 
 $mNoDuplicates
 
 $mSubject
 
 $subSemanticData
 
 $subDataAllowed = true
 
 $errors = array()
 

Static Protected Attributes

static $mPropertyPrefix = ''
 

Detailed Description

Class for representing chunks of semantic data for one given subject. This consists of property-value pairs, grouped by property, and possibly by SMWSemanticData objects about subobjects.

Data about subobjects can be added in two ways: by directly adding it using addSubSemanticData() or by adding a property value of type SMWDIContainer.

By its very design, the container is unable to hold inverse properties. For one thing, it would not be possible to identify them with mere keys. Since SMW cannot annotate pages with inverses, this is not a limitation.

Author
Markus Krötzsch
Jeroen De Dauw

Constructor & Destructor Documentation

SMW\SemanticData::__construct ( DIWikiPage  $subject,
  $noDuplicates = true 
)

Constructor.

Parameters
DIWikiPage$subjectto which this data refers
boolean$noDuplicatesstating if duplicate data should be avoided

Member Function Documentation

SMW\SemanticData::__sleep ( )

This object is added to the parser output of MediaWiki, but it is not useful to have all its data as part of the parser cache since the data is already stored in more accessible format in SMW. Hence this implementation of __sleep() makes sure only the subject is serialised, yielding a minimal stub data container after unserialisation. This is a little safer than serialising nothing: if, for any reason, SMW should ever access an unserialised parser output, then the Semdata container will at least look as if properly initialised (though empty).

Returns
array
SMW\SemanticData::addDataValue ( SMWDataValue  $dataValue)
Since
1.9
Parameters
SMWDataValue$dataValue
SMW\SemanticData::addError (   $error)

Adds an error array

Since
1.9
Returns
array|string
SMW\SemanticData::addPropertyObjectValue ( DIProperty  $property,
SMWDataItem  $dataItem 
)

Store a value for a property identified by its SMWDataItem object.

Note
There is no check whether the type of the given data item agrees with the type of the property. Since property types can change, all parts of SMW are prepared to handle mismatched data item types anyway.
Parameters
$propertyDIProperty
$dataItemSMWDataItem
SMW\SemanticData::addPropertyValue (   $propertyName,
SMWDataItem  $dataItem 
)

Store a value for a given property identified by its text label (without namespace prefix).

Parameters
$propertyNamestring
$dataItemSMWDataItem
SMW\SemanticData::addSubobject ( Subobject  $subobject)
Since
2.1
Parameters
Subobject$subobject
SMW\SemanticData::addSubSemanticData ( SemanticData  $semanticData)
See also
SubSemanticData::addSubSemanticData
Since
1.8
Parameters
SemanticData$semanticData
Exceptions
SubSemanticDataException
SMW\SemanticData::clear ( )

Delete all data other than the subject.

SMW\SemanticData::clearSubSemanticData ( )
Since
2.5
SMW\SemanticData::findSubSemanticData (   $subobjectName)
See also
SubSemanticData::findSubSemanticData
Since
1.9
Parameters
string$subobjectName
Returns
SMWContainerSemanticData|null
SMW\SemanticData::getErrors ( )

Returns collected errors occurred during processing

Since
1.9
Returns
array
SMW\SemanticData::getHash ( )

Generate a hash value to simplify the comparison of this data container with other containers. Subdata is taken into account.

The hash uses PHP's md5 implementation, which is among the fastest hash algorithms that PHP offers.

Note
This function may be used to obtain keys for SemanticData objects or to do simple equality tests. Equal hashes with very high probability indicate equal data.
Returns
string
SMW\SemanticData::getOption (   $key)
Since
2.5
Parameters
string$key
Returns
mixed
SMW\SemanticData::getProperties ( )

Get the array of all properties that have stored values.

Returns
array of DIProperty objects
SMW\SemanticData::getPropertyValues ( DIProperty  $property)

Get the array of all stored values for some property.

Parameters
DIProperty$property
Returns
SMWDataItem[]
SMW\SemanticData::getSubject ( )

Return subject to which the stored semantic annotations refer to.

Returns
DIWikiPage subject
SMW\SemanticData::getSubSemanticData ( )
See also
SubSemanticData::getSubSemanticData
Since
1.8
Returns
ContainerSemanticData[]
SMW\SemanticData::hasProperty ( DIProperty  $property)
Since
2.4
Parameters
DIProperty$property
Returns
boolean
SMW\SemanticData::hasSubSemanticData (   $subobjectName = null)
See also
SubSemanticData::hasSubSemanticData
Since
1.9
Parameters
string$subobjectName,|null
Returns
boolean
SMW\SemanticData::hasVisibleProperties ( )

Return true if there are any visible properties.

Note
While called "visible" this check actually refers to the function DIProperty::isShown(). The name is kept for compatibility.
Returns
boolean
SMW\SemanticData::hasVisibleSpecialProperties ( )

Return true if there are any special properties that can be displayed.

Note
While called "visible" this check actually refers to the function DIProperty::isShown(). The name is kept for compatibility.
Returns
boolean
SMW\SemanticData::importDataFrom ( SemanticData  $semanticData)

Add all data from the given SMWSemanticData. Only works if the imported SMWSemanticData has the same subject as this SMWSemanticData; an exception is thrown otherwise.

Since
1.7
Parameters
SemanticData$semanticDataobject to copy from
Exceptions
SemanticDataImportException
SMW\SemanticData::isEmpty ( )

Return true if this SemanticData is empty. This is the case when the subject has neither property values nor data for subobjects.

Since
1.8
Returns
boolean
SMW\SemanticData::removeDataFrom ( SemanticData  $semanticData)

Removes data from the given SMWSemanticData. If the subject of the data that is to be removed is not equal to the subject of this SMWSemanticData, it will just be ignored (nothing to remove). Likewise, removing data that is not present does not change anything.

Since
1.8
Parameters
SemanticData$semanticData
SMW\SemanticData::removeProperty ( DIProperty  $property)

Removes a property and all the values associated with this property.

Since
2.5
Parameters
$propertyDIProperty
SMW\SemanticData::removePropertyObjectValue ( DIProperty  $property,
SMWDataItem  $dataItem 
)

Remove a value for a property identified by its SMWDataItem object. This method removes a property-value specified by the property and dataitem. If there are no more property-values for this property it also removes the property from the mProperties.

Note
There is no check whether the type of the given data item agrees with the type of the property. Since property types can change, all parts of SMW are prepared to handle mismatched data item types anyway.
Parameters
$propertyDIProperty
$dataItemSMWDataItem
Since
1.8
SMW\SemanticData::removeSubSemanticData ( SemanticData  $semanticData)
See also
SubSemanticData::removeSubSemanticData
Since
1.8
Parameters
SemanticData$semanticData
SMW\SemanticData::setOption (   $key,
  $value 
)
Since
2.5
Parameters
string$key
string$value

Member Data Documentation

SMW\SemanticData::$errors = array()
protected
SMW\SemanticData::$mHasVisibleProps = false
protected
SMW\SemanticData::$mHasVisibleSpecs = false
protected
SMW\SemanticData::$mNoDuplicates
protected
SMW\SemanticData::$mProperties = array()
protected
SMW\SemanticData::$mPropertyPrefix = ''
staticprotected
SMW\SemanticData::$mPropVals = array()
protected
SMW\SemanticData::$mSubject
protected
SMW\SemanticData::$stubObject
SMW\SemanticData::$subContainerDepthCounter = 0
SMW\SemanticData::$subDataAllowed = true
protected

Internal flag that indicates if this semantic data will accept subdata. Semantic data objects that are subdata already do not allow (second level) subdata to be added. This ensures that all data is collected on the top level, and in particular that there is only one way to represent the same data with subdata. This is also useful for diff computation.

SMW\SemanticData::$subSemanticData
protected
const SMW\SemanticData::OPT_LAST_MODIFIED = 'opt.last.modified'

Returns the last modified timestamp the data were stored to the Store or have been fetched from cache.


The documentation for this class was generated from the following file: