Skip to content

Commit

Permalink
Merge branch 'release-15.27.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jul 13, 2023
2 parents bcd7946 + d24b378 commit 8647c2d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions core/kernel/api/class.ModelExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,38 @@

class core_kernel_api_ModelExporter
{
private const DEFAULT_FORMAT = 'rdfxml';

/**
* Export the entire ontology
*
* @param string $format (optional) which format resulted ontology will be.
*
* @return string
*/
public static function exportAll()
public static function exportAll($format = self::DEFAULT_FORMAT)
{
$dbWrapper = core_kernel_classes_DbWrapper::singleton();
$result = $dbWrapper->query('SELECT DISTINCT "subject", "predicate", "object", "l_language" FROM "statements"');
return self::statement2rdf($result);
return self::statement2rdf($result, $format);
}

/**
* Export models by id
*
* @param array $modelIds
* @param string $format (optional) which format resulted models ontology will be.
*
* @return string
*/
public static function exportModels($modelIds)
public static function exportModels($modelIds, $format = self::DEFAULT_FORMAT)
{
$dbWrapper = core_kernel_classes_DbWrapper::singleton();
$result = $dbWrapper->query('SELECT DISTINCT "subject", "predicate", "object", "l_language" FROM "statements"
WHERE "modelid" IN (\'' . implode('\',\'', $modelIds) . '\')');

common_Logger::i('Found ' . $result->rowCount() . ' entries for models ' . implode(',', $modelIds));
return self::statement2rdf($result);
return self::statement2rdf($result, $format);
}

/**
Expand All @@ -68,20 +74,20 @@ public static function exportModelByUri()
* @throws \EasyRdf\Exception
* @ignore
*/
private static function statement2rdf(PDOStatement $statement)
private static function statement2rdf($statement, $format = self::DEFAULT_FORMAT)
{
$graph = new Graph();
while ($r = $statement->fetch()) {
if (isset($r['l_language']) && !empty($r['l_language'])) {
$graph->addLiteral($r['subject'], $r['predicate'], $r['object'], $r['l_language']);
} elseif (common_Utils::isUri($r['object'])) {
$graph->add($r['subject'], $r['predicate'], $r['object']);
$graph->addResource($r['subject'], $r['predicate'], $r['object']);
} else {
$graph->addLiteral($r['subject'], $r['predicate'], $r['object']);
}
}

$format = Format::getFormat('rdfxml');
$format = Format::getFormat($format);

return $graph->serialise($format);
}
Expand Down

0 comments on commit 8647c2d

Please sign in to comment.