function extractLinkedData($link, $origin)
{
    global $ep;
    // Wenn es die URL im Graph schon gibt, nichts machen, TODO besser updaten?
    if (graphContainsUrl($link)) {
        $res = new Response(null, "URL {$link} already visited, skip indexing");
        return res;
    } else {
        $parser = ARC2::getTurtleParser();
        //$data = $_POST['turtle'];
        $parser->parse($link);
        $triples = $parser->getTriples();
        // print_r($triples);
        // Wenn keine Tripel gefunden wurden
        if (count($triples) < 1) {
            $res = new Response(null, "URL {$link} contains no triples");
        } else {
            // in Datenbank einfügen
            $ep->insert($triples, $origin);
            //echo "<pre>";
            //print_r($triples);
            //echo "</pre>";
            $res = new Response(null, "URL {$link}: added " . count($triples) . " triples");
        }
        return $res;
    }
}
예제 #2
0
 function parse($q, $src = '', $iso_fallback = 'ignore')
 {
     $this->setDefaultPrefixes();
     $this->base = $src ? $this->calcBase($src) : ARC2::getRequestURI();
     $this->r = array('base' => '', 'vars' => array(), 'prefixes' => array());
     $this->unparsed_code = $q;
     list($r, $v) = $this->xQuery($q);
     if ($r) {
         $this->r['query'] = $r;
         $this->unparsed_code = trim($v);
     } elseif (!$this->getErrors() && !$this->unparsed_code) {
         $this->addError('Query not properly closed');
     }
     $this->r['prefixes'] = $this->prefixes;
     $this->r['base'] = $this->base;
     /* remove trailing comments */
     while (preg_match('/^\\s*(\\#[^\\xd\\xa]*)(.*)$/si', $this->unparsed_code, $m)) {
         $this->unparsed_code = $m[2];
     }
     if ($this->unparsed_code && !$this->getErrors()) {
         $rest = preg_replace('/[\\x0a|\\x0d]/i', ' ', substr($this->unparsed_code, 0, 30));
         $msg = trim($rest) ? 'Could not properly handle "' . $rest . '"' : 'Syntax error, probably an incomplete pattern';
         $this->addError($msg);
     }
 }
예제 #3
0
파일: Sparql.php 프로젝트: Tjoosten/input
 /**
  * Perform the load.
  *
  * @param EasyRdf_Graph $chunk
  * @return void
  */
 public function execute(&$chunk)
 {
     if (!$chunk->isEmpty()) {
         // Don't use EasyRdf's ntriple serializer, as something might be wrong with its unicode byte characters
         // After serializing with semsol/arc and easyrdf, the output looks the same (with unicode characters), but after a
         // binary utf-8 conversion (see $this->serialize()) the outcome is very different, leaving easyrdf's encoding completely different
         // from the original utf-8 characters, and the semsol/arc encoding correct as the original.
         $ttl = $chunk->serialise('turtle');
         $arc_parser = \ARC2::getTurtleParser();
         $ser = \ARC2::getNTriplesSerializer();
         $arc_parser->parse('', $ttl);
         $triples = $ser->getSerializedTriples($arc_parser->getTriples());
         preg_match_all("/(<.*\\.)/", $triples, $matches);
         if ($matches[0]) {
             $this->buffer = array_merge($this->buffer, $matches[0]);
         }
         $triple_count = count($matches[0]);
         $this->log("Added {$triple_count} triples to the load buffer.");
         while (count($this->buffer) >= $this->loader->buffer_size) {
             // Log the time it takes to load the triples into the store
             $start = microtime(true);
             $buffer_size = $this->loader->buffer_size;
             $triples_to_send = array_slice($this->buffer, 0, $buffer_size);
             $this->addTriples($triples_to_send);
             $this->buffer = array_slice($this->buffer, $buffer_size);
             $duration = round((microtime(true) - $start) * 1000, 2);
             $this->log("Took {$buffer_size} triples from the load buffer, loading them took {$duration} ms.");
         }
     }
 }
