Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Commit

Permalink
RdfHelpers: extended guessFormat to recognize rdf/turtle; extended re…
Browse files Browse the repository at this point in the history
…lated test cases
  • Loading branch information
k00ni committed May 31, 2017
1 parent 1474c2a commit 91d75b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RdfHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ public function guessFormat($stringToCheck)
// RDF/XML
} elseif (0 < preg_match('/<rdf:/i', $short, $matches)) {
return 'rdf-xml';

// turtle
} elseif (0 < preg_match('/@prefix\s|@base\s/i', $short, $matches)) {
return 'turtle';
}

return null;
Expand Down
8 changes: 8 additions & 0 deletions Test/RdfHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,17 @@ public function testGetQueryTypeSelect()

public function testGuessFormat()
{
// n-triples
$this->assertEquals('n-triples', $this->fixture->guessFormat('<foo><bar>'));
$this->assertEquals('n-triples', $this->fixture->guessFormat('<foo>'));

// rdf xml
$this->assertEquals('rdf-xml', $this->fixture->guessFormat('<rdf:aa'));

// turtle
$this->assertEquals('turtle', $this->fixture->guessFormat('@prefix foo:<http://bar>'));

// invalid strings
$this->assertEquals(null, $this->fixture->guessFormat('<foo'));
$this->assertEquals(null, $this->fixture->guessFormat('foo://>'));
}
Expand Down

0 comments on commit 91d75b9

Please sign in to comment.