Class N3Parser

Description

PHP Notation3 Parser

This parser can parse a subset of n3, reporting triples to a callback function or constructing a RAP Model ( http://www.wiwiss.fu-berlin.de/suhl/bizer/rdfapi )

Supported N3 features:

  • Standard things, repeated triples ( ; and , ), blank nodes using [ ], self-reference ('<>')
  • @prefix mappings
  • = maps to owl#sameAs
  • a maps to rdf-syntax-ns#type
  • Literal datytype- and xmlLanguageTag support
Un-supported N3 Features include:
  • Reification using { }
  • . and ^ operators for tree traversal
  • Any log operators, like log:forAll etc.

This parser is based on n3.py from Epp released 2nd March, 2002. by Sean B. Palmer ( http://infomesh.net/2002/eep/20020302-013802/n3.py )

This parser is released under the GNU GPL license. ( http://www.gnu.org/licenses/gpl.txt )

  • access: public
  • version: $Id: N3Parser.html,v 1.15 2006/06/26 12:34:21 tgauss Exp $
  • author: Sean B. Palmer <sean@mysterylights.com>, Gunnar AA. Grimnes <ggrimnes@csd.abdn.ac.uk>, Daniel Westphal <mail@d-westphal.de>

Located in /syntax/N3Parser.php (line 44)

Object
   |
   --N3Parser
Variable Summary
mixed $bNode
mixed $DAML_NS
mixed $debug
mixed $OWL_NS
mixed $parseError
mixed $RDF_NS
mixed $Tokens
Method Summary
N3Parser N3Parser ()
$list applyStuff (array $prefixes, array $list)
array array_concat (array $a, array $b)
string bnodeID ()
array doLists (array $list, string $schar, string $echar)
array expandLists (array $list)
void filterWs (array $list)
array fixAnon (array $list)
object MemModel &generateModel (mixed $path, [ $dummy = false], [ $model = false])
array getObjs (array $list)
array getPovs (array $list)
array getPrefixes (array $list)
array getSpan (array $list, integer $start, integer $end)
array getStatements (array $list)
void isWS (string $s)
array listify (array $list, integer $start, integer $end)
array listStuff (mixed $list)
array n3tolist (string $s)
boolean notComment (string $s)
void parse (string $s)
object Model parse2model (string $s, [ $model = false])
array posns (array $list, string $item)
void replace_a_type ( &$l,  $p, string $l)
void replace_equal ( &$l,  $p, string $l)
void replace_this (string $l,  $p)
void setFixBnodes (mixed $set)
array statementize (array $list)
String str2unicode_nfc ([String $str = ""])
array toke (string $s)
object RDFNode toRDFNode (string $s,  $state)
void uparse (string $s, string $func)
Variables
mixed $bNode (line 50)
mixed $DAML_NS (line 51)
mixed $debug (line 52)
mixed $OWL_NS (line 51)
mixed $parsedNamespaces = array() (line 54)
mixed $parseError (line 53)
mixed $RDF_NS (line 51)
mixed $Tokens (line 49)
Methods
Constructor N3Parser (line 62)

Constructor

  • access: public
N3Parser N3Parser ()
applyStuff (line 531)

Applies stuff :) Expands namespace prefixes etc.

  • access: private
$list applyStuff (array $prefixes, array $list)
  • array $prefixes
  • array $list
array_concat (line 378)

Concatenates two arrays

  • access: private
array array_concat (array $a, array $b)
  • array $a
  • array $b
bnodeID (line 839)

Generates a new node id.

  • access: private
string bnodeID ()
doLists (line 784)

Makes lists of elements in list into a seperate array element.

e.g. doLists(["a","b","[","c","]","d"], "[","]")=> ["a","b", ["c"], "d"]

  • access: private
array doLists (array $list, string $schar, string $echar)
  • array $list
  • string $schar
  • string $echar
expandLists (line 872)

This makes [ ] lists into bnodes.

  • access: private
array expandLists (array $list)
  • array $list
filterWs (line 258)

Removes all whitespace tokens from list

  • access: private
void filterWs (array $list)
  • array $list
fixAnon (line 851)

This makes bNodes out of variables like _:a etc.

  • access: private
array fixAnon (array $list)
  • array $list
generateModel (line 205)

Generate a new MemModel from an URI or file.

  • throws: PhpError
  • access: public
object MemModel &generateModel (mixed $path, [ $dummy = false], [ $model = false])
  • $dummy
  • $model
getObjs (line 666)

Gets a list of triples with same predicate e.g. :Gunnar :likes "Cheese", "Wine".

  • access: private
array getObjs (array $list)
  • array $list
getPovs (line 641)

Gets a list of triples with same subject e.g. :Gunnar :firstname "Gunnar" ; :lastname "Grimnes.

array getPovs (array $list)
  • array $list
getPrefixes (line 472)

Returns an array with prefixes=>namespace mappings

  • access: private
array getPrefixes (array $list)
  • array $list
getSpan (line 362)

Gets a slice of an array.

Returns the wanted slice, as well as the remainder of the array. e.g. getSpan(['p', 'q', 'r'], 1, 2) gives (['q'], ['p', 'r'])

  • access: private
array getSpan (array $list, integer $start, integer $end)
  • array $list
  • integer $start
  • integer $end
getStatements (line 611)

Returns an array of triples extracted from the list of n3 tokens

  • access: private
array getStatements (array $list)
  • array $list
isWS (line 233)

Returns FALSE if argument is a whitespace character

  • access: private
void isWS (string $s)
  • string $s
listify (line 449)

Returns a list with the elements between start and end as one quoted string

e.g. listify(["a","b","c","d"],1,2) => ["a","b c", "d"]

  • access: private
array listify (array $list, integer $start, integer $end)
  • array $list
  • integer $start
  • integer $end
listStuff (line 826)

Apply doLists for all different types of list.

  • access: private
array listStuff (mixed $list)
n3tolist (line 944)

Main work-horse function. This converts a N3 string to a list of statements

  • access: private
array n3tolist (string $s)
  • string $s
notComment (line 245)

Returns true if the string is not a comment

  • access: private
boolean notComment (string $s)
  • string $s
parse (line 115)

This parses a N3 string and prints out the triples

  • access: public
void parse (string $s)
  • string $s
parse2model (line 172)

This parses a N3 string and returns a memmodel

  • access: public
object Model parse2model (string $s, [ $model = false])
  • string $s
  • $model
posns (line 390)

Returns an array with all indexes where item appears in list

  • access: private
array posns (array $list, string $item)
  • array $list
  • string $item
replace_a_type (line 501)

Callback function for replacing "a" elements with the right RDF uri.

  • access: private
void replace_a_type ( &$l,  $p, string $l)
  • string $l
  • &$l
  • $p
replace_equal (line 510)

Callback function for replacing "=" elements with the right DAML+OIL uri.

  • access: private
void replace_equal ( &$l,  $p, string $l)
  • string $l
  • &$l
  • $p
replace_this (line 519)

Callback function for replacing "this" elements with the right RDF uri.

  • access: private
void replace_this (string $l,  $p)
  • string $l
  • $p
setFixBnodes (line 104)

Sets, if BlankNode labels should be replaced by the generic label from the constants.php file

default is "false" -> the used label in n3 is parsed to the model

  • access: public
void setFixBnodes (mixed $set)
statementize (line 708)

Does the real work, returns a list of subject, predicate, object triples.

  • access: private
array statementize (array $list)
  • array $list
str2unicode_nfc (line 273)

converts a string to its unicode NFC form (e.g. \uHHHH or \UHHHHHHHH).

  • access: private
String str2unicode_nfc ([String $str = ""])
  • String $str
toke (line 410)

Returns a list of tokens

  • access: private
array toke (string $s)
  • string $s
toRDFNode (line 1006)

Constructs a RAP RDFNode from URI/Literal/Bnode

  • access: private
object RDFNode toRDFNode (string $s,  $state)
  • string $s
  • $state
uparse (line 143)

This parses a N3 string and calls func($subject, $predicate, $object) with each trioke

  • access: public
void uparse (string $s, string $func)
  • string $s
  • string $func

Inherited Methods

Inherited From Object

Object::toString()

Documentation generated on Mon, 26 Jun 2006 14:25:41 +0200 by phpDocumentor 1.3.0RC6