getTriplesFromIndex() static public method

static public getTriplesFromIndex ( $index )
 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));
 }
示例#2
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));
         }
     }
 }
 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));
 }
 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 extractRDF()
 {
     $t_vals = array();
     $t = '';
     foreach ($this->nodes as $n) {
         if (isset($n['tag']) && $n['tag'] == 'link') {
             $m = 'extract' . ucfirst($n['tag']);
             list($t_vals, $t) = $this->{$m}($n, $t_vals, $t);
         }
     }
     if ($t) {
         $doc = $this->getFilledTemplate($t, $t_vals, $n['doc_base']);
         $this->addTs(ARC2::getTriplesFromIndex($doc));
     }
 }
 function extractRDF()
 {
     $t_vals = array();
     $t = '';
     foreach ($this->nodes as $n) {
         if (isset($n['tag']) && $n['tag'] == 'img' && $this->v('id', '', $n['a']) == 'profile-image') {
             $t_vals['vcard_id'] = $this->getDocID($n) . '#resource(side/1/2/1)';
             $t .= '?vcard_id mf:photo <' . $n['a']['src'] . '> . ';
             break;
         }
     }
     if ($t) {
         $doc = $this->getFilledTemplate($t, $t_vals, $n['doc_base']);
         $this->addTs(ARC2::getTriplesFromIndex($doc));
     }
 }
 function extractRDF()
 {
     foreach ($this->nodes as $n) {
         if (!($vals = $this->v('class m', array(), $n['a']))) {
             continue;
         }
         if (!in_array('vevent', $vals)) {
             continue;
         }
         /* vevent  */
         $t_vals = array('s' => $this->getResID($n, 'vevent') . '_event', 's_type' => $this->a['ns']['cal'] . 'Vevent');
         $t = ' ?s a ?s_type . ';
         /* 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 deleteConstructedGraph()
 {
     ARC2::inc('StoreConstructQueryHandler');
     $h =& new ARC2_StoreConstructQueryHandler($this->a, $this->store);
     $sub_r = $h->runQuery($this->infos);
     $triples = ARC2::getTriplesFromIndex($sub_r);
     $tgs = $this->infos['query']['target_graphs'];
     $this->infos = array('query' => array('construct_triples' => $triples, 'target_graphs' => $tgs));
     return $this->deleteTriples();
 }
 function toTriples($v)
 {
     if (is_array($v)) {
         if (isset($v[0]) && isset($v[0]['s'])) {
             return $v;
         }
         return ARC2::getTriplesFromIndex($v);
     }
     $parser = ARC2::getRDFParser($this->a);
     if ($v && !preg_match('/\\s/', $v)) {
         /* assume graph URI */
         $parser->parse($v);
     } else {
         $parser->parse('', $v);
     }
     return $parser->getTriples();
 }
示例#10
0
 function extractRDF()
 {
     $index = $this->getNodeIndex();
     //print_r($index);
     $this->rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
     $this->atom = 'http://www.w3.org/2005/atom';
     $this->rss = 'http://purl.org/rss/1.0/';
     $this->dc = 'http://purl.org/dc/elements/1.1/';
     $this->dct = 'http://purl.org/dc/terms/';
     $this->content = 'http://purl.org/rss/1.0/modules/content/';
     $this->enc = 'http://purl.oclc.org/net/rss_2.0/enc#';
     $this->mappings = array('feed' => $this->rss . 'channel', 'entry' => $this->rss . 'item', 'title' => $this->rss . 'title', 'link' => $this->rss . 'link', 'summary' => $this->rss . 'description', 'content' => $this->content . 'encoded', 'id' => $this->dc . 'identifier', 'author' => $this->dc . 'creator', 'category' => $this->dc . 'subject', 'updated' => $this->dc . 'date', 'source' => $this->dc . 'source');
     $this->dt_props = array($this->dc . 'identifier', $this->rss . 'link');
     foreach ($index as $p_id => $nodes) {
         foreach ($nodes as $pos => $node) {
             $tag = $this->v('tag', '', $node);
             if ($tag == 'feed') {
                 $struct = $this->extractChannel($index[$node['id']]);
                 $triples = ARC2::getTriplesFromIndex($struct);
                 foreach ($triples as $t) {
                     $this->addT($t);
                 }
             } elseif ($tag == 'entry') {
                 $struct = $this->extractItem($index[$node['id']]);
                 $triples = ARC2::getTriplesFromIndex($struct);
                 foreach ($triples as $t) {
                     $this->addT($t);
                 }
             }
         }
     }
 }
 /**
  * Get all triples with a given subject
  * @param string $subjecturi
  * @return array $triples
  */
 function getTriplesForSubject( $subjecturi ) {
     $reconstructedIndex = array( $subjecturi => $this->m_tripleindex[$subjecturi] );
     $triples = ARC2::getTriplesFromIndex( $reconstructedIndex );
     return $triples;
 }
