source: Dev/branches/rest-dojo-ui/jos-branch/server/rdfapi/model/Resource.php @ 312

Last change on this file since 312 was 312, checked in by jkraaijeveld, 13 years ago
File size: 3.2 KB
Line 
1<?php
2require_once RDFAPI_INCLUDE_DIR . 'model/Node.php';
3
4// ----------------------------------------------------------------------------------
5// Class: Resource
6// ----------------------------------------------------------------------------------
7
8/**
9 * An RDF resource.
10 * Every RDF resource must have a URIref.
11 * URIrefs are treated as logical constants, i.e. as names which denote something
12 * (the things are called 'resources', but no assumptions are made about the nature of resources.)
13 * Many RDF resources are pieces of vocabulary. They typically have a namespace
14 * and a local name. In this case, a URI is composed as a
15 * concatenation of the namespace and the local name.
16 *
17 *
18 * @version  $Id: Resource.php 453 2007-06-20 21:19:09Z cweiske $
19 * @author Chris Bizer <chris@bizer.de>
20 *
21 * @package model
22 * @access      public
23 *
24 */
25 class Resource extends Node {
26
27        /**
28        * URIref to the resource
29        * @var          string
30        * @access       private
31        */
32    var $uri;
33
34
35   /**
36    * Constructor
37        * Takes an URI or a namespace/localname combination
38    *
39    * @param    string  $namespace_or_uri
40        * @param string $localName
41        * @access       public
42    */
43    function Resource($namespace_or_uri , $localName = NULL) {
44                if ($localName == NULL) {
45                        $this->uri = $namespace_or_uri;
46                } else {
47                        $this->uri = $namespace_or_uri . $localName;
48            }
49        }
50
51
52  /**
53   * Returns the URI of the resource.
54   * @return string
55   * @access    public
56   */
57  function getURI() {
58                        return $this->uri;
59   }
60
61        /**
62         * Returns the label of the resource, which is the URI of the resource.
63     * @access  public
64         * @return string
65         */
66    function getLabel() {
67        return $this->getURI();
68    }
69
70  /**
71   * Returns the namespace of the resource. May return null.
72   * @access    public
73   * @return string
74   */
75  function getNamespace() {
76        // Import Package Utility
77        include_once(RDFAPI_INCLUDE_DIR.PACKAGE_UTILITY);
78        $rdfUtil = new RDFUtil();
79        return $rdfUtil->guessNamespace($this->uri);
80  }
81
82  /**
83   * Returns the local name of the resource.
84   * @access    public
85   * @return string
86   */
87    function getLocalName() {
88        // Import Package Utility
89                include_once(RDFAPI_INCLUDE_DIR.PACKAGE_UTILITY);
90               
91                $rdfUtil = new RDFUtil();               
92            return $rdfUtil->guessName($this->uri);
93        }
94
95  /**
96   * Dumps resource.
97   * @access    public
98   * @return string
99   */
100  function toString() {
101        return 'Resource("' . $this->uri .'")';
102  }
103
104  /**
105   * Checks if the resource equals another resource.
106   * Two resources are equal, if they have the same URI
107   *
108   * @access    public
109   * @param             object  resource $that
110   * @return    boolean
111   */
112   function equals ($that) {
113
114            if ($this == $that) {
115              return true;
116            }
117
118            if (($that == NULL) or !(is_a($that, 'Resource')) or (is_a($that, 'BlankNode'))) {
119              return false;
120            }
121
122                if ($this->getURI() == $that->getURI()) {
123              return true;
124            }
125
126            return false;
127        }
128
129
130
131
132    /**
133    *   Doing string magic in PHP5
134    *   @return string String representation of this Resource
135    */
136    function __toString()
137    {
138        return $this->toString();
139    }
140
141}
142
143?>
Note: See TracBrowser for help on using the repository browser.