Class SparqlParser

Description

Parses a SPARQL Query string and returns a Query Object.

Located in /sparql/SparqlParser.php (line 21)

Object
   |
   --SparqlParser
Variable Summary
static array $operatorPrecedence
static array $sops
string $querystring
int $tmp
array $tokens
Method Summary
static void balanceTree ( &$tree, array $tree)
static void fixNegationInFuncName ( &$tree)
SparqlParser SparqlParser ()
boolean bNodeCheck (String $token)
void checkDtypeLang ( &$node, String $node)
boolean dtypeCheck ( &$node, String $node)
String error (SparqlException $e)
boolean iriCheck (String $token)
boolean literalCheck (String $token)
Query parse ([String $queryString = false])
void parseAsk (string $form)
void parseBase ()
void parseBrackettedExpression ( &$constraint, Constraint $constraint)
Node parseCollection ( &$trp, TriplePattern $trp)
void parseConstraint ( &$pattern, boolean $outer, GraphPattern $pattern)
array parseConstraintTree ([ $nLevel = 0], [ $bParameter = false])
void parseConstruct ()
void parseDescribe ()
void parseExpression ( &$constraint, Constraint $constrain)
void parseFrom ()
void parseGraph (GraphPattern $pattern)
void parseGraphPattern ([int $optional = false], [int $union = false], [string $graph = false], [boolean $constr = false], [ $external = false])
void parseLiteral ( &$node, String $sep, String $node)
void parseModifier ()
Node parseNode ([String $node = false])
void parsePrefix ()
void parseQuery ()
void parseSelect ()
void parseTriplePattern ( &$pattern, GraphPattern $pattern)
void parseWhere ()
void prepare ()
boolean qnameCheck (String $token)
void tokenize (String $queryString)
String uncomment (String $queryString)
boolean varCheck (String $token)
void _fastForward ()
void _rewind ()
Variables
static array $operatorPrecedence = array(
'||' => 0,
'&&' => 1,
'=' => 2,
'!=' => 3,
'<' => 4,
'>' => 5,
'<=' => 6,
'>=' => 7,
'*' => 0,
'/' => 0,
'+' => 0,
'-' => 0,
)
(line 69)

Which order operators are to be treated.

(11.3 Operator Mapping)

  • access: protected
static array $sops = array(
'regex',
'bound',
'isuri',
'isblank',
'isliteral',
'str',
'lang',
'datatype',
'langmatches'
)
(line 52)

Operators introduced by sparql

  • access: protected
Query $query (line 28)

The query Object

  • access: protected
string $querystring (line 34)

The Querystring

  • access: protected
int $tmp (line 46)

Last parsed graphPattern

  • access: protected
array $tokens = array() (line 40)

The tokenized Query

  • access: protected
Methods
static balanceTree (line 960)

"Balances" the filter tree in the way that operators on the same level are nested according to their precedence defined in $operatorPrecedence array.

  • access: protected
static void balanceTree ( &$tree, array $tree)
  • array $tree: Tree to be modified
  • &$tree
static fixNegationInFuncName (line 983)
  • access: protected
static void fixNegationInFuncName ( &$tree)
  • &$tree
Constructor SparqlParser (line 89)

Constructor of SparqlParser

  • access: public
SparqlParser SparqlParser ()
bNodeCheck (line 478)

Checks if $token is a Blanknode.

  • return: TRUE if the token is BNode false if not
  • access: protected
boolean bNodeCheck (String $token)
  • String $token: The token
checkDtypeLang (line 1287)

Checks if there is a datatype given and appends it to the node.

  • access: protected
void checkDtypeLang ( &$node, String $node)
  • String $node
  • &$node
dtypeCheck (line 1338)

Checks if the Node is a typed Literal.

  • return: TRUE if typed FALSE if not
  • access: protected
boolean dtypeCheck ( &$node, String $node)
  • String $node
  • &$node
error (line 1399)

Error reporting.

  • access: protected
String error (SparqlException $e)
  • SparqlException $e
iriCheck (line 464)

Checks if $token is an IRI.

  • return: TRUE if the token is an IRI false if not
  • access: protected
boolean iriCheck (String $token)
  • String $token: The token
literalCheck (line 517)

Checks if $token is a Literal.

  • return: TRUE if the token is a Literal false if not
  • access: protected
boolean literalCheck (String $token)
  • String $token: The token
parse (line 102)

Main function of SparqlParser. Parses a query string.

  • return: The query object
  • throws: SparqlParserException
  • access: public
Query parse ([String $queryString = false])
  • String $queryString: The SPARQL query
parseAsk (line 368)

Sets result form to 'ASK' and 'COUNT'.

  • access: protected
void parseAsk (string $form)
  • string $form: if it's an ASK or COUNT query
parseBase (line 246)

Parses the BASE part of the query.

  • throws: SparqlParserException
  • access: protected
void parseBase ()
parseBrackettedExpression (line 1006)

