def uuid_subject(namespace=None): """ This function generates a unique subject in the provided `namespace` based on the :func:`uuid.uuid4()` method, If `namespace` is not specified than the default `SURF` namespace is used .. code-block:: python >>> from surf import namespace as ns >>> print uuid_subject(ns.SIOC) http://rdfs.org/sioc/ns#1b6ca1d5-41ed-4768-b86a-42185169faff :param namespace: the given namespace :type namespace: None or :class:`rdflib.namespace.Namespace` or str or unicode :return: the *RDF* subject identifier in the specified namespace :rtype: :class:`rdflib.term.URIRef` """ if not namespace: namespace = get_fallback_namespace() if not isinstance(namespace, Namespace): namespace = Namespace(namespace) return namespace[str(uuid4())]
def test_register(): ns.register(test='http://sometest.ns/ns#') assert ns.TEST == Namespace('http://sometest.ns/ns#')
def test_get_prefix(): name = ns.get_prefix(Namespace('http://sometest.ns/ns#')) assert name == 'TEST' name1 = ns.get_prefix('http://sometest1.ns/ns#') assert name1 == 'NS1'
def test_get_namespace_url(): url = ns.get_namespace_url('TEST') assert url == Namespace('http://sometest.ns/ns#') url1 = ns.get_namespace_url('NS1') assert url1 == Namespace('http://sometest1.ns/ns#')
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # -*- coding: utf-8 -*- __author__ = ['Cosmin Basca', 'Peteris Caune'] from copy import deepcopy import sys from surf.rdf import ClosedNamespace, Namespace, RDF, RDFS __anonymous = 'NS' __anonymous_count = 0 ANNOTATION = Namespace('http://www.w3.org/2000/10/annotation-ns#') ANNOTEA = Namespace('http://www.w3.org/2002/01/bookmark#') ATOM = Namespace('http://atomowl.org/ontologies/atomrdf#') BIBO = Namespace('http://purl.org/ontology/bibo/') BIBO_DEGREES = Namespace('http://purl.org/ontology/bibo/degrees/') BIBO_EVENTS = Namespace('http://purl.org/ontology/bibo/events/') BIBO_ROLES = Namespace('http://purl.org/ontology/bibo/roles/') BIBO_STATUS = Namespace('http://purl.org/ontology/bibo/status/') CALENDAR = Namespace('http://www.w3.org/2002/12/cal/icaltzd#') CONTACT = Namespace('http://www.w3.org/2000/10/swap/pim/contact#') CORRIB_TAX = Namespace('http://jonto.corrib.org/taxonomies#') DBLP = Namespace('http://www4.wiwiss.fu-berlin.de/dblp/terms.rdf#') DBPEDIA = Namespace('http://dbpedia.org/property/') DC = Namespace('http://purl.org/dc/elements/1.1/') DCTERMS = Namespace('http://purl.org/dc/terms/') DOAP = Namespace('http://usefulinc.com/ns/doap#')
def test_01_register(self): ns.register(test='http://sometest.ns/ns#') self.assertEqual(ns.TEST, Namespace('http://sometest.ns/ns#'))
def test_04_get_prefix(self): name = ns.get_prefix(Namespace('http://sometest.ns/ns#')) self.assertEqual(name, 'TEST') name1 = ns.get_prefix('http://sometest1.ns/ns#') self.assertEqual(name1, 'NS1')
def test_03_get_namespace_url(self): url = ns.get_namespace_url('TEST') self.assertEqual(url, Namespace('http://sometest.ns/ns#')) url1 = ns.get_namespace_url('NS1') self.assertEqual(url1, Namespace('http://sometest1.ns/ns#'))