Пример #1
0
  /**
   * Creates an EasyRdf_Graph object from the given URI.
   *
   * @param string $uri
   *     URL of a web resource or path of the cached file.
   * @param string $type
   *    Format of the document.
   *
   * @throws \Doctrine\Common\Proxy\Exception\InvalidArgumentException
   *    If invalid type or URL is passed as parameters.
   */
  protected function createGraph($uri, $type) {
    /*
     * Initialize an EasyRdf_Graph object using
     * _construct(string $uri = null, string $data = null,
     *     string $format = null)
     */
    if (!is_string($type) or $type == NULL or $type == '') {
      throw new InvalidArgumentException("\$type should be a string and cannot be null or empty");
    }
    if (!is_string($uri) or $uri == NULL or $uri == '') {
      throw new InvalidArgumentException("\$uri should be a string and cannot be null or empty");
    }

    try {
      if (preg_match('#^http#i', $uri) === 1) {
        $this->graph = new \EasyRdf_Graph($uri, NULL, $type);
        $this->graph->load();
      }
      else {
        $this->graph = new \EasyRdf_Graph(NULL);
        $this->graph->parseFile($uri);
      }
      $this->iterateGraph();
    }
    catch (\Exception $e) {
      throw new InvalidArgumentException("Invalid uri + $e");
    }

  }
 protected function getTriples($file)
 {
     if (!file_exists($file)) {
         throw new Exception($file . ' not found');
     }
     // validate the file to import
     $parser = new tao_models_classes_Parser($file, array('extension' => 'rdf'));
     $parser->validate();
     if (!$parser->isValid()) {
         throw new common_Exception('Invalid RDF file ' . $file);
     }
     $modelDefinition = new EasyRdf_Graph();
     $modelDefinition->parseFile($file);
     /*
     $graph = $modelDefinition->toRdfPhp();
     $resources = $modelDefinition->resources();
     */
     $format = EasyRdf_Format::getFormat('php');
     $data = $modelDefinition->serialise($format);
     $triples = array();
     foreach ($data as $subjectUri => $propertiesValues) {
         foreach ($propertiesValues as $prop => $values) {
             foreach ($values as $k => $v) {
                 $triples[] = array('s' => $subjectUri, 'p' => $prop, 'o' => $v['value'], 'l' => isset($v['lang']) ? $v['lang'] : '');
             }
         }
     }
     return $triples;
 }
Пример #3
0
 /**
  * @author "Lionel Lecaque, <*****@*****.**>"
  * @param string $namespace
  * @param string $data xml content
  */
 public function createModel($namespace, $data)
 {
     $modelId = $this->getModelId($namespace);
     if ($modelId === false) {
         common_Logger::d('modelId not found, need to add namespace ' . $namespace);
         $this->addNewModel($namespace);
         //TODO bad way, need to find better
         $modelId = $this->getModelId($namespace);
     }
     $modelDefinition = new EasyRdf_Graph($namespace);
     if (is_file($data)) {
         $modelDefinition->parseFile($data);
     } else {
         $modelDefinition->parse($data);
     }
     $graph = $modelDefinition->toRdfPhp();
     $resources = $modelDefinition->resources();
     $format = EasyRdf_Format::getFormat('php');
     $data = $modelDefinition->serialise($format);
     foreach ($data as $subjectUri => $propertiesValues) {
         foreach ($propertiesValues as $prop => $values) {
             foreach ($values as $k => $v) {
                 $this->addStatement($modelId, $subjectUri, $prop, $v['value'], isset($v['lang']) ? $v['lang'] : null);
             }
         }
     }
     return true;
 }
 public function testParseWebId()
 {
     $graph = new EasyRdf_Graph();
     $graph->parseFile(fixturePath('webid.ttl'), 'turtle');
     $me = $graph->resource('http://www.example.com/myfoaf#me');
     $modulus = $me->get('cert:key')->get('cert:modulus');
     $this->assertStringEquals('CB24ED85D64D794B69C701C186ACC059501E856000F661C93204D8380E07191C' . '5C8B368D2AC32A428ACB970398664368DC2A867320220F755E99CA2EECDAE62E' . '8D15FB58E1B76AE59CB7ACE8838394D59E7250B449176E51A494951A1C366C62' . '17D8768D682DDE78DD4D55E613F8839CF275D4C8403743E7862601F3C49A6366' . 'E12BB8F498262C3C77DE19BCE40B32F89AE62C3780F5B6275BE337E2B3153AE2' . 'BA72A9975AE71AB724649497066B660FCF774B7543D980952D2E8586200EDA41' . '58B014E75465D91ECF93EFC7AC170C11FC7246FC6DED79C37780000AC4E079F6' . '71FD4F207AD770809E0E2D7B0EF5493BEFE73544D8E1BE3DDDB52455C61391A1', $modulus);
     $this->assertInternalType('string', $modulus->getValue());
     $this->assertSame(NULL, $modulus->getLang());
     $this->assertSame('xsd:hexBinary', $modulus->getDatatype());
 }