예제 #4
0
 /**
  * Connexion au store
  * @return bool
  */
 private function connect()
 {
     $this->store = ARC2::getStore($this->config);
     if (!@$this->store->getDBCon()) {
         //On regarde si l'on peut se connecter avec les informations fournies
         $this->errors[] = "Error connexion";
         return false;
     } else {
         if (!$this->store->isSetUp()) {
             //Si les tables du store n'existent pas
             $this->store->setUp();
             //On crée les tables
             if ($erreurs = $this->store->getErrors()) {
                 //Si la création à échouée
                 foreach ($erreurs as $value) {
                     $this->errors[] = $value;
                 }
                 return false;
                 $this->store->closeDBCon();
             } else {
                 //Si on vient de faire la création pour pouvoir faire autre chose on doit se déconnecter et se reconnecter
                 $this->store->closeDBCon();
                 $this->store = ARC2::getStore($this->config);
             }
         }
     }
     return true;
 }
예제 #5
0
 function parse($path, $data = '')
 {
     $this->state = 0;
     /* reader */
     if (!$this->v('reader')) {
         ARC2::inc('Reader');
         $this->reader =& new ARC2_Reader($this->a, $this);
     }
     $this->reader->setAcceptHeader('Accept: sparql-results+xml; q=0.9, */*; q=0.1');
     $this->reader->activate($path, $data);
     $this->x_base = isset($this->a['base']) && $this->a['base'] ? $this->a['base'] : $this->reader->base;
     /* xml parser */
     $this->initXMLParser();
     /* parse */
     $first = true;
     while ($d = $this->reader->readStream()) {
         if (!xml_parse($this->xml_parser, $d, false)) {
             $error_str = xml_error_string(xml_get_error_code($this->xml_parser));
             $line = xml_get_current_line_number($this->xml_parser);
             $this->tmp_error = 'XML error: "' . $error_str . '" at line ' . $line . ' (parsing as ' . $this->getEncoding() . ')';
             return $this->addError($this->tmp_error);
         }
     }
     $this->target_encoding = xml_parser_get_option($this->xml_parser, XML_OPTION_TARGET_ENCODING);
     xml_parser_free($this->xml_parser);
     $this->reader->closeStream();
     return $this->done();
 }
 function extractRDF()
 {
     $tc = 0;
     $t = '';
     $t_vals = array();
     foreach ($this->nodes as $n) {
         if ($n['tag'] != 'a') {
             continue;
         }
         if (!($href = $this->v('href uri', '', $n['a']))) {
             continue;
         }
         if (!($rels = $this->v('rel m', array(), $n['a']))) {
             continue;
         }
         if (!($vals = array_intersect($this->terms, $rels))) {
             continue;
         }
         $parts = preg_match('/^(.*\\/)([^\\/]+)\\/?$/', $href, $m) ? array('space' => $m[1], 'tag' => rawurldecode($m[2])) : array('space' => '', 'tag' => '');
         if ($tag = $parts['tag']) {
             $t_vals['s_' . $tc] = $this->getContainerResIDByClass($n, $this->containers);
             $t_vals['concept_' . $tc] = $this->createBnodeID() . '_concept';
             $t_vals['tag_' . $tc] = $tag;
             $t_vals['space_' . $tc] = $parts['space'];
             $t .= '?s_' . $tc . ' skos:subject [skos:prefLabel ?tag_' . $tc . ' ; skos:inScheme ?space_' . $tc . '] . ';
             $tc++;
         }
     }
     $doc = $this->getFilledTemplate($t, $t_vals, $n['doc_base']);
     $this->addTs(ARC2::getTriplesFromIndex($doc));
 }
