Created
September 11, 2010 02:00
-
-
Save edsu/574679 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| # this script reads n-quads on stdin, and writes the same quads separated with tabs to stdout | |
| # the thought being that it is then easier to munge with unix tools like split, grep, etc | |
| # more about n-quads can be found at: http://sw.deri.org/2008/07/n-quads/ | |
| use strict; | |
| my $space = qr/ /; | |
| my $uri = qr/<.+?>/; | |
| my $bnode = qr/_:.+?/; | |
| my $langtag = qr/@.+?/; | |
| my $datatype = qr/\^\^$uri/; | |
| my $literal = qr/(?<!\\)".+?(?<!\\)"(?:$langtag|$datatype)?/; | |
| my $nquad = qr/ | |
| ^ | |
| ($uri|$bnode) # subject | |
| $space | |
| ($uri|$bnode) # predicate | |
| $space | |
| ($uri|$bnode|$literal) # object | |
| $space | |
| ($uri) # context | |
| $space | |
| \. # end-of-quad | |
| /x; | |
| while (<>) { | |
| s/\t//; | |
| my @parts = m/$nquad/; | |
| print join("\t", @parts), "\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
qr FTW!