Ejemplo n.º 1
0
 /**
  * Set all required type mappers
  *
  * @return void
  */
 public static function setTypeMappers()
 {
     EasyRdf_Namespace::set('spl', 'http://spinrdf.org/spl#');
     EasyRdf_Namespace::set('spin', 'http://spinrdf.org/spin#');
     EasyRdf_Namespace::set('sp', 'http://spinrdf.org/sp#');
     // Query
     EasyRdf_TypeMapper::set('sp:Ask', 'EasySpinRdf_Query_Ask');
     EasyRdf_TypeMapper::set('sp:Select', 'EasySpinRdf_Query_Select');
     EasyRdf_TypeMapper::set('sp:Describe', 'EasySpinRdf_Query_Describe');
     EasyRdf_TypeMapper::set('sp:Construct', 'EasySpinRdf_Query_Construct');
     // Elements
     EasyRdf_TypeMapper::set('sp:TriplePattern', 'EasySpinRdf_Element_TriplePattern');
     EasyRdf_TypeMapper::set('sp:SubQuery', 'EasySpinRdf_Element_SubQuery');
     EasyRdf_TypeMapper::set('sp:NamedGraph', 'EasySpinRdf_Element_NamedGraph');
     EasyRdf_TypeMapper::set('sp:Optional', 'EasySpinRdf_Element_Optional');
     EasyRdf_TypeMapper::set('sp:Union', 'EasySpinRdf_Element_Union');
     EasyRdf_TypeMapper::set('sp:Bind', 'EasySpinRdf_Element_Bind');
     EasyRdf_TypeMapper::set('sp:Filter', 'EasySpinRdf_Element_Filter');
     EasyRdf_TypeMapper::set('sp:TriplePath', 'EasySpinRdf_Element_TriplePath');
 }
Ejemplo n.º 2
0
<?php

require_once 'BBC/Programmes/Base.php';
class BBC_Programmes_Version extends BBC_Programmes_Base
{
    public function broadcasts()
    {
        return self::getGraph()->resourcesMatching('po:broadcast_of', $this);
    }
}
EasyRdf_TypeMapper::set('po:Version', 'BBC_Programmes_Version');
    function age()
    {
        $birth = $this->birthEvent();
        if ($birth) {
            $year = substr($birth->get('bio:date'), 0, 4);
            if ($year) {
                return date('Y') - $year;
            }
        }
        return 'unknown';
    }
}
## Add namespaces
EasyRdf_Namespace::set('mo', 'http://purl.org/ontology/mo/');
EasyRdf_Namespace::set('bio', 'http://purl.org/vocab/bio/0.1/');
EasyRdf_TypeMapper::set('mo:MusicArtist', 'Model_MusicArtist');
?>
<html>
<head><title>EasyRdf Artist Info Example</title></head>
<body>
<h1>EasyRdf Artist Info Example</h1>

<?php 
echo form_tag();
echo text_field_tag('uri', 'http://www.bbc.co.uk/music/artists/70248960-cb53-4ea4-943a-edb18f7d336f.rdf', array('size' => 50));
echo submit_tag();
echo form_end_tag();
?>

