Skip to content

Commit

Permalink
Merge pull request #19 from pietercolpaert/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
pietercolpaert authored Nov 27, 2017
2 parents 56e3f4d + 21e29b0 commit 3fa0c84
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
11 changes: 5 additions & 6 deletions perf/parser-streaming-perf.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
$TEST = microtime(true);

$count = 0;
$parser = new TriGParser([ "documentIRI" => $base ]);
$callback = function ($error, $triple) use (&$count, $TEST, $filename) {
$parser = new TriGParser([ "documentIRI" => $base ], function ($error, $triple) use (&$count, $TEST, $filename) {
if ($triple) {
$count++;
}
Expand All @@ -23,14 +22,14 @@
echo '* Triples parsed: ' . $count . "\n";
echo '* Memory usage: ' . (memory_get_usage() / 1024 / 1024) . "MB\n";
}
};
});

$handle = fopen($filename, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$parser->parseChunk($line, $callback);
while (($line = fgets($handle, 4096)) !== false) {
$parser->parseChunk($line);
}
$parser->end($callback);
$parser->end();
fclose($handle);
} else {
// error opening the file.
Expand Down
10 changes: 5 additions & 5 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public static function getLiteralValue ($literal)
{
preg_match("/^\"(.*)\"/", $literal, $match); //TODO: somehow the copied regex did not work. To be checked. Contained [^]
if (empty($match)) {
throw new \Exception($literal + ' is not a literal');
throw new \Exception($literal . ' is not a literal');
}
return $match[1];
}
// Gets the type of a literal in the N3 library
public static function getLiteralType ($literal)
{
preg_match('/^".*"(?:\^\^([^"]+)|(@)[^@"]+)?$/',$literal,$match);//TODO: somehow the copied regex did not work. To be checked. Contained [^] instead of the .
preg_match('/^".*"(?:\^\^([^"]+)|(@)[^@"]+)?$/s',$literal,$match);//TODO: somehow the copied regex did not work. To be checked. Contained [^] instead of the .
if (empty($match))
throw new \Exception($literal + ' is not a literal');
throw new \Exception($literal . ' is not a literal');
if (!empty($match[1])) {
return $match[1];
} else {
Expand All @@ -70,9 +70,9 @@ public static function getLiteralType ($literal)
// Gets the language of a literal in the N3 library
public static function getLiteralLanguage ($literal)
{
preg_match('/^".*"(?:@([^@"]+)|\^\^[^"]+)?$/', $literal, $match);
preg_match('/^".*"(?:@([^@"]+)|\^\^[^"]+)?$/s', $literal, $match);
if (empty($match))
throw new \Exception($literal + ' is not a literal');
throw new \Exception($literal . ' is not a literal');
return isset($match[1]) ? strtolower($match[1]) : '';
}

Expand Down
46 changes: 41 additions & 5 deletions test/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ public function testGetLiteralValue () {
//it('does not work with null', function () {
//TODO: Util::getLiteralValue.bind(null, null).should.throw('null is not a literal');
}

// tests reaction if no literal was given
public function testGetLiteralValueNoLiteralGiven()
{
$this->expectException('\Exception');

Util::getLiteralValue('invalid');
}

public function testGetLiteralType () {
//it('gets the type of a literal', function () {
Expand Down Expand Up @@ -151,8 +159,18 @@ public function testGetLiteralType () {
//it('does not work with null', function () {
//TODO: Util::getLiteralType.bind(null, null).should.throw('null is not a literal');

}

}

// tests getLiteralType if multi line string was given (check for adaption of Util.php,
// adding an s to the regex)
public function testGetLiteralTypeMultilineString()
{
$literal = '"This document is published by the Provenance Working Group (http://www.w3.org/2011/prov/wiki/Main_Page).
If you wish to make comments regarding this document, please send them to public-prov-comments@w3.org (subscribe public-prov-comments-request@w3.org, archives http://lists.w3.org/Archives/Public/public-prov-comments/). All feedback is welcome."^^<http://>';

$this->assertEquals('<http://>', Util::getLiteralType($literal));
}

public function testGetLiteralLanguage () {
//it('gets the language of a literal', function () {
Expand Down Expand Up @@ -188,9 +206,27 @@ public function testGetLiteralLanguage () {


//it('does not work with null', function () {
//TODO: Util::getLiteralLanguage.bind(null, null).should.throw('null is not a literal');
//TODO: Util::getLiteralLanguage.bind(null, null).should.throw('null is not a literal');
}

// tests getLiteralLanguage if multi line string was given (check for adaption of Util.php,
// adding an s to the regex)
public function testGetLiteralLanguageMultilineString()
{
$literal = '"This document is published by the Provenance Working Group (http://www.w3.org/2011/prov/wiki/Main_Page).
If you wish to make comments regarding this document, please send them to public-prov-comments@w3.org (subscribe public-prov-comments-request@w3.org, archives http://lists.w3.org/Archives/Public/public-prov-comments/). All feedback is welcome."@en';

$this->assertEquals('en', Util::getLiteralLanguage($literal));
}

// tests reaction if no language was given
public function testGetLiteralLanguageNoLiteralGiven()
{
$this->expectException('\Exception');

Util::getLiteralLanguage('invalid');
}


public function testIsPrefixedName () {
//it('matches a prefixed name', function () {
Expand Down Expand Up @@ -353,4 +389,4 @@ public function testthe function () {
}
*/
}


0 comments on commit 3fa0c84

Please sign in to comment.