예제 #7
0
 function extractRDF()
 {
     foreach ($this->nodes as $n) {
         if ($n['tag'] != 'a') {
             continue;
         }
         if (!($href = $this->v('href iri', '', $n['a']))) {
             continue;
         }
         if (!($rels = $this->v('rel m', array(), $n['a']))) {
             continue;
         }
         if (!($vals = array_intersect($this->terms, $rels))) {
             continue;
         }
         $t_vals = array('s' => $this->getDocOwnerID($n), 's_page' => $this->getDocID($n), 'o' => $this->getPersonID($n), 'o_label' => $this->getResLabel($n), 'o_page' => $href);
         $t = '';
         foreach ($vals as $val) {
             $t .= '?s xfn:' . $val . ' ?o . ';
             $t .= $val == 'me' ? '?s foaf:homepage ?o_page . ' : '';
         }
         if ($t) {
             $t .= '?s a foaf:Person ; foaf:homepage ?s_page . ';
             $t .= '?o a foaf:Person ; foaf:homepage ?o_page ';
             $t .= $t_vals['o_label'] ? '; foaf:name ?o_label . ' : '. ';
             $doc = $this->getFilledTemplate($t, $t_vals, $n['doc_base']);
             $this->addTs(ARC2::getTriplesFromIndex($doc));
         }
     }
 }
    public function __construct() {
        parent::__construct();
        global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $smwgARC2StoreConfig;

        /* instantiation */
        $this->arc2store = ARC2::getStore( $smwgARC2StoreConfig );
    }
 function extractRDF()
 {
     foreach ($this->nodes as $n) {
         if (!($vals = $this->v('class m', array(), $n['a']))) {
             continue;
         }
         if (!in_array('adr', $vals)) {
             continue;
         }
         /* node  */
         $t_vals = array('s' => $this->getResID($n, 'adr'));
         $t = '';
         /* context */
         list($t_vals, $t) = $this->extractContext($n, $t_vals, $t);
         /* properties */
         foreach ($this->terms as $term) {
             $m = 'extract' . $this->camelCase($term);
             if (method_exists($this, $m)) {
                 list($t_vals, $t) = $this->{$m}($n, $t_vals, $t);
             }
         }
         /* result */
         $doc = $this->getFilledTemplate($t, $t_vals, $n['doc_base']);
         $this->addTs(ARC2::getTriplesFromIndex($doc));
     }
 }
 function test_set_comment_add_rdfs_comment_triple()
 {
     $fpmap = new QueryProfile("http://example.org/store/queryprofiles/1");
     $fpmap->set_comment('my qp is kewl');
     $index = ARC2::getSimpleIndex($fpmap->get_triples(), true);
     $this->assertEquals("my qp is kewl", $index[$fpmap->uri]['http://www.w3.org/2000/01/rdf-schema#comment'][0]);
 }
예제 #11
0
 public function testSelectSerializeAndDelete()
 {
     global $EndPoint4store, $modeDebug, $prefixSparql, $prefixTurtle, $graph1, $graph2;
     $s = new Endpoint($EndPoint4store, false, $modeDebug);
     $this->checkIfInitialState($s);
     $r = $s->set($graph1, $prefixTurtle . "\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\t\t\t\t\ta:A b:Name \"Test2\"@en.\n\t\t\t\t\ta:A b:Name \"Test3\"@fr.\n\t\t\t\t\ta:A b:Name \"Test4\".\n\t\t\t\t\ta:A b:date \"2010-03-09T22:30:00Z\"^^xsd:dateTime .\n\t\t\t\t\t");
     $q = $prefixSparql . "\n select * where {GRAPH <" . $graph1 . "> {a:A ?p ?o.}} ";
     $triples = $s->query($q, 'rows');
     $err = $s->getErrors();
     if ($err) {
         print_r($err);
         $this->assertTrue(false);
     }
     for ($i = 0, $i_max = count($triples); $i < $i_max; $i++) {
         $triples[$i]['s'] = "http://example.com/test/a/A";
         $triples[$i]['s type'] = "uri";
     }
     //print_r($triples);
     /* Serializer instantiation */
     $ser = ARC2::getNTriplesSerializer();
     /* Serialize a triples array */
     $docd = $ser->getSerializedTriples($triples, 1);
     $q = "DELETE DATA {  \n\t\t\t\tGRAPH <" . $graph1 . "> {    \n\t\t\t\t{$docd} \n    \t\t}}";
     //print_r($q);
     $res = $s->query($q, 'raw');
     $err = $s->getErrors();
     if ($err) {
         print_r($err);
         $this->assertTrue(false);
     }
     $this->assertTrue($res);
     $this->checkIfInitialState($s);
 }