Parses a bracketted expression.

  • throws: SparqlParserException
  • access: protected
void parseBrackettedExpression ( &$constraint, Constraint $constraint)
parseCollection (line 1376)

Parses an RDF collection.

  • return: The first parsed label
  • access: protected
Node parseCollection ( &$trp, TriplePattern $trp)
  • TriplePattern $trp
  • &$trp
parseConstraint (line 728)

Parses a value constraint.

  • access: protected
void parseConstraint ( &$pattern, boolean $outer, GraphPattern $pattern)
  • GraphPattern $pattern
  • boolean $outer: If the constraint is an outer one.
  • &$pattern
parseConstraintTree (line 788)

Parses a constraint string recursively.

The result array is one "element" which may contain subelements. All elements have one key "type" that determines which other array keys the element array has. Valid types are:

  • "value": Just a plain value with a value key, nothing else
  • "function" A function has a name and an array of parameter(s). Each parameter is an element.
  • "equation" An equation has an operator, and operand1 and operand2 which are elements themselves
Any element may have the "negated" value set to true, which means that is is - negated (!).

  • return: Nested tree array representing the filter
  • access: protected
array parseConstraintTree ([ $nLevel = 0], [ $bParameter = false])
  • $nLevel
  • $bParameter
parseConstruct (line 413)

Parses the CONSTRUCT clause.

  • throws: SparqlParserException
  • access: protected
void parseConstruct ()
parseDescribe (line 347)

Adds a new variable to the query and sets result form to 'DESCRIBE'.

  • access: protected
void parseDescribe ()
parseExpression (line 1046)

Parses an expression.

  • throws: SparqlParserException
  • access: protected
void parseExpression ( &$constraint, Constraint $constrain)
parseFrom (line 383)

Parses the FROM clause.

  • throws: SparqlParserException
  • access: protected
void parseFrom ()
parseGraph (line 1076)

Parses a GRAPH clause.

  • throws: SparqlParserException
  • access: protected
void parseGraph (GraphPattern $pattern)
parseGraphPattern (line 559)

Parses a graph pattern.

  • access: protected
void parseGraphPattern ([int $optional = false], [int $union = false], [string $graph = false], [boolean $constr = false], [ $external = false])
  • int $optional: Optional graph pattern
  • int $union: Union graph pattern
  • string $graph: Graphname
  • boolean $constr: TRUE if the pattern is a construct pattern
  • $external
parseLiteral (line 1323)

Parses a literal.

  • access: protected
void parseLiteral ( &$node, String $sep, String $node)
  • String $node
  • String $sep: used separator " or '
  • &$node
parseModifier (line 1102)

Parses the solution modifiers of a query.

  • throws: SparqlParserException
  • access: protected
void parseModifier ()
parseNode (line 1194)

Parses a String to an RDF node.

  • return: The parsed RDF node
  • throws: SparqlParserException
  • access: protected
Node parseNode ([String $node = false])
  • String $node
parseOrderCondition (line 1136)

Parses order conditions of a query.

  • throws: SparqlParserException
  • access: protected
void parseOrderCondition ()
parsePrefix (line 270)

Adds a new namespace prefix to the query object.

  • throws: SparqlParserException
  • access: protected
void parsePrefix ()
parseQuery (line 196)

Starts parsing the tokenized SPARQL Query.

  • access: protected
void parseQuery ()
parseSelect (line 297)

Parses the SELECT part of a query.

  • throws: SparqlParserException
  • access: protected
void parseSelect ()
parseTriplePattern (line 619)

Parses a triple pattern.

  • access: protected
void parseTriplePattern ( &$pattern, GraphPattern $pattern)
parseWhere (line 432)

Parses the WHERE clause.

  • throws: SparqlParserException
  • access: protected
void parseWhere ()
prepare (line 133)

Set all internal variables to a clear state before we start parsing.

  • access: protected
void prepare ()
qnameCheck (line 493)

Checks if $token is a qname.

  • return: TRUE if the token is a qname false if not
  • throws: SparqlParserException
  • access: protected
boolean qnameCheck (String $token)
  • String $token: The token
tokenize (line 152)

Tokenizes the querystring.

  • access: protected
void tokenize (String $queryString)
  • String $queryString
uncomment (line 181)

Removes comments in the query string. Comments are indicated by '#'.

  • return: The uncommented query string
  • access: protected
String uncomment (String $queryString)
  • String $queryString
varCheck (line 449)

Checks if $token is a variable.

  • return: TRUE if the token is a variable false if not
  • access: protected
boolean varCheck (String $token)
  • String $token: The token
_fastForward (line 529)

FastForward until next token which is not blank.

  • access: protected
void _fastForward ()
_rewind (line 542)

Rewind until next token which is not blank.

  • access: protected
void _rewind ()

Inherited Methods

Inherited From Object

Object::toString()

Documentation generated on Fri, 1 Jun 2007 16:52:17 +0200 by phpDocumentor 1.3.2