Skip to content

Commit

Permalink
Optimize export orig uri conversion a little with a cache
Browse files Browse the repository at this point in the history
  • Loading branch information
samuell committed Jul 1, 2017
1 parent 3068a83 commit d6fc843
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
45 changes: 33 additions & 12 deletions classes/RDFIO_ARC2StoreWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,51 @@ function __construct( $tripleStore = null ) {
*/
function toEquivUrisInTriples( $triples, $propUrisFilter = null ) {

$equivUriCache = array();

foreach ( $triples as $tripleidx => $triple ) {
// Subject
if ( $triple['s_type'] === 'uri' ) {
$subjEquivUris = $this->getEquivURIsForURI( $triple['s'] );
$subjUri = $triple['s'];
if ( array_key_exists( $subjUri, $equivUriCache ) ) {
echo "Cache hit!\n";
$triples[$tripleidx]['s'] = $equivUriCache[$subjUri];
} else {
$subjEquivUris = $this->getEquivURIsForURI( $subjUri );
if ( count( $subjEquivUris ) > 0 ) {
$triples[$tripleidx]['s'] = $subjEquivUris[0];
$equivUriCache[$subjUri] = $subjEquivUris[0];
}
}

// Property
$propEquivUris = $this->getEquivURIsForURI( $triple['p'] );
if ( !is_null( $propUrisFilter ) ) {
// Only include URIs that occur in the filter
$propEquivUris = array_intersect( $propEquivUris, $propUrisFilter );
}
if ( count( $propEquivUris ) > 0 ) {
$triples[$tripleidx]['p'] = $propEquivUris[0];
$propUri = $triple['p'];
if ( array_key_exists( $propUri, $equivUriCache ) ) {
echo "Cache hit!\n";
$triples[$tripleidx]['p'] = $equivUriCache[$propUri];
} else {
$propEquivUris = $this->getEquivURIsForURI( $triple['p'] );
if ( !is_null( $propUrisFilter ) ) {
// Only include URIs that occur in the filter
$propEquivUris = array_intersect( $propEquivUris, $propUrisFilter );
}
if ( count( $propEquivUris ) > 0 ) {
$triples[$tripleidx]['p'] = $propEquivUris[0];
$equivUriCache[$propUri] = $propEquivUris[0];
}
}

// Object
if ( $triple['o_type'] === 'uri' ) {
$objEquivUris = $this->getEquivURIsForURI( $triple['o'] );
if ( count( $objEquivUris ) > 0 ) {
$triples[$tripleidx]['o'] = $objEquivUris[0];
$objUri = $triple['o'];
if ( array_key_exists( $objUri, $equivUriCache ) ) {
echo "Cache hit!\n";
$triples[$tripleidx]['o'] = $equivUriCache[$objUri];
} else {
$objEquivUris = $this->getEquivURIsForURI( $objUri );
if ( count( $objEquivUris ) > 0 ) {
$triples[$tripleidx]['o'] = $objEquivUris[0];
$equivUriCache[$objUri] = $objEquivUris[0];
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion maintenance/exportRdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function execute() {
$store = new SMWARC2Store();

$offset = 0;
$limit = 100;
$limit = 250;

$this->output( "Starting RDF export to file $outPath ...\n" );
while ( true ) {
Expand Down

0 comments on commit d6fc843

Please sign in to comment.