예제 #12
0
 public function testBlockUpdateWithoutGraph()
 {
     global $prefixSparql, $graph1;
     $q = $prefixSparql . " \n\t\t\tINSERT DATA { \n\t\t\t\ta:A b:Name \"Test2\" . \n    \t\t}";
     $p = ARC2::getSPARQLPlusParser();
     $p->parse($q);
     $infos = $p->getQueryInfos();
     $t1 = ARC2::mtime();
     $err = $p->getErrors();
     if ($err) {
         print_r($err);
         $this->assertTrue(true);
     } else {
         $this->assertTrue(false);
     }
     $q = $prefixSparql . " \n\t\t\tDELETE DATA { \n\t\t\t\ta:A b:Name \"Test2\" . \n    \t\t}";
     $p = ARC2::getSPARQLPlusParser();
     $p->parse($q);
     $infos = $p->getQueryInfos();
     $t1 = ARC2::mtime();
     $err = $p->getErrors();
     if ($err) {
         print_r($err);
         $this->assertTrue(true);
     } else {
         $this->assertTrue(false);
     }
 }
예제 #13
0
 public function __construct($contextURI)
 {
     global $config;
     $this->store = ARC2::getStore($config);
     $this->contextURI = $contextURI;
     $this->query = "\n\nSELECT DISTINCT ?rName ?pURL ?pTitle  ?lvDesc  ?lvScore \nWHERE  {\n\t<{$this->contextURI}> r:hasRubric ?rubric ; \nr:hasRubric ?rubric ; \n\t    r:hasRecording ?rec .\n        ?rubric sioc:name ?rName . \n\t?rec r:hasLineValue ?lv ;\n\t\tr:hasPage ?pURL ; \n\t\t sioc:has_creator ?recCreator . \n\t?lv r:score ?lvScore ;\n\t\tr:description ?lvDesc . \nOPTIONAL {\n\t?pURL dc:title ?pTitle . \n}\t\n}\n\n\t";
 }
예제 #14
0
 public function testAddGraphToStore()
 {
     $storeConf = array('db_host' => 'localhost', 'db_name' => 'negtest', 'db_user' => 'negtest', 'db_pwd' => 'negtest');
     $store = ARC2::getStore($storeConf);
     $store->reset();
     if (!$store->isSetUp()) {
         $store->setUp();
     }
     $docNeg = $this->getDOMDocNeg();
     $docNeg->setStore($store);
     $docNeg->process();
     $docNeg->gatherSubnegotiatorGraphs(false);
     $docNeg->addGraphToStore();
     $q = 'SELECT DISTINCT ?s ?p ?o WHERE { ?s ?p ?o }';
     $rs = $store->query($q);
     if (!$store->getErrors()) {
         $rows = $rs['result']['rows'];
         $this->assertEquals('http://example.org/domDoc', $rows[0]['s']);
     }
     $q = 'SELECT DISTINCT ?s ?p ?o WHERE { GRAPH <http://example.org/graphURI> { ?s ?p ?o } }';
     $rs = $store->query($q);
     if (!$store->getErrors()) {
         $rows = $rs['result']['rows'];
         $this->assertEquals('http://example.org/domDoc', $rows[0]['s']);
         $this->assertEquals(2, count($rows));
     }
     $q = 'SELECT DISTINCT ?s ?p ?o WHERE { GRAPH <http://example.org/graphURIX> { ?s ?p ?o } }';
     $rs = $store->query($q);
     if (!$store->getErrors()) {
         $rows = $rs['result']['rows'];
         $this->assertEquals(0, count($rows));
     }
 }
