当前位置: 首页>>代码示例>>PHP>>正文


PHP ARC2::getTurtleParser方法代码示例

本文整理汇总了PHP中ARC2::getTurtleParser方法的典型用法代码示例。如果您正苦于以下问题:PHP ARC2::getTurtleParser方法的具体用法?PHP ARC2::getTurtleParser怎么用?PHP ARC2::getTurtleParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ARC2的用法示例。


在下文中一共展示了ARC2::getTurtleParser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * 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.");
         }
     }
 }
开发者ID:Tjoosten,项目名称:input,代码行数:36,代码来源:Sparql.php

示例2: extractLinkedData

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;
    }
}
开发者ID:neumann89,项目名称:FUB-xml-project6-2013,代码行数:27,代码来源:linkeddataendpoint.php

示例3: __construct

 public function __construct($a = '')
 {
     parent::__construct();
     $this->a = $a;
     /* parse the before and after graphs if necessary*/
     foreach (array('before', 'after', 'before_rdfxml', 'after_rdfxml') as $rdf) {
         if (!empty($a[$rdf])) {
             if (is_string($a[$rdf])) {
                 /** @var \ARC2_RDFParser $parser */
                 $parser = \ARC2::getRDFParser();
                 $parser->parse(false, $a[$rdf]);
                 $a[$rdf] = $parser->getSimpleIndex(0);
             } else {
                 if (is_array($a[$rdf]) and isset($a[$rdf][0]) and isset($a[$rdf][0]['s'])) {
                     //triples array
                     /** @var \ARC2_RDFSerializer $ser */
                     $ser = \ARC2::getTurtleSerializer();
                     /** @var string $turtle */
                     $turtle = $ser->getSerializedTriples($a[$rdf]);
                     /** @var \ARC2_RDFParser $parser */
                     $parser = \ARC2::getTurtleParser();
                     $parser->parse(false, $turtle);
                     $a[$rdf] = $parser->getSimpleIndex(0);
                 }
             }
             $nrdf = str_replace('_rdfxml', '', $rdf);
             $this->{$nrdf} = $a[$rdf];
         }
     }
     $this->__init();
 }
开发者ID:talis,项目名称:tripod-php,代码行数:31,代码来源:ChangeSet.class.php

示例4: __construct

    function __construct( $importdata, $dataformat ) {
        global $rdfiogExtraNSPrefixes,
        $rdfiogPropertiesToUseAsWikiTitle,
        $rdfiogUseNSPrefixInWikiTitleForProperties,
        $rdfiogUseNSPrefixInWikiTitleForEntities;

        if ( $dataformat == 'triples_array' ) {
            $this->m_triples = $importdata;
        } else {
            $this->m_unparseddata = $importdata;
        }
        $this->m_dataformat = $dataformat;
        $this->m_haserrors = false;
        $this->m_delete = false;
        if ( $this->m_dataformat == 'rdfxml' ) {
            $this->m_unparseddata = $this->cleanupXML( $this->m_unparseddata );
            $this->m_parser = ARC2::getRDFXMLParser();
            $this->parse();
        } elseif ( $this->m_dataformat == 'turtle' ) {
            $this->m_unparseddata = $wgRequest->getText( 'importdata' );
            $this->m_parser = ARC2::getTurtleParser();
            $this->parse();
        }
        $this->extractTripleIndex();
        $this->m_nsprefixes = $this->getNSPrefixMappingFromParser();
        if ( $rdfiogExtraNSPrefixes != '' ) {
            $this->addNamespacePrefixes( $rdfiogExtraNSPrefixes );
        }
        $nsprefixes = $this->m_nsprefixes;
        $this->setNSPrefixes( $nsprefixes );
        $this->setTripleIndex( $this->m_tripleindex );

        // Previously in Equiv URI Class

        if ( isset($rdfiogUsePseudoNamespacesForProperties) ) { // TODO: Change to check options from import screen
            // use parameter set in LocalSettings.php
            $this->m_usenspintitles_properties = $rdfiogUsePseudoNamespacesForProperties;
        }

        if ( isset($rdfiogUsePseudoNamespacesForEntities) ) {
            // use parameter set in LocalSettings.php
            $this->m_usenspintitles_entities = $rdfiogUsePseudoNamespacesForEntities;
        }

        if ( !empty( $rdfiogPropertiesToUseAsWikiTitle ) ) {
            $this->m_wikititlepropertyuris = $rdfiogPropertiesToUseAsWikiTitle;
        } else {
            $this->m_wikititlepropertyuris = array(
            	'http://semantic-mediawiki.org/swivt/1.0#page', // Suggestion for new property
            	'http://www.w3.org/2000/01/rdf-schema#label',
            	'http://purl.org/dc/elements/1.1/title',
            	'http://www.w3.org/2004/02/skos/core#preferredLabel',
            	'http://xmlns.com/foaf/0.1/name'
            	);
        }

        $this->m_store = new RDFIOStore();
    }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:58,代码来源:SMWBatchWriter.php