示例#12
0
 /**
  * Execute method for SPARQL queries that only queries and returns results, but
  * does not modify, add or delete triples.
  */
 function executeNonEditSparqlQuery()
 {
     global $wgOut;
     $output = $this->passSparqlToARC2AndGetAsPhpSerialization();
     $outputtype = $this->determineOutputType();
     if ($outputtype == 'rdfxml') {
         # Here the results should be RDF/XML triples,
         # not just plain XML SPARQL result set
         $output_structure = unserialize($output);
         $tripleindex = $output_structure['result'];
         $triples = ARC2::getTriplesFromIndex($tripleindex);
         if ($this->requestdata->outputequivuris) {
             // FIXME: Why is this uncommented???
             # $triples = $this->complementTriplesWithEquivURIsForProperties( $triples );
             $triples = $this->complementTriplesWithEquivURIs($triples);
         }
         $output = $this->triplesToRDFXML($triples);
         # Using echo instead of $wgOut->addHTML() here, since output format is not HTML
         echo $output;
     } else {
         // TODO: Add some kind of check that the output is really an object
         if (count($output) > 0) {
             $output_structure = unserialize($output);
             if ($this->requestdata->outputequivuris) {
                 $output_structure = $this->urisToEquivURIsInSparqlResults($output_structure);
             }
             if ($outputtype == 'htmltab') {
                 $output = $this->sparqlResultToHTML($output_structure);
                 $wgOut->addHTML($output);
             } else {
                 # Using echo instead of $wgOut->addHTML() here, since output format is not HTML
                 $output = $this->sparqlendpoint->getSPARQLXMLSelectResultDoc($output_structure);
                 echo $output;
             }
         } else {
             $wgOut->setHTML("ERROR: No results from SPARQL query!");
         }
     }
 }
    /**
     * The main function
     */
    function execute() {
        global $wgRequest, $wgOut, $wgUser;

        $this->setHeaders();
        $this->handleRequestData();

        $executesparql = true;

        if ( $this->m_query == '' ) {
            $this->printHTMLForm();
        } else {
            $this->ensureSparqlEndpointInstalled();
            $this->convertURIsInQuery();

            if ( $this->m_querytype == 'insert' ) { // TODO
                if ( $this->checkAllowInsert() ) {
                    $this->importTriplesInQuery();
                }
                $this->printHTMLForm();
            } elseif ( $this->m_querytype == 'delete' ) {
                if ( $this->checkAllowDelete() ) {
                    $this->deleteTriplesInQuery();
                }
                // TODO Add a "successfully inserted/deleted" message here
                $this->printHTMLForm();
            } else { // We are querying/outputting data, not editing

                if ( $this->m_outputtype == 'htmltab' ) {
                    $this->printHTMLForm();
                    if ( $wgRequest->getBool( 'showquery', false ) ) {
                        $this->printQueryStructure();
                        $executesparql = false;
                    }
                } elseif ( $this->m_outputtype == 'rdfxml' && $this->m_querytype != 'construct' ) {
                    $errormessage = "RDF/XML can only be used with CONSTRUCT, if constructing triples";
                    $wgOut->addHTML( RDFIOUtils::formatErrorHTML( "Invalid choice", $errormessage ) );
                    $this->printHTMLForm();
                    $executesparql = false;
                } else {
                    $this->prepareCreatingDownloadableFile();
                }

                if ( $executesparql ) {
                    $outputtype = $this->m_outputtype;
                    if ( $outputtype == '' && $this->m_querytype == 'construct' ) {
                        $outputtype = 'rdfxml';
                    }
                    if ( $outputtype == 'rdfxml' || $outputtype == 'xml' || $outputtype == '' ) {
                        // Make sure that ARC outputs data in a format that we can
                        // easily work with programmatically
                        $this->setOutputTypeInPost( 'php_ser' );
                    }

                    // Pass on the request handling to ARC2:s SPARQL Endpoint
                    $this->m_sparqlendpoint->handleRequest();
                    $this->handleSPARQLErrors();
                    $output = $this->m_sparqlendpoint->getResult();

                    if ( $outputtype == 'htmltab' ) {
                        if ( $this->m_outputoriguris ) {
                            $output = $this->convertURIsToOrigURIsInText( $output );
                        }
                        $output = $this->extractPrepareARCHTMLOutput( $output );
                        $wgOut->addHTML( $output );
                    } elseif ( $outputtype == 'rdfxml' ) {
                        $output_structure = unserialize( $output );
                        $tripleindex = $output_structure['result'];
                        $triples = ARC2::getTriplesFromIndex( $tripleindex );
                        if ( $this->m_outputoriguris ) {
                            $triples = $this->convertURIsToOrigURIsInTriples( $triples );
                        }
                        if ( $this->m_outputequivuris ) {
                            # $triples = $this->complementTriplesWithEquivURIsForProperties( $triples );
                            if ( $this->m_filtervocab && ( $this->m_filtervocaburl != '' ) ) {
                                $vocab_p_uri_filter = $this->getVocabPropertyUriFilter();
                                $triples = $this->complementTriplesWithEquivURIs( $triples, $vocab_p_uri_filter );
                            } else {
                                $triples = $this->complementTriplesWithEquivURIs( $triples );
                            }
                        }
                        $output = $this->triplesToRDFXML( $triples );
                        echo $output;
                    } else {
                        $output_structure = unserialize( $output );
                        if ( $this->m_outputoriguris ) {
                            $output_structure = $this->convertURIsToOrigURIsInSPARQLResultSet( $output_structure );
                        }
                        if ( $this->m_outputequivuris ) {
                            $vocab_p_uri_filter = $this->getVocabPropertyUriFilter();
                            $output_structure = $this->complementSPARQLResultRowsWithEquivURIs( $output_structure, $vocab_p_uri_filter );
                        }
                        $output = $this->m_sparqlendpoint->getSPARQLXMLSelectResultDoc( $output_structure );
                        echo $output;
                    }
                }
            }
        }
    }
 /**
  * @deprecated this is deprecated
  */
 function get_triples()
 {
     return ARC2::getTriplesFromIndex($this->_to_arc_index($this->_index));
 }