Пример #5
0
function dissertationen($atts)
{
    EasyRdf_Namespace::set('bibo', 'http://purl.org/ontology/bibo/');
    EasyRdf_Namespace::set('sd', 'http://symbolicdata.org/Data/Model#');
    EasyRdf_Namespace::set('dct', 'http://purl.org/dc/terms/');
    $people = new EasyRdf_Graph("http://symbolicdata.org/Data/People/");
    $people->parseFile("http://symbolicdata.org/rdf/People.rdf");
    //$people->parseFile("/home/graebe/git/SD/web/rdf/People.rdf");
    $out = "\n\n<h2 align=\"center\">Habilitationen</h2>\n\n";
    $out .= displayAll(getDissertations('habil'), $people);
    $out .= "\n\n<h2 align=\"center\">Promotionen</h2>\n\n";
    $out .= displayAll(getDissertations('phd'), $people);
    return $out;
}
Пример #6
0
function casystems()
{
    EasyRdf_Namespace::set('sd', 'http://symbolicdata.org/Data/Model#');
    EasyRdf_Namespace::set('dct', 'http://purl.org/dc/terms/');
    EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
    $people = new EasyRdf_Graph("http://symbolicdata.org/Data/People/");
    $people->parseFile("http://symbolicdata.org/rdf/People.rdf");
    //$people->parseFile("/home/graebe/git/SD/web/rdf/People.rdf");
    $systems = new EasyRdf_Graph("http://symbolicdata.org/Data/CA-Systems/");
    $systems->parseFile("http://symbolicdata.org/rdf/CA-Systems.rdf");
    //$systems->parseFile("/home/graebe/git/SD/web/rdf/CA-Systems.rdf");
    $out = displaySystems($systems, $people);
    return $out;
}
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configArgument = $input->getArgument('config');
     if ($configArgument) {
         $parser = new Parser();
         $config = $parser->parse(file_get_contents($configArgument));
         unset($parser);
     } else {
         $config = [];
     }
     $processor = new Processor();
     $configuration = new TypesGeneratorConfiguration();
     $processedConfiguration = $processor->processConfiguration($configuration, [$config]);
     $processedConfiguration['output'] = realpath($input->getArgument('output'));
     if (!$processedConfiguration['output']) {
         throw new \RuntimeException('The specified output is invalid');
     }
     $graphs = [];
     foreach ($processedConfiguration['rdfa'] as $rdfa) {
         $graph = new \EasyRdf_Graph();
         if ('http://' === substr($rdfa['uri'], 0, 7) || 'https://' === substr($rdfa['uri'], 0, 8)) {
             $graph->load($rdfa['uri'], $rdfa['format']);
         } else {
             $graph->parseFile($rdfa['uri'], $rdfa['format']);
         }
         $graphs[] = $graph;
     }
     $relations = [];
     foreach ($processedConfiguration['relations'] as $relation) {
         $relations[] = new \SimpleXMLElement($relation, 0, true);
     }
     $goodRelationsBridge = new GoodRelationsBridge($relations);
     $cardinalitiesExtractor = new CardinalitiesExtractor($graphs, $goodRelationsBridge);
     $ucfirstFilter = new \Twig_SimpleFilter('ucfirst', 'ucfirst');
     $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../templates/');
     $twig = new \Twig_Environment($loader, ['autoescape' => false, 'debug' => $processedConfiguration['debug']]);
     $twig->addFilter($ucfirstFilter);
     if ($processedConfiguration['debug']) {
         $twig->addExtension(new \Twig_Extension_Debug());
     }
     $logger = new ConsoleLogger($output);
     $entitiesGenerator = new TypesGenerator($twig, $logger, $graphs, $cardinalitiesExtractor, $goodRelationsBridge);
     $entitiesGenerator->generate($processedConfiguration);
 }
