本文整理汇总了PHP中SMWQuery类的典型用法代码示例。如果您正苦于以下问题:PHP SMWQuery类的具体用法?PHP SMWQuery怎么用?PHP SMWQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SMWQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStringFrom
/**
* Generate textual debug output that shows an arbitrary list of informative
* fields. Used for formatting query debug output.
*
* @note All strings given must be usable and safe in wiki and HTML
* contexts.
*
* @param $storeName string name of the storage backend for which this is generated
* @param $entries array of name => value of informative entries to display
* @param $query SMWQuery or null, if given add basic data about this query as well
*
* @return string
*/
public static function getStringFrom($storeName, array $entries, Query $query = null)
{
if ($query instanceof Query) {
$preEntries = array();
$preEntries['ASK Query'] = '<div class="smwpre">' . str_replace('[', '[', $query->getDescription()->getQueryString()) . '</div>';
$entries = array_merge($preEntries, $entries);
$entries['Query Metrics'] = 'Query-Size:' . $query->getDescription()->getSize() . '<br />' . 'Query-Depth:' . $query->getDescription()->getDepth();
$errors = '';
$queryErrors = ProcessingErrorMsgHandler::normalizeMessages($query->getErrors());
foreach ($queryErrors as $error) {
$errors .= $error . '<br />';
}
if ($errors === '') {
$errors = 'None';
}
$entries['Errors and Warnings'] = $errors;
}
$result = '<div style="border: 5px dotted #ffcc00; background: #FFF0BD; padding: 20px; ">' . "<div class='smw-column-header'><big>{$storeName} debug output</big></div>";
foreach ($entries as $header => $information) {
$result .= "<div class='smw-column-header'>{$header}</div>";
if ($information !== '') {
$result .= "{$information}";
}
}
$result .= '</div>';
return $result;
}
示例2: formatOutputFor
/**
* Generate textual debug output that shows an arbitrary list of informative
* fields. Used for formatting query debug output.
*
* @note All strings given must be usable and safe in wiki and HTML
* contexts.
*
* @param $storeName string name of the storage backend for which this is generated
* @param $entries array of name => value of informative entries to display
* @param $query SMWQuery or null, if given add basic data about this query as well
*
* @return string
*/
public static function formatOutputFor($storeName, array $entries, Query $query = null)
{
if ($query instanceof Query) {
$preEntries = array();
$preEntries['Ask query'] = '<div class="smwpre">' . str_replace('[', '[', $query->getDescription()->getQueryString()) . '</div>';
$entries = array_merge($preEntries, $entries);
$entries['Query Metrics'] = 'Query-Size:' . $query->getDescription()->getSize() . '<br />' . 'Query-Depth:' . $query->getDescription()->getDepth();
$errors = '';
foreach ($query->getErrors() as $error) {
$errors .= $error . '<br />';
}
if ($errors === '') {
$errors = 'None';
}
$entries['Errors and Warnings'] = $errors;
}
$result = '<div style="border: 5px dotted #A1FB00; background: #FFF0BD; padding: 20px; ">' . "<h3>Debug Output by {$storeName}</h3>";
foreach ($entries as $header => $information) {
$result .= "<h4>{$header}</h4>";
if ($information !== '') {
$result .= "{$information}";
}
}
$result .= '</div>';
return $result;
}
示例3: addQueryData
/**
* Add data about the query and its parameters to the semantic data of
* the given parser. The $queryKey is a string key that uniquely
* identifies the query; this is difficult to create in a stable way
* from the processed query object and parameters, but easy to get from
* the raw user input.
*
* @param string $queryKey
* @param SMWQuery $query
* @param array $params
* @param Parser $parser
*
* @since 1.8
*/
public static function addQueryData($queryKey, SMWQuery $query, array $params, Parser $parser)
{
$mainSemanticData = SMWParseData::getSMWData($parser);
$subject = $mainSemanticData->getSubject();
$diSubWikiPage = new SMWDIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), "_QUERY" . $queryKey);
$semanticData = new SMWContainerSemanticData($diSubWikiPage);
$description = $query->getDescription();
// Add query string
$propertyDi = new SMWDIProperty('_ASKST');
$valueDi = new SMWDIBlob($description->getQueryString());
$semanticData->addPropertyObjectValue($propertyDi, $valueDi);
// Add query size
$propertyDi = new SMWDIProperty('_ASKSI');
$valueDi = new SMWDINumber($description->getSize());
$semanticData->addPropertyObjectValue($propertyDi, $valueDi);
// Add query depth
$propertyDi = new SMWDIProperty('_ASKDE');
$valueDi = new SMWDINumber($description->getDepth());
$semanticData->addPropertyObjectValue($propertyDi, $valueDi);
// Add query format
$propertyDi = new SMWDIProperty('_ASKFO');
$valueDi = new SMWDIString($params['format']->getValue());
$semanticData->addPropertyObjectValue($propertyDi, $valueDi);
$propertyDi = new SMWDIProperty('_ASK');
$subObjectDi = new SMWDIContainer($semanticData);
SMWParseData::getSMWData($parser)->addPropertyObjectValue($propertyDi, $subObjectDi);
}
示例4: testGetImmediateEmptyQueryResultForLimitLessThanOne
public function testGetImmediateEmptyQueryResultForLimitLessThanOne()
{
$connection = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock();
$this->store->expects($this->never())->method('getConnection')->will($this->returnValue($connection));
$this->querySegmentListBuilder->expects($this->any())->method('getErrors')->will($this->returnValue(array()));
$description = $this->getMockForAbstractClass('\\SMW\\Query\\Language\\Description');
$instance = new QueryEngine($this->store, $this->querySegmentListBuilder, $this->querySegmentListProcessor, $this->engineOptions);
$query = new Query($description);
$query->setUnboundLimit(-1);
$this->assertInstanceOf('\\SMWQueryResult', $instance->getQueryResult($query));
}
示例5: enableNotify
/**
* Enable a NotifyMe with specified id and querystring
*
* used for inline query only
*/
static public function enableNotify( $notify_id, $querystring, &$msg = NULL ) {
wfProfileIn( 'SMWNotifyProcessor::enableNotify (SMW)' );
$sStore = NMStorage::getDatabase();
global $smwgQDefaultNamespaces;
SMWQueryProcessor::processFunctionParams( SMWNotifyProcessor::getQueryRawParams( $querystring ), $querystring, $params, $printouts );
$relatedArticles = array();
foreach ( $printouts as $po ) {
$printoutArticles[] = array(
'namespace' => SMW_NS_PROPERTY,
'title' => Title::makeTitle( SMW_NS_PROPERTY, $po->getText( SMW_OUTPUT_WIKI ) )->getDBkey() );
}
$qp = new SMWNotifyParser( $notify_id, $printoutArticles );
$qp->setDefaultNamespaces( $smwgQDefaultNamespaces );
$desc = $qp->getQueryDescription( $querystring );
if ( !$qp->m_result ) {
$qp->m_errors[] = wfMsg( 'smw_nm_proc_pagenotexist' );
}
if ( isset( $msg ) && $qp->hasSubquery() ) {
$msg .= "\n" . wfMsg( 'smw_nm_proc_subqueryhint' );
}
$query = new SMWQuery( $desc, true, false );
$query->setQueryString( $querystring );
$query->addErrors( $qp->getErrors() ); // keep parsing errors for later output
$res = $sStore->getNMQueryResult( $query );
if ( count( $query->getErrors() ) > 0 ) {
if ( isset( $msg ) ) {
$msg .= "\n\n" . implode( '\n', $query->getErrors() ) . "\n\n" . wfMsg( 'smw_nm_proc_enablehint' );
}
$sStore->disableNotifyState( $notify_id );
wfProfileOut( 'SMWNotifyProcessor::enableNotify (SMW)' );
return false;
}
$sStore->updateNMSql( $notify_id, $res['sql'], $res['tmp_hierarchy'] );
if ( count( $res['page_ids'] ) > 0 ) {
$add_monitor = array();
foreach ( $res['page_ids'] as $page_id ) {
$add_monitor[] = array( 'notify_id' => $notify_id, 'page_id' => $page_id );
}
$sStore->addNotifyMonitor( $add_monitor );
}
$sStore->updateNotifyState( $notify_id, 1 );
wfProfileOut( 'SMWNotifyProcessor::enableNotify (SMW)' );
return true;
}
示例6: testEmptyGetQueryResultWhereQueryContainsErrors
public function testEmptyGetQueryResultWhereQueryContainsErrors()
{
$connection = $this->getMockBuilder('\\SMW\\SPARQLStore\\RepositoryConnection')->disableOriginalConstructor()->getMockForAbstractClass();
$store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
$compoundConditionBuilder = $this->getMockBuilder('\\SMW\\SPARQLStore\\QueryEngine\\CompoundConditionBuilder')->disableOriginalConstructor()->getMock();
$description = $this->getMockForAbstractClass('\\SMW\\Query\\Language\\Description');
$engineOptions = new EngineOptions();
$engineOptions->set('smwgIgnoreQueryErrors', false);
$instance = new QueryEngine($connection, $compoundConditionBuilder, new QueryResultFactory($store), $engineOptions);
$query = new Query($description);
$query->addErrors(array('Foo'));
$this->assertInstanceOf('\\SMWQueryResult', $instance->getQueryResult($query));
$this->assertEmpty($instance->getQueryResult($query)->getResults());
}
示例7: testNullQueryResult
public function testNullQueryResult()
{
$term = '[[Some_string_to_query]]';
$description = new ValueDescription(new DIWikiPage($term, NS_MAIN), null);
$query = new Query($description, false, false);
$query->querymode = Query::MODE_INSTANCES;
$description = $query->getDescription();
$namespacesDisjunction = new Disjunction(array_map(function ($ns) {
return new NamespaceDescription($ns);
}, array(NS_MAIN)));
$description = new Conjunction(array($description, $namespacesDisjunction));
$query->setDescription($description);
$this->assertInstanceOf('\\SMWQueryResult', ApplicationFactory::getInstance()->getStore()->getQueryResult($query));
}
示例8: toArray
/**
* Returns a serialized SMWQueryResult object with additional meta data
*
* This methods extends the serializeToArray() for additional meta
* that are useful when handling data via the api
*
* @note should be used instead of SMWQueryResult::serializeToArray()
* as this method contains additional informaion
*
* @since 1.9
*
* @return array
*/
public function toArray()
{
// @note micro optimization: We call getSerializedQueryResult()
// only once and create the hash here instead of calling getHash()
// to avoid getSerializedQueryResult() being called again
// @note count + offset equals total therefore we deploy both values
$serializeArray = $this->serializeToArray();
return array_merge($serializeArray, array('meta' => array('hash' => md5(FormatJson::encode($serializeArray)), 'count' => $this->getCount(), 'offset' => $this->mQuery->getOffset())));
}
示例9: toArray
/**
* Returns a serialized SMWQueryResult object with additional meta data
*
* This methods extends the serializeToArray() for additional meta
* that are useful when handling data via the api
*
* @note should be used instead of SMWQueryResult::serializeToArray()
* as this method contains additional informaion
*
* @since 1.9
*
* @return array
*/
public function toArray()
{
$time = microtime(true);
// @note micro optimization: We call getSerializedQueryResult()
// only once and create the hash here instead of calling getHash()
// to avoid getSerializedQueryResult() being called again
// @note count + offset equals total therefore we deploy both values
$serializeArray = $this->serializeToArray();
return array_merge($serializeArray, array('meta' => array('hash' => HashBuilder::createHashIdForContent($serializeArray), 'count' => $this->getCount(), 'offset' => $this->mQuery->getOffset(), 'source' => $this->mQuery->getQuerySource(), 'time' => number_format(microtime(true) - $time, 6, '.', ''))));
}
示例10: getLink
/**
* Returns an SMWInfolink object with the QueryResults print requests as parameters.
*
* @since 1.8
*
* @return SMWInfolink
*/
public function getLink()
{
$params = array(trim($this->mQuery->getQueryString()));
foreach ($this->mQuery->getExtraPrintouts() as $printout) {
$serialization = $printout->getSerialisation();
// TODO: this is a hack to get rid of the mainlabel param in case it was automatically added
// by SMWQueryProcessor::addThisPrintout. Should be done nicer when this link creation gets redone.
if ($serialization !== '?#') {
$params[] = $serialization;
}
}
// Note: the initial : prevents SMW from reparsing :: in the query string.
return SMWInfolink::newInternalLink('', ':Special:Ask', false, $params);
}
示例11: getQueryId
/**
* @since 2.4
*
* @return string
*/
public function getQueryId()
{
if ($this->queryId === null) {
$this->queryId = $this->query->getQueryId();
}
return $this->queryId;
}
示例12: makeQueryResultForInstance
private function makeQueryResultForInstance(FederateResultSet $federateResultSet, Query $query)
{
$resultDataItems = array();
foreach ($federateResultSet as $resultRow) {
if (count($resultRow) > 0) {
$dataItem = Exporter::findDataItemForExpElement($resultRow[0]);
if (!is_null($dataItem)) {
$resultDataItems[] = $dataItem;
}
}
}
if ($federateResultSet->numRows() > $query->getLimit()) {
array_pop($resultDataItems);
$hasFurtherResults = true;
} else {
$hasFurtherResults = false;
}
$result = new QueryResult($query->getDescription()->getPrintrequests(), $query, $resultDataItems, $this->store, $hasFurtherResults);
switch ($federateResultSet->getErrorCode()) {
case FederateResultSet::ERROR_NOERROR:
break;
case FederateResultSet::ERROR_INCOMPLETE:
$result->addErrors(array(wfMessage('smw_db_sparqlqueryincomplete')->inContentLanguage()->text()));
break;
default:
$result->addErrors(array(wfMessage('smw_db_sparqlqueryproblem')->inContentLanguage()->text()));
break;
}
return $result;
}
示例13: newJointProfileAnnotator
/**
* @since 2.1
*
* @param Title $title
* @param Query $query
* @param string $format
* @param integer|null $duration
*
* @return ProfileAnnotator
*/
public function newJointProfileAnnotator(Title $title, Query $query, $format, $duration = null)
{
$profiler = new NullProfile(new Subobject($title), $query->getHash());
$profiler = new DescriptionProfile($profiler, $query->getDescription());
$profiler = new FormatProfile($profiler, $format);
$profiler = new DurationProfile($profiler, $duration);
return $profiler;
}
示例14: newJointProfileAnnotator
/**
* @since 2.1
*
* @param Query $query
* @param string $format
* @param integer|null $duration
*
* @return ProfileAnnotator
*/
public function newJointProfileAnnotator(Query $query, $format, $duration = null)
{
$nullProfileAnnotator = new NullProfileAnnotator(new Subobject($query->getSubject()->getTitle()), $query->getQueryId());
$descriptionProfileAnnotator = new DescriptionProfileAnnotator($nullProfileAnnotator, $query->getDescription());
$formatProfileAnnotator = new FormatProfileAnnotator($descriptionProfileAnnotator, $format);
$durationProfileAnnotator = new DurationProfileAnnotator($formatProfileAnnotator, $duration);
return $durationProfileAnnotator;
}
示例15: testGetHash
public function testGetHash()
{
$description = $this->getMockForAbstractClass('\\SMW\\Query\\Language\\Description');
$instance = new Query($description, Query::INLINE_QUERY);
$instance->setLimit(50);
$hash = $instance->getHash();
$this->assertInternalType('string', $hash);
$instance->setLimit(100);
$this->assertNotEquals($hash, $instance->getHash());
}