Commits

Toby Inkster committed 2b77cd4

bugfixes; add support for N3's <= and =>.

  • Participants
  • Parent commits f8120fd

Comments (0)

Files changed (2)

 use lib "lib";
 use RDF::MicroTurtle::Parser;
 use JSON;
+use utf8;
 
 my $p    = RDF::MicroTurtle::Parser->new;
-my $mttl = 'lalala #mttl <#me> has #person foaf:name "Bob" ; is foaf:member of @blah ; foaf:page http://example.net/ .';
+my $mttl = 'lalala #mttl <#me> has #person foaf:name "Bob" ; is foaf:member of @blah ;  http://example.org/ .';
 
 $p->parse(
 	'http://example.net/',

lib/RDF/MicroTurtle/Parser.pm

 
 use Data::UUID;
 use Digest::SHA1 qw'sha1_hex';
+use Encode;
 use LWP::UserAgent;
 use RDF::MicroTurtle::Context;
 use RDF::TrineShortcuts qw':nodes rdf_statement';
 {
 	my ($self, $ts) = @_;
 	my @rv;
-	
+
 	if ($ts =~ /^[\s\r\n]*\{.*\}[\s\r\n]*$/s)
 	{
 		$ts =~ s/^([\s\r\n]*\{)|(\}[\s\r\n]*$)//gs;
 			push @rv, $1;
 			$ts = substr($ts, length $1);
 		}
+		elsif ($ts =~ /^=>/)
+		{
+			push @rv, '<http://www.w3.org/2000/10/swap/log#implies>';
+			$ts = substr($ts, 2);
+		}
+		elsif ($ts =~ /^<=/)
+		{
+			push @rv, ('is', '<http://www.w3.org/2000/10/swap/log#implies>', 'of');
+			$ts = substr($ts, 2);
+		}
 		elsif ($ts =~ /^(<[^>]*>)/)
 		{
 			push @rv, $1;
 			push @rv, 'has';
 			$ts = substr($ts, 3);
 		}
-		elsif ($ts =~ /^=>/)
-		{
-			push @rv, '<http://www.w3.org/2000/10/swap/log#implies>';
-			$ts = substr($ts, 2);
-		}
-		elsif ($ts =~ /^<=/)
-		{
-			push @rv, ('is', '<http://www.w3.org/2000/10/swap/log#implies>', 'of');
-			$ts = substr($ts, 2);
-		}
 		elsif ($ts =~ /^at\b/)
 		{
 			push @rv, '<http://www.w3.org/2003/01/geo/wgs84_pos#location>';
 			push @rv, '<http://www.w3.org/2002/07/owl#sameAs>';
 			$ts = substr($ts, 1);
 		}
-		elsif ($ts =~ /^\s*([→])/)
+		elsif ($ts =~ /^(→)/)
 		{
 			push @rv, '<http://xmlns.com/foaf/0.1/homepage>';
 			$ts = substr($ts, length($1));
 		}
-		elsif ($ts =~ /^\s*([←])/)
+		elsif ($ts =~ /^(←)/)
 		{
 			push @rv, ('<http://xmlns.com/foaf/0.1/primaryTopic>');
 			$ts = substr($ts, length($1));
 		}
-		elsif ($ts =~ /^\s*([♥♡❤])/)
+		elsif ($ts =~ /^([♥♡❤])/)
 		{
 			push @rv, '<http://ontologi.es/like#likes>';
 			$ts = substr($ts, length($1));
 		else
 		{
 			warn "Possible Turtle tokenisation problem!\n";
+			# warn join ';', map {ord($_)} split //, $ts;
 			push @rv, "???ERRORCOND???";
 			return @rv;
 		}