Пример #8
0
 /**
  * Imports the rdf file into the selected class
  * 
  * @param string $file
  * @param core_kernel_classes_Class $class
  * @return common_report_Report
  */
 private function flatImport($file, core_kernel_classes_Class $class)
 {
     $report = common_report_Report::createSuccess(__('Data imported successfully'));
     $graph = new EasyRdf_Graph();
     $graph->parseFile($file);
     // keep type property
     $map = array(RDF_PROPERTY => RDF_PROPERTY);
     foreach ($graph->resources() as $resource) {
         $map[$resource->getUri()] = common_Utils::getNewUri();
     }
     $format = EasyRdf_Format::getFormat('php');
     $data = $graph->serialise($format);
     foreach ($data as $subjectUri => $propertiesValues) {
         $resource = new core_kernel_classes_Resource($map[$subjectUri]);
         $subreport = $this->importProperties($resource, $propertiesValues, $map, $class);
         $report->add($subreport);
     }
     return $report;
 }
Пример #9
0
<?php

require_once '.php/EasyRdf.php';
$graph = new EasyRdf_Graph();
foreach (new DirectoryIterator(dirname(__FILE__)) as $dir_entry) {
    if ($dir_entry->getExtension() == 'ttl') {
        $graph->parseFile($dir_entry->getPathname());
    }
}
$sidebar = '';
// TODO: construct TOC
if (preg_match('|^/([0-9A-Za-z&-]+)$|', $_SERVER['REQUEST_URI'], $matches) && file_exists($matches[1] . '.ttl')) {
    // TODO
    $link = $matches[1];
    $content = '';
    $title = '';
} else {
    http_response_code(404);
    $content = '<h1>404 Not Found</h1>';
    $title = '404 Not Found';
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title><?php 
echo $title ? "{$title} &mdash; " : '';
?>
Пример #10
0
        $item->property = $property;
        $item->value = $uri;
        $result[] = $item;
    }
    return $result;
}
// print '<pre>';
if (isset($_GET['resource'])) {
    $requested_resource = 'univ:' . $_GET['resource'];
    //////////////////////////////////////////////////////////////////////////////////////
    // Set the namespace related to our RDF file namespace
    // Note:
    // For the standard namespaces like rdf,rdf,owl,foaf is already defined by the API
    // so we do not need to explicitly define it here
    // ////////////////////////////////////////////////////////////////////////////////////
    EasyRdf_Namespace::set('univ', 'http://www.semanticweb.org/workshop/2016/ontologies/university#');
    // instansiate the Graph Object
    $graph = new EasyRdf_Graph();
    //////////////////////////////////////////////////////////////////
    // load the RDF file into the graph object
    // Note:
    // Here we load the RDF via file I/O path, if you want to load
    // the RDF via HTTP then use load() method instead ($graph->load())
    // ////////////////////////////////////////////////////////////////
    $graph->parseFile('../ontology/universitas-live-example.ttl', 'turtle');
    // At this stage, we are ready to process the graph
    // ==========================================================
    $response_object = graph_walker($graph, $requested_resource);
    header('Content-Type:application/json');
    echo json_encode($response_object);
}
Пример #11
0
 public function get()
 {
     $graph = new Graph();
     $graph->parseFile('sample.ttl');
     return $graph;
 }
 public function testParseFileRelativeUri()
 {
     $graph = new EasyRdf_Graph();
     $count = $graph->parseFile(fixturePath('foaf.rdf'));
     $this->assertSame(14, $count);
     $doc = $graph->get('foaf:PersonalProfileDocument', '^rdf:type');
     $this->assertClass('EasyRdf_Resource', $doc);
     $this->assertRegExp('|^file://.+/fixtures/foaf\\.rdf$|', $doc->getUri());
 }