예제 #15
0
 function extractRDF()
 {
     $tc = 0;
     $t = '';
     $t_vals = array();
     foreach ($this->nodes as $n) {
         if ($n['tag'] != 'a') {
             continue;
         }
         if (!($href = $this->v('href uri', '', $n['a']))) {
             continue;
         }
         if (!($rels = $this->v('rel m', array(), $n['a']))) {
             continue;
         }
         if (!($vals = array_intersect($this->terms, $rels))) {
             continue;
         }
         if (in_array('category', $this->v('class m', array(), $n['a']))) {
             continue;
         }
         /* hcard/hcalendar categories */
         $parts = preg_match('/^(.*\\/)([^\\/]+)\\/?$/', $href, $m) ? array('space' => $m[1], 'tag' => rawurldecode($m[2])) : array('space' => '', 'tag' => '');
         if ($tag = $parts['tag']) {
             $t_vals['s_' . $tc] = $this->getContainerResIDByClass($n, $this->containers);
             $t_vals['tag_' . $tc] = $tag;
             $t .= '?s_' . $tc . ' dc:subject ?tag_' . $tc . ' . ';
             $tc++;
         }
     }
     $doc = $this->getFilledTemplate($t, $t_vals, $n['doc_base']);
     $this->addTs(ARC2::getTriplesFromIndex($doc));
 }
 public function testGetFormatWithNTriples()
 {
     $data = file_get_contents('../data/nt/test.nt');
     $actual = ARC2::getFormat($data);
     $this->assertEquals('ntriples', $actual);
     $actual = ARC2::getFormat($data, '', 'nt');
     $this->assertEquals('ntriples', $actual);
 }
예제 #17
0
 public function __construct($contextURIs)
 {
     global $config;
     global $graphConfig;
     $this->store = ARC2::getStore($config);
     $this->uris = $contextURIs;
     $this->graph = ARC2::getComponent('PMJ_ResourceGraphPlugin', $graphConfig);
 }
 public function getResourcePredicates($subject)
 {
     $resource = ARC2::getResource();
     $resource->setStore($this->getStore());
     $resource->setURI($subject);
     $properties = $resource->getProps();
     return $properties;
 }
예제 #19
0
 /**
  * function  mergeResource
  * @param PMJ_ResourcePlus $res
  */
 public function mergeResource($res)
 {
     if ($res - uri != $this->uri) {
         $this->addError('Resource uris must match');
         return false;
     }
     $this->index = ARC2::getMergedIndex($res->index, $this->index);
 }
예제 #20
0
 public static function query($query)
 {
     $dbpconfig = array("remote_store_endpoint" => "http://localhost:8000/sparql/");
     $store = ARC2::getRemoteStore($dbpconfig);
     $query = $query;
     $rows = $store->query($query, 'rows');
     /* execute the query */
     return $rows;
 }
 function runQuery($infos, $keep_bnode_ids = 0)
 {
     $this->infos = $infos;
     $con = $this->store->getDBCon();
     ARC2::inc('StoreDumper');
     $d = new ARC2_StoreDumper($this->a, $this->store);
     $d->dumpSPOG();
     return 1;
 }
예제 #22
0
 public function getNegotiators($val, $nArray = false)
 {
     $retArray = array();
     $nArray = $nArray ? $nArray : $this->negotiators;
     foreach ($this->negotiators as $n) {
         if ($this->applyTestOnNegotiator($n, $val)) {
             $retArray[] = ARC2::getComponent($n);
         }
     }
 }
예제 #23
0
파일: JSON.php 프로젝트: tdt/formatters
 public function printGraph()
 {
     /* Serializer instantiation */
     $ser = \ARC2::getRDFJSONSerializer();
     foreach ($this->objectToPrint as $class => $prop) {
         $triples = $prop->getTriples();
     }
     /* Serialize a triples array */
     echo $ser->getSerializedTriples($triples);
 }
예제 #24
0
 /**
  * Executes endpoint action
  *
  */
 public function executeEndpoint()
 {
     require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'arc_config.php';
     /* instantiation */
     $ep = ARC2::getStoreEndpoint($arc_config);
     /* request handling */
     $ep->go();
     $this->ep = $ep;
     return sfView::NONE;
 }
