SMWQueryParser Class Reference
[SMWQuery]

Objects of this class are in charge of parsing a query string in order to create an SMWDescription. More...

List of all members.

Public Member Functions

 __construct ($queryfeatures=false)
 setDefaultNamespaces ($nsarray)
 Provide an array of namespace constants that are used as default restrictions.
 getQueryDescription ($querystring)
 Compute an SMWDescription from a query string.
 getErrors ()
 Return array of error messages (possibly empty).
 getErrorString ()
 Return error message or empty string if no error occurred.

Protected Member Functions

 getSubqueryDescription (&$setNS)
 Compute an SMWDescription for current part of a query, which should be a standalone query (the main query or a subquery enclosed within "\<q\>...\</q\>".
 getLinkDescription (&$setNS)
 Compute an SMWDescription for current part of a query, which should be the content of "[[ ... ]]".
 getClassDescription (&$setNS, $category=true)
 Parse a category description (the part of an inline query that is in between "[[Category:" and the closing "]]" and create a suitable description.
 getPropertyDescription ($propertyname, &$setNS)
 Parse a property description (the part of an inline query that is in between "[[Some property::" and the closing "]]" and create a suitable description.
 getArticleDescription ($firstchunk, &$setNS)
 Parse an article description (the part of an inline query that is in between "[[" and the closing "]]" assuming it is not specifying a category or property) and create a suitable description.
 finishLinkDescription ($chunk, $hasNamespaces, $result, &$setNS)
 readChunk ($stoppattern= '', $consume=true, $trim=true)
 Get the next unstructured string chunk from the query string.
 pushDelimiter ($endstring)
 Enter a new subblock in the query, which must at some time be terminated by the given $endstring delimiter calling popDelimiter();.
 popDelimiter ($endstring)
 Exit a subblock in the query ending with the given delimiter.
 addDescription ($curdesc, $newdesc, $conjunction=true)
 Extend a given description by a new one, either by adding the new description (if the old one is a container description) or by creating a new container.

Protected Attributes

 $m_sepstack
 $m_curstring
 $m_errors
 $m_defaultns
 $m_categoryprefix
 $m_conceptprefix
 $m_categoryPrefixCannonical
 $m_conceptPrefixCannonical
 $m_queryfeatures


Detailed Description

Objects of this class are in charge of parsing a query string in order to create an SMWDescription.

The class and methods are not static in order to more cleanly store the intermediate state and progress of the parser.

Definition at line 15 of file SMW_QueryParser.php.


Constructor & Destructor Documentation

SMWQueryParser::__construct ( queryfeatures = false  ) 

Definition at line 28 of file SMW_QueryParser.php.

References $smwgQFeatures.


Member Function Documentation

SMWQueryParser::setDefaultNamespaces ( nsarray  ) 

Provide an array of namespace constants that are used as default restrictions.

If NULL is given, no such default restrictions will be added (faster).

Definition at line 44 of file SMW_QueryParser.php.

References addDescription().

SMWQueryParser::getQueryDescription ( querystring  ) 

Compute an SMWDescription from a query string.

Returns whatever descriptions could be wrestled from the given string (the most general result being SMWThingDescription if no meaningful condition was extracted).

Parameters:
string $querystring
Returns:
SMWDescription

Definition at line 63 of file SMW_QueryParser.php.

References addDescription(), and getSubqueryDescription().

SMWQueryParser::getErrors (  ) 

Return array of error messages (possibly empty).

Returns:
array

Definition at line 90 of file SMW_QueryParser.php.

Referenced by getPropertyDescription().

SMWQueryParser::getErrorString (  ) 

Return error message or empty string if no error occurred.

Returns:
string

Definition at line 99 of file SMW_QueryParser.php.

References smwfEncodeMessages().

SMWQueryParser::getSubqueryDescription ( &$  setNS  )  [protected]

Compute an SMWDescription for current part of a query, which should be a standalone query (the main query or a subquery enclosed within "\<q\>...\</q\>".

Recursively calls similar methods and returns NULL upon error.

The call-by-ref parameter $setNS is a boolean. Its input specifies whether the query should set the current default namespace if no namespace restrictions were given. If false, the calling super-query is happy to set the required NS-restrictions by itself if needed. Otherwise the subquery has to impose the defaults. This is so, since outermost queries and subqueries of disjunctions will have to set their own default restrictions.

The return value of $setNS specifies whether or not the subquery has a namespace specification in place. This might happen automatically if the query string imposes such restrictions. The return value is important for those callers that otherwise set up their own restrictions.

Note that $setNS is no means to switch on or off default namespaces in general, but just controls query generation. For general effect, the default namespaces should be set to NULL.

Returns:
SMWDescription or null

Definition at line 126 of file SMW_QueryParser.php.

References addDescription(), getLinkDescription(), popDelimiter(), pushDelimiter(), and readChunk().

Referenced by getPropertyDescription(), and getQueryDescription().

SMWQueryParser::getLinkDescription ( &$  setNS  )  [protected]

Compute an SMWDescription for current part of a query, which should be the content of "[[ ... ]]".

Returns NULL upon error.

Parameters $setNS has the same use as in getSubqueryDescription().

Definition at line 232 of file SMW_QueryParser.php.

References getArticleDescription(), getClassDescription(), getPropertyDescription(), readChunk(), and smwfNormalTitleText().

Referenced by getSubqueryDescription().

SMWQueryParser::getClassDescription ( &$  setNS,
category = true 
) [protected]

Parse a category description (the part of an inline query that is in between "[[Category:" and the closing "]]" and create a suitable description.

NOTE: we add m_c...prefix to prevent problems with, e.g., [[Category:Template:Test]]

Definition at line 263 of file SMW_QueryParser.php.

References addDescription(), finishLinkDescription(), and readChunk().

Referenced by getLinkDescription().

SMWQueryParser::getPropertyDescription ( propertyname,
&$  setNS 
) [protected]

Parse a property description (the part of an inline query that is in between "[[Some property::" and the closing "]]" and create a suitable description.

The "::" is the first chunk on the current string.

TODO: read some more chunks and try to finish [[ ]]

TODO: read some more chunks and try to finish [[ ]]

NOTE: after iteration, $property and $typeid correspond to last value

TODO: report error; this is not good right now

NOTE: at this point, we normally already read one more chunk behind the value

Definition at line 297 of file SMW_QueryParser.php.

References addDescription(), finishLinkDescription(), getErrors(), getSubqueryDescription(), SMWPropertyValue::makeUserProperty(), SMWDataValueFactory::newPropertyObjectValue(), pushDelimiter(), and readChunk().

Referenced by getLinkDescription().

SMWQueryParser::getArticleDescription ( firstchunk,
&$  setNS 
) [protected]

Parse an article description (the part of an inline query that is in between "[[" and the closing "]]" assuming it is not specifying a category or property) and create a suitable description.

The first chunk behind the "[[" has already been read and is passed as a parameter.

Definition at line 413 of file SMW_QueryParser.php.

References addDescription(), finishLinkDescription(), and readChunk().

Referenced by getLinkDescription().

SMWQueryParser::finishLinkDescription ( chunk,
hasNamespaces,
result,
&$  setNS 
) [protected]

SMWQueryParser::readChunk ( stoppattern = '',
consume = true,
trim = true 
) [protected]

Get the next unstructured string chunk from the query string.

Chunks are delimited by any of the special strings used in inline queries (such as [[, ]], <q>, ...). If the string starts with such a delimiter, this delimiter is returned. Otherwise the first string in front of such a delimiter is returned. Trailing and initial spaces are ignored if $trim is true, and chunks consisting only of spaces are not returned. If there is no more qurey string left to process, the empty string is returned (and in no other case).

The stoppattern can be used to customise the matching, especially in order to overread certain special symbols.

$consume specifies whether the returned chunk should be removed from the query string.

Definition at line 518 of file SMW_QueryParser.php.

Referenced by finishLinkDescription(), getArticleDescription(), getClassDescription(), getLinkDescription(), getPropertyDescription(), and getSubqueryDescription().

SMWQueryParser::pushDelimiter ( endstring  )  [protected]

Enter a new subblock in the query, which must at some time be terminated by the given $endstring delimiter calling popDelimiter();.

Definition at line 555 of file SMW_QueryParser.php.

Referenced by getPropertyDescription(), and getSubqueryDescription().

SMWQueryParser::popDelimiter ( endstring  )  [protected]

Exit a subblock in the query ending with the given delimiter.

If the delimiter does not match the top-most open block, false will be returned. Otherwise return true.

Definition at line 564 of file SMW_QueryParser.php.

Referenced by getSubqueryDescription().

SMWQueryParser::addDescription ( curdesc,
newdesc,
conjunction = true 
) [protected]

Extend a given description by a new one, either by adding the new description (if the old one is a container description) or by creating a new container.

The parameter $conjunction determines whether the combination of both descriptions should be a disjunction or conjunction.

In the special case that the current description is NULL, the new one will just replace the current one.

The return value is the expected combined description. The object $curdesc will also be changed (if it was non-NULL).

Definition at line 581 of file SMW_QueryParser.php.

Referenced by finishLinkDescription(), getArticleDescription(), getClassDescription(), getPropertyDescription(), getQueryDescription(), getSubqueryDescription(), and setDefaultNamespaces().


Member Data Documentation

SMWQueryParser::$m_sepstack [protected]

Definition at line 17 of file SMW_QueryParser.php.

SMWQueryParser::$m_curstring [protected]

Definition at line 18 of file SMW_QueryParser.php.

SMWQueryParser::$m_errors [protected]

Definition at line 19 of file SMW_QueryParser.php.

SMWQueryParser::$m_defaultns [protected]

Definition at line 20 of file SMW_QueryParser.php.

SMWQueryParser::$m_categoryprefix [protected]

Definition at line 22 of file SMW_QueryParser.php.

SMWQueryParser::$m_conceptprefix [protected]

Definition at line 23 of file SMW_QueryParser.php.

SMWQueryParser::$m_categoryPrefixCannonical [protected]

Definition at line 24 of file SMW_QueryParser.php.

SMWQueryParser::$m_conceptPrefixCannonical [protected]

Definition at line 25 of file SMW_QueryParser.php.

SMWQueryParser::$m_queryfeatures [protected]

Definition at line 26 of file SMW_QueryParser.php.


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

Generated on Thu Feb 9 07:15:42 2012 for Semantic MediaWiki by  doxygen 1.5.6