Пример #13
0
$uniqid = uniqid();
$suchbegriff = str_replace(" ", "+", $_GET["qname"]);
//$suchbegriff='123apfelkuchen';
$rdf = "";
if (isset($_GET["rdf"])) {
    $rdf = $_GET["rdf"];
}
$basedir = dirname(realpath(__FILE__));
$root = $basedir;
$ldfu = $root . '/ldfu/bin/ldfu.sh';
$n3_programm = $root . '/n3-files/chefkoch.n3';
$input = 'http://manke-hosting.de/wrapper/index.php/explore/' . $suchbegriff;
$output = $root . '/output/' . $suchbegriff . '.nt';
if (!file_exists($output)) {
    $command = 'sh ' . $ldfu . ' ' . '-i ' . $input . ' ' . '-p ' . $n3_programm . ' ' . '-o ' . $output;
    shell_exec($command);
}
$graph->parseFile($output);
//$graph ->parseFile('/Users/raphaelmanke/Downloads/linked-data-fu-0.9.9/streuselkuchen3.nt');
//$me = $foaf->primaryTopic();
//echo $graph->dump('html');
$resources = $graph->resources();
$namespace = new EasyRdf_Namespace();
$namespace->set('rezept', "http://manke-hosting.de/ns-syntax#");
$rezepte = $graph->resourcesMatching('rezept:RezeptName');
if ($rdf == "true") {
    header("Content-Type: text/turtle; charset=utf-8");
    echo $graph->serialise("turtle");
} else {
    include 'results/rezept.php';
}
Пример #14
0
                        $xml = file_get_contents($filePath);
                        $xmlObject = simplexml_load_string($xml);
                        $namespace = 'xsd';
                        if ($vocabulary == 'xsd') {
                            $namespace = 'xs';
                        }
                        $children = $xmlObject->children($namespace, true);
                        foreach ($children->complexType as $v) {
                            $results[] = $vocabulary . ':' . (string) $v->attributes()->name;
                        }
                        foreach ($children->simpleType as $v) {
                            $results[] = $vocabulary . ':' . (string) $v->attributes()->name;
                        }
                    } elseif ($value['extension'] == 'rdf' || $value['extension'] == 'html') {
                        $graph = new EasyRdf_Graph();
                        $graph->parseFile($filePath);
                        $rdfPhp = $graph->toRdfPhp();
                        foreach ($rdfPhp as $key => $resource) {
                            if (strpos($key, $value['namespace']) === 0) {
                                $key = str_replace($value['namespace'], $vocabulary . ':', $key);
                                $results[] = $key;
                            }
                        }
                    }
                }
            }
            $app->response->headers->set('Content-Type', 'application/json');
            $app->response->write(json_encode($results));
        });
    });
});
Пример #15
0
<?php

require_once 'EasyRdf.php';
header('Content-Type: text/turtle; charset=UTF-8');
//$graph = EasyRdf_Graph::newAndLoad('http://manke-hosting.de/wrapper/index.php/explore/apfelkuchen');
$graph = new EasyRdf_Graph();
$out = "";
$uniqid = uniqid();
//$me = $foaf->primaryTopic();
//echo $graph->dump('html');
//print_r($graph ->get("rdf:type") );
$graph->parseFile('/Users/raphaelmanke/Downloads/linked-data-fu-0.9.9/schokokuchen.nt');
//$me = $foaf->primaryTopic();
//echo $graph->dump('html');
$resources = $graph->resources();
$namespace = new EasyRdf_Namespace();
$namespace->set('rezept', "http://manke-hosting.de/ns-syntax#");
echo $graph->serialise("turtle");
//print_r($graph->allOfType("rdf:RezeptName"));
/*
	foreach ($resources as $value) {
		if ($value -> get("rdf:type", "arecipe:Recipe") != ""){
			echo $value;
		}
		echo "bla" . "<br>";
		print_r( $value ->all('^rdf:type') );
	} 
*/
Пример #16
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
// Prepare app
$app = new Slim(array('negotiation.enabled' => true));
// Setup routes
$app->get('/', function () use($app) {
    $format = $app->respondTo('html', 'rdf', 'ttl', 'json', 'nt');
    switch ($format) {
        case 'html':
            return $app->redirect('http://www.aelius.com/njh/', 303);
        default:
            $rootUrl = $app->request()->getUrl() . $app->request()->getScriptName();
            return $app->redirect("{$rootUrl}/foaf.{$format}", 303);
    }
});
$app->get('/foaf:format', function () use($app) {
    $format = $app->respondTo('rdf', 'ttl', 'json', 'nt');
    $uri = $app->request()->getUrl() . $app->request()->getPath();
    $foaf = new EasyRdf_Graph($uri);
    $foaf->parseFile(__DIR__ . '/../data/foaf.ttl', 'turtle', $uri);
    $app->response()->body($foaf->serialise($format));
});
// Run app
$app->run();
Пример #17
0
 public static function processFile($file)
 {
     $rdf = new EasyRdf_Graph();
     $rdf->parseFile($file);
     return $rdf->toRdfPhp();
 }