示例5: importTurtle

 /**
  * Import RDF/XML, e.g. from the RDF Import Special Page.
  * @param string $importData
  */
 public function importTurtle($importData)
 {
     // Parse RDF/XML to triples
     $arc2turtleparser = ARC2::getTurtleParser($importData);
     $arc2turtleparser->parseData($importData);
     // Receive the data
     $triples = $arc2turtleparser->triples;
     $tripleIndex = $arc2turtleparser->getSimpleIndex();
     $namespaces = $arc2turtleparser->nsp;
     /* DEBUGGING
     		echo "*** Triples ***";
     		echo( print_r( $triples, true ));
     		echo "*** Triple index ***";
     		echo( print_r( $tripleIndex, true ));
     		echo "*** Namespaces ***";
     		echo( print_r( $namespaces, true ));
     		 */
     $this->importFromArc2Data($triples, $tripleIndex, $namespaces);
     return $output = array('triples' => $triples, 'tripleIndex' => $tripleIndex, 'namespaces' => $namespaces);
 }
开发者ID:rdfio,项目名称:RDFIO,代码行数:24,代码来源:RDFIO_RDFImporter.php

示例6: load

 public function load($uri, $aliases = array(), $map = array())
 {
     $this->forceString($uri);
     $uri = $this->expandURI($uri);
     if (substr($uri, 0, 5) == "data:") {
         $data = urldecode(preg_replace("/^data:[^,]*,/", "", $uri));
         $parser = ARC2::getTurtleParser();
         $parser->parse($uri, $data);
     } else {
         if (isset($this->loaded[$uri])) {
             return $this->loaded[$uri];
         }
         if (isset($this->cacheDir)) {
             $filename = $this->cacheDir . "/" . md5($uri);
             if (!file_exists($filename) || filemtime($filename) + $this->cacheAge < time()) {
                 # decache if out of date, even if we fail to re cache.
                 if (file_exists($filename)) {
                     unlink($filename);
                 }
                 $url = $uri;
                 $ttl = 16;
                 $mime = "";
                 $old_user_agent = ini_get('user_agent');
                 ini_set('user_agent', "PHP\r\nAccept: application/rdf+xml");
                 while ($ttl > 0) {
                     # dirty hack to set the accept header without using curl
                     if (!($rdf_fp = fopen($url, 'r'))) {
                         break;
                     }
                     $meta_data = stream_get_meta_data($rdf_fp);
                     $redir = 0;
                     foreach ($meta_data['wrapper_data'] as $response) {
                         if (substr(strtolower($response), 0, 10) == 'location: ') {
                             $newurl = substr($response, 10);
                             if (substr($newurl, 0, 1) == "/") {
                                 $parts = preg_split("/\\//", $url);
                                 $newurl = $parts[0] . "//" . $parts[2] . $newurl;
                             }
                             $url = $newurl;
                             $redir = 1;
                         }
                         if (substr(strtolower($response), 0, 14) == 'content-type: ') {
                             $mime = preg_replace("/\\s*;.*\$/", "", substr($response, 14));
                         }
                     }
                     if (!$redir) {
                         break;
                     }
                     $ttl--;
                     fclose($rdf_fp);
                 }
                 ini_set('user_agent', $old_user_agent);
                 if ($ttl > 0 && $mime == "application/rdf+xml" && $rdf_fp) {
                     # candidate for caching!
                     if (!($cache_fp = fopen($filename, 'w'))) {
                         echo "Cannot write file ({$filename})";
                         exit;
                     }
                     while (!feof($rdf_fp)) {
                         fwrite($cache_fp, fread($rdf_fp, 8192));
                     }
                     fclose($cache_fp);
                 }
                 fclose($rdf_fp);
             }
         }
         if (isset($filename) && file_exists($filename)) {
             $parser = ARC2::getRDFXMLParser();
             $parser->parse($filename);
         } else {
             $parser = ARC2::getRDFParser();
             # Don't try to load the same URI twice!
             if (!isset($this->firstGraphURI)) {
                 $this->firstGraphURI = $uri;
             }
             $parser->parse($uri);
         }
     }
     $errors = $parser->getErrors();
     $parser->resetErrors();
     if (sizeof($errors)) {
         if ($this->debug) {
             print "<h3>Error loading: {$uri}</h3>";
             print "<ul><li>" . join("</li><li>", $errors) . "</li></ul>";
         }
         return 0;
     }
     $triples = $parser->getTriples();
     foreach ($triples as $t) {
         $t["s"] = $this->cleanURI($t["s"]);
         if (!isset($map[$t["s"]])) {
             continue;
         }
         $t["p"] = $this->cleanURI($t["p"]);
         if ($t["p"] != "http://www.w3.org/2002/07/owl#sameAs") {
             continue;
         }
         $aliases[$t["o"]] = $t["s"];
     }
     foreach ($triples as $t) {
//.........这里部分代码省略.........
开发者ID:bridharr,项目名称:storyscope-lite,代码行数:101,代码来源:Graphite.php

示例7: getFilledTemplate

 function getFilledTemplate($t, $vals, $g = '')
 {
     $parser = ARC2::getTurtleParser();
     $parser->parse($g, $this->getTurtleHead() . $t);
     return $parser->getSimpleIndex(0, $vals);
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:6,代码来源:ARC2_Class.php

示例8: run

 public function run()
 {
     set_time_limit(0);
     error_reporting(E_ERROR);
     if (is_file(FILE)) {
         echo "There is an existing " . FILE . " file on this installation. Please remove it before importing a new one";
         exit(0);
     }
     if (!isset($_GET['import']) && !isset($_POST['importtext'])) {
         $this->showInterface();
         exit(0);
     }
     if (!is_writable('.')) {
         echo 'The webserver needs write permissions in "lodspeakr/" "lodspeakr/models/" and "lodspeakr/views/" dirs to import settings.';
         exit(0);
     }
     echo $this->external_basedir;
     include_once 'lib/arc2/ARC2.php';
     $parser = ARC2::getTurtleParser();
     if (isset($_GET['import'])) {
         $parser->parse($_GET['import']);
         $this->external_basedir = str_replace('export', '', $_GET['import']);
     } elseif (isset($_POST['importtext'])) {
         $parser->parse(RDF, $_POST['importtext']);
     } else {
         HTTPStatus::send500();
         exit(0);
     }
     $triples = $parser->getTriples();
     $appArr = $this->search($triples, null, RDF . 'type', LS . 'Application');
     if (!(sizeof($appArr) > 0)) {
         echo "I can't find an application from the URL given";
         exit(0);
     }
     $app = $appArr[0]['s'];
     $this->external_basedir = $app;
     $compArr = $this->search($triples, null, SKOS . 'broader', $app);
     $content = "<?\n\$conf['debug'] = false;\n\$conf['mirror_external_uris'] = true;\n\n";
     $this->basedir = preg_replace('/import$/', '', !empty($_SERVER['HTTPS']) ? "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
     //$arr = explode("lodspeakr/benegesserit", $this->basedir);
     //$this->basedir = $arr[0];
     $content .= "\$conf['basedir'] = \"{$this->basedir}\";\n";
     $content .= "\$conf['parentApp'] = \"{$app}\";\n";
     $pwd = getcwd();
     $content .= "\$conf['home'] = \"{$pwd}/\";\n";
     //App params
     $q = $this->search($triples, $app, LS . 'usedParameter', null);
     $appParams = array();
     foreach ($q as $p) {
         $param = $p['o'];
         $labelArr = $this->search($triples, $param, RDFS . 'label', null);
         $label = $labelArr[0]['o'];
         $format = $this->search($triples, $param, DC . 'hasFormat', null);
         $cntArr = $this->search($triples, $format[0]['o'], CNT . 'chars', null);
         $cnt = $cntArr[0]['o'];
         $appParams[$label] = $cnt;
     }
     foreach ($appParams as $k => $v) {
         $content .= "\$conf['{$k}'] = \"{$v}\";\n";
     }
     $content .= "/*ATTENTION: By default this application is available to\n * be exported and copied (its configuration)\n * by others. If you do not want that, \n * turn the next option as false\n */ \n\$conf['export'] = true;\n\n";
     //Components
     foreach ($compArr as $v) {
         $component = $v['s'];
         $componentTypeArr = $this->search($triples, $component, RDF . 'type', null);
         $compType = $componentTypeArr[0]['o'];
         $params = array();
         $q = $this->search($triples, $component, LS . 'usedParameter', null);
         foreach ($q as $p) {
             $param = $p['o'];
             $labelArr = $this->search($triples, $param, RDFS . 'label', null);
             $label = $labelArr[0]['o'];
             $format = $this->search($triples, $param, DC . 'hasFormat', null);
             $cntArr = $this->search($triples, $format[0]['o'], CNT . 'chars', null);
             $cnt = $cntArr[0]['o'];
             $params[$label] = $cnt;
         }
         $inputs = array();
         $q = $this->search($triples, $component, LS . 'usedInput', null);
         foreach ($q as $p) {
             $param = $p['o'];
             $labelArr = $this->search($triples, $param, RDFS . 'label', null);
             if (sizeof($labelArr) > 0) {
                 $label = $labelArr[0]['o'];
                 $format = $this->search($triples, $param, DC . 'hasFormat', null);
                 $cntArr = $this->search($triples, $format[0]['o'], CNT . 'chars', null);
                 $cnt = $cntArr[0]['o'];
                 $inputs[$label] = $cnt;
             }
         }
         if ($compType == LS . "LodspeakrEndpointManagerComponent") {
             $content .= $this->createEndpoints($params);
         } elseif ($compType == LS . "LodspeakrNamespaceManagerComponent") {
             $content .= $this->createNamespaces($params);
         } elseif ($compType == LS . "LodspeakrSparqlEndpointRetriever") {
             $this->createModels($inputs);
         } elseif ($compType == LS . "LodspeakrStaticElementsComponent") {
             $this->createStatics($inputs);
         } elseif ($compType == LS . "LodspeakrVisualComponent") {
             $this->createViews($inputs);
//.........这里部分代码省略.........
开发者ID:narock,项目名称:lodspeakr,代码行数:101,代码来源:Importer.php

示例9: cacheTriples

 /**
  * Store triples into our local store
  *
  * @param integer $id     The id of the configured semantic source
  * @param array   $config The configuration needed to extract the triples
  */
 public function cacheTriples($id, array $config)
 {
     // Fetch the ARC2 triplestore
     $store = $this->setUpArc2Store();
     // Fetch the data extractor for the given type
     $type = $config['type'];
     $source_type = strtolower($type);
     $graph = '';
     $caching_necessary = true;
     switch ($source_type) {
         case 'turtle':
             $rdf_reader = \App::make('\\Tdt\\Core\\DataControllers\\RDFController');
             $configuration = array('uri' => $config['uri'], 'format' => 'turtle');
             $data = $rdf_reader->readData($configuration, array());
             $graph = $data->data;
             break;
         case 'rdf':
             $rdf_reader = \App::make('\\Tdt\\Core\\DataControllers\\RDFController');
             $configuration = array('uri' => $config['uri'], 'format' => 'xml');
             $data = $rdf_reader->readData($configuration, array());
             $graph = $data->data;
             break;
         case 'sparql':
             // Do nothing, the sparql endpoint is already optimized for read operations
             $caching_necessary = false;
             break;
         case 'ldf':
             // Do nothing the ldf endpoint is a queryable endpoint itself
             $caching_necessary = false;
             break;
         default:
             \App::abort(400, "The source type, {$source_type}, was configured, but no reader has been found\n                    to extract semantic data from it.");
             break;
     }
     // If the semantic source needs caching in our local store@
     if ($caching_necessary) {
         // Make the graph name to cache the triples into
         $graph_name = self::$graph_name . $id;
         // Serialise the triples into a turtle string
         $ttl = $graph->serialise('turtle');
         // Parse the turtle into an ARC graph
         $arc_parser = \ARC2::getTurtleParser();
         $ser = \ARC2::getNTriplesSerializer();
         // Parse the turtle string
         $arc_parser->parse('', $ttl);
         // Serialize the triples again, this is because an EasyRdf_Graph has
         // troubles with serializing some unicode characters. The underlying bytes are
         // not properly converted to utf8
         // A dump shows that all unicode encodings through serialization are the same (in easyrdf and arc)
         // however when we convert the string (binary) into a utf8, only the arc2 serialization
         // comes out correctly, hence something beneath the encoding (byte sequences?) must hold some wrongs in the EasyRdf library.
         $triples = $ser->getSerializedTriples($arc_parser->getTriples());
         preg_match_all("/(<.*\\.)/", $triples, $matches);
         $triples_buffer = array();
         if ($matches[0]) {
             $triples_buffer = $matches[0];
         }
         \Log::info("--------------- CACHING TRIPLES -------------------------");
         \Log::info("Starting insertion of triples into the ARC2 RDF Store into the graph with the name " . $graph_name);
         // Insert the triples in a chunked manner (not all triples at once)
         $buffer_size = 20;
         while (count($triples_buffer) >= $buffer_size) {
             $triples_to_cache = array_slice($triples_buffer, 0, $buffer_size);
             \Log::info("Caching " . count($triples_to_cache) . " triples into the store.");
             $this->addTriples($graph_name, $triples_to_cache, $store);
             $triples_buffer = array_slice($triples_buffer, $buffer_size);
         }
         // Insert the last triples in the buffer
         \Log::info("Caching " . count($triples_buffer) . " triples into the store.");
         $this->addTriples($graph_name, $triples_buffer, $store);
         \Log::info("--------------- DONE CACHING TRIPLES -------------------");
     }
 }
开发者ID:tdt,项目名称:triples,代码行数:79,代码来源:TripleRepository.php

示例10: curl_init

 //this is a workaround while its being fixed in ARC2
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $u);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: text/turtle, text/n3; q=0.9, application/turtle; q=0.8, application/n-triples; q=0.7, application/rdf+xml; q=0.6, application/json; q=0.4, */*; q=0.1"));
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $data = curl_exec($ch);
 $_aux = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
 $_aux2 = explode(";", $_aux);
 $content_type = array_shift($_aux2);
 curl_close($ch);
 $parser = NULL;
 $parsers = array();
 $parsers[0]['formats'] = array('text/n3', 'application/x-turtle', 'application/turtle', 'text/turtle');
 $parsers[0]['parser'] = ARC2::getTurtleParser();
 $parsers[1]['formats'] = array('application/rdf+xml');
 $parsers[1]['parser'] = ARC2::getRDFXMLParser();
 $parsers[2]['formats'] = array('application/json', 'application/x-javascript', 'text/javascript', 'text/x-javascript', 'text/x-json');
 $parsers[2]['parser'] = ARC2::getJSONParser();
 foreach ($parsers as $v) {
     if (in_array($content_type, $v['formats'])) {
         $parser = $v['parser'];
     }
 }
 //If nothing fits, pray to your favorite god that this can be detected and parsed correctly by ARC2.
 $parser = ARC2::getRDFParser();
 //end of workaround
 $parser->parse($u, $data);
 //Since IDK which namespace the documents contains, lets use the uri requested
 $triples = $parser->getTriples();
开发者ID:sahilshekhawat,项目名称:owlviz,代码行数:31,代码来源:rdf2json.php

示例11: addTurtle

 /**
  * Take a base URI and a string of turtle RDF and load the new triples into the graph. Return the number of triples loaded.
  */
 function addTurtle($base, $data)
 {
     $parser = ARC2::getTurtleParser($this->arc2config);
     $parser->parse($base, $data);
     $errors = $parser->getErrors();
     $parser->resetErrors();
     if (sizeof($errors)) {
         if ($this->debug) {
             print "<h3>Error loading turtle string</h3>";
             print "<ul><li>" . join("</li><li>", $errors) . "</li></ul>";
         }
         return 0;
     }
     return $this->addTriples($parser->getTriples());
 }
开发者ID:rebe100x,项目名称:YAKREP,代码行数:18,代码来源:Graphite.php

示例12: readScaffold

 protected function readScaffold($scaffold, $serviceArgs)
 {
     global $conf;
     require_once $conf['home'] . 'lib/arc2/ARC2.php';
     $parser = ARC2::getTurtleParser();
     $parser->parse($scaffold);
     $triples = $parser->getTriples();
     $aux = Utils::filterTriples($triples, array(null, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://lodspeakr.org/vocab/ScaffoldedService"));
     $scaffoldUri = $aux[0][0];
     $aux = Utils::filterTriples($triples, array($scaffoldUri, "http://lodspeakr.org/vocab/scaffold", null));
     foreach ($aux as $r) {
         $patterns = Utils::filterTriples($triples, array($r[2], "http://lodspeakr.org/vocab/uriPattern", null));
         $pattern = stripcslashes($patterns[0][2]);
         if (preg_match("|{$pattern}|", $serviceArgs) > 0) {
             //        echo "match ! \n ".$pattern."\n";
             $patternDir = Utils::filterTriples($triples, array($r[2], "http://lodspeakr.org/vocab/subComponent", null));
             return $patternDir[0][2];
         }
     }
     //        exit(0);
     return "";
 }
开发者ID:narock,项目名称:lodspeakr,代码行数:22,代码来源:serviceModule.php

示例13: add_turtle

 /**
  * Add the triples parsed from the supplied Turtle to the graph
  * @see http://www.dajobe.org/2004/01/turtle/
  * @param string $turtle the Turtle to parse
  * @param string $base the base URI against which relative URIs in the Turtle document will be resolved
  */
 public function add_turtle($turtle, $base = '')
 {
     if ($turtle) {
         /** @var \ARC2_TurtleParser $parser */
         $parser = \ARC2::getTurtleParser();
         $parser->parse($base, $turtle);
         $triples = $parser->getTriples();
         $this->_add_arc2_triple_list($triples);
         unset($parser);
     }
 }
开发者ID:talis,项目名称:tripod-php,代码行数:17,代码来源:ExtendedGraph.class.php

示例14: microtime

    $time_start = microtime(true);
    //	$uri = $service . "?input-type=text&nif=true&prefix=" . urlencode ( $prefix ) . "&urirecipe=$urirecipe&input=" . urlencode ( $_REQUEST ['text'] );
    $uri = $service . "?f=text&prefix=" . urlencode($prefix) . "&input=" . urlencode($_REQUEST['text']);
    // case opennlp was chosen we need add &modelFolder=model in order to se the defauld model folder
    if (strstr($uri, "opennlp")) {
        $uri = $uri . "&modelFolder=model";
    }
    if (strstr($uri, "spotlight")) {
        $uri = $uri . "&confidence=" . $_REQUEST['confidence'];
    }
    $data = file_get_contents($uri);
    $time_end = microtime(true);
    $time_service_needed = round($time_end - $time_start, 2);
    // parsing
    $time_start = microtime(true);
    $parser = ARC2::getTurtleParser();
    $parser->parse($prefix, $data);
    $triples = $parser->getTriples();
    $alltriples = array_merge($alltriples, $triples);
    $time_end = microtime(true);
    $time_arc2_needed = round($time_end - $time_start, 2);
    $meta .= "\n\t<p>Sevice was {$service}:</p>\n\t<ul class=\"checks\">\n\t  <li>NLP component needed: {$time_service_needed} seconds.</li>\n\t  <li>ARC2 RDF Parser overhead: {$time_arc2_needed} seconds.</li>\n\t  <li><a href=\"{$uri}\" >request url</a> </li>\n\t  <li>Text size: " . strlen($_REQUEST['text']) . "</li>\n\t  <li>Triples: " . count($triples) . "</li>\n\t</ul>";
}
$ns = array('p' => trim($prefix), 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'owl' => 'http://www.w3.org/2002/07/owl#', 'sso' => 'http://nlp2rdf.lod2.eu/schema/sso/', 'str' => 'http://nlp2rdf.lod2.eu/schema/string/', 'topic' => 'http://nlp2rdf.lod2.eu/schema/topic/', 'error' => 'http://nlp2rdf.lod2.eu/schema/error/', 'olia' => 'http://purl.org/olia/olia.owl#', 'olia-top' => 'http://purl.org/olia/olia-top.owl#', 'olia_system' => 'http://purl.org/olia/system.owl#', 'penn' => 'http://purl.org/olia/penn.owl#', 'penn-syntax' => 'http://purl.org/olia/penn-syntax.owl#', 'stanford' => 'http://purl.org/olia/stanford.owl#', 'brown' => 'http://purl.org/olia/brown.owl#', 'dbo' => 'http://dbpedia.org/ontology/', 'dbpedia' => 'http://dbpedia.org/resource/', 'nerd' => 'http://nerd.eurecom.fr/ontology#', 'scms' => 'http://ns.aksw.org/scms/', 'spotlight' => 'http://dbpedia.org/spotlight/', 'nif' => "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#", 'rlog' => "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/rlog#", 'dc' => "http://purl.org/dc/elements/1.1/", 'stanford' => "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/vm/dep/stanford#", 'itsrdf' => "http://www.w3.org/2005/11/its/rdf#");
if ($format == "turtle") {
    $ser = ARC2::getTurtleSerializer(array('ns' => $ns));
    $output = $ser->getSerializedTriples($alltriples);
    header("Content-Type: text/turtle");
    echo $output;
} else {
    if ($format == "rdfxml") {
开发者ID:dougj0220,项目名称:software,代码行数:31,代码来源:demo.php

示例15: turtle2xml

function turtle2xml($file)
{
    //Andrea Mazzocchi
    //Includo le librerie necessarie per gestire Turtle
    include_once "semsol-arc2-c7c03da/ARC2.php";
    //Instanziazione del parser...
    $parser = ARC2::getTurtleParser();
    $parser->parse($file);
    //...parsing delle triple
    $triples = $parser->getSimpleIndex();
    //Inizializzo nuovo documento DOM (con versione, codifica e DTD)
    $doc = new DOMDocument("1.0", "UTF-8");
    $imple = new DOMImplementation();
    $dtd = $imple->createDocumentType('locations', '', 'http://vitali.web.cs.unibo.it/twiki/pub/TechWeb12/DTDs/locations.dtd');
    $doc = $imple->createDocument('', '', $dtd);
    $doc->formatOutput = true;
    //Inializzo il nodo radice "locations"
    $root = $doc->appendChild($doc->createElement("locations"));
    //Prelevo le chiavi dell'array associativo
    $index = array_keys($triples);
    //Eseguo un ciclo su quante sono le chiavi
    for ($i = 0; $i < count($index); $i++) {
        //Separo l'URL secondo gli "/"
        $temp = explode("/", $index[$i]);
        $a = count($temp) - 1;
        $id = $temp[$a];
        //Codice per il riempimento del tag "metadata"
        if (stristr($id, '.ttl') == true) {
            //"metadata" viene riconosciuto con ".ttl" al termine del prefix "this"
            $root2 = $root->appendChild($doc->createElement("metadata"));
            $temp1 = $index[$i];
            //Secondo le direttive del DTD, un database XML non ha il tag
            //"description" ("version" dell'XML corrisponde a "description"
            //del Turtle), quindi sostituisco "description" (dal Turtle)
            //in "version" (per XML)
            foreach ($triples[$temp1] as $deep1 => $deep2) {
                if (stristr($temp1, "description") == true) {
                    $temp1 = "version";
                } else {
                    $b = explode("/", $deep1);
                }
                //Costruisco i "metadata" nel DOM
                $root30 = $root2->appendChild($doc->createElement($b[count($b) - 1]));
                $root30->appendChild($doc->createTextNode($deep2[0]));
            }
        } else {
            $root3 = $root->appendChild($doc->createElement("location"));
            $id = $temp[$a];
            //"id" deve essere attributo di "location"
            $root3->setAttribute("id", $id);
            $temp2 = $index[$i];
            //Costruisco le varie "location"
            foreach ($triples[$temp2] as $key => $value) {
                if (stristr($key, "fn") == true) {
                    $key = "name";
                }
                if (stristr($key, "extended-address") == true) {
                    $key = "address";
                }
                //anche "latitude" e "longitude" devono essere attributi di "location"
                if (stristr($key, "latitude") == true) {
                    $root3->setAttribute("lat", $value[0]);
                    unset($value);
                }
                if (stristr($key, "longitude") == true) {
                    $root3->setAttribute("long", $value[0]);
                    unset($value);
                }
                if (stristr($key, "opening") == true or stristr($key, "closing") == true) {
                    $b = explode("/", $key);
                } else {
                    $b = explode("ns#", $key);
                }
                foreach ($value as $deep1 => $deep2) {
                    $root30 = $root3->appendChild($doc->createElement($b[count($b) - 1]));
                    $root30->appendChild($doc->createTextNode($deep2));
                }
            }
        }
    }
    //Salvo il documento DOM in XML
    echo $doc->saveXML();
}
开发者ID:raelix,项目名称:TechWeb-Unibo,代码行数:83,代码来源:CONVERSIONI_NEW.php


注:本文中的ARC2::getTurtleParser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。