答案 0 :(得分:2)
您也可以使用https://github.com/vedmaka/SemanticQueryInterface - 它是SMW内部API的包装器,允许您执行以下操作:
$results = $sqi->condition("My property", "My value")->toArray();
在https://www.mediawiki.org/wiki/User:Vedmaka/Semantic_Query_Interface
了解详情答案 1 :(得分:0)
通过查看Semantic Title扩展程序的方式,我能够编写一个函数来执行我需要的操作:
/**
* Given a wiki page DB key and a Semantic MediaWiki property name, get
* the value for that page.
*
* Remarks: Assumes that the property is of type "string" or "blob", and that
* there is only one value for that page/property combination.
*
* @param string $dbKey The MediaWiki DB key for the page (i.e., "Test_Page")
* @param string $propertyLabel The property label used to set the Semantic MediaWiki property
* @return string The property value, or NULL if none exists
*/
static function getSemanticProperty($dbKey, $propertyLabel) {
// Use Semantic MediaWiki code to properly retrieve the value
$page = SMWDIWikiPage::newFromTitle( Title::newFromDBkey($dbKey) );
$store = \SMW\StoreFactory::getStore();
$data = $store->getSemanticData( $page );
$property = SMWDIProperty::newFromUserLabel( $propertyLabel );
$values = $data->getPropertyValues( $property );
if (count($values) > 0) {
$value = array_shift( $values );
if ( $value->getDIType() == SMWDataItem::TYPE_STRING ||
$value->getDIType() == SMWDataItem::TYPE_BLOB ) {
return $value->getString();
}
} else {
return null;
}
}