<?php 
if (isset($_REQUEST['uri'])) {
Ejemplo n.º 4
0
        }
        if (!is_string($class) or $class == null or $class == '') {
            throw new InvalidArgumentException("\$class should be a string and cannot be null or empty");
        }
        $type = EasyRdf_Namespace::expand($type);
        return self::$map[$type] = $class;
    }
    /**
     * Delete an existing RDF type mapping.
     *
     * @param  string  $type   The RDF type (e.g. foaf:Person)
     */
    public static function delete($type)
    {
        if (!is_string($type) or $type == null or $type == '') {
            throw new InvalidArgumentException("\$type should be a string and cannot be null or empty");
        }
        $type = EasyRdf_Namespace::expand($type);
        if (isset(self::$map[$type])) {
            unset(self::$map[$type]);
        }
    }
}
/*
   Register default set of mapped types
*/
EasyRdf_TypeMapper::set('rdf:Alt', 'EasyRdf_Container');
EasyRdf_TypeMapper::set('rdf:Bag', 'EasyRdf_Container');
EasyRdf_TypeMapper::set('rdf:List', 'EasyRdf_Collection');
EasyRdf_TypeMapper::set('rdf:Seq', 'EasyRdf_Container');
Ejemplo n.º 5
0
                $key = $property->shorten();
                if ($key) {
                    $properties[$key] = $property;
                }
            }
        }
        return $properties;
    }
    /**
     * Get the cardinality of a property.
     *
     * @return string '1' if the property takes a single value, otherwise 'N'.
     */
    public function cardinality()
    {
        $types = $this->types();
        # Apart from owl_FunctionalProperty, these rules really correct,
        # but they provide a good set of defaults
        if (in_array('owl:FunctionalProperty', $types) or in_array('owl:DatatypeProperty', $types) or in_array('owl:InverseFunctionalProperty', $types)) {
            return '1';
        } else {
            return 'N';
        }
    }
}
## FIXME: Don't Repeat Yourself
EasyRdf_TypeMapper::set('rdf:Property', 'EasyRdf_Owl_Property');
EasyRdf_TypeMapper::set('owl:Property', 'EasyRdf_Owl_Property');
EasyRdf_TypeMapper::set('owl:ObjectProperty', 'EasyRdf_Owl_Property');
EasyRdf_TypeMapper::set('owl:DatatypeProperty', 'EasyRdf_Owl_Property');
 public function testInstantiate()
 {
     EasyRdf_TypeMapper::set('foaf:Person', 'MyType_Class');
     $data = readFixture('foaf.json');
     $graph = new EasyRdf_Graph('http://www.example.com/joe/foaf.rdf', $data, 'json');
     $joe = $graph->resource('http://www.example.com/joe#me');
     $this->assertClass('MyType_Class', $joe);
     $this->assertTrue($joe->myMethod());
 }
Ejemplo n.º 7
0
<?php

require_once 'BBC/Programmes/Base.php';
class BBC_Programmes_Service extends BBC_Programmes_Base
{
}
EasyRdf_TypeMapper::set('po:Service', 'BBC_Programmes_Service');
Ejemplo n.º 8
0
<?php

require_once 'BBC/Programmes/Programme.php';
class BBC_Programmes_Series extends BBC_Programmes_Programme
{
}
EasyRdf_TypeMapper::set('po:Series', 'BBC_Programmes_Series');
Ejemplo n.º 9
0
EasyRdf_TypeMapper::set('sp:Count', 'EasySpinRdf_Expression_Aggregation_Count');
EasyRdf_TypeMapper::set('sp:Max', 'EasySpinRdf_Expression_Aggregation_Max');
EasyRdf_TypeMapper::set('sp:Min', 'EasySpinRdf_Expression_Aggregation_Min');
EasyRdf_TypeMapper::set('sp:Sum', 'EasySpinRdf_Expression_Aggregation_Sum');
EasyRdf_TypeMapper::set('sp:Asc', 'EasySpinRdf_Expression_Aggregation_Asc');
EasyRdf_TypeMapper::set('sp:Desc', 'EasySpinRdf_Expression_Aggregation_Desc');
// Mathematical
EasyRdf_TypeMapper::set('sp:mul', 'EasySpinRdf_Expression_Mathematical_Multiply');
EasyRdf_TypeMapper::set('sp:add', 'EasySpinRdf_Expression_Mathematical_Add');
EasyRdf_TypeMapper::set('sp:sub', 'EasySpinRdf_Expression_Mathematical_Substract');
EasyRdf_TypeMapper::set('sp:divide', 'EasySpinRdf_Expression_Mathematical_Divide');
// Path
EasyRdf_TypeMapper::set('sp:SeqPath', 'EasySpinRdf_Expression_Path_SeqPath');
EasyRdf_TypeMapper::set('sp:AltPath', 'EasySpinRdf_Expression_Path_AltPath');
EasyRdf_TypeMapper::set('sp:ModPath', 'EasySpinRdf_Expression_Path_ModPath');
EasyRdf_TypeMapper::set('sp:ReversePath', 'EasySpinRdf_Expression_Path_ReversePath');
/**
 * Abstract class that represents an SPIN resource
 *
 * @package    EasySpinRdf
 * @copyright  Conjecto - Blaise de Carné
 * @license    http://www.opensource.org/licenses/bsd-license.php
 */
