00001 <?php
00016 class SMWConceptValue extends SMWDataValue {
00017
00018 protected function parseUserValue( $value ) {
00019 throw new Exception( 'Concepts cannot be initialised from user-provided strings. This should not happen.' );
00020 }
00021
00027 protected function loadDataItem( SMWDataItem $dataItem ) {
00028 if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONCEPT ) {
00029 $this->m_dataitem = $dataItem;
00030 $this->m_caption = $dataItem->getConceptQuery();
00031 return true;
00032 } else {
00033 return false;
00034 }
00035 }
00036
00037 protected function clear() {
00038 $this->m_dataitem = new SMWDIConcept( '', '', 0, -1, -1, $this->m_typeid );
00039 }
00040
00041 public function getShortWikiText( $linked = null ) {
00042 return $this->m_caption;
00043 }
00044
00045 public function getShortHTMLText( $linker = null ) {
00046 return $this->getShortWikiText( $linker );
00047 }
00048
00049 public function getLongWikiText( $linked = null ) {
00050 if ( !$this->isValid() ) {
00051 return $this->getErrorText();
00052 } else {
00053 return $this->m_caption;
00054 }
00055 }
00056
00057 public function getLongHTMLText( $linker = null ) {
00058 if ( !$this->isValid() ) {
00059 return $this->getErrorText();
00060 } else {
00061 return $this->m_caption;
00062 }
00063 }
00064
00065 public function getWikiValue() {
00067 return str_replace( array( '<', '>', '&' ), array( '<', '>', '&' ), $this->m_dataitem->getConceptQuery() );
00068 }
00069
00074 private function getExportData() {
00075 if ( $this->isValid() ) {
00076 $qp = new SMWQueryParser();
00077 $desc = $qp->getQueryDescription( str_replace( array( '<', '>', '&' ), array( '<', '>', '&' ), $this->m_dataitem->getConceptQuery() ) );
00078 $exact = true;
00079 $owldesc = $this->descriptionToExpData( $desc, $exact );
00080 if ( !$exact ) {
00081 $result = new SMWExpData( new SMWExpResource( '' ) );
00082 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ),
00083 new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Class' ) ) );
00084 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdfs', 'subClassOf' ), $owldesc );
00085 return $result;
00086 } else {
00087 return $owldesc;
00088 }
00089 } else {
00090 return null;
00091 }
00092 }
00093
00094 public function descriptionToExpData( $desc, &$exact ) {
00095 if ( ( $desc instanceof SMWConjunction ) || ( $desc instanceof SMWDisjunction ) ) {
00096 $result = new SMWExpData( new SMWExpResource( '' ) );
00097 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ),
00098 new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Class' ) ) );
00099 $elements = array();
00100 foreach ( $desc->getDescriptions() as $subdesc ) {
00101 $element = $this->descriptionToExpData( $subdesc, $exact );
00102 if ( $element === false ) {
00103 $element = new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Thing' ) );
00104 }
00105 $elements[] = $element;
00106 }
00107 $prop = ( $desc instanceof SMWConjunction ) ? 'intersectionOf':'unionOf';
00108 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', $prop ),
00109 SMWExpData::makeCollection( $elements ) );
00110 } elseif ( $desc instanceof SMWClassDescription ) {
00111 if ( count( $desc->getCategories() ) == 1 ) {
00112 $result = new SMWExpData( SMWExporter::getResourceElement( end( $desc->getCategories() ) ) );
00113 } else {
00114 $result = new SMWExpData( new SMWExpResource( '' ) );
00115 $elements = array();
00116 foreach ( $desc->getCategories() as $cat ) {
00117 $elements[] = new SMWExpData( SMWExporter::getResourceElement( $cat ) ); ;
00118 }
00119 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', 'unionOf' ),
00120 SMWExpData::makeCollection( $elements ) );
00121 }
00122 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ),
00123 new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Class' ) ) );
00124 } elseif ( $desc instanceof SMWConceptDescription ) {
00125 $result = new SMWExpData( SMWExporter::getResourceElement( $desc->getConcept() ) );
00126 } elseif ( $desc instanceof SMWSomeProperty ) {
00127 $result = new SMWExpData( new SMWExpResource( '' ) );
00128 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ),
00129 new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Restriction' ) ) );
00130 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', 'onProperty' ),
00131 new SMWExpData( SMWExporter::getResourceElement( $desc->getProperty() ) ) );
00132 $subdata = $this->descriptionToExpData( $desc->getDescription(), $exact );
00133 if ( ( $desc->getDescription() instanceof SMWValueDescription ) &&
00134 ( $desc->getDescription()->getComparator() == SMW_CMP_EQ ) ) {
00135 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', 'hasValue' ), $subdata );
00136 } else {
00137 if ( $subdata === false ) {
00138 $owltype = SMWExporter::getOWLPropertyType( $desc->getProperty()->getPropertyTypeID() );
00139 if ( $owltype == 'ObjectProperty' ) {
00140 $subdata = new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Thing' ) );
00141 } elseif ( $owltype == 'DatatypeProperty' ) {
00142 $subdata = new SMWExpData( SMWExporter::getSpecialNsResource( 'rdfs', 'Literal' ) );
00143 } else {
00144 return new SMWExpData( SMWExporter::getSpecialNsResource( 'owl', 'Thing' ) );
00145 }
00146 }
00147 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'owl', 'someValuesFrom' ), $subdata );
00148 }
00149 } elseif ( $desc instanceof SMWValueDescription ) {
00150 if ( $desc->getComparator() == SMW_CMP_EQ ) {
00151 $result = SMWExporter::getDataItemExpElement( $desc->getDataItem() );
00152 } else {
00153 $exact = false;
00154 $result = false;
00155 }
00156 } elseif ( $desc instanceof SMWThingDescription ) {
00157 $result = false;
00158 } else {
00159 $result = false;
00160 $exact = false;
00161 }
00162 return $result;
00163 }
00164
00166 public function getConceptText() {
00167 return $this->m_dataitem->getConceptQuery();
00168 }
00169
00171 public function getDocu() {
00172 return $this->m_dataitem->getDocumentation();
00173 }
00174
00176 public function getSize() {
00177 return $this->m_dataitem->getSize();
00178 }
00179
00181 public function getDepth() {
00182 return $this->m_dataitem->getDepth();
00183 }
00184
00186 public function getQueryFeatures() {
00187 return $this->m_dataitem->getQueryFeatures();
00188 }
00189
00190 }