예제 #25
0
function parse_to_simple_index($rdfxml)
{
    $triples = array();
    if (strlen($rdfxml) > 0) {
        $parser = ARC2::getRDFXMLParser();
        $parser->parse(null, $rdfxml);
        $triples = $parser->getSimpleIndex(0);
    }
    return $triples;
}
예제 #26
0
function get_openlink_acct($acct)
{
    $parser = ARC2::getRDFParser();
    $parser->parse($acct);
    $triples = $parser->getTriples();
    foreach ($triples as $row) {
        if (strcmp($row[p], "http://xmlns.com/foaf/0.1/accountServiceHomepage") == 0) {
            return convert_to_rss($row[o]);
        }
    }
}
예제 #27
0
 public function __construct()
 {
     $this->store = ARC2::getStore($this->config);
     if (!$this->store->isSetUp()) {
         $this->store->setUp();
     }
     //$this->store->reset();
     //$this->store->query('LOAD <person.rdf>');
     //$this->store->query('LOAD <http://xmlns.com/foaf/0.1/>');
     $this->ns = array('rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'foaf' => 'http://xmlns.com/foaf/0.1/', 's' => 'http://www.w3.org/2000/01/rdf-schema#', 'view' => 'http://purl.org/aquarium/engine/MVC/', 'tal' => 'http://xml.zope.org/namespaces/tal');
 }
예제 #28
0
 function parse($path, $data = '', $iso_fallback = false)
 {
     /* reader */
     if (!$this->v('reader')) {
         ARC2::inc('Reader');
         $this->reader = new ARC2_Reader($this->a, $this);
     }
     $this->reader->setAcceptHeader('Accept: application/rdf+xml; q=0.9, */*; q=0.1');
     $this->reader->activate($path, $data);
     $this->x_base = isset($this->a['base']) && $this->a['base'] ? $this->a['base'] : $this->reader->base;
     /* xml parser */
     $this->initXMLParser();
     /* parse */
     $first = true;
     while ($d = $this->reader->readStream()) {
         if (!$this->keep_time_limit) {
             @set_time_limit($this->v('time_limit', 60, $this->a));
         }
         if ($iso_fallback && $first) {
             $d = '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n" . preg_replace('/^\\<\\?xml [^\\>]+\\?\\>\\s*/s', '', $d);
             $first = false;
         }
         preg_match_all('/<<<(.+?\\s*?)*?>>>/', $d, $res);
         if (isset($res)) {
             foreach ($res[0] as $templ) {
                 $key = 'template_' . count($this->templates);
                 $this->templates[$key] = str_replace('<<<', '', str_replace('>>>', '', $templ));
                 $d = str_replace($templ, $key, $d);
             }
         }
         if (!xml_parse($this->xml_parser, $d, false)) {
             $error_str = xml_error_string(xml_get_error_code($this->xml_parser));
             $line = xml_get_current_line_number($this->xml_parser);
             $this->tmp_error = 'XML error: "' . $error_str . '" at line ' . $line . ' (parsing as ' . $this->getEncoding() . ')';
             if (!$iso_fallback && preg_match("/Invalid character/i", $error_str)) {
                 xml_parser_free($this->xml_parser);
                 unset($this->xml_parser);
                 $this->reader->closeStream();
                 $this->__init();
                 $this->encoding = 'ISO-8859-1';
                 unset($this->xml_parser);
                 unset($this->reader);
                 return $this->parse($path, $data, true);
             } else {
                 return $this->addError($this->tmp_error);
             }
         }
     }
     $this->target_encoding = xml_parser_get_option($this->xml_parser, XML_OPTION_TARGET_ENCODING);
     xml_parser_free($this->xml_parser);
     $this->reader->closeStream();
     unset($this->reader);
     return $this->done();
 }
예제 #29
0
 public function setNegotiators()
 {
     if ($handle = opendir('./')) {
         while (false !== ($file = readdir($handle))) {
             if (substr($file, 0, 12) == 'negotiators_' && $file != 'negotiators_DataNegotiatorPlugin' && substr($file, -1) != '~') {
                 ARC2::inc(rtrim($file, '.php'));
                 $this->negotiators[] = rtrim($file, '.php');
             }
         }
         closedir($handle);
     }
 }
예제 #30
0
 function render($context, $stream)
 {
     global $dbh;
     global $class_path;
     $query_stream = new StreamWriter();
     $this->sparql_query->render($context, $query_stream);
     $query = $query_stream->close();
     require_once "{$class_path}/rdf/arc2/ARC2.php";
     $config = array('remote_store_endpoint' => $this->endpoint, 'remote_store_timeout' => 10);
     $store = ARC2::getRemoteStore($config);
     $context->set($this->struct_name, $store->query($query, 'rows'));
 }