abstract class EasySpinRdf_Resource extends EasyRdf_Resource
{
    /**
     * Get the SPARQL representation of the resource
     * @return string
     */
    public abstract function getSparql();
    /**
Ejemplo n.º 10
0
<?php

require_once 'BBC/Programmes/Programme.php';
class BBC_Programmes_Clip extends BBC_Programmes_Programme
{
}
EasyRdf_TypeMapper::set('po:Clip', 'BBC_Programmes_Clip');
Ejemplo n.º 11
0
        return $html;
    }
}
# Extra namespaces we use
EasyRdf_Namespace::set('vann', 'http://purl.org/vocab/vann/');
EasyRdf_Namespace::set('vs', 'http://www.w3.org/2003/06/sw-vocab-status/ns#');
## Add mappings
EasyRdf_TypeMapper::set('owl:Ontology', 'Phpspecgen_Vocab');
EasyRdf_TypeMapper::set('owl:Class', 'Phpspecgen_Class');
EasyRdf_TypeMapper::set('rdfs:Class', 'Phpspecgen_Class');
EasyRdf_TypeMapper::set('owl:Property', 'Phpspecgen_Property');
EasyRdf_TypeMapper::set('owl:DatatypeProperty', 'Phpspecgen_Property');
EasyRdf_TypeMapper::set('owl:ObjectProperty', 'Phpspecgen_Property');
EasyRdf_TypeMapper::set('owl:InverseFunctionalProperty', 'Phpspecgen_Property');
EasyRdf_TypeMapper::set('owl:FunctionalProperty', 'Phpspecgen_Property');
EasyRdf_TypeMapper::set('rdf:Property', 'Phpspecgen_Property');
?>
<html>
<head>
  <title>phpspecgen</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>

<?php 
$options = getopt('u:');
if (!empty($_REQUEST['uri'])) {
    $uri = $_REQUEST['uri'];
} elseif (array_key_exists('u', $options)) {
    $uri = $options['u'];
}
Ejemplo n.º 12
0
    {
        return str_replace('_', '/', $this->className()) . '.php';
    }
    /**
     * Get an array of properties for a class
     *
     * If no properties are found for the class, an empty array is returned.
     *
     * @return array An array of EasyRdf_Property associated with the class
     */
    function classProperties($graph)
    {
        // FIXME: not ideal having to pass graph in here
        $properties = array();
        # FIXME: cache this somehow?
        $owlThing = $graph->get('http://www.w3.org/2002/07/owl#Thing');
        $superClass = $this->get('rdfs_subClassOf');
        if ($superClass == $owlThing) {
            $superClass = '';
        }
        $allProperties = EasyRdf_Owl_Property::findAll($graph);
        foreach ($allProperties as $name => $property) {
            if ($superClass == '' and (count($property->all('rdfs:domain')) == 0 or in_array($owlThing, $property->all('rdfs:domain'))) or in_array($this, $property->all('rdfs:domain'))) {
                array_push($properties, $property);
            }
        }
        return $properties;
    }
}
EasyRdf_TypeMapper::set('owl:Class', 'EasyRdf_Owl_Class');
Ejemplo n.º 13
0
<?php

require_once 'BBC/Programmes/Programme.php';
class BBC_Programmes_Episode extends BBC_Programmes_Programme
{
    public function broadcasts()
    {
        $broadcasts = array();
        foreach ($this->all('po:version') as $version) {
            $broadcasts = array_merge(self::getGraph()->resourcesMatching('po:broadcast_of', $version), $broadcasts);
        }
        return $broadcasts;
    }
}
EasyRdf_TypeMapper::set('po:Episode', 'BBC_Programmes_Episode');
Ejemplo n.º 14
0
<?php

require_once 'BBC/Programmes/Base.php';
class BBC_Programmes_Broadcast extends BBC_Programmes_Base
{
}
EasyRdf_TypeMapper::set('po:FirstBroadcast', 'BBC_Programmes_Broadcast');
EasyRdf_TypeMapper::set('po:RepeatBroadcast', 'BBC_Programmes_Broadcast');
Ejemplo n.º 15
0
<?php

require_once 'BBC/Programmes/Programme.php';
class BBC_Programmes_Brand extends BBC_Programmes_Programme
{
}
EasyRdf_TypeMapper::set('po:Brand', 'BBC_Programmes_Brand');