[moriarty] r310 committed - added submit_ntriples_in_batches method to Graph

0 views
Skip to first unread message

mori...@googlecode.com

unread,
Jul 29, 2011, 9:58:30 AM7/29/11
to moriarty...@googlegroups.com
Revision: 310
Author: k.j.w.a...@gmail.com
Date: Fri Jul 29 06:57:23 2011
Log: added submit_ntriples_in_batches method to Graph
http://code.google.com/p/moriarty/source/detail?r=310

Added:
/branches/2011-05-02-mirror_from_url/tests/documents/10-ntriples.nt
Modified:
/branches/2011-05-02-mirror_from_url/graph.class.php
/branches/2011-05-02-mirror_from_url/tests/graph.test.php
/branches/2011-05-02-mirror_from_url/tests/simplegraph.test.php

=======================================
--- /dev/null
+++ /branches/2011-05-02-mirror_from_url/tests/documents/10-ntriples.nt Fri
Jul 29 06:57:23 2011
@@ -0,0 +1,10 @@
+<http://example.com/a> <http://example.com/b> 1 .
+<http://example.com/a> <http://example.com/b> 2 .
+<http://example.com/a> <http://example.com/b> 3 .
+<http://example.com/a> <http://example.com/b> 4 .
+<http://example.com/a> <http://example.com/b> 5 .
+<http://example.com/a> <http://example.com/b> 6 .
+<http://example.com/a> <http://example.com/b> 7 .
+<http://example.com/a> <http://example.com/b> 8 .
+<http://example.com/a> <http://example.com/b> 9 .
+<http://example.com/a> <http://example.com/b> 10 .
=======================================
--- /branches/2011-05-02-mirror_from_url/graph.class.php Wed Dec 15
15:35:07 2010
+++ /branches/2011-05-02-mirror_from_url/graph.class.php Fri Jul 29
06:57:23 2011
@@ -125,6 +125,31 @@
$request->set_body( $turtle );
return $request->execute();
}
+
+ function
submit_ntriples_in_batches_from_file($filename,$no_of_lines=500,
$stop_on_failure=true) {
+ $responses = array();
+ $pointer = fopen($filename, 'r');
+ $batch = '';
+ $lineCount=0;
+ while($line = fgets($pointer)){
+ $batch.=$line;
+ $lineCount++;
+ if($lineCount==$no_of_lines){
+ $response = $this->submit_turtle($batch);
+ $responses[] = $response;
+ if($response->is_success()===false AND $stop_on_failure){
+ return $responses;
+ } else {
+ $lineCount=0;
+ $batch='';
+ }
+ }
+ }
+ if(!empty($batch)){
+ $responses[]=$this->submit_turtle($batch);
+ }
+ return $responses;
+ }

/**
* Obtain the graph's bounded description of a given resource
=======================================
--- /branches/2011-05-02-mirror_from_url/tests/graph.test.php Sun Mar 21
05:36:37 2010
+++ /branches/2011-05-02-mirror_from_url/tests/graph.test.php Fri Jul 29
06:57:23 2011
@@ -352,6 +352,27 @@
$response = $g->submit_turtle( $this->_turtle_doc );
$this->assertTrue( in_array('Accept: */*',
$fake_request->get_headers() ) );
}
+
+ function test_submit_ntriples_from_file_in_batches(){
+ $response = new HttpResponse('202');
+ $graph = $this->getMock('Graph', array('submit_turtle'),
array(),'',false );
+ $graph->expects($this->exactly(10))
+ ->method('submit_turtle')
+ ->will($this->returnValue($response));
+ $filename = dirname(__FILE__).'/documents/10-ntriples.nt';
+ $result = $graph->submit_ntriples_in_batches_from_file($filename,1);
+ $this->assertEquals(count($result), 10);
+ }
+ function test_submit_ntriples_from_file_in_batches_stop_on_failure(){
+ $response = new HttpResponse('500');
+ $graph = $this->getMock('Graph', array('submit_turtle'),
array(),'',false );
+ $graph->expects($this->exactly(1))
+ ->method('submit_turtle')
+ ->will($this->returnValue($response));
+ $filename = dirname(__FILE__).'/documents/10-ntriples.nt';
+ $result =
$graph->submit_ntriples_in_batches_from_file($filename,1,true);
+ $this->assertEquals(count($result), 1);
+ }


}
=======================================
--- /branches/2011-05-02-mirror_from_url/tests/simplegraph.test.php Thu Jul
28 02:39:23 2011
+++ /branches/2011-05-02-mirror_from_url/tests/simplegraph.test.php Fri Jul
29 06:57:23 2011
@@ -1113,8 +1113,21 @@
'value' => 'A Bnode',
'type' => 'literal',
),
+ array(
+ 'value' => '_:b',
+ 'type' => 'bnode',
+ ),
),
- ),
+ ),
+
+ '_:b' => array(
+ RDFS_LABEL => array(
+ array(
+ 'type' => 'literal',
+ 'value' => 'bnode B',
+ )
+ )
+ )

);

@@ -1125,8 +1138,21 @@
'value' => 'A Bnode',
'type' => 'literal',
),
+ array(
+ 'value' => 'http://example.org/document/id-2',
+ 'type' => 'uri',
+ ),
+
),
),
+ 'http://example.org/document/id-2' => array(
+ RDFS_LABEL => array(
+ array(
+ 'type' => 'literal',
+ 'value' => 'bnode B',
+ )
+ )
+ )
);

$graph = new SimpleGraph($input);
@@ -1136,14 +1162,18 @@


}
+
+
+ function test_graph_pattern_is_unchanged_by_replace_resource(){
+
+ }

function
test_number_of_resources_remains_constant_after_skolemise_bnodes(){
$graph = new
SimpleGraph(file_get_contents(dirname(__FILE__).'/documents/ckan-ds.ttl'));
$index = $graph->get_index();
- $before = count(array_keys($index));
+ $before = count($graph->get_subjects());
$graph->skolemise_bnodes('http://example.com/test/');
- $index = $graph->get_index();
- $after = count(array_keys($index));
+ $after = count($graph->get_subjects());
$this->assertEquals($before, $after, "skolemise_bnodes shouldn't
reduce the number of resources");
}

Reply all
Reply to author
Forward
0 new messages