Notation 3 Parser ================== The directories N3Parser and testCases have to be installed beneath the main Python directory. THe program should be used within a scrollable window.(Use the IDLE or other environment , a unix shell window or W2000 dos window; however W95 and W98 dos windows will give problems). Start the program and install the parameters files(menu item 6). Explanation is given in menu items 1 and 6 and hereafter. Explanations =============== The testcases should be in a directory named "testCases\".The path prefix for this directory must be in the file:"pathPrefix.txt\" (with trailing slash)." Proxy definition ================== Proxy with authentication: put the proxy address and port in "proxy.txt\" and the userid and password (userid:password) in the file "userPass.txt\". For a proxy without authentication put "noAuth\" in the file "proxy.txt\" and put the address and port number of the proxy in the environment variable: "http-proxy\".(in DOS: set http-proxy = .... If no proxy is required leave the files empty. Both files should exist. # N3 parser #-------------------------------------- # # Author : G.Naudts E-mail : naudts_vannoten@yahoo.com # Address : Secretarisdreef 5 2288 Bouwel Belgium # The parser is based on the grammar at the back and has been token from : # http://2001/blindfold/sample/n3.bnf # and the parser uses also the structures defined in N3 primer : # http://www.w3.org/200/10/swap/Primer.htm # The output data structure consists basically of triples # (id,short value, full value) . The full value gives the complete URI. # The tree structure of N3 is kept intact, but dummy subjects and verbs # are introduced where these are missing (_subject and _verb) # Points are eliminated. # In ":a is :b of :c" of is eliminated and the verb :b is preceded # by "Reverse" meaning subject and object have to be reversed. # In ":a has :b of :c" has and of are eliminated. # # Anonymous nodes get an anonymous subject value = _T$$$1 ... _T$$$n where # n is the index of the last anonymous node . # The parser is basically recursive descent with look-ahead features. # The prelude used is standard.pre . # When an error occurs the stream is synchronized on the next point # and an error message is included in the stream. # With thanks to Mark P.Jones for his inspiring prolog interpreter. # # I give here a bnf of the output : # # ParserOutput ::= Triple (ParserOutput)*| # TripleSet (ParserOutput)*| # AnonSet (ParserOutput)* # # Triple ::= "Triple" Sep Subject Verb Object # # AnonTriple ::= AnonSubject Verb Object # # TripleSet ::= Sep Triple* "EndOfSet" Sep # # AnonSet ::= Sep AnonTriple* "EndOfSet" Sep # # Subject ::= "Subject" Sep String Sep| # "Set" Sep TripleSet| # "AnonSet" Sep AnonSet # # AnonSubject ::= "Subject" Sep "_T$$$" n Sep # # Verb ::= ["Reverse" sep] "Verb" Sep String Sep| (Reverse means subject # and object must be reversed) # "Set" Sep TripleList| # "AnonSet" Sep AnonSet # # Object ::= "Object" Sep String Sep| # "ObjectSet" Sep TripleSet| # "AnonSet" Sep AnonSet # # n ::= (digit)* # # Sep ::= Separator # # Prefix ::= "Prefix" Sep String Sep # # The separator is defined in the source code; might be : /@/ # The output is defined by constants that are defined in a section # indicated by the header : Constants . # _subject and _verb refer to the latest subject and verb. # # To do: better synchronization && error messages. # # # The bnf grammar #---------------------- # # Taken from # on 2001-08-03 (version of 2001-04-10) # # Modifications: # # $Log: n3.bnf,v $ # Revision 1.4 2001/08/06 20:56:21 sandro # added space* and space+ in several places # removed "#" from forbidden chars in URI_Reference # handles comments # made directives actually part of the grammar (!) # allowed nprefix to be zero-length # # Revision 1.3 2001/08/03 13:44:43 sandro # filled in remaining non-terminals # # Revision 1.2 2001/08/03 13:02:48 sandro # standardized BNF so blindfold can compile it # added ::= for each rule # added | for branches # added ; at end of rule # added # before comments # put quotes around literals # turn hypen into underscore in identifiers # rename prefix to nprefix (hack around blindfold keyword for now) # # Revision 1.1 2001/08/03 12:34:38 sandro # added opening comments # # # # document ::= void # | statementlist; # # space ::= " " | "\n" | "\r" | comment; # # comment ::= "#" [^\r\n]*; # # statement ::= subject space+ property_list # | directive # ; # # statementlist ::= (statement space* ("." space*)?)* ; # # subject ::= node; # # verb ::= ">-" prop "->" # has xxx of # | "<-" prop "<-" # is xxx of # # | operator # has operator:xxx of??? NOT IMPLMENTED # | prop # has xxx of -- shorthand # | "has" prop # has xxx of # | "is" prop "of" # is xxx of # | "a" # has rdf:type of # | "=" # has daml:equivalent of # ; # # prop ::= node; # # node ::= uri_ref2 # | anonnode # | "this" # | node # ; # # nodelist ::= void # (used in lists) # | node # | node nodelist # ; # # anonnode ::= "[" property_list "]" # something which ... # | "{" statementlist "}" # the statementlist itself as a resource # | "(" nodelist ")" # short for eg [ n3:first node1; n3:rest [ n3:first node2; n3:rest: n3:null ]] # ; # # property_list ::= void # to allow [...]. # | verb space+ object_list # | verb space+ object_list space+ ";" space+ property_list # | ":-" anonnode #to allow two anonymous forms to be given eg [ a :Truth; :- { :sky :color :blue } ] ) # | ":-" anonnode ";" property_list # ; # # object_list ::= object # | object "," object_list # ; # # uri_ref2 ::= qname # | "<" URI_Reference ">" # ; # # qname ::= nprefix ":" localname; # ??? Allow omit colon when prefix void - keyword clash # # object ::= subject # | string1 # " constant-value-with-escaping " # | string2 # """ constant value with escaping including single or double occurences of quotes and/or newlines """ # # well-formed-xml-element ???? legacy or structured stuff - not implemented or distinguished # ; # # directive ::= "bind" space+ nprefix ":" uri_ref2 # Namespace declartion. Trailing "#" is omitted & assumed. Obsolete. # | "@prefix" space+ nprefix ":" space+ uri_ref2 # Namespace declaration # ; # ## operator ::= (Not implemented) ## + >- operator:plus -> ## - >- operator:minus -> ## / >- operator:slash-> ## * >- operator:star-> (etc? @@) # # fragid ::= alpha alphanumeric* ; # # alpha ::= [a-zA-Z]; # # alphanumeric ::= alpha | [0-9] | "_"; # # void ::= "" ; # nothing # # URI_Reference ::= [^{}<>]*; # short version # # nprefix ::= "" | ((alpha | "_") alphanumeric*); # # localname ::= fragid; # # string1 ::= '"' string1_char* '"'; # # string1_char ::= '\\"' | [^\"] ; # should disallow some other characters, etc. # # string2 ::= '"""' string2_char* '"""'; # # string2_char ::= [^"] | ([^] [^] [^"]); # something like this; need to think about it some more # #-----------------------------------------------------------------------}